113b9f610SMax Laier.\" $OpenBSD: ftp-proxy.8,v 1.37 2003/09/05 12:27:47 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.\" 3013b9f610SMax Laier.Dd August 17, 2001 3113b9f610SMax Laier.Dt FTP-PROXY 8 3213b9f610SMax Laier.Os 3313b9f610SMax Laier.Sh NAME 3413b9f610SMax Laier.Nm ftp-proxy 3513b9f610SMax Laier.Nd Internet File Transfer Protocol proxy server 3613b9f610SMax Laier.Sh SYNOPSIS 3713b9f610SMax Laier.Nm ftp-proxy 3813b9f610SMax Laier.Op Fl AnrVw 3913b9f610SMax Laier.Op Fl D Ar debuglevel 4013b9f610SMax Laier.Op Fl g Ar group 4113b9f610SMax Laier.Op Fl m Ar minport 4213b9f610SMax Laier.Op Fl M Ar maxport 4313b9f610SMax Laier.Op Fl t Ar timeout 4413b9f610SMax Laier.Op Fl u Ar user 4513b9f610SMax Laier.Sh DESCRIPTION 4613b9f610SMax Laier.Nm 4713b9f610SMax Laieris a proxy for the Internet File Transfer Protocol. 4813b9f610SMax LaierThe proxy uses 4913b9f610SMax Laier.Xr pf 4 5013b9f610SMax Laierand expects to have the FTP control connection as described in 5113b9f610SMax Laier.Xr services 5 5213b9f610SMax Laierredirected to it via a 5313b9f610SMax Laier.Xr pf 4 5413b9f610SMax Laier.Em rdr 5513b9f610SMax Laiercommand. 5613b9f610SMax LaierAn example of how to do that is further down in this document. 5713b9f610SMax Laier.Pp 5813b9f610SMax LaierThe options are as follows: 5913b9f610SMax Laier.Bl -tag -width Ds 6013b9f610SMax Laier.It Fl A 6113b9f610SMax LaierPermit only anonymous FTP connections. 6213b9f610SMax LaierThe proxy will allow connections to log in to other sites as the user 6313b9f610SMax Laier.Qq ftp 6413b9f610SMax Laieror 6513b9f610SMax Laier.Qq anonymous 6613b9f610SMax Laieronly. 6713b9f610SMax LaierAny attempt to log in as another user will be blocked by the proxy. 6813b9f610SMax Laier.It Fl D Ar debuglevel 6913b9f610SMax LaierSpecify a debug level, where the proxy emits verbose debug output 7013b9f610SMax Laierinto 7113b9f610SMax Laier.Xr syslogd 8 7213b9f610SMax Laierat level 7313b9f610SMax Laier.Dv LOG_DEBUG . 7413b9f610SMax LaierMeaningful values of debuglevel are 0-3, where 0 is no debug output and 7513b9f610SMax Laier3 is lots of debug output, the default being 0. 7613b9f610SMax Laier.It Fl g Ar group 7713b9f610SMax LaierSpecify the named group to drop group privileges to, after doing 7813b9f610SMax Laier.Xr pf 4 7913b9f610SMax Laierlookups which require root. 8013b9f610SMax LaierBy default, 8113b9f610SMax Laier.Nm 8213b9f610SMax Laieruses the default group of the user it drops privilege to. 8313b9f610SMax Laier.It Fl m Ar minport 8413b9f610SMax LaierSpecify the lower end of the port range the proxy will use for all 8513b9f610SMax Laierdata connections it establishes. 8613b9f610SMax LaierThe default is 8713b9f610SMax Laier.Dv IPPORT_HIFIRSTAUTO 8813b9f610SMax Laierdefined in 8913b9f610SMax Laier.Aq Pa netinet/in.h 9013b9f610SMax Laieras 49152. 9113b9f610SMax Laier.It Fl M Ar maxport 9213b9f610SMax LaierSpecify the upper end of the port range the proxy will use for the 9313b9f610SMax Laierdata connections it establishes. 9413b9f610SMax LaierThe default is 9513b9f610SMax Laier.Dv IPPORT_HILASTAUTO 9613b9f610SMax Laierdefined in 9713b9f610SMax Laier.Aq Pa netinet/in.h 9813b9f610SMax Laieras 65535. 9913b9f610SMax Laier.It Fl n 10013b9f610SMax LaierActivate network address translation 10113b9f610SMax Laier.Pq NAT 10213b9f610SMax Laiermode. 10313b9f610SMax LaierIn this mode, the proxy will not attempt to proxy passive mode 10413b9f610SMax Laier.Pq PASV or EPSV 10513b9f610SMax Laierdata connections. 10613b9f610SMax LaierIn order for this to work, the machine running the proxy will need to 10713b9f610SMax Laierbe forwarding packets and doing network address translation to allow 10813b9f610SMax Laierthe outbound passive connections from the client to reach the server. 10913b9f610SMax LaierSee 11013b9f610SMax Laier.Xr pf.conf 5 11113b9f610SMax Laierfor more details on NAT. 11213b9f610SMax LaierThe proxy only ignores passive mode data connections when using this flag; 11313b9f610SMax Laierit will still proxy PORT and EPRT mode data connections. 11413b9f610SMax LaierWithout this flag, 11513b9f610SMax Laier.Nm 11613b9f610SMax Laierdoes not require any IP forwarding or NAT beyond the 11713b9f610SMax Laier.Em rdr 11813b9f610SMax Laiernecessary to capture the FTP control connection. 11913b9f610SMax Laier.It Fl r 12013b9f610SMax LaierUse reverse host 12113b9f610SMax Laier.Pq reverse DNS 12213b9f610SMax Laierlookups for logging and libwrap use. 12313b9f610SMax LaierBy default, 12413b9f610SMax Laierthe proxy does not look up hostnames for libwrap or logging purposes. 12513b9f610SMax Laier.It Fl t Ar timeout 12613b9f610SMax LaierSpecifies a timeout, in seconds. 12713b9f610SMax LaierThe proxy will exit and close open connections if it sees no data 12813b9f610SMax Laierfor the duration of the timeout. 12913b9f610SMax LaierThe default is 0, which means the proxy will not time out. 13013b9f610SMax Laier.It Fl u Ar user 13113b9f610SMax LaierSpecify the named user to drop privilege to, after doing 13213b9f610SMax Laier.Xr pf 4 13313b9f610SMax Laierlookups which require root privilege. 13413b9f610SMax LaierBy default, 13513b9f610SMax Laier.Nm 13613b9f610SMax Laierdrops privilege to the user 13713b9f610SMax Laier.Em proxy . 13813b9f610SMax Laier.Pp 13913b9f610SMax LaierRunning as root means that the source of data connections the proxy makes 14013b9f610SMax Laierfor PORT and EPRT will be the RFC mandated port 20. 14113b9f610SMax LaierWhen running as a non-root user, the source of the data connections from 14213b9f610SMax Laier.Nm 14313b9f610SMax Laierwill be chosen randomly from the range 14413b9f610SMax Laier.Ar minport 14513b9f610SMax Laierto 14613b9f610SMax Laier.Ar maxport 14713b9f610SMax Laieras described above. 14813b9f610SMax Laier.It Fl V 14913b9f610SMax LaierBe verbose. 15013b9f610SMax LaierWith this option the proxy logs the control commands 15113b9f610SMax Laiersent by clients and the replies sent by the servers to 15213b9f610SMax Laier.Xr syslogd 8 . 15313b9f610SMax Laier.It Fl w 15413b9f610SMax LaierUse the tcp wrapper access control library 15513b9f610SMax Laier.Xr hosts_access 3 , 15613b9f610SMax Laierallowing connections to be allowed or denied based on the tcp wrapper's 15713b9f610SMax Laier.Xr hosts.allow 5 15813b9f610SMax Laierand 15913b9f610SMax Laier.Xr hosts.deny 5 16013b9f610SMax Laierfiles. 16113b9f610SMax LaierThe proxy does libwrap operations after determining the destination 16213b9f610SMax Laierof the captured control connection, so that tcp wrapper rules may 16313b9f610SMax Laierbe written based on the destination as well as the source of FTP connections. 16413b9f610SMax Laier.El 16513b9f610SMax Laier.Pp 16613b9f610SMax Laier.Nm ftp-proxy 16713b9f610SMax Laieris run from 16813b9f610SMax Laier.Xr inetd 8 16913b9f610SMax Laierand requires that FTP connections are redirected to it using a 17013b9f610SMax Laier.Em rdr 17113b9f610SMax Laierrule. 17213b9f610SMax LaierA typical way to do this would be to use a 17313b9f610SMax Laier.Xr pf.conf 5 17413b9f610SMax Laierrule such as 17513b9f610SMax Laier.Bd -literal -offset 2n 17613b9f610SMax Laierint_if = xl0 17713b9f610SMax Laierrdr on $int_if proto tcp from any to any port 21 -> 127.0.0.1 port 8021 17813b9f610SMax Laier.Ed 17913b9f610SMax Laier.Pp 18013b9f610SMax Laier.Xr inetd 8 18113b9f610SMax Laiermust then be configured to run 18213b9f610SMax Laier.Nm 18313b9f610SMax Laieron the port from above using 18413b9f610SMax Laier.Bd -literal -offset 2n 18513b9f610SMax Laier127.0.0.1:8021 stream tcp nowait root /usr/libexec/ftp-proxy ftp-proxy 18613b9f610SMax Laier.Ed 18713b9f610SMax Laier.Pp 18813b9f610SMax Laierin 18913b9f610SMax Laier.Xr inetd.conf 5 . 19013b9f610SMax Laier.Pp 19113b9f610SMax Laier.Nm 19213b9f610SMax Laieraccepts the redirected control connections and forwards them 19313b9f610SMax Laierto the server. 19413b9f610SMax LaierThe proxy replaces the address and port number that the client 19513b9f610SMax Laiersends through the control connection to the server with its own 19613b9f610SMax Laieraddress and proxy port, where it listens for the data connection. 19713b9f610SMax LaierWhen the server opens the data connection back to this port, the 19813b9f610SMax Laierproxy forwards it to the client. 19913b9f610SMax LaierThe 20013b9f610SMax Laier.Xr pf.conf 5 20113b9f610SMax Laierrules need to let pass connections to these proxy ports 20213b9f610SMax Laier(see options 20313b9f610SMax Laier.Fl u , m , 20413b9f610SMax Laierand 20513b9f610SMax Laier.Fl M 20613b9f610SMax Laierabove) in on the external interface. 20713b9f610SMax LaierThe following example allows only ports 49152 to 65535 to pass in 20813b9f610SMax Laierstatefully: 20913b9f610SMax Laier.Bd -literal -offset indent 21013b9f610SMax Laierblock in on $ext_if proto tcp all 21113b9f610SMax Laierpass in on $ext_if inet proto tcp from any to $ext_if \e 21213b9f610SMax Laier port > 49151 keep state 21313b9f610SMax Laier.Ed 21413b9f610SMax Laier.Pp 21513b9f610SMax LaierAlternatively, rules can make use of the fact that by default, 21613b9f610SMax Laier.Nm 21713b9f610SMax Laierruns as user 21813b9f610SMax Laier.Qq proxy 21913b9f610SMax Laierto allow the backchannel connections, as in the following example: 22013b9f610SMax Laier.Bd -literal -offset indent 22113b9f610SMax Laierblock in on $ext_if proto tcp all 22213b9f610SMax Laierpass in on $ext_if inet proto tcp from any to $ext_if \e 22313b9f610SMax Laier user proxy keep state 22413b9f610SMax Laier.Ed 22513b9f610SMax Laier.Pp 22613b9f610SMax LaierThese examples do not cover the connections from the proxy to the 22713b9f610SMax Laierforeign FTP server. 22813b9f610SMax LaierIf one does not pass outgoing connections by default additional rules 22913b9f610SMax Laierare needed. 23013b9f610SMax Laier.Sh SEE ALSO 23113b9f610SMax Laier.Xr ftp 1 , 23213b9f610SMax Laier.Xr pf 4 , 23313b9f610SMax Laier.Xr hosts.allow 5 , 23413b9f610SMax Laier.Xr hosts.deny 5 , 23513b9f610SMax Laier.Xr inetd.conf 5 , 23613b9f610SMax Laier.Xr pf.conf 5 , 23713b9f610SMax Laier.Xr inetd 8 , 23813b9f610SMax Laier.Xr pfctl 8 , 23913b9f610SMax Laier.Xr syslogd 8 24013b9f610SMax Laier.Sh BUGS 24113b9f610SMax LaierExtended Passive mode 24213b9f610SMax Laier.Pq EPSV 24313b9f610SMax Laieris not supported by the proxy and will not work unless the proxy is run 24413b9f610SMax Laierin network address translation mode. 24513b9f610SMax LaierWhen not in network address translation mode, the proxy returns an error 24613b9f610SMax Laierto the client, hopefully forcing the client to revert to passive mode 24713b9f610SMax Laier.Pq PASV 24813b9f610SMax Laierwhich is supported. 24913b9f610SMax LaierEPSV will work in network address translation mode, assuming a 25013b9f610SMax Laier.Xr pf.conf 5 25113b9f610SMax Laiersetup which allows the EPSV connections through to their destinations. 25213b9f610SMax Laier.Pp 25313b9f610SMax LaierIPv6 is not yet supported. 254