xref: /freebsd/contrib/pf/ftp-proxy/ftp-proxy.8 (revision 22ac3ead26f49483410317f82ce328741b1cf975)
122ac3eadSMax Laier.\"	$OpenBSD: ftp-proxy.8,v 1.40 2004/03/16 08:50:07 jmc Exp $
213b9f610SMax Laier.\"
313b9f610SMax Laier.\" Copyright (c) 1996-2001
413b9f610SMax Laier.\"	Obtuse Systems Corporation, All rights reserved.
513b9f610SMax Laier.\"
613b9f610SMax Laier.\" Redistribution and use in source and binary forms, with or without
713b9f610SMax Laier.\" modification, are permitted provided that the following conditions
813b9f610SMax Laier.\" are met:
913b9f610SMax Laier.\" 1. Redistributions of source code must retain the above copyright
1013b9f610SMax Laier.\"    notice, this list of conditions and the following disclaimer.
1113b9f610SMax Laier.\" 2. Redistributions in binary form must reproduce the above copyright
1213b9f610SMax Laier.\"    notice, this list of conditions and the following disclaimer in the
1313b9f610SMax Laier.\"    documentation and/or other materials provided with the distribution.
1413b9f610SMax Laier.\" 3. Neither the name of the University nor the names of its contributors
1513b9f610SMax Laier.\"    may be used to endorse or promote products derived from this software
1613b9f610SMax Laier.\"    without specific prior written permission.
1713b9f610SMax Laier.\"
1813b9f610SMax Laier.\" THIS SOFTWARE IS PROVIDED BY OBTUSE SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
1913b9f610SMax Laier.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2013b9f610SMax Laier.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2113b9f610SMax Laier.\" ARE DISCLAIMED.  IN NO EVENT SHALL OBTUSE OR CONTRIBUTORS BE LIABLE
2213b9f610SMax Laier.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2313b9f610SMax Laier.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2413b9f610SMax Laier.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2513b9f610SMax Laier.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2613b9f610SMax Laier.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2713b9f610SMax Laier.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2813b9f610SMax Laier.\" SUCH DAMAGE.
2913b9f610SMax Laier.\"
30abbfafd2SMax Laier.\" $FreeBSD$
31abbfafd2SMax Laier.\"
3213b9f610SMax Laier.Dd August 17, 2001
3313b9f610SMax Laier.Dt FTP-PROXY 8
3413b9f610SMax Laier.Os
3513b9f610SMax Laier.Sh NAME
3613b9f610SMax Laier.Nm ftp-proxy
3713b9f610SMax Laier.Nd Internet File Transfer Protocol proxy server
3813b9f610SMax Laier.Sh SYNOPSIS
3913b9f610SMax Laier.Nm ftp-proxy
4013b9f610SMax Laier.Op Fl AnrVw
4122ac3eadSMax Laier.Op Fl a Ar address
4213b9f610SMax Laier.Op Fl D Ar debuglevel
4313b9f610SMax Laier.Op Fl g Ar group
4413b9f610SMax Laier.Op Fl M Ar maxport
4522ac3eadSMax Laier.Op Fl m Ar minport
4613b9f610SMax Laier.Op Fl t Ar timeout
4713b9f610SMax Laier.Op Fl u Ar user
4813b9f610SMax Laier.Sh DESCRIPTION
4913b9f610SMax Laier.Nm
5013b9f610SMax Laieris a proxy for the Internet File Transfer Protocol.
5113b9f610SMax LaierThe proxy uses
5213b9f610SMax Laier.Xr pf 4
5313b9f610SMax Laierand expects to have the FTP control connection as described in
5413b9f610SMax Laier.Xr services 5
5513b9f610SMax Laierredirected to it via a
5613b9f610SMax Laier.Xr pf 4
5713b9f610SMax Laier.Em rdr
5813b9f610SMax Laiercommand.
5913b9f610SMax LaierAn example of how to do that is further down in this document.
6013b9f610SMax Laier.Pp
6113b9f610SMax LaierThe options are as follows:
6213b9f610SMax Laier.Bl -tag -width Ds
6313b9f610SMax Laier.It Fl A
6413b9f610SMax LaierPermit only anonymous FTP connections.
6513b9f610SMax LaierThe proxy will allow connections to log in to other sites as the user
6613b9f610SMax Laier.Qq ftp
6713b9f610SMax Laieror
6813b9f610SMax Laier.Qq anonymous
6913b9f610SMax Laieronly.
7013b9f610SMax LaierAny attempt to log in as another user will be blocked by the proxy.
7122ac3eadSMax Laier.It Fl a Ar address
7222ac3eadSMax LaierSpecify the local IP address to use in
7322ac3eadSMax Laier.Xr bind 2
7422ac3eadSMax Laieras the source for connections made by
7522ac3eadSMax Laier.Nm ftp-proxy
7622ac3eadSMax Laierwhen connecting to destination FTP servers.
7722ac3eadSMax LaierThis may be necessary if the interface address of
7822ac3eadSMax Laieryour default route is not reachable from the destinations
7922ac3eadSMax Laier.Nm
8022ac3eadSMax Laieris attempting connections to, or this address is different from the one
8122ac3eadSMax Laierconnections are being NATed to.
8222ac3eadSMax LaierIn the usual case this means that
8322ac3eadSMax Laier.Ar address
8422ac3eadSMax Laiershould be a publicly visible IP address assigned to one of
8522ac3eadSMax Laierthe interfaces on the machine running
8622ac3eadSMax Laier.Nm
8722ac3eadSMax Laierand should be the same address to which you are translating traffic
8822ac3eadSMax Laierif you are using the
8922ac3eadSMax Laier.Fl n
9022ac3eadSMax Laieroption.
9113b9f610SMax Laier.It Fl D Ar debuglevel
9213b9f610SMax LaierSpecify a debug level, where the proxy emits verbose debug output
9313b9f610SMax Laierinto
9413b9f610SMax Laier.Xr syslogd 8
9513b9f610SMax Laierat level
9613b9f610SMax Laier.Dv LOG_DEBUG .
9713b9f610SMax LaierMeaningful values of debuglevel are 0-3, where 0 is no debug output and
9813b9f610SMax Laier3 is lots of debug output, the default being 0.
9913b9f610SMax Laier.It Fl g Ar group
10013b9f610SMax LaierSpecify the named group to drop group privileges to, after doing
10113b9f610SMax Laier.Xr pf 4
10213b9f610SMax Laierlookups which require root.
10313b9f610SMax LaierBy default,
10413b9f610SMax Laier.Nm
10513b9f610SMax Laieruses the default group of the user it drops privilege to.
10613b9f610SMax Laier.It Fl M Ar maxport
10713b9f610SMax LaierSpecify the upper end of the port range the proxy will use for the
10813b9f610SMax Laierdata connections it establishes.
10913b9f610SMax LaierThe default is
11013b9f610SMax Laier.Dv IPPORT_HILASTAUTO
11113b9f610SMax Laierdefined in
11213b9f610SMax Laier.Aq Pa netinet/in.h
11313b9f610SMax Laieras 65535.
11422ac3eadSMax Laier.It Fl m Ar minport
11522ac3eadSMax LaierSpecify the lower end of the port range the proxy will use for all
11622ac3eadSMax Laierdata connections it establishes.
11722ac3eadSMax LaierThe default is
11822ac3eadSMax Laier.Dv IPPORT_HIFIRSTAUTO
11922ac3eadSMax Laierdefined in
12022ac3eadSMax Laier.Aq Pa netinet/in.h
12122ac3eadSMax Laieras 49152.
12213b9f610SMax Laier.It Fl n
12313b9f610SMax LaierActivate network address translation
12413b9f610SMax Laier.Pq NAT
12513b9f610SMax Laiermode.
12613b9f610SMax LaierIn this mode, the proxy will not attempt to proxy passive mode
12713b9f610SMax Laier.Pq PASV or EPSV
12813b9f610SMax Laierdata connections.
12913b9f610SMax LaierIn order for this to work, the machine running the proxy will need to
13013b9f610SMax Laierbe forwarding packets and doing network address translation to allow
13113b9f610SMax Laierthe outbound passive connections from the client to reach the server.
13213b9f610SMax LaierSee
13313b9f610SMax Laier.Xr pf.conf 5
13413b9f610SMax Laierfor more details on NAT.
13513b9f610SMax LaierThe proxy only ignores passive mode data connections when using this flag;
13613b9f610SMax Laierit will still proxy PORT and EPRT mode data connections.
13713b9f610SMax LaierWithout this flag,
13813b9f610SMax Laier.Nm
13913b9f610SMax Laierdoes not require any IP forwarding or NAT beyond the
14013b9f610SMax Laier.Em rdr
14113b9f610SMax Laiernecessary to capture the FTP control connection.
14213b9f610SMax Laier.It Fl r
14313b9f610SMax LaierUse reverse host
14413b9f610SMax Laier.Pq reverse DNS
14513b9f610SMax Laierlookups for logging and libwrap use.
14613b9f610SMax LaierBy default,
14713b9f610SMax Laierthe proxy does not look up hostnames for libwrap or logging purposes.
14813b9f610SMax Laier.It Fl t Ar timeout
14913b9f610SMax LaierSpecifies a timeout, in seconds.
15013b9f610SMax LaierThe proxy will exit and close open connections if it sees no data
15113b9f610SMax Laierfor the duration of the timeout.
15213b9f610SMax LaierThe default is 0, which means the proxy will not time out.
15313b9f610SMax Laier.It Fl u Ar user
15413b9f610SMax LaierSpecify the named user to drop privilege to, after doing
15513b9f610SMax Laier.Xr pf 4
15613b9f610SMax Laierlookups which require root privilege.
15713b9f610SMax LaierBy default,
15813b9f610SMax Laier.Nm
15913b9f610SMax Laierdrops privilege to the user
16013b9f610SMax Laier.Em proxy .
16113b9f610SMax Laier.Pp
16213b9f610SMax LaierRunning as root means that the source of data connections the proxy makes
16313b9f610SMax Laierfor PORT and EPRT will be the RFC mandated port 20.
16413b9f610SMax LaierWhen running as a non-root user, the source of the data connections from
16513b9f610SMax Laier.Nm
16613b9f610SMax Laierwill be chosen randomly from the range
16713b9f610SMax Laier.Ar minport
16813b9f610SMax Laierto
16913b9f610SMax Laier.Ar maxport
17013b9f610SMax Laieras described above.
17113b9f610SMax Laier.It Fl V
17213b9f610SMax LaierBe verbose.
17313b9f610SMax LaierWith this option the proxy logs the control commands
17413b9f610SMax Laiersent by clients and the replies sent by the servers to
17513b9f610SMax Laier.Xr syslogd 8 .
17613b9f610SMax Laier.It Fl w
17713b9f610SMax LaierUse the tcp wrapper access control library
17813b9f610SMax Laier.Xr hosts_access 3 ,
17913b9f610SMax Laierallowing connections to be allowed or denied based on the tcp wrapper's
18013b9f610SMax Laier.Xr hosts.allow 5
18113b9f610SMax Laierand
18213b9f610SMax Laier.Xr hosts.deny 5
18313b9f610SMax Laierfiles.
18413b9f610SMax LaierThe proxy does libwrap operations after determining the destination
18513b9f610SMax Laierof the captured control connection, so that tcp wrapper rules may
18613b9f610SMax Laierbe written based on the destination as well as the source of FTP connections.
18713b9f610SMax Laier.El
18813b9f610SMax Laier.Pp
18913b9f610SMax Laier.Nm ftp-proxy
19013b9f610SMax Laieris run from
19113b9f610SMax Laier.Xr inetd 8
19213b9f610SMax Laierand requires that FTP connections are redirected to it using a
19313b9f610SMax Laier.Em rdr
19413b9f610SMax Laierrule.
19513b9f610SMax LaierA typical way to do this would be to use a
19613b9f610SMax Laier.Xr pf.conf 5
19713b9f610SMax Laierrule such as
19813b9f610SMax Laier.Bd -literal -offset 2n
19922ac3eadSMax Laierint_if = \&"xl0\&"
20022ac3eadSMax Laierrdr pass on $int_if proto tcp from any to any port 21 -> 127.0.0.1 port 8021
20113b9f610SMax Laier.Ed
20213b9f610SMax Laier.Pp
20313b9f610SMax Laier.Xr inetd 8
20413b9f610SMax Laiermust then be configured to run
20513b9f610SMax Laier.Nm
20613b9f610SMax Laieron the port from above using
20713b9f610SMax Laier.Bd -literal -offset 2n
208abbfafd2SMax Laierftp-proxy stream tcp nowait root /usr/libexec/ftp-proxy ftp-proxy
20913b9f610SMax Laier.Ed
21013b9f610SMax Laier.Pp
21113b9f610SMax Laierin
21213b9f610SMax Laier.Xr inetd.conf 5 .
21313b9f610SMax Laier.Pp
21413b9f610SMax Laier.Nm
21513b9f610SMax Laieraccepts the redirected control connections and forwards them
21613b9f610SMax Laierto the server.
21713b9f610SMax LaierThe proxy replaces the address and port number that the client
21813b9f610SMax Laiersends through the control connection to the server with its own
21913b9f610SMax Laieraddress and proxy port, where it listens for the data connection.
22013b9f610SMax LaierWhen the server opens the data connection back to this port, the
22113b9f610SMax Laierproxy forwards it to the client.
22213b9f610SMax LaierThe
22313b9f610SMax Laier.Xr pf.conf 5
22413b9f610SMax Laierrules need to let pass connections to these proxy ports
22513b9f610SMax Laier(see options
22613b9f610SMax Laier.Fl u , m ,
22713b9f610SMax Laierand
22813b9f610SMax Laier.Fl M
22913b9f610SMax Laierabove) in on the external interface.
23013b9f610SMax LaierThe following example allows only ports 49152 to 65535 to pass in
23113b9f610SMax Laierstatefully:
23213b9f610SMax Laier.Bd -literal -offset indent
23313b9f610SMax Laierblock in on $ext_if proto tcp all
23413b9f610SMax Laierpass  in on $ext_if inet proto tcp from any to $ext_if \e
23513b9f610SMax Laier    port > 49151 keep state
23613b9f610SMax Laier.Ed
23713b9f610SMax Laier.Pp
23813b9f610SMax LaierAlternatively, rules can make use of the fact that by default,
23913b9f610SMax Laier.Nm
24013b9f610SMax Laierruns as user
24113b9f610SMax Laier.Qq proxy
24213b9f610SMax Laierto allow the backchannel connections, as in the following example:
24313b9f610SMax Laier.Bd -literal -offset indent
24413b9f610SMax Laierblock in on $ext_if proto tcp all
24513b9f610SMax Laierpass  in on $ext_if inet proto tcp from any to $ext_if \e
24613b9f610SMax Laier    user proxy keep state
24713b9f610SMax Laier.Ed
24813b9f610SMax Laier.Pp
24913b9f610SMax LaierThese examples do not cover the connections from the proxy to the
25013b9f610SMax Laierforeign FTP server.
25113b9f610SMax LaierIf one does not pass outgoing connections by default additional rules
25213b9f610SMax Laierare needed.
25313b9f610SMax Laier.Sh SEE ALSO
25413b9f610SMax Laier.Xr ftp 1 ,
25513b9f610SMax Laier.Xr pf 4 ,
25613b9f610SMax Laier.Xr hosts.allow 5 ,
25713b9f610SMax Laier.Xr hosts.deny 5 ,
25813b9f610SMax Laier.Xr inetd.conf 5 ,
25913b9f610SMax Laier.Xr pf.conf 5 ,
26013b9f610SMax Laier.Xr inetd 8 ,
26113b9f610SMax Laier.Xr pfctl 8 ,
26213b9f610SMax Laier.Xr syslogd 8
26313b9f610SMax Laier.Sh BUGS
26413b9f610SMax LaierExtended Passive mode
26513b9f610SMax Laier.Pq EPSV
26613b9f610SMax Laieris not supported by the proxy and will not work unless the proxy is run
26713b9f610SMax Laierin network address translation mode.
26813b9f610SMax LaierWhen not in network address translation mode, the proxy returns an error
26913b9f610SMax Laierto the client, hopefully forcing the client to revert to passive mode
27013b9f610SMax Laier.Pq PASV
27113b9f610SMax Laierwhich is supported.
27213b9f610SMax LaierEPSV will work in network address translation mode, assuming a
27313b9f610SMax Laier.Xr pf.conf 5
27413b9f610SMax Laiersetup which allows the EPSV connections through to their destinations.
27513b9f610SMax Laier.Pp
27613b9f610SMax LaierIPv6 is not yet supported.
277