FTP
FTP (File Transfer Protocol) is a standard network protocol used to transfer files between a client and a server over a TCP/IP network (such as the Internet). It was developed in 1971 and remains widely used for uploading, downloading, and managing files on remote servers.
Key Features of FTP
Uses TCP ports 20 (data transfer) and 21 (command control)
Supports authentication (username/password) but can also allow anonymous access
Operates in two modes:
Active Mode (server initiates data connection)
Passive Mode (client initiates data connection, better for firewalls)
Transfers files in binary or ASCII mode
Allows file upload, download, rename, delete, and directory listing
How FTP Works
FTP uses two separate connections:
Control Connection (Port 21)
Used for sending commands (e.g.,
USER,PASS,LIST,RETR,STOR)Maintained throughout the session
Data Connection (Port 20 in Active Mode, random port in Passive Mode)
Used for actual file transfers
Opened and closed per transfer
FTP Communication Example
Client connects to server on port 21 (control connection)
Client authenticates (username/password)
Client sends commands (e.g.,
LISTto list files,RETRto download)Server responds and establishes a data connection (active/passive)
File transfer occurs
Data connection closes, but control connection stays open
FTP Commands & Responses
Common FTP Commands
USER
Specifies the username
PASS
Specifies the password
LIST
Lists files in current directory
RETR
Downloads a file (RETR filename.txt)
STOR
Uploads a file (STOR filename.txt)
DELE
Deletes a file
CWD
Changes working directory
PWD
Prints current directory
QUIT
Closes the FTP session
Common FTP Responses
200
Command OK
230
Login successful
331
Username OK, password required
425
Can't open data connection
550
File not found / Permission denied
FTP Modes: Active vs. Passive
1. Active Mode (Default)
Client connects to server on port 21 (control)
Server connects back to client on port 20 (data)
Problem: May fail if client has a firewall blocking incoming connections
2. Passive Mode (Recommended for modern networks)
Client connects to server on port 21 (control)
Server provides a random port for data transfer
Client connects to that port for file transfer
Better for firewalls/NAT (avoids blocking issues)
FTP Example (Manual Connection via Command Line)
Setting Up vsFTPd on Ubuntu (Secure FTP Server)
This guide covers installing and configuring vsFTPd (Very Secure FTP Daemon) on Ubuntu 22.04/20.04 with security best practices.
Step 1: Install vsFTPd
Update packages and install vsftpd:
Check if the service is running:
(Expected output: active (running))
Step 2: Configure vsFTPd
Edit the config file:
Basic Secure Configuration
Optional: Enable SSL/TLS (FTPS)
Generate SSL certificates:
Then add to vsftpd.conf:
Step 3: Restart vsFTPd
Apply changes:
Step 4: Configure Firewall (UFW)
Allow FTP & passive ports:
Step 5: Create FTP User
Option 1: Use Existing System User
Option 2: Create a New FTP-Only User
Step 6: Test FTP Connection
From Linux Terminal
(Login with your FTP user credentials.)
Using FileZilla (GUI)
Host:
your_server_ipUsername:
ftpuserPassword:
your_passwordPort:
21Encryption: "Require explicit FTP over TLS" (if SSL enabled)
Step 7: Troubleshooting
Check Logs
Common Issues
"500 OOPS: vsftpd: refusing to run with writable root inside chroot" Fix:
allow_writeable_chroot=YESin config."Connection refused" Check firewall (
sudo ufw status).SSL Errors Ensure correct cert paths in
vsftpd.conf.
vsFTPd server config:
The vsFTPd (Very Secure FTP Daemon) server is a popular FTP server for Linux, known for its security, performance, and stability. Below is an explanation of its key configurations, typically found in /etc/vsftpd.conf or /etc/vsftpd/vsftpd.conf.
Basic vsFTPd Configurations
1. Server Access & Network Settings
listen=YESRuns vsFTPd in standalone mode (not via inetd/xinetd).
listen_ipv6=YESEnables IPv6 support (use either IPv4 or IPv6, not both).
listen_address=192.168.1.100Binds vsFTPd to a specific IP.
port_enable=YESAllows active mode FTP (default port: 20 for data, 21 for control).
2. Anonymous FTP Settings
anonymous_enable=YESAllows anonymous logins (username:
anonymousorftp).
anon_root=/var/ftpSets the root directory for anonymous users.
no_anon_password=YESAnonymous users don't need a password.
anon_upload_enable=YESAllows anonymous uploads (requires write permissions).
anon_mkdir_write_enable=YESAllows anonymous users to create directories.
anon_other_write_enable=YESAllows deletion/renaming by anonymous users (risky!).
3. Local User Settings
local_enable=YESAllows system users to log in via FTP.
local_root=/home/$USER/ftpSets a custom FTP root directory for local users.
userlist_enable=YESEnables user-based access control.
userlist_file=/etc/vsftpd.user_listSpecifies the user list file (whitelist/blacklist).
userlist_deny=YES(default)If
YES, listed users are denied access (blacklist).If
NO, only listed users are allowed (whitelist).
4. Security & Permissions
chroot_local_user=YESRestricts local users to their home directories (jail).
allow_writeable_chroot=YESAllows write access in chroot (use carefully).
write_enable=YESEnables file uploads and modifications.
hide_ids=YESShows all files as owned by
ftp:ftpfor anonymity.
tcp_wrappers=YESUses
/etc/hosts.allowand/etc/hosts.denyfor access control.
5. SSL/TLS Encryption (FTPS)
ssl_enable=YESEnables SSL/TLS encryption.
rsa_cert_file=/etc/ssl/certs/vsftpd.pemPath to SSL certificate.
rsa_private_key_file=/etc/ssl/private/vsftpd.keyPath to private key.
allow_anon_ssl=NODisables SSL for anonymous users (recommended).
force_local_data_ssl=YESForces SSL for data connections.
force_local_logins_ssl=YESForces SSL for login authentication.
6. Logging & Debugging
xferlog_enable=YESEnables transfer logging.
xferlog_file=/var/log/vsftpd.logCustom log file path.
log_ftp_protocol=YESLogs FTP protocol details (debugging).
dual_log_enable=YESLogs in both vsftpd and wu-ftp formats.
7. Connection & Rate Limiting
max_clients=50Maximum simultaneous connections.
max_per_ip=5Connections per IP.
local_max_rate=100000(bytes/sec)Speed limit for local users.
anon_max_rate=50000Speed limit for anonymous users.
idle_session_timeout=300(seconds)Disconnects idle sessions.
data_connection_timeout=120Timeout for data transfers.
8. Passive Mode (Firewall-Friendly)
pasv_enable=YESEnables passive mode (recommended for NAT/firewalls).
pasv_min_port=40000Minimum passive mode port.
pasv_max_port=50000Maximum passive mode port.
pasv_address=your.public.ipPublic IP for passive mode (needed for NAT).
Example vsftpd.conf
Post-Configuration Steps
Restart vsFTPd:
Open Firewall Ports:
Test FTP Access:
or use an FTP client like FileZilla.
footprinting using Nmap scripts:
FTP server version
Supported authentication methods
Anonymous login availability
Vulnerabilities (e.g., CVE checks)
1. Basic FTP Service Detection
First, scan the target to detect if FTP (port 21) is open:
Example output:
2. Enumerate FTP Version & Basic Info
Use Nmap’s ftp-anon script to check for anonymous login and ftp-syst to get system info:
ftp-anon: Checks if anonymous login is allowed.ftp-syst: Retrieves FTP server system info (useful for fingerprinting).
Example Output:
3. Detect Vulnerabilities (CVE Checks)
Use ftp-vsftpd-backdoor to check for the infamous vsFTPd 2.3.4 backdoor (CVE-2011-2523):
If vulnerable, it may return:
4. Brute-Force FTP Logins (If Allowed)
If you want to test weak credentials, use ftp-brute:
userdb: List of usernames (e.g.,admin, ftp, root).passdb: List of passwords (e.g.,password, 123456, admin).
5. Check for FTP Bounce Attack (CVE-1999-0017)
Some FTP servers allow proxy connections (bounce attack):
If vulnerable:
6. Full FTP Enumeration (Aggressive Scan)
Combine all useful FTP scripts:
-sV: Detects service version.ftp-*: Runs all FTP-related scripts (excluding brute-force).
Summary of Useful Nmap FTP Scripts
Script
Purpose
ftp-anon
Checks for anonymous FTP access
ftp-syst
Retrieves FTP server system info
ftp-vsftpd-backdoor
Checks for vsFTPd 2.3.4 backdoor
ftp-brute
Tests weak FTP credentials
ftp-bounce
Checks for FTP bounce attack vulnerability
ftp-vuln-cve2010-4221
Checks for ProFTPD vulnerability
Last updated