burngreave.net

Developing Community IT tools
Home   ::    E-mail    ::    FAQ    ::   Projects  :: Contact
Burngreave News  Indymedia Community Networks

Navigation

  • recent posts
  • news aggregator

Browse archives

« July 2008  
Su Mo Tu We Th Fr Sa
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Syndicate

XML feed
Home » blogs » aland's blog

Script to block ssh brute force attacks

My servers are being attacked regulary with ssh brute force attacks. I had 40,000 attempted failed logons over 7 hours from one ip address recently, at the peak it was doing 4 attempts a second.

This script works fine on the Debian Servers
Its very simple and can be run from cron every 15 minutes ( or less ).

It looks for the 'Illegal user' entries in a LOGFILE. If more than BADCOUNT are seen from the same ip address it gets added to hosts.deny ( man 5 hosts_access ) and thus is unable to bother sshd again. root will get mail when it does stuff.

You can make sure it doesn't lock you out by adding your trusted ip addresses to hosts.allow

#!/bin/bash
LOGFILE="/var/log/auth.log"
HOSTSDENY="/etc/hosts.deny"
BADCOUNT="10"
grep "Illegal user" $LOGFILE | cut -d':' -f 7 | cut -d' ' -f1 | sort | uniq -c | while read i
do
        count=`echo $i | cut -d" " -f1`
        ip=`echo $i | cut -d" " -f2`
#       echo "count="$count
#       echo "ip="$ip
        already=`grep $ip $HOSTSDENY | grep sshd`
        if [ -z "$already"  ]
        then
                if [ "$count" -ge "$BADCOUNT" ]
                then
                        echo "banned from sshd: "$ip
                        echo "sshd: "$ip >> $HOSTSDENY
                fi
        fi
done

By aland at 2006-04-16 09:13 | Internet | Open Source | aland's blog | login to post comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

DenyHosts

hi al

i've been using this for a few months:

http://denyhosts.sourceforge.net/

es muy bueno!

bill

By billbest at Thu, 2006-05-11 15:27 | login to post comments

Works on SUSE servers too

for SUSE servers too just change the LOGFILE to /var/log/messages

By aland at Sun, 2006-04-16 10:10 | login to post comments
Any Articles on this site are copylefted Copyright (c) 2003 Burngreave IT Partnership. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

User login



  • Request new password

burngreave.net projects

The burngreave.net  umbrella covers a number of different projects.

  1. Community Area Network
  2. Cafe: - Volunteer PC support for the community at the PC Fixit  Cafe.
  3. Community Radio
  4. BITWork  :- IT consultancy services / workers co-operative
  5. Community ISP services, hosting web sites and email for a number of organisations and bodies.

Burngreave Community Web Sites

Burngreave Community Radio
IRC chat channel
Social Enterprise Community Library
Burngreave Learning Campaign
Burngreave Messenger
New Deal for Communities
Community Area Network

Recent blog posts

  • TLI National Road Race 2008
  • Debunking the deniers
  • The most terrifying video you'll ever see
  • chesterfield to Sheffield via beeley
  • Web 2.0 Privacy and Control - Who has your data ?
  • death threat
  • OLSR and Freifunk use in Burngreave Community Area Network, Sheffield
  • Converting to RAID 1
  • Ideas for treating music
  • backup script
more

Top 20 files

fileverdls
1.BitPartFSfro...11776
2.BurngreaveIn...v0.31591
3.bitpartrepor...1.01352
4.FOABFPARK250...11270
5.Social2.xls21206
6.All people a...Word 20001189
7.Spital-Hill-...11184
8.BurngreaveIn...0.21110
9.BurngreaveIn...0.11098
10.SEBplan16-5-...11026
11.radionetwork...11020
12.CINrifvs1.doc1961
13.Socialfirmri...1937
14.TSCFlyer.doc1891
15.ITSupportEnt...3884
16.Socialfirmri...2880
17.Lindholme Ap...01372
18.italy.png1365
19.NIS_Options_...187