mwnovak
May 19th, 2005, 05:04 PM
I'm trying to run vsftpd 2.0.3 on Ubuntu 5.04. The server is behind a Netgear WGR614 wireless router/firewall, but it also runs its own iptables ruleset. The problem is simply that, after successfully logging in and establishing a control connection, the FTP session chokes while trying to establish a passive data connection (e.g. listing a directory, downloading a file, etc).
For example, the Captain FTP client shows the following (I get similar results with SmartFTP and plain-vanilla *nix command-line clients):
PASV
227 Entering Passive Mode (63,199,226,113,244,27)
LIST
425 Failed to establish connection.
Note that everything works fine for active transfers if the client's firewall allows active ftp (i.e. accepts new connections to "high" ports). However, most users don't have/want their "high" ports open ... which leaves me trying to make passive transfers work correctly.
So...
I'm mostly convinced this is a firewall issue because, if I forward ports 20-21 and 49152-65535 on the router while setting iptables on the server to allow NEW connections to those ports, passive FTP works just fine. Of course, I don't want to leave the ephemeral port range sitting wide open to new connections (seems like an awfully big hole, no?). It's my understanding that the ip_conntrack_ftp module (http://www.sns.ias.edu/~jns/security/iptables/iptables_conntrack.html) should help me out by noting control connections to port 21 and allowing RELATED inbound connections to 49152-65535... but it doesn't seem to work. If anyone wants to take a crack at this, my config details are listed below.
In vsftpd.conf, I have the following relevant lines:
pasv_enable=YES
pasv_promiscuous=NO
port_enable=NO
port_promiscuous=NO
pasv_max_port=65534
pasv_min_port=49152
pasv_address=63.199.xx.xx # my external ip address
I'm forcing passive mode here for testing, but active transfers work just fine when I set "port_enable=YES". I've tried running in the promiscuous modes, with the default pasv_min/max port range, and/or without specifying a "pasv_address" ip. In every event, the client can't establish a passive data connection.
On the Netgear router, I have ports 20-21 and 49152-65534 forwarded to the server's local/internal ip (192.168.1.10). For the sake of testing, I've tried assigning the server as an un-firewalled DMZ host, and I've also tried disabling SPI on the router... no joy.
So, now for the server's iptables script... I won't post the entire script unless someone asks for it, but it's based on an example by James C. Stephens (http://www.sns.ias.edu/~jns/security/iptables/rules.html). The integral bits are as follows:
# modules
modprobe ip_tables
modprobe ip_nat_ftp
modprobe ip_conntrack
modprobe ip_conntrack_ftp
# drop by default
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# SSH
iptables -A OUTPUT -o $IFACE -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i $IFACE -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
# ftp
UP_PORTS="49152:65534"
# control
iptables -A INPUT -i $IFACE -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j LOG --log-prefix "1: FTP Control IN "
iptables -A INPUT -i $IFACE -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o $IFACE -p tcp --sport 21 -m state --state ESTABLISHED -j LOG --log-prefix "2: FTP Control OUT "
iptables -A OUTPUT -o $IFACE -p tcp --sport 21 -m state --state ESTABLISHED -j ACCEPT
# active data (used with "port_enable=YES" in vsftpd.conf; commented out for the moment)
#iptables -A OUTPUT -o $IFACE -p tcp --sport 20 -m state --state NEW,ESTABLISHED -j LOG --log-prefix "3a: Active FTP Data OUT "
#iptables -A OUTPUT -o $IFACE -p tcp --sport 20 -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -A INPUT -i $IFACE -p tcp --dport 20 -m state --state ESTABLISHED -j LOG --log-prefix "4a: Active FTP Data IN "
#iptables -A INPUT -i $IFACE -p tcp --dport 20 -m state --state ESTABLISHED -j ACCEPT
# passive data
iptables -A INPUT -i $IFACE -p tcp --dport $UP_PORTS -m state --state ESTABLISHED,RELATED -j LOG --log-prefix "3b: Pasv FTP Data IN "
iptables -A INPUT -i $IFACE -p tcp --dport $UP_PORTS -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o $IFACE -p tcp --sport $UP_PORTS -m state --state ESTABLISHED -j LOG --log-prefix "4b: Pasv FTP Data OUT "
iptables -A OUTPUT -o $IFACE -p tcp --sport $UP_PORTS -m state --state ESTABLISHED -j ACCEPT
# Any tcp not already allowed is logged and then dropped.
iptables -A INPUT -i $IFACE -p tcp -j LOG --log-prefix "IPTABLES TCP-IN: "
iptables -A INPUT -i $IFACE -p tcp -j DROP
iptables -A OUTPUT -o $IFACE -p tcp -j LOG --log-prefix "IPTABLES TCP-OUT: "
iptables -A OUTPUT -o $IFACE -p tcp -j DROP
Logging of the FTP control/data bits is to help debug the problem. Note that I've used information presented in the Linux Home Networking tutorial on FTP Server Setup (http://www.siliconvalleyccie.com/linux-hn/ftp-server.htm) to guide my construction of rules for FTP control and active/passive data connections. Someone double-check me, but I think I've got it right.
Now for the logs...
A passive FTP session gives the following (edited for brevity; 67.161.xx.xx is the client's external ip, 63.199.xx.xx is the server's external ip, 192.168.1.10 is the server's internal/non-public ip):
May 19 12:52:29 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=2641 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 SYN URGP=0
May 19 12:52:29 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=5760 RES=0x00 ACK SYN URGP=0
May 19 12:52:29 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=52 TOS=0x00 PREC=0x00 TTL=50 ID=2642 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0
May 19 12:52:29 localhost vsftpd: Thu May 19 12:52:29 2005 [pid 7445] CONNECT: Client "67.161.xx.xx"
May 19 12:52:29 localhost vsftpd: Thu May 19 12:52:29 2005 [pid 7445] FTP response: Client "67.161.xx.xx", "220 -- welcome to [hostname].org -- explicit SSL is required -- play nice --"
## the client and server proceed to negotiate a login, eventually resulting in:
May 19 12:52:29 localhost vsftpd: Thu May 19 12:52:29 2005 [pid 7444] [cjjohnston] OK LOGIN: Client "67.161.xx.xx"
May 19 12:52:29 localhost vsftpd: Thu May 19 12:52:29 2005 [pid 7446] [cjjohnston] FTP response: Client "67.161.xx.xx", "230 Login successful."
## after a bit more negotiation (SYST, etc), we get:
May 19 12:52:31 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=105 TOS=0x00 PREC=0x00 TTL=64 ID=54560 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost vsftpd: Thu May 19 12:52:31 2005 [pid 7446] [cjjohnston] FTP command: Client "67.161.xx.xx", "PWD"
May 19 12:52:31 localhost vsftpd: Thu May 19 12:52:31 2005 [pid 7446] [cjjohnston] FTP response: Client "67.161.xx.xx", "257 "/cjjohnston""
May 19 12:52:31 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=89 TOS=0x00 PREC=0x00 TTL=50 ID=2655 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=97 TOS=0x00 PREC=0x00 TTL=64 ID=54562 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=89 TOS=0x00 PREC=0x00 TTL=50 ID=2656 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost vsftpd: Thu May 19 12:52:31 2005 [pid 7446] [cjjohnston] FTP command: Client "67.161.xx.xx", "PASV"
May 19 12:52:31 localhost vsftpd: Thu May 19 12:52:31 2005 [pid 7446] [cjjohnston] FTP response: Client "67.161.xx.xx", "227 Entering Passive Mode (63,199,xx,xx,217,2)"
May 19 12:52:31 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=129 TOS=0x00 PREC=0x00 TTL=64 ID=54564 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=52 TOS=0x00 PREC=0x00 TTL=50 ID=2658 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0
May 19 12:52:34 localhost kernel: IPTABLES TCP-IN: IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=2659 PROTO=TCP SPT=32776 DPT=55554 WINDOW=65535 RES=0x00 SYN URGP=0
May 19 12:52:37 localhost kernel: IPTABLES TCP-IN: IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=2660 PROTO=TCP SPT=32776 DPT=55554 WINDOW=65535 RES=0x00 SYN URGP=0
## after several lines like the last two listed above (dropped SYN packets,
## labeled with "IPTABLES TCP-IN"), we get:
May 19 12:53:46 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=89 TOS=0x00 PREC=0x00 TTL=50 ID=2675 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK PSH URGP=0
May 19 12:53:46 localhost vsftpd: Thu May 19 12:53:46 2005 [pid 7446] [cjjohnston] FTP command: Client "67.161.xx.xx", "LIST"
May 19 12:53:46 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=54566 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK URGP=0
May 19 12:54:17 localhost kernel: IPTABLES TCP-IN: IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=63.199.xx.xx DST=192.168.1.10 LEN=52 TOS=0x10 PREC=0x00 TTL=64 ID=42294 PROTO=TCP SPT=22 DPT=63521 WINDOW=2352 RES=0x00 ACK RST URGP=0
May 19 12:54:46 localhost vsftpd: Thu May 19 12:54:46 2005 [pid 7446] [cjjohnston] FTP response: Client "67.161.xx.xx", "425 Failed to establish connection."
May 19 12:54:46 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=121 TOS=0x00 PREC=0x00 TTL=64 ID=54568 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK PSH URGP=0
May 19 12:54:46 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=52 TOS=0x00 PREC=0x00 TTL=50 ID=2688 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0
Note that it steps through the control connection ("1: FTP Control IN" and "2: FTP Control OUT") without a hitch. However, what _should_ be the first part of the passive data connection gets dropped ("IPTABLES TCP-IN") as not matching any ACCEPT rules in the firewall script. My assumption is that the ruleset doesn't see that incoming SYN packet ("SPT=32776 DPT=55554") as RELATED to the previous control connection. But, isn't that what ip_conntrack_ftp is for? If not, is there any way to get that incoming packet seen as related to the FTP session without simply opening the ephemeral range to all NEW connections?
I'd thought this might be impossible until I started reading about the ip_conntrack_ftp module... unless I've misunderstood and it's only designed for client (not server) firewalls, everything I've found suggests that module should be exactly what I need to get passive connections working. But, again, no joy. One thought: is it possible that the Netgear router is somehow mangling the incoming data packets such that ip_conntrack_ftp can't see them as related to the extant control connection on port 21? I dunno.
Suggestions? Comments? Reading material?
--MW
For example, the Captain FTP client shows the following (I get similar results with SmartFTP and plain-vanilla *nix command-line clients):
PASV
227 Entering Passive Mode (63,199,226,113,244,27)
LIST
425 Failed to establish connection.
Note that everything works fine for active transfers if the client's firewall allows active ftp (i.e. accepts new connections to "high" ports). However, most users don't have/want their "high" ports open ... which leaves me trying to make passive transfers work correctly.
So...
I'm mostly convinced this is a firewall issue because, if I forward ports 20-21 and 49152-65535 on the router while setting iptables on the server to allow NEW connections to those ports, passive FTP works just fine. Of course, I don't want to leave the ephemeral port range sitting wide open to new connections (seems like an awfully big hole, no?). It's my understanding that the ip_conntrack_ftp module (http://www.sns.ias.edu/~jns/security/iptables/iptables_conntrack.html) should help me out by noting control connections to port 21 and allowing RELATED inbound connections to 49152-65535... but it doesn't seem to work. If anyone wants to take a crack at this, my config details are listed below.
In vsftpd.conf, I have the following relevant lines:
pasv_enable=YES
pasv_promiscuous=NO
port_enable=NO
port_promiscuous=NO
pasv_max_port=65534
pasv_min_port=49152
pasv_address=63.199.xx.xx # my external ip address
I'm forcing passive mode here for testing, but active transfers work just fine when I set "port_enable=YES". I've tried running in the promiscuous modes, with the default pasv_min/max port range, and/or without specifying a "pasv_address" ip. In every event, the client can't establish a passive data connection.
On the Netgear router, I have ports 20-21 and 49152-65534 forwarded to the server's local/internal ip (192.168.1.10). For the sake of testing, I've tried assigning the server as an un-firewalled DMZ host, and I've also tried disabling SPI on the router... no joy.
So, now for the server's iptables script... I won't post the entire script unless someone asks for it, but it's based on an example by James C. Stephens (http://www.sns.ias.edu/~jns/security/iptables/rules.html). The integral bits are as follows:
# modules
modprobe ip_tables
modprobe ip_nat_ftp
modprobe ip_conntrack
modprobe ip_conntrack_ftp
# drop by default
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# SSH
iptables -A OUTPUT -o $IFACE -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i $IFACE -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
# ftp
UP_PORTS="49152:65534"
# control
iptables -A INPUT -i $IFACE -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j LOG --log-prefix "1: FTP Control IN "
iptables -A INPUT -i $IFACE -p tcp --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o $IFACE -p tcp --sport 21 -m state --state ESTABLISHED -j LOG --log-prefix "2: FTP Control OUT "
iptables -A OUTPUT -o $IFACE -p tcp --sport 21 -m state --state ESTABLISHED -j ACCEPT
# active data (used with "port_enable=YES" in vsftpd.conf; commented out for the moment)
#iptables -A OUTPUT -o $IFACE -p tcp --sport 20 -m state --state NEW,ESTABLISHED -j LOG --log-prefix "3a: Active FTP Data OUT "
#iptables -A OUTPUT -o $IFACE -p tcp --sport 20 -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -A INPUT -i $IFACE -p tcp --dport 20 -m state --state ESTABLISHED -j LOG --log-prefix "4a: Active FTP Data IN "
#iptables -A INPUT -i $IFACE -p tcp --dport 20 -m state --state ESTABLISHED -j ACCEPT
# passive data
iptables -A INPUT -i $IFACE -p tcp --dport $UP_PORTS -m state --state ESTABLISHED,RELATED -j LOG --log-prefix "3b: Pasv FTP Data IN "
iptables -A INPUT -i $IFACE -p tcp --dport $UP_PORTS -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o $IFACE -p tcp --sport $UP_PORTS -m state --state ESTABLISHED -j LOG --log-prefix "4b: Pasv FTP Data OUT "
iptables -A OUTPUT -o $IFACE -p tcp --sport $UP_PORTS -m state --state ESTABLISHED -j ACCEPT
# Any tcp not already allowed is logged and then dropped.
iptables -A INPUT -i $IFACE -p tcp -j LOG --log-prefix "IPTABLES TCP-IN: "
iptables -A INPUT -i $IFACE -p tcp -j DROP
iptables -A OUTPUT -o $IFACE -p tcp -j LOG --log-prefix "IPTABLES TCP-OUT: "
iptables -A OUTPUT -o $IFACE -p tcp -j DROP
Logging of the FTP control/data bits is to help debug the problem. Note that I've used information presented in the Linux Home Networking tutorial on FTP Server Setup (http://www.siliconvalleyccie.com/linux-hn/ftp-server.htm) to guide my construction of rules for FTP control and active/passive data connections. Someone double-check me, but I think I've got it right.
Now for the logs...
A passive FTP session gives the following (edited for brevity; 67.161.xx.xx is the client's external ip, 63.199.xx.xx is the server's external ip, 192.168.1.10 is the server's internal/non-public ip):
May 19 12:52:29 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=2641 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 SYN URGP=0
May 19 12:52:29 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=5760 RES=0x00 ACK SYN URGP=0
May 19 12:52:29 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=52 TOS=0x00 PREC=0x00 TTL=50 ID=2642 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0
May 19 12:52:29 localhost vsftpd: Thu May 19 12:52:29 2005 [pid 7445] CONNECT: Client "67.161.xx.xx"
May 19 12:52:29 localhost vsftpd: Thu May 19 12:52:29 2005 [pid 7445] FTP response: Client "67.161.xx.xx", "220 -- welcome to [hostname].org -- explicit SSL is required -- play nice --"
## the client and server proceed to negotiate a login, eventually resulting in:
May 19 12:52:29 localhost vsftpd: Thu May 19 12:52:29 2005 [pid 7444] [cjjohnston] OK LOGIN: Client "67.161.xx.xx"
May 19 12:52:29 localhost vsftpd: Thu May 19 12:52:29 2005 [pid 7446] [cjjohnston] FTP response: Client "67.161.xx.xx", "230 Login successful."
## after a bit more negotiation (SYST, etc), we get:
May 19 12:52:31 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=105 TOS=0x00 PREC=0x00 TTL=64 ID=54560 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost vsftpd: Thu May 19 12:52:31 2005 [pid 7446] [cjjohnston] FTP command: Client "67.161.xx.xx", "PWD"
May 19 12:52:31 localhost vsftpd: Thu May 19 12:52:31 2005 [pid 7446] [cjjohnston] FTP response: Client "67.161.xx.xx", "257 "/cjjohnston""
May 19 12:52:31 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=89 TOS=0x00 PREC=0x00 TTL=50 ID=2655 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=97 TOS=0x00 PREC=0x00 TTL=64 ID=54562 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=89 TOS=0x00 PREC=0x00 TTL=50 ID=2656 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost vsftpd: Thu May 19 12:52:31 2005 [pid 7446] [cjjohnston] FTP command: Client "67.161.xx.xx", "PASV"
May 19 12:52:31 localhost vsftpd: Thu May 19 12:52:31 2005 [pid 7446] [cjjohnston] FTP response: Client "67.161.xx.xx", "227 Entering Passive Mode (63,199,xx,xx,217,2)"
May 19 12:52:31 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=129 TOS=0x00 PREC=0x00 TTL=64 ID=54564 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK PSH URGP=0
May 19 12:52:31 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=52 TOS=0x00 PREC=0x00 TTL=50 ID=2658 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0
May 19 12:52:34 localhost kernel: IPTABLES TCP-IN: IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=2659 PROTO=TCP SPT=32776 DPT=55554 WINDOW=65535 RES=0x00 SYN URGP=0
May 19 12:52:37 localhost kernel: IPTABLES TCP-IN: IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=2660 PROTO=TCP SPT=32776 DPT=55554 WINDOW=65535 RES=0x00 SYN URGP=0
## after several lines like the last two listed above (dropped SYN packets,
## labeled with "IPTABLES TCP-IN"), we get:
May 19 12:53:46 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=89 TOS=0x00 PREC=0x00 TTL=50 ID=2675 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK PSH URGP=0
May 19 12:53:46 localhost vsftpd: Thu May 19 12:53:46 2005 [pid 7446] [cjjohnston] FTP command: Client "67.161.xx.xx", "LIST"
May 19 12:53:46 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=54566 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK URGP=0
May 19 12:54:17 localhost kernel: IPTABLES TCP-IN: IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=63.199.xx.xx DST=192.168.1.10 LEN=52 TOS=0x10 PREC=0x00 TTL=64 ID=42294 PROTO=TCP SPT=22 DPT=63521 WINDOW=2352 RES=0x00 ACK RST URGP=0
May 19 12:54:46 localhost vsftpd: Thu May 19 12:54:46 2005 [pid 7446] [cjjohnston] FTP response: Client "67.161.xx.xx", "425 Failed to establish connection."
May 19 12:54:46 localhost kernel: 2: FTP Control OUT IN= OUT=eth0 SRC=192.168.1.10 DST=67.161.xx.xx LEN=121 TOS=0x00 PREC=0x00 TTL=64 ID=54568 DF PROTO=TCP SPT=21 DPT=32775 WINDOW=1708 RES=0x00 ACK PSH URGP=0
May 19 12:54:46 localhost kernel: 1: FTP Control IN IN=eth0 OUT= MAC=00:30:65:c1:8d:72:00:09:5b:d6:06:0c:08:00 SRC=67.161.xx.xx DST=192.168.1.10 LEN=52 TOS=0x00 PREC=0x00 TTL=50 ID=2688 PROTO=TCP SPT=32775 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0
Note that it steps through the control connection ("1: FTP Control IN" and "2: FTP Control OUT") without a hitch. However, what _should_ be the first part of the passive data connection gets dropped ("IPTABLES TCP-IN") as not matching any ACCEPT rules in the firewall script. My assumption is that the ruleset doesn't see that incoming SYN packet ("SPT=32776 DPT=55554") as RELATED to the previous control connection. But, isn't that what ip_conntrack_ftp is for? If not, is there any way to get that incoming packet seen as related to the FTP session without simply opening the ephemeral range to all NEW connections?
I'd thought this might be impossible until I started reading about the ip_conntrack_ftp module... unless I've misunderstood and it's only designed for client (not server) firewalls, everything I've found suggests that module should be exactly what I need to get passive connections working. But, again, no joy. One thought: is it possible that the Netgear router is somehow mangling the incoming data packets such that ip_conntrack_ftp can't see them as related to the extant control connection on port 21? I dunno.
Suggestions? Comments? Reading material?
--MW