From 26a762ac942519bdacaac7a7ddd15d20b07fed17 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Thu, 4 Jan 2007 23:34:35 +0000 Subject: [PATCH 01/29] - Added signal handling in fail2ban-client - Added a wonderful visual effect when waiting on the server - Improved error message. Thanks to Yaroslav Halchenko git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@515 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 7 ++++++- fail2ban-client | 40 ++++++++++++++++++++++++++++++++++++---- fail2ban-server | 2 +- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 71983906..65285a81 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,9 +4,14 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.7.6) 2007/01/04 +Fail2Ban (version 0.7.7) 2007/??/?? ============================================================= +ver. 0.7.7 (2007/??/??) +---------- +- Added signal handling in fail2ban-client +- Added a wonderful visual effect when waiting on the server + ver. 0.7.6 (2007/01/04) - beta ---------- - Added a "sleep 1" in redhat-initd. Thanks to Jim Wight diff --git a/fail2ban-client b/fail2ban-client index 14aeabd0..52103d19 100755 --- a/fail2ban-client +++ b/fail2ban-client @@ -25,7 +25,7 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -import sys, string, os, pickle, re, logging +import sys, string, os, pickle, re, logging, signal import getopt, time, readline, shlex, socket # Inserts our own modules path first in the list @@ -87,7 +87,7 @@ class Fail2banClient: print " -i interactive mode" print " -v increase verbosity" print " -q decrease verbosity" - print " -x force execution of the server" + print " -x force execution of the server (remove socket file)" print " -h, --help display this help message" print " -V, --version print the version" print @@ -103,7 +103,13 @@ class Fail2banClient: print "Fail2Ban v" + version + " reads log file that contains password failure report" print "and bans the corresponding IP addresses using firewall rules." print - + + def __sigTERMhandler(self, signum, frame): + # Print a new line because we probably come from wait + print + logSys.warn("Caught signal %d. Exiting" % signum) + sys.exit(-1) + def __getCmdLineOptions(self, optList): """ Gets the command line options """ @@ -180,7 +186,11 @@ class Fail2banClient: self.__processCmd(self.__stream, False) return True except ServerExecutionException: - logSys.error("Could not start server. Try -x option") + logSys.error("Could not start server. Maybe an old " + + "socket file is still present. Try to " + + "remove " + self.__conf["socket"] + ". If " + + "you used fail2ban-client to start the " + + "server, adding the -x option will do it") return False elif len(cmd) == 1 and cmd[0] == "reload": if self.__ping(): @@ -229,18 +239,40 @@ class Fail2banClient: def __waitOnServer(self): # Wait for the server to start cnt = 0 + if self.__conf["verbose"] > 1: + pos = 0 + delta = 1 + mask = "[ ]" while not self.__ping(): + # Wonderful visual :) + if self.__conf["verbose"] > 1: + pos += delta + sys.stdout.write("\rINFO " + mask[:pos] + '#' + mask[pos+1:] + + " Waiting on the server...") + sys.stdout.flush() + if pos > len(mask)-3: + delta = -1 + elif pos < 2: + delta = 1 # The server has 30 secondes to start. if cnt >= 300: + if self.__conf["verbose"] > 1: + sys.stdout.write('\n') raise ServerExecutionException("Failed to start server") time.sleep(0.1) cnt += 1 + if self.__conf["verbose"] > 1: + sys.stdout.write('\n') def start(self, argv): # Command line options self.__argv = argv + # Install signal handlers + signal.signal(signal.SIGTERM, self.__sigTERMhandler) + signal.signal(signal.SIGINT, self.__sigTERMhandler) + # Reads the command line options. try: cmdOpts = 'hc:s:xdviqV' diff --git a/fail2ban-server b/fail2ban-server index bdb7455f..e706d04e 100755 --- a/fail2ban-server +++ b/fail2ban-server @@ -78,7 +78,7 @@ class Fail2banServer: print " -b start in background" print " -f start in foreground" print " -s socket path" - print " -x force execution of the server" + print " -x force execution of the server (remove socket file)" print " -h, --help display this help message" print " -V, --version print the version" print From daabd590add392843850c13b8d562b428e842d9f Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Thu, 4 Jan 2007 23:35:57 +0000 Subject: [PATCH 02/29] - Updated man pages git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@516 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- man/fail2ban-client.1 | 6 +++--- man/fail2ban-regex.1 | 4 ++-- man/fail2ban-server.1 | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/man/fail2ban-client.1 b/man/fail2ban-client.1 index b905634d..1ee203c7 100644 --- a/man/fail2ban-client.1 +++ b/man/fail2ban-client.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH FAIL2BAN-CLIENT "1" "December 2006" "fail2ban-client v0.7.5-SVN" "User Commands" +.TH FAIL2BAN-CLIENT "1" "January 2007" "fail2ban-client v0.7.6" "User Commands" .SH NAME fail2ban-client \- configure and control the server .SH SYNOPSIS .B fail2ban-client [\fIOPTIONS\fR]... \fI\fR .SH DESCRIPTION -Fail2Ban v0.7.5\-SVN reads log file that contains password failure report +Fail2Ban v0.7.6 reads log file that contains password failure report and bans the corresponding IP addresses using firewall rules. .SH OPTIONS .TP @@ -29,7 +29,7 @@ increase verbosity decrease verbosity .TP \fB\-x\fR -force execution of the server +force execution of the server (remove socket file) .TP \fB\-h\fR, \fB\-\-help\fR display this help message diff --git a/man/fail2ban-regex.1 b/man/fail2ban-regex.1 index a1352142..16e3fa5a 100644 --- a/man/fail2ban-regex.1 +++ b/man/fail2ban-regex.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH FAIL2BAN-REGEX "1" "December 2006" "fail2ban-regex v0.7.5-SVN" "User Commands" +.TH FAIL2BAN-REGEX "1" "January 2007" "fail2ban-regex v0.7.6" "User Commands" .SH NAME fail2ban-regex \- test Fail2ban "failregex" option .SH SYNOPSIS .B fail2ban-regex \fI \fR .SH DESCRIPTION -Fail2Ban v0.7.5\-SVN reads log file that contains password failure report +Fail2Ban v0.7.6 reads log file that contains password failure report and bans the corresponding IP addresses using firewall rules. .PP This tools can test and benchmark your regular expressions for the "failregex" diff --git a/man/fail2ban-server.1 b/man/fail2ban-server.1 index d58ba373..85780a23 100644 --- a/man/fail2ban-server.1 +++ b/man/fail2ban-server.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH FAIL2BAN-SERVER "1" "December 2006" "fail2ban-server v0.7.5-SVN" "User Commands" +.TH FAIL2BAN-SERVER "1" "January 2007" "fail2ban-server v0.7.6" "User Commands" .SH NAME fail2ban-server \- start the server .SH SYNOPSIS .B fail2ban-server [\fIOPTIONS\fR] .SH DESCRIPTION -Fail2Ban v0.7.5\-SVN reads log file that contains password failure report +Fail2Ban v0.7.6 reads log file that contains password failure report and bans the corresponding IP addresses using firewall rules. .PP Only use this command for debugging purpose. Start the server with @@ -24,7 +24,7 @@ start in foreground socket path .TP \fB\-x\fR -force execution of the server +force execution of the server (remove socket file) .TP \fB\-h\fR, \fB\-\-help\fR display this help message From ffc9c5d8f96271b3ac72e0ad269ac673cb00790b Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 8 Jan 2007 21:09:50 +0000 Subject: [PATCH 03/29] - Removed sys.path.insert as fail2ban-testcases is not installed git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@517 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban-testcases | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fail2ban-testcases b/fail2ban-testcases index 38ab89d7..11f4a3ce 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -28,10 +28,6 @@ __license__ = "GPL" import unittest, logging, sys -# Inserts our own modules path first in the list -# fix for bug #343821 -sys.path.insert(1, "/usr/share/fail2ban") - from common.version import version from testcases import banmanagertestcase from testcases import clientreadertestcase From 2725dd6f22bfe8e9c54c8a910f283b77a7226a82 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 8 Jan 2007 21:15:47 +0000 Subject: [PATCH 04/29] - fail2ban-client returns an error code if configuration is not valid git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@518 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 2 ++ client/configurator.py | 2 +- client/jailsreader.py | 2 ++ fail2ban-client | 20 ++++++++++++++------ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 65285a81..bd9e6631 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,8 @@ ver. 0.7.7 (2007/??/??) ---------- - Added signal handling in fail2ban-client - Added a wonderful visual effect when waiting on the server +- fail2ban-client returns an error code if configuration is + not valid ver. 0.7.6 (2007/01/04) - beta ---------- diff --git a/client/configurator.py b/client/configurator.py index f4882f4b..8181a889 100644 --- a/client/configurator.py +++ b/client/configurator.py @@ -60,7 +60,7 @@ class Configurator: def getAllOptions(self): self.__fail2ban.getOptions() - self.__jails.getOptions() + return self.__jails.getOptions() def convertToProtocol(self): self.__streams["general"] = self.__fail2ban.convert() diff --git a/client/jailsreader.py b/client/jailsreader.py index 6208572d..ada5fe09 100644 --- a/client/jailsreader.py +++ b/client/jailsreader.py @@ -54,6 +54,8 @@ class JailsReader(ConfigReader): self.__jails.append(jail) else: logSys.error("Errors in jail '" + sec + "'. Skipping...") + return False + return True def convert(self): stream = list() diff --git a/fail2ban-client b/fail2ban-client index 52103d19..dbb0f185 100755 --- a/fail2ban-client +++ b/fail2ban-client @@ -175,10 +175,14 @@ class Fail2banClient: logSys.error("Server already running") return False else: + # Read the config + ret = self.__readConfig() + # Do not continue if configuration is not 100% valid + if not ret: + return False + # Start the server self.__startServerAsync(self.__conf["socket"], self.__conf["force"]) - # Read the config while the server is starting - self.__readConfig() try: # Wait for the server to start self.__waitOnServer() @@ -194,7 +198,10 @@ class Fail2banClient: return False elif len(cmd) == 1 and cmd[0] == "reload": if self.__ping(): - self.__readConfig() + ret = self.__readConfig() + # Do not continue if configuration is not 100% valid + if not ret: + return False self.__processCmd([['stop', 'all']], False) # Configure the server return self.__processCmd(self.__stream, False) @@ -312,9 +319,9 @@ class Fail2banClient: logSys.info("Using socket file " + self.__conf["socket"]) if self.__conf["dump"]: - self.__readConfig() + ret = self.__readConfig() self.dumpConfig(self.__stream) - return True + return ret # Interactive mode if self.__conf["interactive"]: @@ -345,9 +352,10 @@ class Fail2banClient: def __readConfig(self): # Read the configuration self.__configurator.readAll() - self.__configurator.getAllOptions() + ret = self.__configurator.getAllOptions() self.__configurator.convertToProtocol() self.__stream = self.__configurator.getConfigStream() + return ret @staticmethod def dumpConfig(cmd): From 079985c14b4b3e76cbc26ccdfd615108efe538b7 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 8 Jan 2007 21:16:57 +0000 Subject: [PATCH 05/29] - Updated to SVN version git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@519 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- common/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/version.py b/common/version.py index e913d1c0..2e3c2d89 100644 --- a/common/version.py +++ b/common/version.py @@ -24,4 +24,4 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -version = "0.7.6" +version = "0.7.6-SVN" From 04cd3f5bd5424d537b2a61fd340db4227b4fec2d Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 8 Jan 2007 21:40:37 +0000 Subject: [PATCH 06/29] - Added new filters/actions. Thanks to Yaroslav Halchenko git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@520 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 1 + MANIFEST | 4 ++ config/action.d/iptables-multiport.conf | 69 +++++++++++++++++++++++ config/action.d/iptables-new.conf | 71 +++++++++++++++++++++++ config/action.d/mail-whois-lines.conf | 75 +++++++++++++++++++++++++ config/filter.d/vsftpd.conf | 1 + config/filter.d/wuftpd.conf | 14 +++++ 7 files changed, 235 insertions(+) create mode 100644 config/action.d/iptables-multiport.conf create mode 100644 config/action.d/iptables-new.conf create mode 100644 config/action.d/mail-whois-lines.conf create mode 100644 config/filter.d/wuftpd.conf diff --git a/CHANGELOG b/CHANGELOG index bd9e6631..ac8ed752 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ ver. 0.7.7 (2007/??/??) - Added a wonderful visual effect when waiting on the server - fail2ban-client returns an error code if configuration is not valid +- Added new filters/actions. Thanks to Yaroslav Halchenko ver. 0.7.6 (2007/01/04) - beta ---------- diff --git a/MANIFEST b/MANIFEST index 57911033..2a71efd5 100644 --- a/MANIFEST +++ b/MANIFEST @@ -70,9 +70,13 @@ config/filter.d/courierlogin.conf config/filter.d/sshd.conf config/filter.d/proftpd.conf config/filter.d/sasl.conf +config/filter.d/wuftpd.conf config/action.d/iptables.conf +config/action.d/iptables-multiport.conf +config/action.d/iptables-new.conf config/action.d/ipfw.conf config/action.d/mail-whois.conf +config/action.d/mail-whois-lines.conf config/action.d/mail.conf config/action.d/hostsdeny.conf config/action.d/shorewall.conf diff --git a/config/action.d/iptables-multiport.conf b/config/action.d/iptables-multiport.conf new file mode 100644 index 00000000..f881a782 --- /dev/null +++ b/config/action.d/iptables-multiport.conf @@ -0,0 +1,69 @@ +# Fail2Ban configuration file +# +# Author: Cyril Jaquier +# Modified by Yaroslav Halchenko for multiport banning +# $Revision$ +# + +[Definition] + +# Option: actionstart +# Notes.: command executed once at the start of Fail2Ban. +# Values: CMD +# +actionstart = iptables -N fail2ban- + iptables -A fail2ban- -j RETURN + iptables -I INPUT -p -m multiport --dports -j fail2ban- + +# Option: actionend +# Notes.: command executed once at the end of Fail2Ban +# Values: CMD +# +actionstop = iptables -D INPUT -p -m multiport --dports -j fail2ban- + iptables -F fail2ban- + iptables -X fail2ban- + +# Option: actioncheck +# Notes.: command executed once before each actionban command +# Values: CMD +# +actioncheck = iptables -n -L INPUT | grep -q fail2ban- + +# 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 +#