ftp6proxy

Intro

ftp6proxy is an ftp proxy for IPv6 gateways and firewalls. It is meant for FreeBSD, but may run on any other (BSD) operating system that support divert sockets, kqueue, IPv6, and pf and/or ipfw. It may be of use for passive FTP with IPv4, too. In contrast to ftp-proxy and the libalias family (natd, ppp), ftp6proxy does not support NAT as we do not need NAT with IPv6, do we? Instead, ftp6proxy intercepts the ftp command channel via a divert socket, and then, if the client wants to initiate a transfer, opens the firewall for two seconds. If the data channel has been established within these 2 seconds, it will have created a dynamic firewall rule in order to let through subsequent packets.
Both ftp-proxy and libalias/natd rewrite each ftp connection in order to make it look like as if it originates on the gateway machine (read: they do NAT). This is great if you're dealing with private (IPv4) addresses. With public addresses or IPv6, NAT becomes less desirable. Furthermore, libalias does not support IPv6 yet.

Installation

Configuration

pf

Why do I have to use ipfw along with pf?

pf has issues diverting IPv6 traffic - at least on FreeBSD 9.2 and 10.0, see my message on the freebsd-pf mailing list.

ipfw

netgraph

From version 0.4 on ftp6proxy supports netgraph and uses ng_ipfw to get a copy of each FTP command packet. If you ftp6proxy along with netgraph, it does not reinject any packets. Instead you have to use the ngtee action of ipfw.

Help

ftp6proxy V0.3 - IPv6/IPv4 FTP firewall helper

compiled-in firewall module: ipfw

usage: ftp6proxy [-b <base>] [-c <count>] [-d [-d]] [-f <facility>]
                 [-i <pidfile>] [-j <target>] [-p <port>] [-q <queue>]
                 [-r <dir>] [-t <timeout>] [-u <user>]
       ftp6proxy -h

  -b <base>      punch holes into firewall starting at this rule number;
                 default: 64000
  -c <count>     use up to <count> firewall rules; default: 100
  -d             run in foreground, don't write pidfile
  -d -d          run in foreground, don't write pidfile, don't chroot,
                 debug log to stderr, don't drop privileges
  -f <facility>  send syslog to <facility>; default: daemon
  -i <pidfile>   write pid to <pidfile> instead of /var/run/ftp6proxy.pid
  -j <target>    call this ipfw rule number instead of allowing the data
                 connection
  -p <port>      divert(4) port number to listen on; defaults to 10004
  -q <queue>     place data connections into this pf QoS class
  -r <dir>       chroot into <dir> instead of /var/empty
  -t <timeout>   wait up to <timeout> seconds for data connections;
                 defaults to 2 seconds
  -u <user>      run as user <user> instead of proxy
  -h             show this help ;-)
ftp6proxy V0.4 - IPv6/IPv4 FTP firewall helper

compiled-in firewall module: ipfw/netgraph

usage: ftp6proxy [-b <base>] [-c <count>] [-d [-d]] [-f <facility>]
                 [-i <pidfile>] [-j <target>] [-p <port>] [-q <queue>]
                 [-r <dir>] [-t <timeout>] [-u <user>]
       ftp6proxy -h

  -b <base>      punch holes into firewall starting at this rule number;
                 default: 64000
  -c <count>     use up to <count> firewall rules; default: 100
  -d             run in foreground, don't write pidfile
  -d -d          run in foreground, don't write pidfile, don't chroot,
                 debug log to stderr, don't drop privileges
  -f <facility>  send syslog to <facility>; default: daemon
  -i <pidfile>   write pid to <pidfile> instead of /var/run/ftp6proxy.pid
  -j <target>    call this ipfw rule number instead of allowing the data
                 connection
  -p <hook>      ng_ipfw(4) hook to connect to; defaults to 10004
  -q <queue>     place data connections into this pf QoS class
  -r <dir>       chroot into <dir> instead of /var/empty
  -t <timeout>   wait up to <timeout> seconds for data connections;
                 defaults to 2 seconds
  -u <user>      run as user <user> instead of proxy
  -h             show this help ;-)

You can override default options by setting ftp6proxy_flags in /etc/rc.conf.

Files

Prototype

Before I started ftp6proxy, I wrote a prototype in Perl. I uploaded it for educational reference. It's called alg.pl.