BSD PF Firewall Block FTP Bruteforce Attacks

I see lots of failed FTP login attempts in my log file. How do I stop FTP bruteforce attack? What should I do to solve this problem under FreeBSD 7.x server operating systems?

You can easily stop bruteforce attacks by limiting connections per IP using pf firewall under FreeBSD or OpenBSD.


Open /etc/pf.conf
# vi /etc/pf.conf

Update it as follows:

# the lists of known FTPD attackers
table <ftp-attacks> persist file "/etc/pf.ftp.block.list"
# block all incoming connections from attackers on FTPD
block in quick on $ext_if from <ftp-attacks>
# Let us allow FTP with bruteforce protection
pass in quick on $ext_if inet proto tcp from any to ($ext_if) port 21 keep state (max-src-conn-rate 5/40, overload <ftp-attacks> flush global)

Above will block FTP connections more than 5 times in 40 seconds. Also append the following line to /etc/rc.shutdown to keep changes after the reboot:
# echo '/sbin/pfctl -t ftp-attacks -T show > /etc/pf.ftp.block.list' >> /etc/rc.shutdown
Finally, reload pf firewall:
# /etc/rc.d/pf reload
To list currently blocked IP (attackers IP), enter:
# pfctl -t ftp-attacks -T show

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

6 comments… add one
  • Shane Aug 13, 2009 @ 9:36

    Will this stop all the FTP brute forcers?

    I see login attempts in the 10’s of thousands on our FTP servers, yet when I look at the number of states created from the attacker IP’s to our FTP servers, the total is often 1 per attacker/server.

    It seems that they open one TCP connection and then keep trying usernames and passwords through that one connection.

  • 🛡️ Vivek Gite (Author and Admin) nixCraft Aug 13, 2009 @ 10:49


    You can configure FTP to drop connection after each failed attempt.

    Another, option is configure keys to login and drop password based login. Or just allow access to vpn authenticated session. Same goes to firewall port and only allow access from limited set of WAN and LAN IPs. However, this will create problem if someone is working from home or using dialup access.

    Finally, strong password is required along with password aging. It all depends upon how much time and money you are willing to put…

  • Shane Aug 13, 2009 @ 12:01

    Hi Vivek,

    Thanks for this. I will see if I can configure our FTP daemon to drop session after failed login.

    Unfortunately we don’t have the luxury of dropping password logins, since we provide last minute adhoc access to clients (who are king in my line of work).

  • SIFE Nov 18, 2009 @ 22:58

    Salamo Alikom
    i have defined a table depend in file ,containt some ip’s to block like so :

    table const file "/etc/pf/banned"

    block in log (all) on $net_card from proto tcp from to any port $ports

    but this does not work ,why ?

  • Tim Jul 25, 2011 @ 13:56

    Could this be combined with some sort of white-list table which is exempt from this rule?
    Also would such a brute force rule be advisable to use for, say a mail gateway – limiting attacks from spamming mail servers?


  • Marc Oct 30, 2011 @ 1:01

    SSHGuard has an interesting comparison of the two approaches for reducing brute force attacks: with plain firewall, or at the application level.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.