Active FTP vs Passive FTP

September 2, 2008 at 1:39 pm | Posted in IOS services | 2 Comments

Resource: Active FTP vs. Passive FTP, a Definitive Explanation

Active FTP

In active mode FTP the client connects from a random unprivileged port (N > 1023) to the FTP server’s command port, port 21. Then, the client starts listening to port N+1 and sends the FTP command PORT N+1 to the FTP server. The server will then connect back to the client’s specified data port from its local data port, which is port 20.

From the server-side firewall’s standpoint, to support active mode FTP the following communication channels need to be opened:

  • FTP server’s port 21 from anywhere (Client initiates connection)
  • FTP server’s port 21 to ports > 1023 (Server responds to client’s control port)
  • FTP server’s port 20 to ports > 1023 (Server initiates data connection to client’s data port)
  • FTP server’s port 20 from ports > 1023 (Client sends ACKs to server’s data port)

This has a problem from a firewall perspective, because the server actively open a connection to port N+1. Also this cannot work with PAT where a NAT table have to be generated from inside, for the return traffic to come in.

Passive FTP

In order to resolve the issue of the server initiating the connection to the client a different method for FTP connections was developed. This was known as passive mode, or PASV, after the command used by the client to tell the server it is in passive mode.

In passive mode FTP the client initiates both connections to the server, solving the problem of firewalls filtering the incoming data port connection to the client from the server. When opening an FTP connection, the client opens two random unprivileged ports locally (N > 1023 and N+1). The first port contacts the server on port 21, but instead of then issuing a PORT command and allowing the server to connect back to its data port, the client will issue the PASV command. The result of this is that the server then opens a random unprivileged port (P > 1023) and sends the PORT P command back to the client. The client then initiates the connection from port N+1 to port P on the server to transfer data.

From the server-side firewall’s standpoint, to support passive mode FTP the following communication channels need to be opened:

  • FTP server’s port 21 from anywhere (Client initiates connection)
  • FTP server’s port 21 to ports > 1023 (Server responds to client’s control port)
  • FTP server’s ports > 1023 from anywhere (Client initiates data connection to random port specified by server)
  • FTP server’s ports > 1023 to remote ports > 1023 (Server sends ACKs (and data) to client’s data port)

As a FTP client, by default, routers work in passive mode. To enable active mode, we need to config:

R5(config)#no ip ftp passive
R5(config)#do sh run | in ftp
no ip ftp passive
R5(config)#do copy ftp://150.1.4.1/test.txt null:

Ftp server feature is no longer supported in newer IOS due to security reasons. In old IOS, we can enable FTP server using the following config.

R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#ip http server
R1(config)#ftp-server enable
R1(config)#ftp-server topdir flash:

Bellow are ACL to allow Active and Passive FTP traffic

ip access-list extended FROM_OUTSIDE
! Active FTP
permit tcp any host 150.1.4.1 range ftp-data ftp 
! Passive FTP
permit tcp any host 150.1.4.1 eq ftp
permit tcp any host 150.1.4.1 range 1023 65535

					
Advertisements

2 Comments »

RSS feed for comments on this post. TrackBack URI

  1. […] Source. […]

  2. […] ACL as you would have to allow any to server for high ports. I found this, looks dangerous though. Active FTP vs Passive FTP Cisco Notepad ! Passive FTP permit tcp any host 150.1.4.1 eq ftp permit tcp any host 150.1.4.1 range 1023 […]


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: