From 97f48991a2f8a0f77644d7a1c76078fee65b5aa5 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 20 Jan 2009 21:24:33 +0000 Subject: [PATCH 01/15] - Remove socket file on startup is fail2ban crashed. Thanks to Detlef Reichelt. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@718 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- ChangeLog | 2 ++ files/suse-initd | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index c6a39d87..1773cc77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,8 @@ ver. 0.8.4 (2008/??/??) - stable - Added/improved filters and date formats. - Added actions to report abuse to ISP, DShield and myNetWatchman. Thanks to Russell Odom. +- Suse init script. Remove socket file on startup is fail2ban + crashed. Thanks to Detlef Reichelt. ver. 0.8.3 (2008/07/17) - stable ---------- diff --git a/files/suse-initd b/files/suse-initd index ecd55d9a..1dec63e2 100755 --- a/files/suse-initd +++ b/files/suse-initd @@ -35,6 +35,13 @@ rc_reset case "$1" in start) echo -n "Starting Fail2Ban " + # a cleanup workaround, since /etc/init.d/boot.local removes only. + # regular files, and not sockets + if test -e $FAIL2BAN_SOCKET; then + if ! lsof -n $FAIL2BAN_SOCKET &>/dev/null; then + rm $FAIL2BAN_SOCKET + fi + fi /sbin/startproc $FAIL2BAN_BIN start &>/dev/null rc_status -v ;; From 870f9d9ea751a3aa6200318a249807de91b23b5c Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 20 Jan 2009 21:48:04 +0000 Subject: [PATCH 02/15] - Removed begin-line anchor for "standard" timestamp. Fixed Debian bug #500824. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@719 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- ChangeLog | 2 ++ server/datedetector.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1773cc77..2cd36723 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,8 @@ ver. 0.8.4 (2008/??/??) - stable myNetWatchman. Thanks to Russell Odom. - Suse init script. Remove socket file on startup is fail2ban crashed. Thanks to Detlef Reichelt. +- Removed begin-line anchor for "standard" timestamp. Fixed + Debian bug #500824. ver. 0.8.3 (2008/07/17) - stable ---------- diff --git a/server/datedetector.py b/server/datedetector.py index e68e5bce..87c87837 100644 --- a/server/datedetector.py +++ b/server/datedetector.py @@ -44,7 +44,7 @@ class DateDetector: # standard template = DateStrptime() template.setName("MONTH Day Hour:Minute:Second") - template.setRegex("^\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}") + template.setRegex("\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}") template.setPattern("%b %d %H:%M:%S") self.__templates.append(template) # asctime From 024a77a679178a13cb2c3a52574a567303fdb68d Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 20 Jan 2009 23:08:59 +0000 Subject: [PATCH 03/15] - Removed print. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@720 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- server/datetemplate.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/datetemplate.py b/server/datetemplate.py index f7f19f0d..6ed61efa 100644 --- a/server/datetemplate.py +++ b/server/datetemplate.py @@ -132,7 +132,7 @@ class DateStrptime(DateTemplate): conv = self.convertLocale(dateMatch.group()) try: date = list(time.strptime(conv, self.getPattern())) - except ValueError: + except ValueError, e: # Try to add the current year to the pattern. Should fix # the "Feb 29" issue. conv += " %s" % MyTime.gmtime()[0] @@ -187,6 +187,5 @@ class DateISO8601(DateTemplate): if dateMatch: # Parses the date. value = dateMatch.group() - print value date = list(iso8601.parse_date(value).utctimetuple()) return date From 756cfcda5f7eee63419d943d3cf93275294836bf Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 27 Jan 2009 22:58:29 +0000 Subject: [PATCH 04/15] - Added nagios script. Thanks to Sebastian Mueller. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@721 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- ChangeLog | 1 + MANIFEST | 2 + files/nagios/check_fail2ban | 106 ++++++++++++++++++++++++++++++++++++ files/nagios/f2ban.txt | 18 ++++++ 4 files changed, 127 insertions(+) create mode 100644 files/nagios/check_fail2ban create mode 100644 files/nagios/f2ban.txt diff --git a/ChangeLog b/ChangeLog index 2cd36723..46fd5f1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ ver. 0.8.4 (2008/??/??) - stable crashed. Thanks to Detlef Reichelt. - Removed begin-line anchor for "standard" timestamp. Fixed Debian bug #500824. +- Added nagios script. Thanks to Sebastian Mueller. ver. 0.8.3 (2008/07/17) - stable ---------- diff --git a/MANIFEST b/MANIFEST index 1ea7a621..39ca0df8 100644 --- a/MANIFEST +++ b/MANIFEST @@ -116,3 +116,5 @@ files/suse-initd files/cacti/fail2ban_stats.sh files/cacti/cacti_host_template_fail2ban.xml files/cacti/README +files/nagios/check_fail2ban +files/nagios/f2ban.txt diff --git a/files/nagios/check_fail2ban b/files/nagios/check_fail2ban new file mode 100644 index 00000000..0b40db53 --- /dev/null +++ b/files/nagios/check_fail2ban @@ -0,0 +1,106 @@ +#!/bin/bash +# +# Usage: ./check_fail2ban +############################################################################################### +# Description: +# This plugin will check the status of Fail2ban. +# +# Created: 2008-10-25 (Sebastian Mueller) +# +# Changes: 2008-10-26 fixed some issues (Sebastian Mueller) +# Changes: 2009-01-25 add the second check, when server is not replying and the +# process is hang-up (Sebastian Mueller) +# +# please visit my website http://www.elchtest.eu or my personal WIKI http://wiki.elchtest.eu +# +################################################################################################ +# if you have any questions, send a mail to linux@krabbe-offline.de +# +# this script is for my personal use. read the script before running/using it!!! +# +# +# YOU HAVE BEEN WARNED. THIS MAY DESTROY YOUR MACHINE. I ACCEPT NO RESPONSIBILITY. +############################################################################################### + + +SECOND_CHECK=0 +STATE_OK=0 +STATE_CRITICAL=2 + +###################################################################### +# Read the Status from fail2ban-client +###################################################################### +check_processes_fail2ban() +{ + + F2B=`sudo -u root fail2ban-client ping | awk -F " " '{print $3}'` + exit_fail2ban=0 + + if [[ $F2B = "pong" ]]; then + exit_fail2ban=$STATE_OK + else + exit_fail2ban=$STATE_CRITICAL + fi + +} +###################################################################### +# first check in the Background, PID will be killed when no response +# after 10 seconds, might be possible, otherwise the scipt will be +# pressent in your memory all the time +# +###################################################################### + +check_processes_fail2ban & +pid=$! + +typeset -i i=0 +while ps $pid >/dev/null +do + sleep 1 + i=$i+1 +if [ $i -ge 10 ] + then + kill $pid + SECOND_CHECK=1 + exit_fail2ban=$STATE_CRITICAL + break +fi +done + +###################################################################### +# when the Server response (doesent mean the FAIL2BAN is working) +# in the first step, then it will run again and test the Service +# and provide the real status +###################################################################### + + +if [ $SECOND_CHECK -eq 0 ]; then + check_processes_fail2ban + elif [ $SECOND_CHECK -eq 1 ]; then + exit_fail2ban=$STATE_CRITICAL +fi + + + +###################################################################### +# Mainmenu +###################################################################### + + +final_exit=$exit_fail2ban +if [ $final_exit -eq 0 ]; then + echo "SYSTEM OK - Fail2ban is working normaly" + exitstatus=$STATE_OK +elif [ $final_exit -ne "0" ]; then + echo "SYSTEM WARNING - Fail2Ban is not working" +###################################################################### +# If don't have a Nagios Server for monitoring, remove the comment and +# add your Mail Addres. You can check it with a Cron Job once a hour. +# put a txt file on your server and describe how to fix the issue, this +# could be attached to the mail. +###################################################################### +# mutt -s "FAIL2BAN NOT WORKING" your@email.com < /home/f2ban.txt + + exitstatus=$STATE_CRITICAL +fi +exit $exitstatus diff --git a/files/nagios/f2ban.txt b/files/nagios/f2ban.txt new file mode 100644 index 00000000..a811cd5d --- /dev/null +++ b/files/nagios/f2ban.txt @@ -0,0 +1,18 @@ +It seems that Fail2ban is currently not working, please login and check + +HELP: + +1.) stop the Service +/etc/init.d/fail2ban stop + +2.) delete the socket if avalible +rm /tmp/fail2ban.sock + +3.) start the Service +/etc/init.d/fail2ban start + +4.) check if fail2ban is working +fail2ban-client ping +Answer should be "pong" + +5.) if the answer is not "pong" run away or CRY FOR HELP ;-) From 6b9896c332057455e91f0e79a36e50400d89cb4c Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 27 Jan 2009 23:21:55 +0000 Subject: [PATCH 05/15] - Added CPanel date format. Thanks to David Collins. Tracker #1967610. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@722 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- ChangeLog | 2 ++ server/datedetector.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index 46fd5f1f..fe73c096 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,8 @@ ver. 0.8.4 (2008/??/??) - stable - Removed begin-line anchor for "standard" timestamp. Fixed Debian bug #500824. - Added nagios script. Thanks to Sebastian Mueller. +- Added CPanel date format. Thanks to David Collins. Tracker + #1967610 ver. 0.8.3 (2008/07/17) - stable ---------- diff --git a/server/datedetector.py b/server/datedetector.py index 87c87837..6ee6870d 100644 --- a/server/datedetector.py +++ b/server/datedetector.py @@ -77,6 +77,12 @@ class DateDetector: template.setRegex("\d{2}/\S{3}/\d{4}:\d{2}:\d{2}:\d{2}") template.setPattern("%d/%b/%Y:%H:%M:%S") self.__templates.append(template) + # CPanel 05/20/2008:01:57:39 + template = DateStrptime() + template.setName("Month/Day/Year:Hour:Minute:Second") + template.setRegex("\d{2}/\d{2}/\d{4}:\d{2}:\d{2}:\d{2}") + template.setPattern("%m/%d/%Y:%H:%M:%S") + self.__templates.append(template) # Exim 2006-12-21 06:43:20 template = DateStrptime() template.setName("Year-Month-Day Hour:Minute:Second") From e46e8ed32e2adc68dda08695ea65202fb9b296f3 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 27 Jan 2009 23:35:46 +0000 Subject: [PATCH 06/15] - Improved SASL filter. Thanks to Loic Pefferkorn. Tracker #2310410. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@723 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- ChangeLog | 4 +++- config/filter.d/sasl.conf | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe73c096..6150aea7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,7 +26,9 @@ ver. 0.8.4 (2008/??/??) - stable Debian bug #500824. - Added nagios script. Thanks to Sebastian Mueller. - Added CPanel date format. Thanks to David Collins. Tracker - #1967610 + #1967610. +- Improved SASL filter. Thanks to Loic Pefferkorn. Tracker + #2310410. ver. 0.8.3 (2008/07/17) - stable ---------- diff --git a/config/filter.d/sasl.conf b/config/filter.d/sasl.conf index c25aca6b..bff6f92b 100644 --- a/config/filter.d/sasl.conf +++ b/config/filter.d/sasl.conf @@ -14,7 +14,7 @@ # (?:::f{4,6}:)?(?P\S+) # Values: TEXT # -failregex = : warning: [-._\w]+\[\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed$ +failregex = (?i): warning: [-._\w]+\[\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [A-Za-z0-9+/]*={0,2})?$ # Option: ignoreregex # Notes.: regex to ignore. If this regex matches, the line is ignored. From e16c18d091e0142ed906a77533a162ad092d21aa Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 27 Jan 2009 23:39:38 +0000 Subject: [PATCH 07/15] - Added NetBSD ipfilter (ipf command) action. Thanks to Ed Ravin. Tracker #2484115. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@724 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- ChangeLog | 2 ++ MANIFEST | 1 + config/action.d/ipfilter.conf | 57 +++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 config/action.d/ipfilter.conf diff --git a/ChangeLog b/ChangeLog index 6150aea7..1b6b6138 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,8 @@ ver. 0.8.4 (2008/??/??) - stable #1967610. - Improved SASL filter. Thanks to Loic Pefferkorn. Tracker #2310410. +- Added NetBSD ipfilter (ipf command) action. Thanks to Ed + Ravin. Tracker #2484115. ver. 0.8.3 (2008/07/17) - stable ---------- diff --git a/MANIFEST b/MANIFEST index 39ca0df8..00040912 100644 --- a/MANIFEST +++ b/MANIFEST @@ -83,6 +83,7 @@ config/action.d/complain.conf config/action.d/dshield.conf config/action.d/hostsdeny.conf config/action.d/ipfw.conf +config/action.d/ipfilter.conf config/action.d/iptables.conf config/action.d/iptables-allports.conf config/action.d/iptables-multiport.conf diff --git a/config/action.d/ipfilter.conf b/config/action.d/ipfilter.conf new file mode 100644 index 00000000..991d9e58 --- /dev/null +++ b/config/action.d/ipfilter.conf @@ -0,0 +1,57 @@ +# Fail2Ban configuration file +# +# NetBSD ipfilter (ipf command) ban/unban +# +# Author: Ed Ravin +# +# + +[Definition] + +# Option: actionstart +# Notes.: command executed once at the start of Fail2Ban. +# Values: CMD +# +# enable IPF if not already enabled +actionstart = /sbin/ipf -E + + +# Option: actionstop +# Notes.: command executed once at the end of Fail2Ban +# Values: CMD +# +# don't disable IPF with "/sbin/ipf -D", there may be other filters in use +actionstop = + + +# Option: actioncheck +# Notes.: command executed once before each actionban command +# Values: CMD +# +actioncheck = + + +# Option: actionban +# Notes.: command executed when banning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: IP address +# number of failures +#