Re: Dictionary sshd attacks

From: James T (turajb_at__NOSPAM_hoflink.com)
Date: 07/17/05


Date: Sun, 17 Jul 2005 14:19:59 -0400

On Sat, 16 Jul 2005 20:38:04 +0000, Wayne wrote:

> Is it possible to have sshd or some other daemon recognize
> a dictionary attack in progress, and to "shun" that IP for
> (say) an hour? The machanics seem simple to me: A log file
> reader spots the pattern in real time and issues an iptables
> command to DROP port 22 packets from the identified IP address,
> sends a syslog message, and creates an "at" job to remove the
> iptabes rule after some period of time. A more sophisticated
> tool could continue to monitor the logs for the attack and only
> reactivate the port after X minutes after the attack ends.
>
> I know I've read of such tools someplace before, but I can't
> remember any details.
>
> Some of my servers have been under attack for many months now.
> Sometimes twice a day, hundreds to thousands of ssh connections
> are attempted using a dictionary of common usernames.
>
> I have been saving the logs but no pattern has emerged yet
> from the IP addresses. Of course they don't get in (yet),
> but I'd like a more automatic way to respond to such attacks.
>
> Lessons learned:
>
> Have account naming policies that forbid usernames that commonly
> appear in dictionary attacks.
>
> Make sure *all* system accounts are disabled, and where possible
> have invalid shells (such as /bin/false or /sbin/nologin).
>
> Never allow sshd (or other) root logins.
>
> Configure the PAM "su" policy to only allow a few select users to
> succeed with the su command. (The members of group "wheel".) Other
> users who attempt "su" will fail even if they know the password.
>
> -Wayne

I have elected to take a different approach.

1 - in the SSH config file, I restrict login ability to specific grouped
users, specific usernames or specific IP/subnets (this depends upon the
type of system I'm protection and who uses it)

2 - I have a perl script cronned to run once a minute which tails the SSH
log and looks for login failures. If a certain number of failures are
seen on a specific IP address or against a specific username, it puts the
user's IP address(es) in the hosts.deny file (this restricting their login
access). It also logs the blocking, and emails me info about the
offending IP address or username being used - so I can review further if I
want to.

3 - If I should want to unblock the blocked IPs on a specific box, I have
another script which can be cronned to auto-unblock IPs after X time or
can be used manually to unblock a specific IP/subnet.

With this home grown solution in place, I never have to worry about those
types of ssh attacks. I mostly address unblock requests manually.
With the amount of users on my servers, it is not much work at all. I can
also customize the solution as things situations change.

I hope this helps give you an alternate solution to your issue.

James



Relevant Pages

  • RE: Trace of 139 attack?
    ... Subject: Trace of 139 attack? ... The Administrator account can be locked out if too many ... deleting the logs he cannot do it. ...
    (Focus-Microsoft)
  • RE: Trace of 139 attack?
    ... Subject: Trace of 139 attack? ... > deleting the logs he cannot do it. ... > If this box of yours is a web server to the world, ... > use it as file server with NetBIOS shares 'n stuff. ...
    (Focus-Microsoft)
  • RE: RE: Help! Red hat doesnt recognize any usernames!
    ... They looked to be fine, permissions, etc. ... I thoroughly went through the logs, ... I chalk it up to a red hat bug. ... Red hat doesn't recognize any usernames! ...
    (RedHat)
  • Re: Auto Populating Blocked IPs List
    ... I just checked my security logs - which I save - and I see ... The earlies attacks were trying to almost invariably login as ... >IP blocks their ISP is handing out and allow only those. ... Bill Vermillion - bv @ wjv. ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Last Login
    ... The table "tblLastLogin" gets updated when ... intCount gets successfully populated with the number of stories since last ... login but intLastLogin does not get updated, ... If it gets updated as soon as the publisher logs in, ...
    (microsoft.public.access.queries)