networking, updated

FTP

The File Transfer Protocol moves files over two TCP connections: one for commands, one per transfer. Clear text by default, so usernames, passwords and files are visible in any capture.

OSI layer
7 Application
Carried in
TCP
Ports
21/tcp (control), 20/tcp (active data), 990/tcp (implicit FTPS), dynamic (passive data)
Specs
RFC 959, RFC 2428, RFC 4217
Wireshark filter
ftp || ftp-data
Encrypted
no

Packet structure

Like SMTP, FTP is line-based text on the control connection (port 21). Files and directory listings travel on a separate data connection.

S: 220 ProFTPD Server ready
C: USER alice
S: 331 Password required for alice
C: PASS hunter2
S: 230 User alice logged in
C: TYPE I
S: 200 Type set to I
C: PASV
S: 227 Entering Passive Mode (192,0,2,10,195,80)
   ... client opens a data connection to 192.0.2.10:50000 ...
C: RETR report.pdf
S: 150 Opening BINARY mode data connection
S: 226 Transfer complete
C: QUIT
S: 221 Goodbye

The passive reply encodes address and port as six numbers: h1,h2,h3,h4,p1,p2, port = p1 × 256 + p2 (195 × 256 + 80 = 50000).

CommandPurpose
USER / PASSLog in (in clear text)
PASV / EPSVPassive mode: the server opens a port for the data connection
PORT / EPRTActive mode: the client tells the server where to connect
LIST, NLST, MLSDDirectory listing (over the data connection)
RETR / STORDownload / upload
CWD, PWD, MKD, DELEChange dir, show dir, make dir, delete
TYPE A / TYPE IASCII / binary mode
AUTH TLSUpgrade to FTPS (explicit)
SITEServer-specific commands (old exploits, e.g. SITE EXEC)
ReplyMeaning
1xxPreliminary (150 opening data connection)
2xxDone (220 ready, 226 transfer complete, 227 passive mode, 230 logged in)
3xxNeed more (331 password required)
4xxTemporary failure (421 service not available, 425 can’t open data connection)
5xxPermanent failure (530 not logged in, 550 file unavailable or no permission)

How it works

ModeData connectionFirewall issue
ActiveServer connects from port 20 to the port the client sent with PORTClient firewalls and NAT block it
PassiveClient connects to the port the server sent in the 227 replyServer needs a range of open ports

Firewalls with an FTP helper read the control connection to open the right data port, which does not work once the control channel is encrypted (FTPS).

In Wireshark

FilterShows
ftpControl connection (commands and replies)
ftp-dataData connections (files, listings)
ftp.request.command == "PASS"Passwords in clear text
ftp.request.command == "USER"User names (look for anonymous)
ftp.response.code == 530Failed logins (brute force if repeated)
ftp.request.command == "STOR"Uploads
ftp.request.command == "PORT"Active mode (and bounce attempts to third-party IPs)

File › Export Objects › FTP-DATA saves transferred files. Follow › TCP Stream on the control connection shows the whole session.

What normal looks like: rare today. Mostly legacy systems, printers and scanners, some industrial devices. Any FTP to the internet deserves a look.

Security notes

References

§ home
~/knubertus/home/
1,1 Top