From af827330b27556f3188d4e5bf674611bebab24b5 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 16 Dec 2005 23:43:46 +0000 Subject: [PATCH 01/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@218 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 99e4402e..d1abc53d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,9 +4,15 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.6.0) 2005/11/20 +Fail2Ban (version 0.6.?) 200?/??/?? ============================================================= +ver. 0.6.? (200?/??/??) - ??? +---------- +- Added permanent banning. Set banTime to a negative value to + enable this feature (-1 is perfect). Thanks to Mannone +- Fixed locale bug. Thanks to Fernando José + ver. 0.6.0 (2005/11/20) - stable ---------- - Propagated patches introduced by Debian maintainer From 52e7a267564dc594587f55be087b5682e1e21406 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 16 Dec 2005 23:44:06 +0000 Subject: [PATCH 02/26] - Updated to CVS version git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@219 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 794dd43b..07149645 100644 --- a/version.py +++ b/version.py @@ -24,4 +24,4 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -version = "0.6.0" +version = "0.6.0-CVS" From cd38dddd0039c656c3e6f51eaf0c0c4226e406fc Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 16 Dec 2005 23:44:34 +0000 Subject: [PATCH 03/26] =?UTF-8?q?-=20Fixed=20locale=20bug.=20Thanks=20to?= =?UTF-8?q?=20Fernando=20Jos=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@220 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fail2ban b/fail2ban index 05213f9e..9b0d4866 100755 --- a/fail2ban +++ b/fail2ban @@ -26,7 +26,14 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -import sys, traceback, logging +import sys, traceback, logging, locale + +# Set the locale with the user's default setting +try: + locale.setlocale(locale.LC_ALL, '') +except Exception: + print "Unable to set locale to " + `locale.getdefaultlocale()` + sys.exit(-1) # Appends our own modules path. sys.path.append("/usr/lib/fail2ban") @@ -41,8 +48,9 @@ logSys = logging.getLogger("fail2ban") # Get PID lock file instance pidLock = PIDLock() -# Start the application. Handle all the unhandled exceptions +# Handle all the unhandled exceptions try: + # Start the application fail2ban.main() except SystemExit: # We called sys.exit(). Nothing wrong so just pass From 716e0840fc6810880c3402f22ce450feda528b27 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 16 Dec 2005 23:47:03 +0000 Subject: [PATCH 04/26] - Removed unneeded semicolon git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@221 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fail2ban.py b/fail2ban.py index d2e88b3e..bd4048bc 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -208,7 +208,7 @@ def main(): # Reads the config file and create a LogReader instance for # each log file to check. - confReader = ConfigReader(conf["conffile"]); + confReader = ConfigReader(conf["conffile"]) confReader.openConf() # Options From 15806fc3daf0ca6f5660eb944f1d991ec4534c4a Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 16 Dec 2005 23:48:52 +0000 Subject: [PATCH 05/26] - Added permanent banning feature git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@222 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- config/fail2ban.conf.default | 3 ++- firewall/firewall.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config/fail2ban.conf.default b/config/fail2ban.conf.default index d841bd7a..a5b69b06 100644 --- a/config/fail2ban.conf.default +++ b/config/fail2ban.conf.default @@ -48,7 +48,8 @@ pidlock = /var/run/fail2ban.pid maxfailures = 5 # Option: bantime -# Notes.: number of seconds an IP will be banned. +# Notes.: number of seconds an IP will be banned. If set to a negative +# value, IP will never be unbanned (permanent banning). # Values: NUM Default: 600 # bantime = 600 diff --git a/firewall/firewall.py b/firewall/firewall.py index e50184bd..ebba2545 100644 --- a/firewall/firewall.py +++ b/firewall/firewall.py @@ -86,7 +86,11 @@ class Firewall: ip = aInfo["ip"] if not self.inBanList(ip): crtTime = time.time() - logSys.warn("%s: Ban "%self.section + ip) + if self.banTime < 0: + banMsg = "Ban (permanent)" + else: + banMsg = "Ban (%d s)"%self.banTime + logSys.warn("%s: %s "%(self.section, banMsg) + ip) self.banList[ip] = crtTime aInfo["bantime"] = crtTime self.runCheck(debug) @@ -138,8 +142,12 @@ class Firewall: return None def checkForUnBan(self, debug): - """ Check for IP to remove from ban list. + """ Check for IP to remove from ban list. If banTime is smaller than + zero, IP will be never removed. """ + if self.banTime < 0: + # Permanent banning + return banListTemp = self.banList.copy() for element in banListTemp.iteritems(): btime = element[1] From 9cd787c50e6818ec78444ff3561a1d789e685971 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 16 Dec 2005 23:50:59 +0000 Subject: [PATCH 06/26] - Fixed crash when time format does not match data git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@223 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- logreader/logreader.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/logreader/logreader.py b/logreader/logreader.py index 1876a395..5ae2ff27 100644 --- a/logreader/logreader.py +++ b/logreader/logreader.py @@ -201,7 +201,12 @@ class LogReader: Pattern should describe the date construction of value. """ - date = list(time.strptime(value, self.timepattern)) + try: + date = list(time.strptime(value, self.timepattern)) + except ValueError, e: + logSys.error(e) + logSys.error("Please check the format and your locale settings.") + return None if date[0] < 2000: # There is probably no year field in the logs date[0] = time.gmtime()[0] From 7494fe283b56a33a25a56479c217e628be35d6aa Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 16 Dec 2005 23:51:59 +0000 Subject: [PATCH 07/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@224 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index d1abc53d..40b8c137 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ ver. 0.6.? (200?/??/??) - ??? - Added permanent banning. Set banTime to a negative value to enable this feature (-1 is perfect). Thanks to Mannone - Fixed locale bug. Thanks to Fernando José +- Fixed crash when time format does not match data ver. 0.6.0 (2005/11/20) - stable ---------- From 3eb0ca0ee5011a1660c9e55a2f6575b2fcaae897 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 27 Dec 2005 15:09:50 +0000 Subject: [PATCH 08/26] propagated fix for the path bug. Thanks to Nick Craig-Wood git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@225 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 3 +++ fail2ban | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 40b8c137..54bf066a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,9 @@ ver. 0.6.? (200?/??/??) - ??? enable this feature (-1 is perfect). Thanks to Mannone - Fixed locale bug. Thanks to Fernando José - Fixed crash when time format does not match data +- Propagated patch from Debian to fix fail2ban search path + addition to the path search list: now it is added first. + Thanks to Nick Craig-Wood ver. 0.6.0 (2005/11/20) - stable ---------- diff --git a/fail2ban b/fail2ban index 9b0d4866..5eace8bd 100755 --- a/fail2ban +++ b/fail2ban @@ -35,8 +35,9 @@ except Exception: print "Unable to set locale to " + `locale.getdefaultlocale()` sys.exit(-1) -# Appends our own modules path. -sys.path.append("/usr/lib/fail2ban") +# Inserts our own modules path first in the list +# fix for bug #343821 +sys.path.insert(1, "/usr/lib/fail2ban") # Now we can import our modules. import fail2ban From be26cd5b751a16af9f2b61b2da202ba26753a5b1 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 3 Jan 2006 15:11:57 +0000 Subject: [PATCH 09/26] - Removed debug option - Added SMTP authentification support - Added TAI64N support git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@226 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- config/fail2ban.conf.default | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/config/fail2ban.conf.default b/config/fail2ban.conf.default index a5b69b06..96337fcd 100644 --- a/config/fail2ban.conf.default +++ b/config/fail2ban.conf.default @@ -11,12 +11,6 @@ # background = false -# Option: debug -# Notes.: enable debug mode. More verbose output and bypass root user test. -# Values: [true | false] Default: false -# -debug = false - # Option: logtargets # Notes.: log targets. Space separated list of logging targets. # Values: STDERR SYSLOG file Default: /var/log/fail2ban.log @@ -120,6 +114,19 @@ host = localhost # port = 25 +# Option: user +# Notes.: the username for smtp-server if authentification is required. +# if user is empty, no authentification is done. +# Values: STR Default: +# +user = + +# Option: password +# Notes.: the smtp-user's password if authentification is required. +# Values: STR Default: +# +password = + # Option: from # Notes.: e-mail address of the sender. # Values: MAIL Default: fail2ban @@ -229,7 +236,8 @@ fwban = iptables -I fail2ban-http 1 -s -j DROP fwunban = iptables -D fail2ban-http -s -j DROP # Option: timeregex -# Notes.: regex to match timestamp in Apache logfile. +# Notes.: regex to match timestamp in Apache logfile. For TAI64N format, +# use timeregex = @[0-9a-f]{24} # Values: [Wed Jan 05 15:08:01 2005] # Default: \S{3} \S{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} # @@ -237,7 +245,8 @@ timeregex = \S{3} \S{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} # Option: timepattern # Notes.: format used in "timeregex" fields definition. Note that '%' must be -# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule) +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule). +# For TAI64N format, use timepattern = tai64n # Values: TEXT Default: %%a %%b %%d %%H:%%M:%%S %%Y # timepattern = %%a %%b %%d %%H:%%M:%%S %%Y @@ -308,7 +317,8 @@ fwban = iptables -I fail2ban-ssh 1 -s -j DROP fwunban = iptables -D fail2ban-ssh -s -j DROP # Option: timeregex -# Notes.: regex to match timestamp in SSH logfile. +# Notes.: regex to match timestamp in SSH logfile. For TAI64N format, +# use timeregex = @[0-9a-f]{24} # Values: [Mar 7 17:53:28] # Default: \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} # @@ -316,7 +326,8 @@ timeregex = \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} # Option: timepattern # Notes.: format used in "timeregex" fields definition. Note that '%' must be -# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule) +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule). +# For TAI64N format, use timepattern = tai64n # Values: TEXT Default: %%b %%d %%H:%%M:%%S # timepattern = %%b %%d %%H:%%M:%%S From fb07353aeb14a5f09ae7769ea092f8e220af5b2e Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 3 Jan 2006 15:13:04 +0000 Subject: [PATCH 10/26] - Added TAI64N support git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@227 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- logreader/logreader.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/logreader/logreader.py b/logreader/logreader.py index 5ae2ff27..72043e4d 100644 --- a/logreader/logreader.py +++ b/logreader/logreader.py @@ -202,7 +202,13 @@ class LogReader: value. """ try: - date = list(time.strptime(value, self.timepattern)) + # Check if the parsed value is in TAI64N format + if not self.timepattern.lower() == "tai64n": + date = list(time.strptime(value, self.timepattern)) + else: + # extract part of format which represents seconds since epoch + seconds_since_epoch = value[2:17] + date = list(time.gmtime(int(seconds_since_epoch, 16))) except ValueError, e: logSys.error(e) logSys.error("Please check the format and your locale settings.") From 85f1d74d85a392f2f6bbc96ad852d54a5260d8eb Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 3 Jan 2006 15:13:24 +0000 Subject: [PATCH 11/26] - Removed debug option git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@228 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- man/fail2ban.8 | 3 --- 1 file changed, 3 deletions(-) diff --git a/man/fail2ban.8 b/man/fail2ban.8 index c43b71ec..1c2e4f73 100644 --- a/man/fail2ban.8 +++ b/man/fail2ban.8 @@ -14,9 +14,6 @@ firewall rules to reject the IP address. \fB\-b\fR start in background .TP -\fB\-d\fR -start in debug mode. Commands are NOT executed but only displayed -.TP \fB\-c\fR \fIFILE\fR read configuration file \fIFILE\fR .TP From 6386c9e5809af60f713b42406eb7e4d4c33151be Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 3 Jan 2006 15:13:41 +0000 Subject: [PATCH 12/26] - Added SMTP authentification support git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@229 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- utils/mail.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/utils/mail.py b/utils/mail.py index 8a244d4f..9a89896e 100644 --- a/utils/mail.py +++ b/utils/mail.py @@ -44,6 +44,16 @@ class Mail: """ Set from: address """ self.fromAddr = fromAddr + + def setUser(self, user): + """ Set smtpuser + """ + self.user = user + + def setPassword(self, password): + """ Set smtppassword + """ + self.password = password def setToAddr(self, toAddr): """ Set to: address @@ -69,6 +79,8 @@ class Mail: try: server = smtplib.SMTP(self.host, self.port) #server.set_debuglevel(1) + if not self.user == '': + server.login(self.user, self.password) server.sendmail(self.fromAddr, self.toAddr, mail) logSys.debug("Email sent to " + `self.toAddr`) server.quit() From 79318b35495725e20d4e34e3e1ebeec67a112132 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 3 Jan 2006 15:14:27 +0000 Subject: [PATCH 13/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@230 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 7 +++++++ README | 8 ++++---- TODO | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 54bf066a..3c37789d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,13 @@ ver. 0.6.? (200?/??/??) - ??? - Propagated patch from Debian to fix fail2ban search path addition to the path search list: now it is added first. Thanks to Nick Craig-Wood +- Added SMTP authentification for mail notification. Thanks + to Markus Hoffmann +- Removed debug mode as it is confusing for people +- Added parsing of timestamp in TAI64N format (#1275325). + Thanks to Mark Edgington +- Added patch #1382936 (Default formatted syslog logging). + Thanks to Patrick Börjesson ver. 0.6.0 (2005/11/20) - stable ---------- diff --git a/README b/README index 915304bb..0c241a8a 100644 --- a/README +++ b/README @@ -62,8 +62,8 @@ To install, just do: > cd fail2ban-0.6.0 > python setup.py install -This will install Fail2Ban into /usr/lib/fail2ban. The fail2ban -executable is placed into /usr/bin. +This will install Fail2Ban into /usr/lib/fail2ban. The +fail2ban executable is placed into /usr/bin. Gentoo: ebuilds are available on the website. Debian: Fail2Ban is in Debian unstable. @@ -96,7 +96,6 @@ the value stored in fail2ban.conf. Here are the command line options: -b start in background - -d start in debug mode -c read configuration file FILE -p create PID lock in FILE -h display this help message @@ -124,7 +123,8 @@ Thanks: Kévin Drapel, Marvin Rouge, Sireyessire, Robert Edeker, Tom Pike, Iain Lea, Andrey G. Grozin, Yaroslav Halchenko, -Jonathan Kamens, Stephen Gildea +Jonathan Kamens, Stephen Gildea, Markus Hoffmann, Mark +Edgington, Patrick Börjesson License: -------- diff --git a/TODO b/TODO index d0028108..190a84cb 100644 --- a/TODO +++ b/TODO @@ -21,3 +21,6 @@ See Feature Request Tracking System at SourceForge.net - remove debug mode (root check) - better return values in function - use more email.Utils in mail.py +- add gettext support +- send an email when fail2ban is running +- use Gentoo Portage style for scripts From 1044b82e128fefa83c480587a01fe49498b2350b Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 3 Jan 2006 15:16:22 +0000 Subject: [PATCH 14/26] - Removed debug option - Added SMTP authentification support - Changed syslog output to a more standard format git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@231 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/fail2ban.py b/fail2ban.py index bd4048bc..f192f5b5 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -56,7 +56,6 @@ def dispUsage(): print "and bans the corresponding IP addresses using firewall rules." print print " -b start in background" - print " -d start in debug mode" print " -c read configuration file FILE" print " -p create PID lock in FILE" print " -h display this help message" @@ -186,6 +185,7 @@ def main(): stdout.setFormatter(formatter) conf["kill"] = False + conf["debug"] = False conf["verbose"] = 0 conf["conffile"] = "/etc/fail2ban.conf" @@ -216,7 +216,6 @@ def main(): ["str", "logtargets", "/var/log/fail2ban.log"], ["str", "syslog-target", "/dev/log"], ["int", "syslog-facility", 1], - ["bool", "debug", False], ["str", "pidlock", "/var/run/fail2ban.pid"], ["int", "maxfailures", 5], ["int", "bantime", 600], @@ -294,8 +293,8 @@ def main(): port = int(syslogtargets[3]) syslogtarget = (syslogtargets[1], port) hdlr = logging.handlers.SysLogHandler(syslogtarget, facility) - tformatter = logging.Formatter("fail2ban[%(process)d]: " + - formatterstring); + tformatter = logging.Formatter("%(asctime)s %(name)s " + + formatterstring, "%b %e %T"); else: # Target should be a file try: @@ -315,14 +314,14 @@ def main(): logSys.setLevel(logging.INFO) elif conf["verbose"] > 1: logSys.setLevel(logging.DEBUG) - - # Set debug log level - if conf["debug"]: - logSys.setLevel(logging.DEBUG) - formatterstring = ('%(levelname)s: [%(filename)s (%(lineno)d)] ' + + if conf["verbose"] > 2: + formatterstring = ('%(levelname)s: [%(filename)s (%(lineno)d)] ' + '%(message)s') - formatter = logging.Formatter("%(asctime)s " + formatterstring) - stdout.setFormatter(formatter) + formatter = logging.Formatter("%(asctime)s " + formatterstring) + stdout.setFormatter(formatter) + + # Debug mode. Should only be used by developers + if conf["debug"]: logSys.warn("DEBUG MODE: FIREWALL COMMANDS ARE _NOT_ EXECUTED BUT " + "ONLY DISPLAYED IN THE LOG MESSAGES") @@ -358,6 +357,8 @@ def main(): ["int", "port", "25"], ["str", "from", "root"], ["str", "to", "root"], + ["str", "user", ''], + ["str", "password", ''], ["bool", "localtime", False], ["str", "subject", "[Fail2Ban] Banned "], ["str", "message", "Fail2Ban notification"]) @@ -370,6 +371,8 @@ def main(): logSys.debug("Mail enabled") mail = Mail(mailConf["host"], mailConf["port"]) mail.setFromAddr(mailConf["from"]) + mail.setUser(mailConf["user"]) + mail.setPassword(mailConf["password"]) mail.setToAddr(mailConf["to"]) mail.setLocalTimeFlag(mailConf["localtime"]) logSys.debug("to: " + mailConf["to"] + " from: " + mailConf["from"]) From 3e86a8204b5c836bc8ded6e4f5c012cf97ee4014 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Thu, 12 Jan 2006 16:20:00 +0000 Subject: [PATCH 15/26] - Removed 192.168.0.0/16 from ignoreip git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@232 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 2 ++ config/fail2ban.conf.default | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3c37789d..42c371a7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,8 @@ ver. 0.6.? (200?/??/??) - ??? Thanks to Mark Edgington - Added patch #1382936 (Default formatted syslog logging). Thanks to Patrick Börjesson +- Removed 192.168.0.0/16 from ignoreip. Attacks could also + come from the local network. ver. 0.6.0 (2005/11/20) - stable ---------- diff --git a/config/fail2ban.conf.default b/config/fail2ban.conf.default index 96337fcd..ad28e1f9 100644 --- a/config/fail2ban.conf.default +++ b/config/fail2ban.conf.default @@ -58,9 +58,9 @@ findtime = 600 # Notes.: space separated list of IP's to be ignored by fail2ban. # You can use CIDR mask in order to specify a range. # Example: ignoreip = 192.168.0.1/24 123.45.235.65 -# Values: IP Default: 192.168.0.0/16 +# Values: IP Default: # -ignoreip = 192.168.0.0/16 +ignoreip = # Option: cmdstart # Notes.: command executed once at the start of Fail2Ban From de7acd4d6cfba925b45b2e29fab39075cfe02e81 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 22 Jan 2006 11:07:22 +0000 Subject: [PATCH 16/26] - Added support for shorewall and hosts.deny - Renamed fail2ban.conf.default to fail2ban.conf.iptables git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@233 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- config/fail2ban.conf.hostsdeny | 287 ++++++++++++++++++ ...an.conf.default => fail2ban.conf.iptables} | 157 +++++----- config/fail2ban.conf.shorewall | 281 +++++++++++++++++ 3 files changed, 638 insertions(+), 87 deletions(-) create mode 100644 config/fail2ban.conf.hostsdeny rename config/{fail2ban.conf.default => fail2ban.conf.iptables} (79%) create mode 100644 config/fail2ban.conf.shorewall diff --git a/config/fail2ban.conf.hostsdeny b/config/fail2ban.conf.hostsdeny new file mode 100644 index 00000000..693d28a9 --- /dev/null +++ b/config/fail2ban.conf.hostsdeny @@ -0,0 +1,287 @@ +# Fail2Ban configuration file +# +# $Revision$ +# +# 2005.06.21 modified for readability Iain Lea iain@bricbrac.de + +[DEFAULT] +# Option: background +# Notes.: start fail2ban as a daemon. Output is redirect to logfile. +# Values: [true | false] Default: false +# +background = false + +# Option: logtargets +# Notes.: log targets. Space separated list of logging targets. +# Values: STDERR SYSLOG file Default: /var/log/fail2ban.log +# +logtargets = /var/log/fail2ban.log + +# Option: syslog-target +# Notes.: where to find syslog facility if logtarget SYSLOG. +# Values: SOCKET HOST HOST:PORT Default: /dev/log +# +syslog-target = /dev/log + +# Option: syslog-facility +# Notes.: which syslog facility to use if logtarget SYSLOG. +# Values: NUM Default: 1 +# +syslog-facility = 1 + +# Option: pidlock +# Notes.: path of the PID lock file (must be able to write to file). +# Values: FILE Default: /var/run/fail2ban.pid +# +pidlock = /var/run/fail2ban.pid + +# Option: maxfailures +# Notes.: number of failures before IP gets banned. +# Values: NUM Default: 5 +# +maxfailures = 5 + +# Option: bantime +# Notes.: number of seconds an IP will be banned. If set to a negative +# value, IP will never be unbanned (permanent banning). +# Values: NUM Default: 600 +# +bantime = 600 + +# Option: findtime +# Notes.: lifetime in seconds of a "failed" log entry. +# Values: NUM Default: 600 +# +findtime = 600 + +# Option: ignoreip +# Notes.: space separated list of IP's to be ignored by fail2ban. +# You can use CIDR mask in order to specify a range. +# Example: ignoreip = 192.168.0.1/24 123.45.235.65 +# Values: IP Default: +# +ignoreip = + +# Option: cmdstart +# Notes.: command executed once at the start of Fail2Ban +# Values: CMD Default: +# +cmdstart = + +# Option: cmdend +# Notes.: command executed once at the end of Fail2Ban. +# Values: CMD Default: +# +cmdend = + +# Option: polltime +# Notes.: number of seconds fail2ban sleeps between iterations. +# Values: NUM Default: 1 +# +polltime = 1 + +# Option: reinittime +# Notes.: minimal number of seconds between the re-initialization of +# firewalls due to external changes in their rules (see fwcheck) +# Values: NUM Default: 100 +# +reinittime = 10 + +# Option: maxreinits +# Notes.: maximal number of re-initialization of firewalls due to external +# changes. -1 stays for infinite, so only reinittime is of importance +# Values: NUM Default: -1 +# +maxreinits = -1 + +# NOTE: Interpolations +# +# fwstart, as well as fwend, fwcheck, fwban, fwunban, use interpolations +# so %(__name__)s will be substituted by a name of each section +# (unless the option is overriden in a section). +# If you are going to use interpolations in your setup, please make +# sure that you specified options port and protocol (which also has +# an option in DEFAULT). +# + +# Option: hostsdeny +# Notes.: hosts.deny file path. +# Values: STR Default: /etc/hosts.deny +# +hostsdeny = /etc/hosts.deny + +# Option: fwban +# Notes.: command executed when banning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: IP address +# number of failures +# unix timestamp of the last failure +# unix timestamp of the ban time +# Values: CMD +# Default: iptables -I INPUT 1 -s -j DROP +# +fwban = IP= && echo "ALL: $IP" >> %(hostsdeny)s + +# Option: fwunban +# Notes.: command executed when unbanning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: IP address +# unix timestamp of the ban time +# unix timestamp of the unban time +# Values: CMD +# Default: iptables -D INPUT -s -j DROP +# +fwunban = IP= && sed -i.old s/ALL:\ $IP// %(hostsdeny)s + +[MAIL] +# Option: enabled +# Notes.: enable mail notification when banning an IP address. +# Values: [true | false] Default: false +# +enabled = false + +# Option: host +# Notes.: host running the mail server. +# Values: STR Default: localhost +# +host = localhost + +# Option: port +# Notes.: port of the mail server. +# Values: INT Default: 25 +# +port = 25 + +# Option: user +# Notes.: the username for smtp-server if authentification is required. +# if user is empty, no authentification is done. +# Values: STR Default: +# +user = + +# Option: password +# Notes.: the smtp-user's password if authentification is required. +# Values: STR Default: +# +password = + +# Option: from +# Notes.: e-mail address of the sender. +# Values: MAIL Default: fail2ban +# +from = fail2ban + +# Option: to +# Notes.: e-mail addresses of the receiver. Addresses are space +# separated. +# Values: MAIL Default: root +# +to = root + +# Option: localtime +# Notes.: report local time (including timezone) or GMT +# Values: [true | false] Default: false +# +localtime = true + +# Option: subject +# Notes.: subject of the e-mail. +# Tags:
active section (eg ssh, apache, etc) +# IP address +# number of failures +# unix timestamp of the last failure +# Values: TEXT Default: [Fail2Ban]
: Banned +# +subject = [Fail2Ban]
: Banned + +# Option: message +# Notes.: message of the e-mail. +# Tags:
active section (eg ssh, apache, etc) +# IP address +# number of failures +# unix timestamp of the last failure +#
new line +# Values: TEXT Default: +# +message = Hi,
+ The IP has just been banned by Fail2Ban after + attempts against
.
+ Regards,
+ Fail2Ban + +# You can define a new section for each log file to check for +# password failure. Each section has to define the following +# options: logfile, fwban, fwunban, timeregex, timepattern, +# failregex. + + +[Apache] +# Option: enabled +# Notes.: enable monitoring for this section. +# Values: [true | false] Default: false +# +enabled = false + +# Option: logfile +# Notes.: logfile to monitor. +# Values: FILE Default: /var/log/httpd/access_log +# +logfile = /var/log/httpd/access_log + +# Option: timeregex +# Notes.: regex to match timestamp in Apache logfile. For TAI64N format, +# use timeregex = @[0-9a-f]{24} +# Values: [Wed Jan 05 15:08:01 2005] +# Default: \S{3} \S{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} +# +timeregex = \S{3} \S{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} + +# Option: timepattern +# Notes.: format used in "timeregex" fields definition. Note that '%' must be +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule). +# For TAI64N format, use timepattern = tai64n +# Values: TEXT Default: %%a %%b %%d %%H:%%M:%%S %%Y +# +timepattern = %%a %%b %%d %%H:%%M:%%S %%Y + +# Option: failregex +# Notes.: regex to match the password failure messages in the logfile. +# Values: TEXT Default: authentication failure|user .* not found +# +failregex = authentication failure|user .* not found + + +[SSH] +# Option: enabled +# Notes.: enable monitoring for this section. +# Values: [true | false] Default: true +# +enabled = true + +# Option: logfile +# Notes.: logfile to monitor. +# Values: FILE Default: /var/log/secure +# +logfile = /var/log/secure + +# Option: timeregex +# Notes.: regex to match timestamp in SSH logfile. For TAI64N format, +# use timeregex = @[0-9a-f]{24} +# Values: [Mar 7 17:53:28] +# Default: \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} +# +timeregex = \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} + +# Option: timepattern +# Notes.: format used in "timeregex" fields definition. Note that '%' must be +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule). +# For TAI64N format, use timepattern = tai64n +# Values: TEXT Default: %%b %%d %%H:%%M:%%S +# +timepattern = %%b %%d %%H:%%M:%%S + +# Option: failregex +# Notes.: regex to match the password failures messages in the logfile. +# Values: TEXT Default: Authentication failure|Failed password|Invalid user +# +failregex = Authentication failure|Failed password|Invalid user diff --git a/config/fail2ban.conf.default b/config/fail2ban.conf.iptables similarity index 79% rename from config/fail2ban.conf.default rename to config/fail2ban.conf.iptables index ad28e1f9..4cf103b5 100644 --- a/config/fail2ban.conf.default +++ b/config/fail2ban.conf.iptables @@ -94,6 +94,66 @@ reinittime = 10 # maxreinits = -1 +# NOTE: Interpolations +# +# fwstart, as well as fwend, fwcheck, fwban, fwunban, use interpolations +# so %(__name__)s will be substituted by a name of each section +# (unless the option is overriden in a section). +# If you are going to use interpolations in your setup, please make +# sure that you specified options port and protocol (which also has +# an option in DEFAULT). +# + +# Option: protocol +# Notes.: internally used by config reader for interpolations. +# Values: [ tcp | udp | icmp | all ] Default: tcp +# +protocol = tcp + +# Option: fwstart +# Notes.: command executed once at the start of Fail2Ban. +# Values: CMD Default: +# +fwstart = iptables -N fail2ban-%(__name__)s + iptables -A fail2ban-%(__name__)s -j RETURN + iptables -I INPUT -p %(protocol)s --dport %(port)s -j fail2ban-%(__name__)s + +# Option: fwend +# Notes.: command executed once at the end of Fail2Ban +# Values: CMD Default: +# +fwend = iptables -D INPUT -p %(protocol)s --dport %(port)s -j fail2ban-%(__name__)s + iptables -F fail2ban-%(__name__)s + iptables -X fail2ban-%(__name__)s + +# Option: fwcheck +# Notes.: command executed once before each fwban command +# Values: CMD Default: +# +fwcheck = iptables -L INPUT | grep -q fail2ban-%(__name__)s + +# Option: fwban +# Notes.: command executed when banning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: IP address +# number of failures +# unix timestamp of the last failure +# unix timestamp of the ban time +# Values: CMD +# Default: iptables -I INPUT 1 -s -j DROP +# +fwban = iptables -I fail2ban-%(__name__)s 1 -s -j DROP + +# Option: fwunban +# Notes.: command executed when unbanning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: IP address +# unix timestamp of the ban time +# unix timestamp of the unban time +# Values: CMD +# Default: iptables -D INPUT -s -j DROP +# +fwunban = iptables -D fail2ban-%(__name__)s -s -j DROP [MAIL] # Option: enabled @@ -190,50 +250,11 @@ enabled = false # logfile = /var/log/httpd/access_log -# Option: fwstart -# Notes.: command executed once at the start of Fail2Ban -# Values: CMD Default: +# Option: port +# Notes.: specifies port to monitor +# Values: [ NUM | STRING ] Default: # -fwstart = iptables -N fail2ban-http - iptables -I INPUT -p tcp --dport http -j fail2ban-http - iptables -A fail2ban-http -j RETURN - -# Option: fwend -# Notes.: command executed once at the end of Fail2Ban -# Values: CMD Default: -# -fwend = iptables -D INPUT -p tcp --dport http -j fail2ban-http - iptables -F fail2ban-http - iptables -X fail2ban-http - -# Option: fwcheck -# Notes.: command executed once before each fwban command -# Values: CMD Default: -# -fwcheck = iptables -L INPUT | grep -q fail2ban-http - -# Option: fwban -# Notes.: command executed when banning an IP. Take care that the -# command is executed with Fail2Ban user rights. -# Tags: IP address -# number of failures -# unix timestamp of the last failure -# unix timestamp of the ban time -# Values: CMD -# Default: iptables -I INPUT 1 -s -j DROP -# -fwban = iptables -I fail2ban-http 1 -s -j DROP - -# Option: fwunban -# Notes.: command executed when unbanning an IP. Take care that the -# command is executed with Fail2Ban user rights. -# Tags: IP address -# unix timestamp of the ban time -# unix timestamp of the unban time -# Values: CMD -# Default: iptables -D INPUT -s -j DROP -# -fwunban = iptables -D fail2ban-http -s -j DROP +port = http # Option: timeregex # Notes.: regex to match timestamp in Apache logfile. For TAI64N format, @@ -269,52 +290,14 @@ enabled = true # Notes.: logfile to monitor. # Values: FILE Default: /var/log/secure # -logfile = /var/log/secure +#logfile = /var/log/secure +logfile = /home/cyril/workspace/fail2ban-stable/log-test/test -# Option: fwstart -# Notes.: command executed once at the start of Fail2Ban -# Values: CMD Default: +# Option: port +# Notes.: specifies port to monitor +# Values: [ NUM | STRING ] Default: # -fwstart = iptables -N fail2ban-ssh - iptables -I INPUT -p tcp --dport ssh -j fail2ban-ssh - iptables -A fail2ban-ssh -j RETURN - -# Option: fwend -# Notes.: command executed once at the end of Fail2Ban -# Values: CMD Default: -# -fwend = iptables -D INPUT -p tcp --dport ssh -j fail2ban-ssh - iptables -F fail2ban-ssh - iptables -X fail2ban-ssh - -# Option: fwcheck -# Notes.: command executed once before each fwban command -# Values: CMD Default: -# -fwcheck = iptables -L INPUT | grep -q fail2ban-ssh - -# Option: fwbanrule -# Notes.: command executed when banning an IP. Take care that the -# command is executed with Fail2Ban user rights. -# Tags: IP address -# number of failures -# unix timestamp of the last failure -# unix timestamp of the ban time -# Values: CMD -# Default: iptables -I INPUT 1 -s -j DROP -# -fwban = iptables -I fail2ban-ssh 1 -s -j DROP - -# Option: fwunbanrule -# Notes.: command executed when unbanning an IP. Take care that the -# command is executed with Fail2Ban user rights. -# Tags: IP address -# unix timestamp of the ban time -# unix timestamp of the unban time -# Values: CMD -# Default: iptables -D INPUT -s -j DROP -# -fwunban = iptables -D fail2ban-ssh -s -j DROP +port = ssh # Option: timeregex # Notes.: regex to match timestamp in SSH logfile. For TAI64N format, diff --git a/config/fail2ban.conf.shorewall b/config/fail2ban.conf.shorewall new file mode 100644 index 00000000..570017fd --- /dev/null +++ b/config/fail2ban.conf.shorewall @@ -0,0 +1,281 @@ +# Fail2Ban configuration file +# +# $Revision$ +# +# 2005.06.21 modified for readability Iain Lea iain@bricbrac.de + +[DEFAULT] +# Option: background +# Notes.: start fail2ban as a daemon. Output is redirect to logfile. +# Values: [true | false] Default: false +# +background = false + +# Option: logtargets +# Notes.: log targets. Space separated list of logging targets. +# Values: STDERR SYSLOG file Default: /var/log/fail2ban.log +# +logtargets = /var/log/fail2ban.log + +# Option: syslog-target +# Notes.: where to find syslog facility if logtarget SYSLOG. +# Values: SOCKET HOST HOST:PORT Default: /dev/log +# +syslog-target = /dev/log + +# Option: syslog-facility +# Notes.: which syslog facility to use if logtarget SYSLOG. +# Values: NUM Default: 1 +# +syslog-facility = 1 + +# Option: pidlock +# Notes.: path of the PID lock file (must be able to write to file). +# Values: FILE Default: /var/run/fail2ban.pid +# +pidlock = /var/run/fail2ban.pid + +# Option: maxfailures +# Notes.: number of failures before IP gets banned. +# Values: NUM Default: 5 +# +maxfailures = 5 + +# Option: bantime +# Notes.: number of seconds an IP will be banned. If set to a negative +# value, IP will never be unbanned (permanent banning). +# Values: NUM Default: 600 +# +bantime = 600 + +# Option: findtime +# Notes.: lifetime in seconds of a "failed" log entry. +# Values: NUM Default: 600 +# +findtime = 600 + +# Option: ignoreip +# Notes.: space separated list of IP's to be ignored by fail2ban. +# You can use CIDR mask in order to specify a range. +# Example: ignoreip = 192.168.0.1/24 123.45.235.65 +# Values: IP Default: +# +ignoreip = + +# Option: cmdstart +# Notes.: command executed once at the start of Fail2Ban +# Values: CMD Default: +# +cmdstart = + +# Option: cmdend +# Notes.: command executed once at the end of Fail2Ban. +# Values: CMD Default: +# +cmdend = + +# Option: polltime +# Notes.: number of seconds fail2ban sleeps between iterations. +# Values: NUM Default: 1 +# +polltime = 1 + +# Option: reinittime +# Notes.: minimal number of seconds between the re-initialization of +# firewalls due to external changes in their rules (see fwcheck) +# Values: NUM Default: 100 +# +reinittime = 10 + +# Option: maxreinits +# Notes.: maximal number of re-initialization of firewalls due to external +# changes. -1 stays for infinite, so only reinittime is of importance +# Values: NUM Default: -1 +# +maxreinits = -1 + +# NOTE: Interpolations +# +# fwstart, as well as fwend, fwcheck, fwban, fwunban, use interpolations +# so %(__name__)s will be substituted by a name of each section +# (unless the option is overriden in a section). +# If you are going to use interpolations in your setup, please make +# sure that you specified options port and protocol (which also has +# an option in DEFAULT). +# + +# Option: fwban +# Notes.: command executed when banning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: IP address +# number of failures +# unix timestamp of the last failure +# unix timestamp of the ban time +# Values: CMD +# Default: iptables -I INPUT 1 -s -j DROP +# +fwban = shorewall drop + +# Option: fwunban +# Notes.: command executed when unbanning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: IP address +# unix timestamp of the ban time +# unix timestamp of the unban time +# Values: CMD +# Default: iptables -D INPUT -s -j DROP +# +fwunban = shorewall allow + +[MAIL] +# Option: enabled +# Notes.: enable mail notification when banning an IP address. +# Values: [true | false] Default: false +# +enabled = false + +# Option: host +# Notes.: host running the mail server. +# Values: STR Default: localhost +# +host = localhost + +# Option: port +# Notes.: port of the mail server. +# Values: INT Default: 25 +# +port = 25 + +# Option: user +# Notes.: the username for smtp-server if authentification is required. +# if user is empty, no authentification is done. +# Values: STR Default: +# +user = + +# Option: password +# Notes.: the smtp-user's password if authentification is required. +# Values: STR Default: +# +password = + +# Option: from +# Notes.: e-mail address of the sender. +# Values: MAIL Default: fail2ban +# +from = fail2ban + +# Option: to +# Notes.: e-mail addresses of the receiver. Addresses are space +# separated. +# Values: MAIL Default: root +# +to = root + +# Option: localtime +# Notes.: report local time (including timezone) or GMT +# Values: [true | false] Default: false +# +localtime = true + +# Option: subject +# Notes.: subject of the e-mail. +# Tags:
active section (eg ssh, apache, etc) +# IP address +# number of failures +# unix timestamp of the last failure +# Values: TEXT Default: [Fail2Ban]
: Banned +# +subject = [Fail2Ban]
: Banned + +# Option: message +# Notes.: message of the e-mail. +# Tags:
active section (eg ssh, apache, etc) +# IP address +# number of failures +# unix timestamp of the last failure +#
new line +# Values: TEXT Default: +# +message = Hi,
+ The IP has just been banned by Fail2Ban after + attempts against
.
+ Regards,
+ Fail2Ban + +# You can define a new section for each log file to check for +# password failure. Each section has to define the following +# options: logfile, fwban, fwunban, timeregex, timepattern, +# failregex. + + +[Apache] +# Option: enabled +# Notes.: enable monitoring for this section. +# Values: [true | false] Default: false +# +enabled = false + +# Option: logfile +# Notes.: logfile to monitor. +# Values: FILE Default: /var/log/httpd/access_log +# +logfile = /var/log/httpd/access_log + +# Option: timeregex +# Notes.: regex to match timestamp in Apache logfile. For TAI64N format, +# use timeregex = @[0-9a-f]{24} +# Values: [Wed Jan 05 15:08:01 2005] +# Default: \S{3} \S{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} +# +timeregex = \S{3} \S{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} + +# Option: timepattern +# Notes.: format used in "timeregex" fields definition. Note that '%' must be +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule). +# For TAI64N format, use timepattern = tai64n +# Values: TEXT Default: %%a %%b %%d %%H:%%M:%%S %%Y +# +timepattern = %%a %%b %%d %%H:%%M:%%S %%Y + +# Option: failregex +# Notes.: regex to match the password failure messages in the logfile. +# Values: TEXT Default: authentication failure|user .* not found +# +failregex = authentication failure|user .* not found + + +[SSH] +# Option: enabled +# Notes.: enable monitoring for this section. +# Values: [true | false] Default: true +# +enabled = true + +# Option: logfile +# Notes.: logfile to monitor. +# Values: FILE Default: /var/log/secure +# +logfile = /var/log/secure + +# Option: timeregex +# Notes.: regex to match timestamp in SSH logfile. For TAI64N format, +# use timeregex = @[0-9a-f]{24} +# Values: [Mar 7 17:53:28] +# Default: \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} +# +timeregex = \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} + +# Option: timepattern +# Notes.: format used in "timeregex" fields definition. Note that '%' must be +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule). +# For TAI64N format, use timepattern = tai64n +# Values: TEXT Default: %%b %%d %%H:%%M:%%S +# +timepattern = %%b %%d %%H:%%M:%%S + +# Option: failregex +# Notes.: regex to match the password failures messages in the logfile. +# Values: TEXT Default: Authentication failure|Failed password|Invalid user +# +failregex = Authentication failure|Failed password|Invalid user From ad4280d50690d9611af3cb38ed336713d51d638a Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 22 Jan 2006 11:08:42 +0000 Subject: [PATCH 17/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@234 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 12 ++++++++++++ MANIFEST | 4 +++- README | 2 +- setup.py | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 42c371a7..5ad5abfe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,6 +25,18 @@ ver. 0.6.? (200?/??/??) - ??? Thanks to Patrick Börjesson - Removed 192.168.0.0/16 from ignoreip. Attacks could also come from the local network. +- Robust startup: if iptables module does not get fully + initialized after startup of fail2ban, fail2ban will do + "maxreinit" attempts to initialize its own firewall. It + will sleep between attempts for "polltime" number of + seconds (closes Debian: #334272). Thanks to Yaroslav + Halchenko +- Added "interpolations" in fail2ban.conf. This is provided + by the ConfigParser module. Old configuration files still + work. Thanks to Yaroslav Halchenko +- Added initial support for hosts.deny and shorewall. Need + more testing. Please test. Thanks to kojiro from Gentoo + forum for hosts.deny support ver. 0.6.0 (2005/11/20) - stable ---------- diff --git a/MANIFEST b/MANIFEST index b56a8b73..22731947 100644 --- a/MANIFEST +++ b/MANIFEST @@ -18,7 +18,9 @@ utils/process.py utils/mail.py utils/strings.py utils/pidlock.py -config/fail2ban.conf.default +config/fail2ban.conf.iptables +config/fail2ban.conf.shorewall +config/fail2ban.conf.hostsdeny config/gentoo-initd config/gentoo-confd config/redhat-initd diff --git a/README b/README index 0c241a8a..0b149723 100644 --- a/README +++ b/README @@ -124,7 +124,7 @@ Thanks: Kévin Drapel, Marvin Rouge, Sireyessire, Robert Edeker, Tom Pike, Iain Lea, Andrey G. Grozin, Yaroslav Halchenko, Jonathan Kamens, Stephen Gildea, Markus Hoffmann, Mark -Edgington, Patrick Börjesson +Edgington, Patrick Börjesson, kojiro License: -------- diff --git a/setup.py b/setup.py index a4f096f3..99b7f024 100755 --- a/setup.py +++ b/setup.py @@ -78,5 +78,5 @@ if obsoleteFiles: if argv[1] == "install": print print "Please do not forget to update your configuration file." - print "Use config/fail2ban.conf.default as example." + print "Use config/fail2ban.conf.* as example." print From d29648d4defb5760f7325b24150d16a937ef4da1 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 22 Jan 2006 11:10:29 +0000 Subject: [PATCH 18/26] - Added a more robust firewall initialization loop. Thanks to Yaroslav Halchenko git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@235 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fail2ban.py b/fail2ban.py index f192f5b5..1ab2ab90 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -423,7 +423,25 @@ def main(): else: logSys.warn(ip + " is not a valid IP address") - initializeFwRules() + # Startup loop -- necessary to avoid crash if it takes time for iptables + # to startup. To avoid introduction of new config options, reusing + # maxreinits and polltime. + reinits = 0 + while True: + try: + initializeFwRules() + break + except ExternalError, e: + reinits += 1 + logSys.warn(e) + if conf["maxreinits"] < 0 or (reinits < conf["maxreinits"]): + logSys.warn("#%d attempt to initialize the firewalls" % reinits) + else: + logSys.error("Exiting: Too many attempts to initialize the " + + "firewall") + killApp() + time.sleep(conf["polltime"]) + # try to reinit once if it fails immediately lastReinitTime = time.time() - conf["reinittime"] - 1 reinits = 0 From 054d18dd28d64c8cefd032d0e7110471425e3221 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Fri, 10 Feb 2006 10:26:16 +0000 Subject: [PATCH 19/26] - Updated with ideas for 0.7 git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@236 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- TODO | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/TODO b/TODO index 190a84cb..6abfc5c1 100644 --- a/TODO +++ b/TODO @@ -4,23 +4,69 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -ToDo $Revision$ +ToDo $Revision$ ============================================================= See Feature Request Tracking System at SourceForge.net - improve installation process (better prefix support) -- install Fail2ban into /usr/share + +- improve documentation and website + - better configuration files + - add a check to see if the time of the log messages is correctly detected (valid regexp) -- split configuration files in /etc/fail2ban/services.d - Example: /etc/fail2ban/services.d/apache -- template for common services in /etc/fail2ban/scripts.d - Example: /etc/fail2ban/scripts.d/apache -- remove debug mode (root check) -- better return values in function -- use more email.Utils in mail.py -- add gettext support -- send an email when fail2ban is running + - use Gentoo Portage style for scripts + - split configuration files in /etc/fail2ban/services.d + Example: /etc/fail2ban/services.d/apache + - template for common services in /etc/fail2ban/scripts.d + Example: /etc/fail2ban/scripts.d/apache + +- remove debug mode (root check) + +- better return values in function + +- use more email.Utils in mail.py + +- add gettext support + +- send an email when fail2ban is running + +- add multithreading. Python threading is not really + efficient. However, fail2ban could benefit of it. We could + use threads like this: + - one thread which check for host to unban. + - one thread per file to watch. This will allow things like + different polling time for each file. + is read-only (we only read log files) thus no locks + are required. However, is read-write and must take + care of concurrency in case of multithreading. + +- add FAM/Gamin support. Should be quite efficient with + threading. Take care that handle_one_event() release the + Python lock. + +- add a test framework. We could use unittest which is in + Python since 2.1. It should be possible to run all tests + automatically. + +- add client/server using socket. Something similar to + gdesklets. DBUS seems to be designed for desktop use. + - fail2ban start -> start the daemon. + - fail2ban stop -> stop the daemon. + - fail2ban add -> add monitoring with + ban method (iptables, hosts.deny, etc). + - fail2ban del -> remove monitoring. + - fail2ban status -> query current fail2ban status. + Should return infos like a ban counter. Could be graph + with rrdtool. + - fail2ban pause -> suspend monitoring. + - fail2ban resume -> resume monitoring. + - fail2ban list -> list available services. + - fail2ban flush -> flush the ban list. + +- remove PID file. + +- remove most of the command lines options if possible. From 7e24b948bf7f3257db8ee6ed503436f83a870d5f Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sat, 11 Feb 2006 15:29:32 +0000 Subject: [PATCH 20/26] - Added vsftpd support. Thanks to zugeschmiert git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@237 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- config/fail2ban.conf.hostsdeny | 40 ++++++++++++++++++++++++++++++++++ config/fail2ban.conf.iptables | 40 ++++++++++++++++++++++++++++++++++ config/fail2ban.conf.shorewall | 33 ++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/config/fail2ban.conf.hostsdeny b/config/fail2ban.conf.hostsdeny index 693d28a9..05c9d582 100644 --- a/config/fail2ban.conf.hostsdeny +++ b/config/fail2ban.conf.hostsdeny @@ -251,6 +251,46 @@ timepattern = %%a %%b %%d %%H:%%M:%%S %%Y failregex = authentication failure|user .* not found +[VSFTPD] +# Option: enabled +# Notes.: enable monitoring for this section. +# Values: [true | false] Default: false +# +enabled = false + +# Option: logfile +# Notes.: logfile to monitor. +# Values: FILE Default: /var/log/secure +# +logfile = /var/log/vsftpd.log + +# Option: port +# Notes.: specifies port to monitor +# Values: [ NUM | STRING ] Default: +# +port = ftp + +# Option: timeregex +# Notes.: regex to match timestamp in VSFTPD logfile. +# Values: [Mar 7 17:53:28] +# Default: \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} +# +timeregex = \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} + +# Option: timepattern +# Notes.: format used in "timeregex" fields definition. Note that '%' must be +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule) +# Values: TEXT Default: %%b %%d %%H:%%M:%%S +# +timepattern = %%b %%d %%H:%%M:%%S + +# Option: failregex +# Notes.: regex to match the password failures messages in the logfile. +# Values: TEXT Default: Authentication failure|Failed password|Invalid user +# +failregex = FAIL LOGIN + + [SSH] # Option: enabled # Notes.: enable monitoring for this section. diff --git a/config/fail2ban.conf.iptables b/config/fail2ban.conf.iptables index 4cf103b5..46da5466 100644 --- a/config/fail2ban.conf.iptables +++ b/config/fail2ban.conf.iptables @@ -279,6 +279,46 @@ timepattern = %%a %%b %%d %%H:%%M:%%S %%Y failregex = authentication failure|user .* not found +[VSFTPD] +# Option: enabled +# Notes.: enable monitoring for this section. +# Values: [true | false] Default: false +# +enabled = false + +# Option: logfile +# Notes.: logfile to monitor. +# Values: FILE Default: /var/log/secure +# +logfile = /var/log/vsftpd.log + +# Option: port +# Notes.: specifies port to monitor +# Values: [ NUM | STRING ] Default: +# +port = ftp + +# Option: timeregex +# Notes.: regex to match timestamp in VSFTPD logfile. +# Values: [Mar 7 17:53:28] +# Default: \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} +# +timeregex = \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} + +# Option: timepattern +# Notes.: format used in "timeregex" fields definition. Note that '%' must be +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule) +# Values: TEXT Default: %%b %%d %%H:%%M:%%S +# +timepattern = %%b %%d %%H:%%M:%%S + +# Option: failregex +# Notes.: regex to match the password failures messages in the logfile. +# Values: TEXT Default: Authentication failure|Failed password|Invalid user +# +failregex = FAIL LOGIN + + [SSH] # Option: enabled # Notes.: enable monitoring for this section. diff --git a/config/fail2ban.conf.shorewall b/config/fail2ban.conf.shorewall index 570017fd..2cb0fc46 100644 --- a/config/fail2ban.conf.shorewall +++ b/config/fail2ban.conf.shorewall @@ -244,6 +244,39 @@ timepattern = %%a %%b %%d %%H:%%M:%%S %%Y # failregex = authentication failure|user .* not found +[VSFTPD] +# Option: enabled +# Notes.: enable monitoring for this section. +# Values: [true | false] Default: false +# +enabled = false + +# Option: logfile +# Notes.: logfile to monitor. +# Values: FILE Default: /var/log/secure +# +logfile = /var/log/vsftpd.log + +# Option: timeregex +# Notes.: regex to match timestamp in VSFTPD logfile. +# Values: [Mar 7 17:53:28] +# Default: \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} +# +timeregex = \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2} + +# Option: timepattern +# Notes.: format used in "timeregex" fields definition. Note that '%' must be +# escaped with '%' (see http://rgruet.free.fr/PQR2.3.html#timeModule) +# Values: TEXT Default: %%b %%d %%H:%%M:%%S +# +timepattern = %%b %%d %%H:%%M:%%S + +# Option: failregex +# Notes.: regex to match the password failures messages in the logfile. +# Values: TEXT Default: Authentication failure|Failed password|Invalid user +# +failregex = FAIL LOGIN + [SSH] # Option: enabled From dfb6f637539244e3f9204db7ad41250326c7f1ed Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sat, 11 Feb 2006 15:30:04 +0000 Subject: [PATCH 21/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@238 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 1 + README | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5ad5abfe..2290b1e7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -37,6 +37,7 @@ ver. 0.6.? (200?/??/??) - ??? - Added initial support for hosts.deny and shorewall. Need more testing. Please test. Thanks to kojiro from Gentoo forum for hosts.deny support +- Added support for vsftpd. Thanks to zugeschmiert ver. 0.6.0 (2005/11/20) - stable ---------- diff --git a/README b/README index 0b149723..397c0814 100644 --- a/README +++ b/README @@ -74,8 +74,17 @@ Fail2Ban should now be correctly installed. Just type: > fail2ban -h to see if everything is alright. You can configure fail2ban -with a config file. Copy config/fail2ban.conf.default to -/etc/fail2ban.conf. +with a config file. Different kind of configuration files are +available: + +iptables: copy config/fail2ban.conf.iptables to + /etc/fail2ban.conf +hosts.deny: copy config/fail2ban.conf.hostsdeny to + /etc/fail2ban.conf +shorewall: copy config/fail2ban.conf.shorewall to + /etc/fail2ban.conf + +Do not forget to edit fail2ban.conf to meet your needs. You can use the initd script available in config/. Copy -initd to /etc/init.d/fail2ban. Gentoo users must copy @@ -124,7 +133,7 @@ Thanks: Kévin Drapel, Marvin Rouge, Sireyessire, Robert Edeker, Tom Pike, Iain Lea, Andrey G. Grozin, Yaroslav Halchenko, Jonathan Kamens, Stephen Gildea, Markus Hoffmann, Mark -Edgington, Patrick Börjesson, kojiro +Edgington, Patrick Börjesson, kojiro, zugeschmiert License: -------- From 83ea17fd245b339939df2803f404f42f6b6bf739 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 12 Feb 2006 12:30:39 +0000 Subject: [PATCH 22/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@239 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- TODO | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 6abfc5c1..a480b6c6 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,9 @@ See Feature Request Tracking System at SourceForge.net - improve installation process (better prefix support) -- improve documentation and website +- improve documentation and website for user + +- use Doxygen - better configuration files @@ -70,3 +72,8 @@ See Feature Request Tracking System at SourceForge.net - remove PID file. - remove most of the command lines options if possible. + +- add the possibility to specify wildcard in log files. + Example: logfile = /var/log/apache2/access-*.log + Should we start one thread per file or just one thread per + serivce? From 293f077d7b3e4dc958a12e2346dbc251f4641c4d Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 12 Feb 2006 18:15:44 +0000 Subject: [PATCH 23/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@240 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- TODO | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TODO b/TODO index a480b6c6..e9058a9b 100644 --- a/TODO +++ b/TODO @@ -77,3 +77,6 @@ See Feature Request Tracking System at SourceForge.net Example: logfile = /var/log/apache2/access-*.log Should we start one thread per file or just one thread per serivce? + +- optionally read failure patterns from file. If one regex + matches, consider it as a breaking in attempt. From b659cb2c2ab36d752c2fd38d258fcd0ea7847ef0 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 13 Feb 2006 21:37:44 +0000 Subject: [PATCH 24/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@241 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- TODO | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index e9058a9b..048f7381 100644 --- a/TODO +++ b/TODO @@ -20,11 +20,18 @@ See Feature Request Tracking System at SourceForge.net - add a check to see if the time of the log messages is correctly detected (valid regexp) -- use Gentoo Portage style for scripts +- use Gentoo Portage style for scripts. + - banning engines script in /etc/fail2ban/scripts.d + Example: /etc/fail2ban/scripts.d/iptables + Will be mostly bash scripting which is more "user + friendly". - split configuration files in /etc/fail2ban/services.d + for log files Example: /etc/fail2ban/services.d/apache - - template for common services in /etc/fail2ban/scripts.d - Example: /etc/fail2ban/scripts.d/apache + Mainly regular expressions. + - template for common regex in /etc/fail2ban/templates.d + Example: /etc/fail2ban/templates.d/date + Mainly regular expressions. - remove debug mode (root check) @@ -32,7 +39,8 @@ See Feature Request Tracking System at SourceForge.net - use more email.Utils in mail.py -- add gettext support +- add gettext support. Is this really needed for a server + utility? - send an email when fail2ban is running @@ -78,5 +86,8 @@ See Feature Request Tracking System at SourceForge.net Should we start one thread per file or just one thread per serivce? -- optionally read failure patterns from file. If one regex - matches, consider it as a breaking in attempt. +- autodetect date format in log file. Match the most popular + format and sort them using the hit ratio. Should avoid + user problem with regex and not have a big impact on perfs. + +- restart automatically the daemon if an exception occurs. From cbc18112bfc7d2242cfb0e5ca12fa724ba4add9f Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 21 Feb 2006 12:46:58 +0000 Subject: [PATCH 25/26] - Updated git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@242 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- TODO | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 048f7381..5e7b6347 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,7 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -ToDo $Revision$ +ToDo $Revision$ ============================================================= See Feature Request Tracking System at SourceForge.net @@ -15,6 +15,8 @@ See Feature Request Tracking System at SourceForge.net - use Doxygen +- use PyLint to check the code + - better configuration files - add a check to see if the time of the log messages is From 97aa913e243eacb8b93610d4ef6954d89c01a5eb Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Wed, 15 Mar 2006 23:07:12 +0000 Subject: [PATCH 26/26] - Updated for 0.6.1 git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@243 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 4 ++-- README | 6 +++--- version.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2290b1e7..fd74f7ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,10 +4,10 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.6.?) 200?/??/?? +Fail2Ban (version 0.6.1) 2006/03/16 ============================================================= -ver. 0.6.? (200?/??/??) - ??? +ver. 0.6.1 (2006/03/16) - stable ---------- - Added permanent banning. Set banTime to a negative value to enable this feature (-1 is perfect). Thanks to Mannone diff --git a/README b/README index 397c0814..c7878a59 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.6.0) 2005/11/20 +Fail2Ban (version 0.6.1) 2006/03/16 ============================================================= Fail2Ban scans log files like /var/log/pwdfail and bans IP @@ -58,8 +58,8 @@ Require: python-2.4 (http://www.python.org) To install, just do: -> tar xvfj fail2ban-0.6.0.tar.bz2 -> cd fail2ban-0.6.0 +> tar xvfj fail2ban-0.6.1.tar.bz2 +> cd fail2ban-0.6.1 > python setup.py install This will install Fail2Ban into /usr/lib/fail2ban. The diff --git a/version.py b/version.py index 07149645..80f0c7a8 100644 --- a/version.py +++ b/version.py @@ -24,4 +24,4 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -version = "0.6.0-CVS" +version = "0.6.1"