How does the FTP bounce attack abuse the PORT command, and what do RFC 2577 and FTP servers do to prevent it?
answer
- the server dials, not you
- PORT names any host
- a third machine's service port
- below 1024, reply 504
- only the client's own address
basics
~20 sPORT lets a client name any address, so an attacker makes the FTP server connect to a third host and send it chosen bytes. RFC 2577 suggests refusing ports below 1024 or disabling PORT; servers also refuse foreign addresses.
solid answer
~50 sIn active mode the client's `PORT` command tells the server where to open the data connection, and RFC 959 places no limit on that address, because it supports transfers between two servers. An attacker therefore sends `PORT` naming a third host and service port, then asks the server to send a file: the server connects from its own address and delivers whatever bytes the attacker chose, for example a file of mail commands uploaded earlier. The target sees the FTP server, so the attacker is hard to trace and address-based trust is bypassed. RFC 2577 (Informational) suggests not opening data connections to ports below 1024, answering such a `PORT` with `504`, and notes that disabling `PORT` is an option. Many servers add their own check: data connections go only to the address of the client on the control connection.
go deeper
Recall that the FTP bounce makes the server, not the attacker, connect to a third host, using an address supplied in PORT.
Explain why RFC 959 lets PORT name any host, how an uploaded file becomes the payload, and RFC 2577's port-below-1024 and disable-PORT suggestions.
Separate the RFC's suggestions from the server's own address check, apply it to EPRT too, and decide whether active mode can be switched off entirely.
Weigh breaking server-to-server transfers and active-mode clients against the exposure of a server that can reach internal hosts on an attacker's behalf.
## Why PORT can name any host In FTP's **active mode**, the client sends `PORT h1,h2,h3,h4,p1,p2` and the **server** opens the data connection to that address and port. (How active and passive modes set up connections is covered with FTP data channels.) RFC 959 deliberately lets the address be any host, not just the client: it describes **server-to-server** transfers, where a user holds control connections to two servers and arranges for one to send data directly to the other. That flexibility is the hole. ## How the bounce works RFC 2577, *FTP Security Considerations*, describes the attack in protocol terms: 1. The attacker logs in to an FTP server, often anonymously, and uploads a file whose contents are commands for some other service, for example mail-protocol commands. 2. The attacker sends `PORT` naming a **third host** and that service's port, such as a mail server's port 25. 3. The attacker asks the FTP server to send the uploaded file. The server connects from its own address to the target and writes the file's bytes into the target service. 4. The target sees a connection from the FTP server and acts on what arrives. ## What it gives the attacker - **Hiding the source.** The connection comes from the FTP server, so the target's logs point there, not at the attacker. - **Crossing address-based trust.** If the FTP server sits inside a network whose hosts trust each other by address, the bounce reaches services the attacker could not connect to directly. - **Reaching internal ports.** An FTP server reachable from outside but able to connect inward can be used to touch internal services. ## Defences | Defence | Where it comes from | Cost | |---|---|---| | Refuse data connections to TCP ports below 1024, answering `504 Command not implemented for that parameter.` | RFC 2577 suggestion | Services on ports above 1023 remain reachable, as the RFC notes | | Disable `PORT` entirely and support only passive mode | RFC 2577 option | Clients that need active mode, and server-to-server transfers, stop working | | Refuse `PORT` naming any address other than the control connection's client | Common server implementation check, not in the RFC | Server-to-server transfers no longer work | | Proper file permissions, so uploaded files cannot later be sent out again | RFC 2577 observation | Upload areas need careful design | Many servers ship the address check, and one widely used server enforces it by default unless an option turns it off; it is a server's own policy, and RFC 2577 only suggests the port limit and disabling `PORT`. `EPRT` (RFC 2428) also names an address, so the same check belongs on it. ## Related weaknesses in RFC 2577 - **Address-based restrictions.** A server restricting files by client address should check the addresses of both the control and the data connection, so a trusted control connection cannot steer data to an untrusted host. - **Port stealing.** If a server hands out predictable passive ports, another client can connect first and steal or inject a file; random data ports reduce that. ## Does TLS help? RFC 4217 argues a bounce is harder under FTPS: the FTP server is always the TLS server on a protected data connection, so only a target service that itself acts as a TLS client could be affected, and a server can reject a data connection whose TLS credentials do not match the control connection. That is a side effect; it does not replace the address check. ## What to check in a review 1. Does the server accept `PORT` or `EPRT` naming an address other than the client's? It should not. 2. Is active mode needed at all? If every client uses passive mode, disable `PORT`. 3. Can anonymous or low-trust users upload files and then retrieve them? That is the staging step the attack relies on. 4. Can the server, reachable from outside, open connections to internal addresses? If so, an egress rule on the server's own host or network segment limits what a bounce could reach even if a check is missing. ## Why passive mode is not the problem The bounce depends on the **server dialling** an address the client supplied. In passive mode (`PASV` or `EPSV`) the roles reverse: the server listens on a port it chose and the **client dials** it, so the server never connects to a client-chosen destination. That is why RFC 2577 can suggest disabling `PORT` outright: most transfers work with passive mode alone, and what is lost is active mode and server-to-server transfers.
- Why does RFC 2577 call refusing ports below 1024 only a partial defence against the FTP bounce attack?Because many services listen above port 1023, and the RFC says so itself: those remain reachable through a bounce. The rule also restricts only the destination port, not the destination host. That is why servers add the stricter check that data connections may go only to the client's own address, and why disabling `PORT` is the cleanest choice where passive mode is enough.
- What legitimate FTP feature does refusing a PORT to a third address break?Server-to-server transfer. RFC 959 lets a user hold control connections to two servers and point one server's `PORT` at the other's passive listener, so files move directly between servers without passing through the user's machine. A server that only connects to its own client's address cannot take part, and most deployments accept that loss.
It is like a mail-forwarding service that will post any parcel you hand it to whatever address you write on the label: the recipient sees the forwarder's return address, not yours, so the protection has to come from the forwarder refusing labels it should not honour.
- Passive mode enables the bounce; PORT is the safe direction
- RFC 2577 requires servers to reject PORT to third-party addresses
- Refusing ports below 1024 fully prevents bounce attacks
- The bounced target logs the attacker's own address
- A bounce needs the attacker to read the FTP password off the wire