Preventing Brute Force Attacks With BlockHosts On Debian Etch
Preventing Brute Force Attacks With BlockHosts On Debian EtchVersion 1.0 In this article I will show how to install and configure BlockHosts on a Debian Etch system. BlockHosts is a Python tool that observes login attempts to various services, e.g. SSH, FTP, etc., and if it finds failed login attempts again and again from the same IP address or host, it stops further login attempts from that IP address/host. By default, BlockHosts supports services that use TCP_WRAPPERS, such as SSH, i.e. services, that use /etc/hosts.allow or /etc/hosts.deny, but it can also block other services using iproute or iptables. This document comes without warranty of any kind! I do not issue any guarantee that this will work for you!
1 Preliminary NoteI have tested BlockHosts on a Debian Etch system. I will show you how to to use it with a service that uses /etc/hosts.allow or /etc/hosts.deny (sshd) and with a service that doesn't use TCP_WRAPPERS, e.g. Debian's ProFTPd package. Services that don't use /etc/hosts.allow or /etc/hosts.deny can be blocked by iproute or iptables. I assume that OpenSSH and ProFTPd are both properly installed and working on your system.
2 Installing BlockHostsAs BlockHosts is written in Python, we must install Python now: apt-get install python Afterwards, we download and install BlockHosts like this: cd /tmp python setup.py install --force Now we have to edit /etc/blockhosts.cfg. Modify it as follows: vi /etc/blockhosts.cfg
In HOSTS_BLOCKFILE we can specify either /etc/hosts.allow or /etc/hosts.deny. It doesn't matter which one we choose. I'm using /etc/hosts.allow here. In the LOGFILES line we specify the log files that BlockHosts should look at. OpenSSH is logging failed login attempts to /var/log/auth.log, ProFTPd to /var/log/proftpd/proftpd.log. COUNT_THRESHOLD specifies the number of failed login attempts from the same host after which BlockHosts should block that host. AGE_THRESHOLD is the numer of hours after which blocked hosts get unblocked. IPBLOCK specifies if you'd like to block hosts with iptables or iproute in addition to adding these hosts to /etc/hosts.allow (or /etc/hosts.deny). Next we must modify /etc/hosts.allow. First back up your current /etc/hosts.allow: cp /etc/hosts.allow /etc/hosts.allow_orig Then empty /etc/hosts.allow and put something like this into it: cat /dev/null > /etc/hosts.allow
In the first section you put hosts that you want to whitelist (e.g. 127.0.0.1). If you'd like to whitelist the whole 192.168.0 subnet, uncomment that line. Then we must add these markers - BlockHosts will add blocked hosts between them: #---- BlockHosts Additions The most important part is this one: sshd: ALL: spawn /usr/bin/blockhosts.py --verbose --mail --iptables \ Now whenever someone tries to log in using SSH, /usr/bin/blockhosts.py is started, checks the log files that we specified in /etc/blockhosts.cfg, and blocks all hosts with more than COUNT_THRESHOLD failed login attempts by adding them to /etc/hosts.allow and by using iptables (which will totally block these hosts from accessing your system). All actions will be logged to /var/log/blockhosts.log. Now we need to initialize BlockHosts. First, we do this with the --dry-run option to see if there are no errors: blockhosts.py --dry-run --verbose The output could look like this: server2:/var/log# blockhosts.py --dry-run --verbose #bh: logfile: /var/log/proftpd/proftpd.log #---- BlockHosts Additions # ---------------------------------------- sshd, proftpd, vsftpd: ALL: spawn /usr/bin/blockhosts.py --verbose --mail \ #--- # See "man hosts.allow" for info on %c and %s identifiers # for non-verbose, with identification, to syslog only (/var/log/messages), # ------------------------------------------------------------------------- Looks ok (apart from the IPv6 error which you can ignore), so we can run it without the --dry-run option: blockhosts.py --verbose This should look like this: server2:/var/log# blockhosts.py --verbose BlockHosts is now ready to check for failed SSH logins, but not for failed ProFTPd logins because Debian's ProFTPd doesn't check /etc/hosts.allow and /etc/hosts.deny, which means BlockHosts isn't invoked when someone tries to log in to ProFTPd (of course, if someone has COUNT_THRESHOLD or more failed log in attempts on ProFTPD and then tries to log in to OpenSSH, he will be blocked, because OpenSSH uses /etc/hosts.allow which then invokes BlockHosts which finds the failed login attempts to ProFTPd; but if someone tries to log in to ProFTPd only, there's no way to catch him with the current setup). To block non-TCP_WRAPPERS services, we will create a cron job that starts BlockHosts every five minutes (for example).
|
www.seamlessenterprise.com
One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com
One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com
One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com
One number. one voicemail. Seize the lead with Sprint. Learn more
AT&T Synaptic Compute as a Service. Boost your power on demand.
Trial: IBM Cognos Express Reporting, Analysis & Planning
Learn benefits of Simpana software.
View the Gartner Video
Sprint 4G - The Ultimate Mobile Broadband
Click here
SAP-Business Objects Crystal Reports Server
Complete reporting without hidden costs. Free Trial




print: 

Recent comments
14 hours 18 min ago
19 hours 29 min ago
20 hours 18 min ago
21 hours 2 min ago
1 day 7 hours ago
1 day 8 hours ago
1 day 19 hours ago
2 days 3 hours ago
2 days 5 hours ago
2 days 5 hours ago