SSH brute force attacks

February 24th, 2010

Yet again I find myself trying to solve the same problem I have been faced with over and over for the last 10 years I have been working with Linux.  How do I stop SSH brute force attacks? I’m pondering this because I logged into one of my systems to discover a brute force attack in progress.  Again…

I know I can install snort and use a complicated set of tools to detect an attack and add firewall rules.  I also know I can implement port knocking or some other complicated means of making SSH unavailable to attackers. All of this seems a little overblown.  It’s probably because someone started working on a way of detecting attacks and featureitis set in.

I keep coming back to the question of what the real problem is that I am solving.  Most of the attacks I am concerned with are dictionary attacks.  An attacker discovers I am listening on SSH and proceeds to try every username and password combination he can think of.

What information do I have?  What information can I gather?

The easiest thing I can think of is to watch /var/log/secure.  Every failed login attempt gets logged with a time, IP and user.  Using popen(“tail -f /var/log/secure”) I can inspect each line of the log as it comes through.  Each time I get a match for a bad user login I can add it to a database.  When a particular IP has too many failed attempts in the last N minutes the IP can be added to a special blacklist table in iptables with a drop rule.

I’m out of time for right now, but a package will be forth coming.  I have gotten this blacklist behavior in only 130 lines of code.  This includes parsing command line options and becoming a daemon in the background.

I call that a win.

Document oriented databases

February 24th, 2010

After many years of deploying and using relational databae management systems as my primary method of storing and retrieving data I was recently introduced to the concept of document oriented databases.  The first one I was introduced to is MongoDB followed shortly by CouchDB.

I have been working with MongoDB for a client of mine and I have been learning quite a bit.  Out of the two Mongo is much more friendly to new users who have no idea what is going on.  The Mongo interactive shell is a great tool that will give you enough access to MongoDB to allow you to start learning about it.

CouchDB looks interesting.  I know I’m a fan of Erlang so it would seem natural that I should be more interested in applications that were written in Erlang, but it just doesn’t seem as accessible as MongoDB.  Though, I still need to evaluate more before I decide to just use one or the other.  For some of my smaller projects where I want minimal overhead I think I’ll be looking at Mongo.  It is entirely possible that CouchDB has a big win hiding in there once you get past the larger learning curve.  I’ll attack that sometime after I finish bending my mind into the document oriented database way of looking at things.