I want to make my ftp server visible only from Tor side.
In regard to the server requirements, there are a few important differences between a hidden FTP service and a regular FTP service. Also, you should check your ftp server software to make sure it doesn't leak your IP address.
Force the client to use passive mode, not active/port mode. In passive mode the client initiates both the control and the data connection. In active mode, the server initiates the data connection. See here for more details. (I think it'd be hard to support active mode, because from the perspective of the ftp server, the client is connecting from localhost, so when the server makes the data connection to the client it will try to connect to localhost. You'd need some serious magic to intercept and redirect that connection, through tor, and to the client's .onion address. So to keep things easy, stick with passive mode.)
To establish the data connection, the server will pick a new port and tell the client to connect to the server at that port. Since tor needs to know about that port range, you'll need to configure the ftp server to use a predefined port range and then add each of the port numbers in that range to a
RFC 959 specifies that the server send the IP address and port number when soliciting a passive mode data connection. Since, from the perspective of the server, the client is localhost, this IP address should be 127.0.0.1. If you configure your ftp server to only bind to the loopback address, then you can be reasonably sure that the server won't send your public IP to the client. If you're paranoid, you can use a tool like
1707 write(0, "227 Entering Passive Mode (127,0,0,1,7,208).\r\n", 46 <unfinished ...>
Here is a concrete example using CentOS 6 and vsftpd (check vsftpd docs here).
- Install vsftpd (
yum install -y vsftpd)
- Disable active mode by appending
- Make sure that vsftpd only binds to localhost, not your public IP address. Append
listen_address=127.0.0.1to vsftpd.conf. For additional safety, reject/drop the ftp port and your chosen data ports at your firewall.
- Force vsftpd to use certain ports for the data connection, by appending these two params to vsftpd.conf:
- Enable and start vsftpd. (
chkconfig vsftpd on; service vsftpd start)
- Test the ftp server by making a local connection. You might have to temporarily disable SElinux (
Configure the FTP service in tor
HiddenServiceDir /var/lib/tor/ftp-service/ HiddenServicePort 21 HiddenServicePort 2000
(you may want to use more than one data port if you expect to support multiple clients at the same time.)
Restart Tor. (
service tor restart)
/var/lib/tor/ftp-service/hostnamefor the hostname of your hidden service.
- Use the tor browser bundle to connect to the hidden ftp service. The Tor wiki talks about it here.
You have to make your FTP server a hidden service. In your torrc, you have to specify:
HiddenServicePort VIRTPORT HSADDRESS:HSPORT
HSDIR is a directory where HS key/data gets stored. Must be r+w for Tor and, as far as I know, by nobody else.
VIRTPORT is the port that clients connect to on your onion address. (You can find your onion address in the directory you specified as
HSADDRESS:HSPORT the address:port where your HS actually listens. You may omit these. By default, this is 127.0.0.1 (same host as your Tor relay) and the port is the same as
See the Tor Manual on hidden services.. Note that this example uses a web server, not an FTP server, but the process is the same.
EDIT: (Because of weasel's comment) - Because of the way the FTP protocol works with setting up data connections, I think it may not be compatible with Tor at all..