merged with upstream 0.6.0

debian-releases/etch
Yaroslav Halchenko 2005-11-21 01:43:13 +00:00
parent 3e2a09cdf7
commit bd3d510f96
22 changed files with 181 additions and 84 deletions

View File

@ -4,9 +4,37 @@
|_| \__,_|_|_/___|_.__/\__,_|_||_|
=============================================================
Fail2Ban (version 0.5.4) 2005/09/13
Fail2Ban (version 0.6.0) 2005/11/20
=============================================================
ver. 0.6.0 (2005/11/20) - stable
----------
- Propagated patches introduced by Debian maintainer
(Yaroslav Halchenko):
* Added an option to report local time (including timezone)
or GMT in mail notification.
ver. 0.5.5 (2005/10/26) - beta
----------
- Propagated patches introduced by Debian maintainer
(Yaroslav Halchenko):
* Introduced fwcheck option to verify consistency of the
chains. Implemented automatic restart of fail2ban main
function in case check of fwban or fwunban command failed
(closes: #329163, #331695). (Introduced patch was further
adjusted by upstream author).
* Added -f command line parameter for [findtime].
* Added a cleanup of firewall rules on emergency shutdown
when unknown exception is catched.
* Fail2ban should not crash now if a wrong file name is
specified in config.
* reordered code a bit so that log targets are setup right
after background and then only loglevel (verbose, debug)
is processed, so the warning could be seen in the logs
* Added a keyword <section> in parsing of the subject and
the body of an email sent out by fail2ban (closes:
#330311)
ver. 0.5.4 (2005/09/13) - beta
----------
- Fixed bug #1286222.

View File

@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: fail2ban
Version: 0.5.4
Version: 0.6.0
Summary: Ban IPs that make too many password failure
Home-page: http://fail2ban.sourceforge.net
Author: Cyril Jaquier

13
README
View File

@ -4,7 +4,7 @@
|_| \__,_|_|_/___|_.__/\__,_|_||_|
=============================================================
Fail2Ban (version 0.5.4) 2005/09/13
Fail2Ban (version 0.6.0) 2005/11/20
=============================================================
Fail2Ban scans log files like /var/log/pwdfail and bans IP
@ -54,12 +54,12 @@ firewalls.
Installation:
-------------
Require: python-2.3 (http://www.python.org)
Require: python-2.4 (http://www.python.org)
To install, just do:
> tar xvfj fail2ban-0.5.4.tar.bz2
> cd fail2ban-0.5.4
> tar xvfj fail2ban-0.6.0.tar.bz2
> cd fail2ban-0.6.0
> python setup.py install
This will install Fail2Ban into /usr/lib/fail2ban. The fail2ban
@ -102,8 +102,9 @@ options:
-h display this help message
-i <IP(s)> IP(s) to ignore
-k kill a currently running instance
-r <VALUE> allow a max of VALUE password failure
-t <TIME> ban IP for TIME seconds
-r <VALUE> allow a max of VALUE password failure [maxfailures]
-t <TIME> ban IP for TIME seconds [bantime]
-f <TIME> lifetime in seconds of failed entry [findtime]
-v verbose. Use twice for greater effect
-V print software version

11
TODO
View File

@ -4,7 +4,7 @@
|_| \__,_|_|_/___|_.__/\__,_|_||_|
=============================================================
ToDo
ToDo $Revision: 1.5 $
=============================================================
See Feature Request Tracking System at SourceForge.net
@ -12,3 +12,12 @@ See Feature Request Tracking System at SourceForge.net
- improve installation process (better prefix support)
- install Fail2ban into /usr/share
- 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

View File

@ -1,6 +1,6 @@
# Fail2Ban configuration file
#
# $Revision: 1.8.2.13 $
# $Revision: 1.9 $
#
# 2005.06.21 modified for readability Iain Lea iain@bricbrac.de
@ -156,9 +156,9 @@ localtime = true
# <ip> IP address
# <failures> number of failures
# <failtime> unix timestamp of the last failure
# Values: TEXT Default: [Fail2Ban:<section>] Banned <ip>
# Values: TEXT Default: [Fail2Ban] <section>: Banned <ip>
#
subject = [Fail2Ban:<section>] Banned <ip>
subject = [Fail2Ban] <section>: Banned <ip>
# Option: message
# Notes.: message of the e-mail.
@ -171,7 +171,7 @@ subject = [Fail2Ban:<section>] Banned <ip>
#
message = Hi,<br>
The IP <ip> has just been banned by Fail2Ban after
<failures> attempts.<br>
<failures> attempts against <section>.<br>
Regards,<br>
Fail2Ban
@ -180,6 +180,7 @@ message = Hi,<br>
# options: logfile, fwban, fwunban, timeregex, timepattern,
# failregex.
[Apache]
# Option: enabled
# Notes.: enable monitoring for this section.
@ -258,6 +259,7 @@ timepattern = %%a %%b %%d %%H:%%M:%%S %%Y
#
failregex = [[]client (?P<host>\S*)[]] user .*(?:: authentication failure|not found)
[SSH]
# Option: enabled
# Notes.: enable monitoring for this section.

View File

@ -16,7 +16,7 @@
#
# Author: Cyril Jaquier
#
# $Revision: 1.1.2.1 $
# $Revision: 1.2 $
# Command line options for Fail2Ban. Refer to "fail2ban -h" for
# valid options.

View File

@ -17,7 +17,7 @@
#
# Author: Sireyessire, Cyril Jaquier
#
# $Revision: 1.1.2.2 $
# $Revision: 1.2 $
opts="start stop restart showlog"

View File

@ -9,7 +9,7 @@
#
# Author: Andrey G. Grozin
#
# $Revision: 1.1.2.2 $
# $Revision: 1.2 $
# Source function library.
. /etc/init.d/functions

View File

@ -16,11 +16,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.5.2.5 $
# $Revision: 1.6 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.5.2.5 $"
__date__ = "$Date: 2005/08/01 16:31:13 $"
__version__ = "$Revision: 1.6 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"

11
debian/changelog vendored
View File

@ -1,3 +1,12 @@
fail2ban (0.6.0-1) unstable; urgency=low
* Merged with the latest stable upstream release. That incure some
changes for the Debian configuration of the package to be more
upstream-like:
- subject in the sent email includes section outside of [Fail2Ban]
-- Yaroslav Halchenko <debian@onerussian.com> Sun, 20 Nov 2005 14:56:41 -0500
fail2ban (0.5.4-10) unstable; urgency=low
* Fixed the order of ssh and apache rules to avoid possible race
@ -10,7 +19,7 @@ fail2ban (0.5.4-9) unstable; urgency=low
* Fixed init.d script so it doesn't return non-0 status if fail2ban is not
running. That fixes issues with purging the package and leaving garbage in
/usr/share/fail2ban (Thanx to Justin Pryzby for the insight)
/usr/share/fail2ban (Thanx to Justin Pryzby for the insight)
(closes: #337223)
-- Yaroslav Halchenko <debian@onerussian.com> Thu, 3 Nov 2005 17:05:20 -0500

View File

@ -18,11 +18,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.4.2.5 $
# $Revision: 1.5 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.4.2.5 $"
__date__ = "$Date: 2005/08/04 20:51:14 $"
__version__ = "$Revision: 1.5 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"

View File

@ -17,11 +17,11 @@
# Author: Cyril Jaquier
# Modified by: Yaroslav Halchenko (SYSLOG, findtime)
#
# $Revision: 1.20.2.18 $
# $Revision: 1.21 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.20.2.18 $"
__date__ = "$Date: 2005/09/13 20:42:33 $"
__version__ = "$Revision: 1.21 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
@ -62,9 +62,9 @@ def dispUsage():
print " -h display this help message"
print " -i <IP(s)> IP(s) to ignore"
print " -k kill a currently running instance"
print " -r <VALUE> allow a max of VALUE password failure [maxfailures]"
print " -r <VALUE> allow a max of VALUE password failures [maxfailures]"
print " -t <TIME> ban IP for TIME seconds [bantime]"
print " -f <TIME> lifetime in secods of failed entry [findtime]"
print " -f <TIME> lifetime in seconds of failed entry [findtime]"
print " -e <NAMEs> enable sections listed in NAMEs (coma or colon separated)"
print " -v verbose. Use twice for greater effect"
print " -V print software version"
@ -94,6 +94,12 @@ def sigTERMhandler(signum, frame):
logSys.debug("Signal handler called with sig "+`signum`)
killApp()
def setFwMustCheck(value):
""" Set the mustCheck value of the firewalls (True/False)
"""
for element in logFwList:
element[2].setMustCheck(value)
def initializeFwRules():
""" Initializes firewalls by running cmdstart and then
fwstart for each section
@ -199,6 +205,7 @@ def main():
formatter = logging.Formatter('%(asctime)s ' + formatterstring)
stdout.setFormatter(formatter)
conf["kill"] = False
conf["verbose"] = 0
conf["conffile"] = "/etc/fail2ban.conf"
@ -241,8 +248,7 @@ def main():
["str", "cmdend", ""],
["int", "reinittime", 100],
["int", "maxreinits", 100])
# Gets global configuration options
conf.update(confReader.getLogOptions("DEFAULT", optionValues))
@ -260,8 +266,7 @@ def main():
pidLock.setPath(conf["pidlock"])
# Now we can kill properly a running instance if needed
try:
conf["kill"]
if conf["kill"]:
pid = pidLock.exists()
if pid:
killPID(int(pid))
@ -270,8 +275,6 @@ def main():
else:
logSys.error("No running Fail2Ban found")
sys.exit(-1)
except KeyError:
pass
# Start Fail2Ban in daemon mode
if conf["background"]:
@ -281,6 +284,7 @@ def main():
logSys.error("Unable to start daemon")
sys.exit(-1)
# Process some options
# First setup Log targets
# Bug fix for #1234699
os.umask(0077)
@ -352,6 +356,24 @@ def main():
logSys.warn("DEBUG MODE: FIREWALL COMMANDS ARE _NOT_ EXECUTED BUT " +
"ONLY DISPLAYED IN THE LOG MESSAGES")
# Verbose level
if conf["verbose"]:
logSys.warn("Verbose level is "+`conf["verbose"]`)
if conf["verbose"] == 1:
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)] ' +
'%(message)s')
formatter = logging.Formatter("%(asctime)s " + formatterstring)
stdout.setFormatter(formatter)
logSys.warn("DEBUG MODE: FIREWALL COMMANDS ARE _NOT_ EXECUTED BUT " +
"ONLY DISPLAYED IN THE LOG MESSAGES")
# Ignores IP list
ignoreIPList = conf["ignoreip"].split(' ')
@ -427,8 +449,8 @@ def main():
lObj = LogReader(l["logfile"], l["timeregex"], l["timepattern"],
l["failregex"], l["maxfailures"], l["findtime"])
# Creates a firewall object
fObj = Firewall(l["fwstart"], l["fwend"],
l["fwban"], l["fwunban"], l["fwcheck"], l["bantime"])
fObj = Firewall(l["fwstart"], l["fwend"], l["fwban"], l["fwunban"],
l["fwcheck"], l["bantime"])
# "Name" the firewall
fObj.setSection(t)
# Links them into a list. I'm not really happy
@ -548,6 +570,9 @@ def main():
logSys.error("Exiting: reinits follow too often, or too many " +
"reinit attempts")
killApp()
# We already failed runCheck so disable it until
# restoring a safe state
setFwMustCheck(False)
# save firewalls to keep a list of IPs for rebanning
logFwListCopy = copy.deepcopy(logFwList)
try:
@ -559,6 +584,8 @@ def main():
logFwList.__init__(logFwListCopy)
# reBan known IPs
reBan()
# Now we can enable the runCheck test again
setFwMustCheck(True)
except ExternalError:
raise ExternalError("Big Oops happened: situation is out of " +
"control. Something is wrong with your " +

View File

@ -16,11 +16,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.8.2.6 $
# $Revision: 1.9 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.8.2.6 $"
__date__ = "$Date: 2005/08/01 16:31:42 $"
__version__ = "$Revision: 1.9 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
@ -32,6 +32,10 @@ from utils.process import executeCmd
# we might endup with not "full" flush unless we handle exception within the loop
from utils.process import ExternalError
from utils.strings import replaceTag
# unfortunately but I have to bring ExternalError in especially for
# flushBanList: if one of IPs got flushed manually outside or something, we
# might endup with not "full" flush unless we handle exception within the loop
from utils.process import ExternalError
# Gets the instance of the logger.
logSys = logging.getLogger("fail2ban")
@ -41,8 +45,8 @@ class Firewall:
the IP.
"""
def __init__(self, startRule, endRule,
banRule, unBanRule, checkRule, banTime):
def __init__(self, startRule, endRule, banRule, unBanRule, checkRule,
banTime):
self.banRule = banRule
self.unBanRule = unBanRule
self.checkRule = checkRule
@ -51,16 +55,27 @@ class Firewall:
self.banTime = banTime
self.banList = dict()
self.section = ""
self.mustCheck = True
def setSection(self, section):
""" Set optional section name for clarify of logging
"""
self.section = section
def initialize(self, debug):
logSys.debug("%s: Initialize firewall rules"%self.section)
executeCmd(self.startRule, debug)
def getMustCheck(self):
""" Return true if the runCheck test is executed
"""
return self.mustCheck
def setMustCheck(self, value):
""" Enable or disable the execution of runCheck test
"""
self.mustCheck = value
def initialize(self, debug):
logSys.debug("%s: Initialize firewall rules"%self.section)
executeCmd(self.startRule, debug)
def restore(self, debug):
logSys.debug("%s: Restore firewall rules"%self.section)
try:
@ -68,7 +83,7 @@ class Firewall:
executeCmd(self.endRule, debug)
except ExternalError:
pass
def addBanIP(self, aInfo, debug):
""" Bans an IP.
"""
@ -79,7 +94,10 @@ class Firewall:
self.banList[ip] = crtTime
aInfo["bantime"] = crtTime
self.runCheck(debug)
executeCmd(self.banIP(aInfo), debug)
cmd = self.banIP(aInfo)
if executeCmd(cmd, debug):
raise ExternalError("Firewall: execution of fwban command " +
"'%s' failed"%cmd)
else:
self.runCheck(debug)
logSys.error("%s: "%self.section+ip+" already in ban list")
@ -102,7 +120,7 @@ class Firewall:
"""
for ip in self.banList:
aInfo = {"ip": ip,
"bantime": self.banList[ip]}
"bantime":self.banList[ip]}
logSys.warn("%s: ReBan "%self.section + ip)
# next piece is similar to the on in addBanIp
# so might be one more function will not hurt
@ -118,8 +136,11 @@ class Firewall:
""" Runs fwcheck command and throws an exception if it returns non-0
result
"""
executeCmd(self.checkRule, debug)
if self.mustCheck:
executeCmd(self.checkRule, debug)
else:
return None
def checkForUnBan(self, debug):
""" Check for IP to remove from ban list.
"""

View File

@ -16,11 +16,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.13.2.8 $
# $Revision: 1.14 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.13.2.8 $"
__date__ = "$Date: 2005/09/05 21:06:15 $"
__version__ = "$Revision: 1.14 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
@ -97,17 +97,15 @@ class LogReader:
"""
try:
self.logStats = os.stat(self.logPath)
if self.lastModTime == self.logStats.st_mtime:
return False
else:
logSys.debug(self.logPath+" has been modified")
self.lastModTime = self.logStats.st_mtime
return True
return True
except OSError:
logSys.error("Unable to get stat on "+self.logPath)
return False
def setFilePos(self, file):
""" Sets the file position. We must take care of log file rotation

View File

@ -33,10 +33,13 @@ display this help message
kill a currently running Fail2Ban instance
.TP
\fB\-r\fR \fIVALUE\fR
allow a max of \fIVALUE\fR password failure
allow a max of \fIVALUE\fR password failure [maxfailures]
.TP
\fB\-t\fR \fITIME\fR
ban IP for \fITIME\fR seconds
ban IP for \fITIME\fR seconds [bantime]
.TP
\fB\-f\fR \fITIME\fR
lifetime in seconds of failed entry [findtime]
.TP
\fB\-v\fR
verbose. Use twice for greater effect

View File

@ -18,11 +18,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.4.2.4 $
# $Revision: 1.5 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.4.2.4 $"
__date__ = "$Date: 2005/08/07 13:10:39 $"
__version__ = "$Revision: 1.5 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"

View File

@ -16,11 +16,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.7.2.3 $
# $Revision: 1.8 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.7.2.3 $"
__date__ = "$Date: 2005/08/17 19:26:49 $"
__version__ = "$Revision: 1.8 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"

View File

@ -16,18 +16,17 @@
# Author: Cyril Jaquier
#
# $Revision: 1.1.2.4 $
# $Revision: 1.2 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.1.2.4 $"
__date__ = "$Date: 2005/09/12 14:42:08 $"
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
import logging, smtplib
import logging, smtplib, email.Utils
from utils.strings import replaceTag
import email.Utils
# Gets the instance of the logger.
logSys = logging.getLogger("fail2ban")
@ -64,7 +63,7 @@ class Mail:
mail = ("From: %s\r\nTo: %s\r\nDate: %s\r\nSubject: %s\r\n\r\n" %
(self.fromAddr, ", ".join(self.toAddr),
email.Utils.formatdate(localtime=self.localTimeFlag),
email.Utils.formatdate(localtime = self.localTimeFlag),
subj)) + msg
try:

View File

@ -16,11 +16,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.1.2.2 $
# $Revision: 1.2 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.1.2.2 $"
__date__ = "$Date: 2005/08/07 13:08:18 $"
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
@ -70,8 +70,8 @@ class PIDLock:
logSys.debug("Removed PID lock " + self.path)
except OSError:
logSys.error("Unable to remove PID lock " + self.path)
# AttributeError if self.path wasn't specified yet
except AttributeError:
# AttributeError if self.path wasn't specified yet
logSys.debug("PID lock not removed because not defined yet")
def exists(self):

View File

@ -16,11 +16,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.1.2.4 $
# $Revision: 1.2 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.1.2.4 $"
__date__ = "$Date: 2005/08/04 20:48:30 $"
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
@ -30,7 +30,7 @@ import os, logging, signal
logSys = logging.getLogger("fail2ban")
class ExternalError(UserWarning):
""" Exception to warn about failed command
""" Exception to warn about failed fwcheck or fwban command
"""
pass

View File

@ -16,11 +16,11 @@
# Author: Cyril Jaquier
#
# $Revision: 1.1.2.2 $
# $Revision: 1.2 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.1.2.2 $"
__date__ = "$Date: 2005/08/01 16:35:18 $"
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"

View File

@ -16,12 +16,12 @@
# Author: Cyril Jaquier
#
# $Revision: 1.12.2.10 $
# $Revision: 1.13 $
__author__ = "Cyril Jaquier"
__version__ = "$Revision: 1.12.2.10 $"
__date__ = "$Date: 2005/09/13 20:43:00 $"
__version__ = "$Revision: 1.13 $"
__date__ = "$Date: 2005/11/20 17:07:47 $"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
version = "0.5.4"
version = "0.6.0"