DenySSH: Block SSH brute force attacks using PF

Thursday July 27, 2006 @ 09:30 PM (PDT)

DenySSH is a Ruby application that monitors the auth log of a BSD system for failed SSH login attempts and adds repeat attackers to a Packet Filter table, allowing you to define PF rules to block the attacking hosts or redirect them to a honeypot for your amusement.

There are already a few excellent tools that do almost the same thing, but none of them use PF to block attackers, which makes them less useful to someone like me. Thus, I wrote this.

It's not quite finished yet (I still need to write some documentation), but I've been using it on my servers for several months now and it works well. If you'd like to try it out, you can grab it from the Subversion repository.

Comments

Hey Wonko,

I do something similar with PF. But I simply monitor for syn packets on port 22. Too many in too short of a period of time and you get dropped into a black list table.

##### Table to hold loser script kiddies tring to brute force ssh logins
table persist file "/etc/pf_bruteforce"


#This should block anyone who tries to make more than 10 ssh connection in 60 seconds or more than 100 simultaneus total connections
pass in on $ExtIF proto tcp to $ExtIF port ssh flags S/SA keep state \
(max-src-conn 100, max-src-conn-rate 8/60, \
overload /etc/pf_bruteforce

I add a small cronjob to save the list:
pfctl -t bruteforce -T show (GREATER THAN SIGN)/etc/pf_bruteforce

Autoformat no-likey the greater than sign. BTW, This wasn't an original idea. I modified something that I lifted from the old interweb.

Also my poor pf deprived linux friends have been using fail2ban for a while. It uses authlog much like your script.

Cheers.

P.S. Congrats on the new WRX. Don't get too arrested. ;)
Gravatar icon
Rednerd
Saturday September 16, 2006 @ 11:05 AM (PDT)

The simpliest way to protect ssh from brute force is to install pam_abl. For interested, I've builded packages for ubuntu:
http://tech.tolero.org/blog/en/linux/ssh-password-brute-force-protection

Gravatar icon
Wednesday February 14, 2007 @ 07:38 AM (PST)

How simple is it to get pam_abl running in FreeBSD?

Gravatar icon
Wednesday February 14, 2007 @ 08:57 AM (PST)
-rw-rw-rw- 1 root wheel 7363 Mar 13 00:43 /var/db/denyssh/hosts.yaml

Perhaps not so good?
Gravatar icon
Tor
Monday March 12, 2007 @ 04:46 PM (PDT)

Ack. Stupid mistake. I've checked a fix into SVN.

Thanks for the heads up, Tor, but in the future, please send me an email and give me an hour or two to release a fix before you publicly announce something like this. You have every right to announce these things publicly of course, but I'd appreciate the courtesy and I think other DenySSH users would appreciate having a fix available before the whole world learns about the problem.

Gravatar icon
Monday March 12, 2007 @ 06:36 PM (PDT)
Wasn't thinking; sorry all!

However, I have been thinking about what it would take to expand DenySSH's functionality so that it can update depending on reject messages in the mail log. Gives me a good reason to look into this Ruby thing too.

Thanks for providing us with DenySSH, btw.
Gravatar icon
Tor
Friday March 16, 2007 @ 02:16 PM (PDT)

"update depending"? Insert 'the table' between those two words. Jeez.

Gravatar icon
Tor
Friday March 16, 2007 @ 02:22 PM (PDT)

table == 'spamd pf table' (and this time i will preview the post before committing =P).

Gravatar icon
Tor
Friday March 16, 2007 @ 02:25 PM (PDT)
No worries. :)

If you want something similar to DenySSH that'll monitor a mail log, check out DenySpam. It's also in a pre-release state, but I've been doing a lot of work on it lately, and like DenySSH, I've been using it successfully on my servers for quite a while.
Gravatar icon
Friday March 16, 2007 @ 02:26 PM (PDT)

Well dang, you've already done it. I'll take a look, thanks!

Gravatar icon
Tor
Friday March 16, 2007 @ 02:46 PM (PDT)

helo mate, thats great tuto.. but i have sick to blocking syn fin nmap, you know to block the syn fin using PF freebsd? thanx anyway.. :)

Gravatar icon
Sunday October 19, 2008 @ 07:30 AM (PDT)

@Rednerd your linux friends do not need any extra software, they can use built in iptables rules:

http://kevin.vanzonneveld.net/techblog/article/block_brute_force_attacks_with_iptables/

Gravatar icon
Saturday December 13, 2008 @ 02:45 PM (PST)

You have to be careful with log analyzers. They are subject to log injection attacks and can make a minor problem worse.
http://www.ossec.net/main/attacking-log-analysis-tools

I use IPtables on Linux not sure what’s a similar option on BSD?

Gravatar icon
Wednesday January 27, 2010 @ 05:08 PM (PST)
New comment

required, won't be displayed

optional

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

Copyright © 2002-2010 Ryan Grove. All rights reserved.
Powered by Thoth.