|
NAMEftpsesame —
automagic packet filter configurator for FTP
SYNOPSIS
DESCRIPTIONftpsesame tracks FTP control connections to be able to
timely add
pf(4) packet
filter rules that allow active and passive FTP data transfers to commence.
This results in the efficiency of a packet filter, and the fine-grained
control of a proxy. It can run on both FTP clients and FTP servers, or a
firewall in front thereof.
Assuming the FTP control connection is from $client to $server,
and $port is negotiated, In case of active mode (PORT or EPRT): pass in log quick inet proto tcp \ from $server to $client port $port flags S/SAFR keep state In case of passive mode (PASV or EPSV): pass in log quick inet proto tcp \ from $client to $server port $port flags S/SAFR keep state In the special case of passive mode where the client is subject to NAT, an extra rule is added, where $client_real is the client's real IP address: pass in log quick inet proto tcp \ from $client_real to $server port $port flags S/SAFR keep state The options are as follows:
CONFIGURATION EXAMPLESTo use the rules set up byftpsesame ,
pf.conf(5)
should be modified to use the anchor. Below are examples that show most of the
possibilities.
# (1) Allow internal LAN to access FTP servers anywhere. # (passive mode only if $lan is subject to NAT, see below) # cmd: ftpsesame -i $ext_if anchor "ftpsesame/*" on { $int_if, $ext_if } pass in quick on $int_if proto tcp from $lan to any port 21 keep state pass out quick on $ext_if proto tcp from $lan to any port 21 keep state # (2) Allow access to FTP servers in the DMZ, while queueing the data # transfers. # cmd: ftpsesame -i $dmz_if -q ftp queue ftp bandwidth 10% # passive anchor "ftpsesame/*" in on $ext_if proto tcp from any to { $ftp_servers } anchor "ftpsesame/*" out on $dmz_if proto tcp from any to { $ftp_servers } # active anchor "ftpsesame/*" in on $dmz_if proto tcp from { $ftp_servers } to any anchor "ftpsesame/*" out on $ext_if proto tcp from { $ftp_servers } to any # ... rules for port 21 omitted ... # (3) Allow access to FTP servers in the DMZ, using tagging for fine # grained control. # cmd: ftpsesame -i $dmz_if -t ftpok anchor "ftpsesame/*" # passive pass in quick on $ext_if proto tcp from to any to $realftp \ port > 49151 tagged ftpok keep state pass in quick on $ext_if proto tcp from any to $msftp \ port 1023 >< 5001 tagged ftpok keep state pass out quick on $dmz_if all tagged ftpok keep state # active pass in quick on $dmz_if proto tcp from $realftp to any \ tagged ftpok keep state pass in quick on $dmz_if proto tcp from $msftp port 20 to any \ tagged ftpok keep state pass out quick on $ext_if all tagged ftpok keep state # ... rules for port 21 omitted ... Keep state is mandatory on the control connection (port 21),
because NAT ISSUESTo enable passive mode connections from clients subject to NAT,ftpsesame must listen on the interface where the NAT
has already taken place, typically the external interface. Otherwise
ftpsesame cannot add the extra rule with the real
client address. Note that this does not have to be a problem, if there are
other rules taking care of that.
Active mode connections from clients subject to NAT are not supported, because it requires commands inside the control connection to be rewritten. ftp-proxy(8) can be used for that purpose. SECURITYPorts below 1024 are not allowed.The negotiated IP address for active mode is ignored for security reasons. This makes third party file transfers impossible.
The concept of rebuilding a TCP session from IP packets on a
passive listener is fundamentally flawed. It is recommended to run CAVEATSThere is always a slight delay before a rule gets added to the anchor. If the data connection is opened within this period, it will get blocked. Ifftpsesame runs on a firewall between the client and
server, this only introduces a slight delay, as TCP will retry within seconds.
If ftpsesame runs on a client or server itself, the
network stack reacts differently on blocked packets ("no route to
host") and either active or passive may mode not work.
SEE ALSObpf(4), ftp(1), ftp-proxy(8), pf(4), pf.conf(5), tcpdump(8)
Visit the GSP FreeBSD Man Page Interface. |