Prevent FTP Brute Force Attacks

Prevent FTP Brute Force Attacks


How to prevent FTP Brute Force Attacks from bots on Linux ftp server at port 21.

Yes It is Possible with BFD tool (brute force detection tool), that comes with APF firewall.

It can be configured to block many attacks including ftp and it works with ip tables, CSF firewall or APF firewall.

Installing BFD on Linux

To install BFD, just follow these steps
Download bfd with below wget command and link.


--2015-12-21 14:26:51--
Resolving (
Connecting to (||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21541 (21K) [application/x-gzip]
Saving to: ‘bfd-current.tar.gz’

bfd-current.tar.gz   100%[=========================================================================================================>]  21.04K  54.0KB/s   in 0.4s   

2015-12-21 14:26:54 (54.0 KB/s) - ‘bfd-current.tar.gz’ saved [21541/21541]

Then Extract “bfd-current.tar.gz”

tar -zxf bfd-current.tar.gz

After extract, go to the bfd folder

cd bfd-1.5-2/

and run the file


and the BFD is installed in this path, by default.

Main executable —> /usr/local/bfd/bfd
BFD config file —> /usr/local/bfd/bfd/conf.bfd
BFD Rules for ftp —> /usr/local/bfd/rules/proftpd

BFD Configuration

Just open /usr/local/bfd/conf.bfd and make small changes to the file like how many number of failed attempts, and which firewall executable.

vi /usr/local/bfd/conf.bfd
# BFD 1.5-2 <>
# Copyright (C) 1999-2014, R-fx Networks <>
# Copyright (C) 2014, Ryan MacDonald <>
# This program may be freely redistributed under the terms of the GNU GPL
# NOTE: This file should be edited with word/line wrapping off,
#       if your using pico please start it with the -w switch.
#       (e.g: pico -w filename)

# how many failure events must an address have before being blocked?
# you can override this on a per rule basis in /usr/local/bfd/rules/

# send email alerts for all events [0 = off; 1 = on]

# local user or email address alerts are sent to (separate multiple with comma)

# subject of email alerts
EMAIL_SUBJECT="Brute Force Warning for $HOSTNAME"

# executable command to block attacking hosts
#BAN_COMMAND="/etc/apf/apf -d $ATTACK_HOST {bfd.$MOD}"
# You should not need to edit any options below this line

# installation path

# rule files path

# track log script path

# syslog kernel log path

# syslog auth log path

# bfd application log path

# log all events to syslog [0 = off; 1 = on]

# log file path for syslog logging

# template of the email message body

# contains list of files to search for addresses that are excluded from bans

# grab the local time zone
TIME_ZONE=`date +"%z"`

# grab the local unix time
TIME_UNIX=`date +"%s"`

# lock file path

# lock file timeout

(i) Number of failure attempts

# how many failure events must an address have before being blocked?
# you can override this on a per rule basis in /usr/local/bfd/rules/

(ii) Set the BAN COMMAND executable
 If you use want to use CSF firewall to block the IP address temporarily block IP for 600 seconds.
 Note: If you remove the 600 (ttl time), the IP address will be banned permanently.
 BAN_COMMAND=”/usr/sbin/csf -d $ATTACK_HOST 600″
 If you are using APF firewall use, this command
 BAN_COMMAND=”/usr/sbin/apf -d $ATTACK_HOST 600″
 To use system route command, to drop the packet, use
 BAN_COMMAND=”route add -host $ATTACK_HOST reject”
 If you are using IP tables, use this line
 Note: Be careful that you dont block your IP address, If you are unsure dont use the above IP table comand, and set the IP block to temporary.

Starting up BFD

To launch the BFD, use the following commands..

——> (quiet mode)

/usr/local/bfd/bfd -q

—–> (standard with output)

/usr/local/bfd/bfd -s

——> (to list attacking hosts)

/usr/local/bfd/bfd -a


Finally, check your firewall deny file,
whether the attacking IP address are listed properly.

cat /etc/csf/csf.deny
cat /etc/apf/apf.deny

Was this article helpful? [ratings] You have any suggestions or question feel free to ask in comment.

Author: Hitesh Satarkar

Hitesh Satarkar currently working as a Linux/Unix administrator. But I also play Windows both in server and desktop area. Interested in information technology, information security and writing.

Leave a Reply

Notify of