carini

Use FTP through SSH tunnel

Nov 6th, 2016
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. Set up a test case to allow FTP through SSH tunnel
  2.  
  3.  
  4. First ... disallow any connection other than SSH, we have to be sure that ftp communicates only through tunnel
  5.  
  6. root@devuan:~# iptables -A OUTPUT -o eth0 -p tcp --dport 22 -j ACCEPT
  7. root@devuan:~# iptables -A OUTPUT -o eth0 -j DROP
  8. root@devuan:~# iptables -A INPUT -i eth0 -p tcp --sport 22 -j ACCEPT
  9. root@devuan:~# iptables -A INPUT -i eth0 -j DROP
  10.  
  11.  
  12. Now set up some parameter on ftp server. We use vsftpd: version 2.3.5
  13.  
  14. root@ftpserver_name:~# diff /etc/vsftpd.conf_orig /etc/vsftpd.conf | grep -v '#'
  15. > pasv_address=127.0.0.1
  16. > pasv_enable=YES
  17. > pasv_min_port=2010
  18. > pasv_max_port=2012
  19.  
  20.  
  21. On client side forward these port to your server
  22.  
  23. ssh -f root@ftpserver_address -N -L 21:ftpserver_address:21 -L 2010:ftpserver_address:2010 -L 2011:ftpserver_address:2011 -L 2012:ftpserver_address:2012
  24.  
  25.  
  26. Then the trick is to make sure that client uses IPv4 only on switch directly to passive mode:
  27.  
  28. root@devuan:~# ftp -4 localhost
  29. Connected to localhost.
  30. 220 This is a private file server.
  31. Name (localhost:administrator): ftp-user
  32. 331 Please specify the password.
  33. Password:
  34. 230 Login successful.
  35. Remote system type is UNIX.
  36. Using binary mode to transfer files.
  37. ftp> passive
  38. Passive mode on.
  39. ftp> put ftptest.PUT
  40. local: ftptest.PUT remote: ftptest.PUT
  41. 227 Entering Passive Mode (127,0,0,1,7,219).
  42. 150 Ok to send data.
  43. 226 Transfer complete.
  44. 47 bytes sent in 0.00 secs (445.6159 kB/s)
  45. ftp> quit
  46. 221 Goodbye.
Advertisement
Add Comment
Please, Sign In to add comment