mirror of https://github.com/fail2ban/fail2ban
merged with upstream 0.6.0
parent
3e2a09cdf7
commit
bd3d510f96
30
CHANGELOG
30
CHANGELOG
|
@ -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
|
ver. 0.5.4 (2005/09/13) - beta
|
||||||
----------
|
----------
|
||||||
- Fixed bug #1286222.
|
- Fixed bug #1286222.
|
||||||
|
|
2
PKG-INFO
2
PKG-INFO
|
@ -1,6 +1,6 @@
|
||||||
Metadata-Version: 1.0
|
Metadata-Version: 1.0
|
||||||
Name: fail2ban
|
Name: fail2ban
|
||||||
Version: 0.5.4
|
Version: 0.6.0
|
||||||
Summary: Ban IPs that make too many password failure
|
Summary: Ban IPs that make too many password failure
|
||||||
Home-page: http://fail2ban.sourceforge.net
|
Home-page: http://fail2ban.sourceforge.net
|
||||||
Author: Cyril Jaquier
|
Author: Cyril Jaquier
|
||||||
|
|
13
README
13
README
|
@ -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
|
Fail2Ban scans log files like /var/log/pwdfail and bans IP
|
||||||
|
@ -54,12 +54,12 @@ firewalls.
|
||||||
Installation:
|
Installation:
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Require: python-2.3 (http://www.python.org)
|
Require: python-2.4 (http://www.python.org)
|
||||||
|
|
||||||
To install, just do:
|
To install, just do:
|
||||||
|
|
||||||
> tar xvfj fail2ban-0.5.4.tar.bz2
|
> tar xvfj fail2ban-0.6.0.tar.bz2
|
||||||
> cd fail2ban-0.5.4
|
> cd fail2ban-0.6.0
|
||||||
> python setup.py install
|
> python setup.py install
|
||||||
|
|
||||||
This will install Fail2Ban into /usr/lib/fail2ban. The fail2ban
|
This will install Fail2Ban into /usr/lib/fail2ban. The fail2ban
|
||||||
|
@ -102,8 +102,9 @@ options:
|
||||||
-h display this help message
|
-h display this help message
|
||||||
-i <IP(s)> IP(s) to ignore
|
-i <IP(s)> IP(s) to ignore
|
||||||
-k kill a currently running instance
|
-k kill a currently running instance
|
||||||
-r <VALUE> allow a max of VALUE password failure
|
-r <VALUE> allow a max of VALUE password failure [maxfailures]
|
||||||
-t <TIME> ban IP for TIME seconds
|
-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 verbose. Use twice for greater effect
|
||||||
-V print software version
|
-V print software version
|
||||||
|
|
||||||
|
|
11
TODO
11
TODO
|
@ -4,7 +4,7 @@
|
||||||
|_| \__,_|_|_/___|_.__/\__,_|_||_|
|
|_| \__,_|_|_/___|_.__/\__,_|_||_|
|
||||||
|
|
||||||
=============================================================
|
=============================================================
|
||||||
ToDo
|
ToDo $Revision: 1.5 $
|
||||||
=============================================================
|
=============================================================
|
||||||
|
|
||||||
See Feature Request Tracking System at SourceForge.net
|
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)
|
- improve installation process (better prefix support)
|
||||||
- install Fail2ban into /usr/share
|
- install Fail2ban into /usr/share
|
||||||
- better configuration files
|
- 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
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Fail2Ban configuration file
|
# Fail2Ban configuration file
|
||||||
#
|
#
|
||||||
# $Revision: 1.8.2.13 $
|
# $Revision: 1.9 $
|
||||||
#
|
#
|
||||||
# 2005.06.21 modified for readability Iain Lea iain@bricbrac.de
|
# 2005.06.21 modified for readability Iain Lea iain@bricbrac.de
|
||||||
|
|
||||||
|
@ -156,9 +156,9 @@ localtime = true
|
||||||
# <ip> IP address
|
# <ip> IP address
|
||||||
# <failures> number of failures
|
# <failures> number of failures
|
||||||
# <failtime> unix timestamp of the last failure
|
# <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
|
# Option: message
|
||||||
# Notes.: message of the e-mail.
|
# Notes.: message of the e-mail.
|
||||||
|
@ -171,7 +171,7 @@ subject = [Fail2Ban:<section>] Banned <ip>
|
||||||
#
|
#
|
||||||
message = Hi,<br>
|
message = Hi,<br>
|
||||||
The IP <ip> has just been banned by Fail2Ban after
|
The IP <ip> has just been banned by Fail2Ban after
|
||||||
<failures> attempts.<br>
|
<failures> attempts against <section>.<br>
|
||||||
Regards,<br>
|
Regards,<br>
|
||||||
Fail2Ban
|
Fail2Ban
|
||||||
|
|
||||||
|
@ -180,6 +180,7 @@ message = Hi,<br>
|
||||||
# options: logfile, fwban, fwunban, timeregex, timepattern,
|
# options: logfile, fwban, fwunban, timeregex, timepattern,
|
||||||
# failregex.
|
# failregex.
|
||||||
|
|
||||||
|
|
||||||
[Apache]
|
[Apache]
|
||||||
# Option: enabled
|
# Option: enabled
|
||||||
# Notes.: enable monitoring for this section.
|
# 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)
|
failregex = [[]client (?P<host>\S*)[]] user .*(?:: authentication failure|not found)
|
||||||
|
|
||||||
|
|
||||||
[SSH]
|
[SSH]
|
||||||
# Option: enabled
|
# Option: enabled
|
||||||
# Notes.: enable monitoring for this section.
|
# Notes.: enable monitoring for this section.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#
|
#
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.1.2.1 $
|
# $Revision: 1.2 $
|
||||||
|
|
||||||
# Command line options for Fail2Ban. Refer to "fail2ban -h" for
|
# Command line options for Fail2Ban. Refer to "fail2ban -h" for
|
||||||
# valid options.
|
# valid options.
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#
|
#
|
||||||
# Author: Sireyessire, Cyril Jaquier
|
# Author: Sireyessire, Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.1.2.2 $
|
# $Revision: 1.2 $
|
||||||
|
|
||||||
opts="start stop restart showlog"
|
opts="start stop restart showlog"
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#
|
#
|
||||||
# Author: Andrey G. Grozin
|
# Author: Andrey G. Grozin
|
||||||
#
|
#
|
||||||
# $Revision: 1.1.2.2 $
|
# $Revision: 1.2 $
|
||||||
|
|
||||||
# Source function library.
|
# Source function library.
|
||||||
. /etc/init.d/functions
|
. /etc/init.d/functions
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.5.2.5 $
|
# $Revision: 1.6 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.5.2.5 $"
|
__version__ = "$Revision: 1.6 $"
|
||||||
__date__ = "$Date: 2005/08/01 16:31:13 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
|
|
@ -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
|
fail2ban (0.5.4-10) unstable; urgency=low
|
||||||
|
|
||||||
* Fixed the order of ssh and apache rules to avoid possible race
|
* 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
|
* 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
|
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)
|
(closes: #337223)
|
||||||
|
|
||||||
-- Yaroslav Halchenko <debian@onerussian.com> Thu, 3 Nov 2005 17:05:20 -0500
|
-- Yaroslav Halchenko <debian@onerussian.com> Thu, 3 Nov 2005 17:05:20 -0500
|
||||||
|
|
6
fail2ban
6
fail2ban
|
@ -18,11 +18,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.4.2.5 $
|
# $Revision: 1.5 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.4.2.5 $"
|
__version__ = "$Revision: 1.5 $"
|
||||||
__date__ = "$Date: 2005/08/04 20:51:14 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
|
53
fail2ban.py
53
fail2ban.py
|
@ -17,11 +17,11 @@
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
# Modified by: Yaroslav Halchenko (SYSLOG, findtime)
|
# Modified by: Yaroslav Halchenko (SYSLOG, findtime)
|
||||||
#
|
#
|
||||||
# $Revision: 1.20.2.18 $
|
# $Revision: 1.21 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.20.2.18 $"
|
__version__ = "$Revision: 1.21 $"
|
||||||
__date__ = "$Date: 2005/09/13 20:42:33 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
@ -62,9 +62,9 @@ def dispUsage():
|
||||||
print " -h display this help message"
|
print " -h display this help message"
|
||||||
print " -i <IP(s)> IP(s) to ignore"
|
print " -i <IP(s)> IP(s) to ignore"
|
||||||
print " -k kill a currently running instance"
|
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 " -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 " -e <NAMEs> enable sections listed in NAMEs (coma or colon separated)"
|
||||||
print " -v verbose. Use twice for greater effect"
|
print " -v verbose. Use twice for greater effect"
|
||||||
print " -V print software version"
|
print " -V print software version"
|
||||||
|
@ -94,6 +94,12 @@ def sigTERMhandler(signum, frame):
|
||||||
logSys.debug("Signal handler called with sig "+`signum`)
|
logSys.debug("Signal handler called with sig "+`signum`)
|
||||||
killApp()
|
killApp()
|
||||||
|
|
||||||
|
def setFwMustCheck(value):
|
||||||
|
""" Set the mustCheck value of the firewalls (True/False)
|
||||||
|
"""
|
||||||
|
for element in logFwList:
|
||||||
|
element[2].setMustCheck(value)
|
||||||
|
|
||||||
def initializeFwRules():
|
def initializeFwRules():
|
||||||
""" Initializes firewalls by running cmdstart and then
|
""" Initializes firewalls by running cmdstart and then
|
||||||
fwstart for each section
|
fwstart for each section
|
||||||
|
@ -199,6 +205,7 @@ def main():
|
||||||
formatter = logging.Formatter('%(asctime)s ' + formatterstring)
|
formatter = logging.Formatter('%(asctime)s ' + formatterstring)
|
||||||
stdout.setFormatter(formatter)
|
stdout.setFormatter(formatter)
|
||||||
|
|
||||||
|
conf["kill"] = False
|
||||||
conf["verbose"] = 0
|
conf["verbose"] = 0
|
||||||
conf["conffile"] = "/etc/fail2ban.conf"
|
conf["conffile"] = "/etc/fail2ban.conf"
|
||||||
|
|
||||||
|
@ -241,8 +248,7 @@ def main():
|
||||||
["str", "cmdend", ""],
|
["str", "cmdend", ""],
|
||||||
["int", "reinittime", 100],
|
["int", "reinittime", 100],
|
||||||
["int", "maxreinits", 100])
|
["int", "maxreinits", 100])
|
||||||
|
|
||||||
|
|
||||||
# Gets global configuration options
|
# Gets global configuration options
|
||||||
conf.update(confReader.getLogOptions("DEFAULT", optionValues))
|
conf.update(confReader.getLogOptions("DEFAULT", optionValues))
|
||||||
|
|
||||||
|
@ -260,8 +266,7 @@ def main():
|
||||||
pidLock.setPath(conf["pidlock"])
|
pidLock.setPath(conf["pidlock"])
|
||||||
|
|
||||||
# Now we can kill properly a running instance if needed
|
# Now we can kill properly a running instance if needed
|
||||||
try:
|
if conf["kill"]:
|
||||||
conf["kill"]
|
|
||||||
pid = pidLock.exists()
|
pid = pidLock.exists()
|
||||||
if pid:
|
if pid:
|
||||||
killPID(int(pid))
|
killPID(int(pid))
|
||||||
|
@ -270,8 +275,6 @@ def main():
|
||||||
else:
|
else:
|
||||||
logSys.error("No running Fail2Ban found")
|
logSys.error("No running Fail2Ban found")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Start Fail2Ban in daemon mode
|
# Start Fail2Ban in daemon mode
|
||||||
if conf["background"]:
|
if conf["background"]:
|
||||||
|
@ -281,6 +284,7 @@ def main():
|
||||||
logSys.error("Unable to start daemon")
|
logSys.error("Unable to start daemon")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
# Process some options
|
||||||
# First setup Log targets
|
# First setup Log targets
|
||||||
# Bug fix for #1234699
|
# Bug fix for #1234699
|
||||||
os.umask(0077)
|
os.umask(0077)
|
||||||
|
@ -352,6 +356,24 @@ def main():
|
||||||
logSys.warn("DEBUG MODE: FIREWALL COMMANDS ARE _NOT_ EXECUTED BUT " +
|
logSys.warn("DEBUG MODE: FIREWALL COMMANDS ARE _NOT_ EXECUTED BUT " +
|
||||||
"ONLY DISPLAYED IN THE LOG MESSAGES")
|
"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
|
# Ignores IP list
|
||||||
ignoreIPList = conf["ignoreip"].split(' ')
|
ignoreIPList = conf["ignoreip"].split(' ')
|
||||||
|
|
||||||
|
@ -427,8 +449,8 @@ def main():
|
||||||
lObj = LogReader(l["logfile"], l["timeregex"], l["timepattern"],
|
lObj = LogReader(l["logfile"], l["timeregex"], l["timepattern"],
|
||||||
l["failregex"], l["maxfailures"], l["findtime"])
|
l["failregex"], l["maxfailures"], l["findtime"])
|
||||||
# Creates a firewall object
|
# Creates a firewall object
|
||||||
fObj = Firewall(l["fwstart"], l["fwend"],
|
fObj = Firewall(l["fwstart"], l["fwend"], l["fwban"], l["fwunban"],
|
||||||
l["fwban"], l["fwunban"], l["fwcheck"], l["bantime"])
|
l["fwcheck"], l["bantime"])
|
||||||
# "Name" the firewall
|
# "Name" the firewall
|
||||||
fObj.setSection(t)
|
fObj.setSection(t)
|
||||||
# Links them into a list. I'm not really happy
|
# 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 " +
|
logSys.error("Exiting: reinits follow too often, or too many " +
|
||||||
"reinit attempts")
|
"reinit attempts")
|
||||||
killApp()
|
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
|
# save firewalls to keep a list of IPs for rebanning
|
||||||
logFwListCopy = copy.deepcopy(logFwList)
|
logFwListCopy = copy.deepcopy(logFwList)
|
||||||
try:
|
try:
|
||||||
|
@ -559,6 +584,8 @@ def main():
|
||||||
logFwList.__init__(logFwListCopy)
|
logFwList.__init__(logFwListCopy)
|
||||||
# reBan known IPs
|
# reBan known IPs
|
||||||
reBan()
|
reBan()
|
||||||
|
# Now we can enable the runCheck test again
|
||||||
|
setFwMustCheck(True)
|
||||||
except ExternalError:
|
except ExternalError:
|
||||||
raise ExternalError("Big Oops happened: situation is out of " +
|
raise ExternalError("Big Oops happened: situation is out of " +
|
||||||
"control. Something is wrong with your " +
|
"control. Something is wrong with your " +
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.8.2.6 $
|
# $Revision: 1.9 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.8.2.6 $"
|
__version__ = "$Revision: 1.9 $"
|
||||||
__date__ = "$Date: 2005/08/01 16:31:42 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__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
|
# we might endup with not "full" flush unless we handle exception within the loop
|
||||||
from utils.process import ExternalError
|
from utils.process import ExternalError
|
||||||
from utils.strings import replaceTag
|
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.
|
# Gets the instance of the logger.
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = logging.getLogger("fail2ban")
|
||||||
|
@ -41,8 +45,8 @@ class Firewall:
|
||||||
the IP.
|
the IP.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, startRule, endRule,
|
def __init__(self, startRule, endRule, banRule, unBanRule, checkRule,
|
||||||
banRule, unBanRule, checkRule, banTime):
|
banTime):
|
||||||
self.banRule = banRule
|
self.banRule = banRule
|
||||||
self.unBanRule = unBanRule
|
self.unBanRule = unBanRule
|
||||||
self.checkRule = checkRule
|
self.checkRule = checkRule
|
||||||
|
@ -51,16 +55,27 @@ class Firewall:
|
||||||
self.banTime = banTime
|
self.banTime = banTime
|
||||||
self.banList = dict()
|
self.banList = dict()
|
||||||
self.section = ""
|
self.section = ""
|
||||||
|
self.mustCheck = True
|
||||||
|
|
||||||
def setSection(self, section):
|
def setSection(self, section):
|
||||||
""" Set optional section name for clarify of logging
|
""" Set optional section name for clarify of logging
|
||||||
"""
|
"""
|
||||||
self.section = section
|
self.section = section
|
||||||
|
|
||||||
def initialize(self, debug):
|
def getMustCheck(self):
|
||||||
logSys.debug("%s: Initialize firewall rules"%self.section)
|
""" Return true if the runCheck test is executed
|
||||||
executeCmd(self.startRule, debug)
|
"""
|
||||||
|
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):
|
def restore(self, debug):
|
||||||
logSys.debug("%s: Restore firewall rules"%self.section)
|
logSys.debug("%s: Restore firewall rules"%self.section)
|
||||||
try:
|
try:
|
||||||
|
@ -68,7 +83,7 @@ class Firewall:
|
||||||
executeCmd(self.endRule, debug)
|
executeCmd(self.endRule, debug)
|
||||||
except ExternalError:
|
except ExternalError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def addBanIP(self, aInfo, debug):
|
def addBanIP(self, aInfo, debug):
|
||||||
""" Bans an IP.
|
""" Bans an IP.
|
||||||
"""
|
"""
|
||||||
|
@ -79,7 +94,10 @@ class Firewall:
|
||||||
self.banList[ip] = crtTime
|
self.banList[ip] = crtTime
|
||||||
aInfo["bantime"] = crtTime
|
aInfo["bantime"] = crtTime
|
||||||
self.runCheck(debug)
|
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:
|
else:
|
||||||
self.runCheck(debug)
|
self.runCheck(debug)
|
||||||
logSys.error("%s: "%self.section+ip+" already in ban list")
|
logSys.error("%s: "%self.section+ip+" already in ban list")
|
||||||
|
@ -102,7 +120,7 @@ class Firewall:
|
||||||
"""
|
"""
|
||||||
for ip in self.banList:
|
for ip in self.banList:
|
||||||
aInfo = {"ip": ip,
|
aInfo = {"ip": ip,
|
||||||
"bantime": self.banList[ip]}
|
"bantime":self.banList[ip]}
|
||||||
logSys.warn("%s: ReBan "%self.section + ip)
|
logSys.warn("%s: ReBan "%self.section + ip)
|
||||||
# next piece is similar to the on in addBanIp
|
# next piece is similar to the on in addBanIp
|
||||||
# so might be one more function will not hurt
|
# 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
|
""" Runs fwcheck command and throws an exception if it returns non-0
|
||||||
result
|
result
|
||||||
"""
|
"""
|
||||||
executeCmd(self.checkRule, debug)
|
if self.mustCheck:
|
||||||
|
executeCmd(self.checkRule, debug)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def checkForUnBan(self, debug):
|
def checkForUnBan(self, debug):
|
||||||
""" Check for IP to remove from ban list.
|
""" Check for IP to remove from ban list.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.13.2.8 $
|
# $Revision: 1.14 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.13.2.8 $"
|
__version__ = "$Revision: 1.14 $"
|
||||||
__date__ = "$Date: 2005/09/05 21:06:15 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
@ -97,17 +97,15 @@ class LogReader:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.logStats = os.stat(self.logPath)
|
self.logStats = os.stat(self.logPath)
|
||||||
|
|
||||||
if self.lastModTime == self.logStats.st_mtime:
|
if self.lastModTime == self.logStats.st_mtime:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
logSys.debug(self.logPath+" has been modified")
|
logSys.debug(self.logPath+" has been modified")
|
||||||
self.lastModTime = self.logStats.st_mtime
|
self.lastModTime = self.logStats.st_mtime
|
||||||
return True
|
return True
|
||||||
except OSError:
|
except OSError:
|
||||||
logSys.error("Unable to get stat on "+self.logPath)
|
logSys.error("Unable to get stat on "+self.logPath)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def setFilePos(self, file):
|
def setFilePos(self, file):
|
||||||
""" Sets the file position. We must take care of log file rotation
|
""" Sets the file position. We must take care of log file rotation
|
||||||
|
|
|
@ -33,10 +33,13 @@ display this help message
|
||||||
kill a currently running Fail2Ban instance
|
kill a currently running Fail2Ban instance
|
||||||
.TP
|
.TP
|
||||||
\fB\-r\fR \fIVALUE\fR
|
\fB\-r\fR \fIVALUE\fR
|
||||||
allow a max of \fIVALUE\fR password failure
|
allow a max of \fIVALUE\fR password failure [maxfailures]
|
||||||
.TP
|
.TP
|
||||||
\fB\-t\fR \fITIME\fR
|
\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
|
.TP
|
||||||
\fB\-v\fR
|
\fB\-v\fR
|
||||||
verbose. Use twice for greater effect
|
verbose. Use twice for greater effect
|
||||||
|
|
6
setup.py
6
setup.py
|
@ -18,11 +18,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.4.2.4 $
|
# $Revision: 1.5 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.4.2.4 $"
|
__version__ = "$Revision: 1.5 $"
|
||||||
__date__ = "$Date: 2005/08/07 13:10:39 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.7.2.3 $
|
# $Revision: 1.8 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.7.2.3 $"
|
__version__ = "$Revision: 1.8 $"
|
||||||
__date__ = "$Date: 2005/08/17 19:26:49 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
|
|
@ -16,18 +16,17 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.1.2.4 $
|
# $Revision: 1.2 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.1.2.4 $"
|
__version__ = "$Revision: 1.2 $"
|
||||||
__date__ = "$Date: 2005/09/12 14:42:08 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
import logging, smtplib
|
import logging, smtplib, email.Utils
|
||||||
|
|
||||||
from utils.strings import replaceTag
|
from utils.strings import replaceTag
|
||||||
import email.Utils
|
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = logging.getLogger("fail2ban")
|
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" %
|
mail = ("From: %s\r\nTo: %s\r\nDate: %s\r\nSubject: %s\r\n\r\n" %
|
||||||
(self.fromAddr, ", ".join(self.toAddr),
|
(self.fromAddr, ", ".join(self.toAddr),
|
||||||
email.Utils.formatdate(localtime=self.localTimeFlag),
|
email.Utils.formatdate(localtime = self.localTimeFlag),
|
||||||
subj)) + msg
|
subj)) + msg
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.1.2.2 $
|
# $Revision: 1.2 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.1.2.2 $"
|
__version__ = "$Revision: 1.2 $"
|
||||||
__date__ = "$Date: 2005/08/07 13:08:18 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ class PIDLock:
|
||||||
logSys.debug("Removed PID lock " + self.path)
|
logSys.debug("Removed PID lock " + self.path)
|
||||||
except OSError:
|
except OSError:
|
||||||
logSys.error("Unable to remove PID lock " + self.path)
|
logSys.error("Unable to remove PID lock " + self.path)
|
||||||
# AttributeError if self.path wasn't specified yet
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
# AttributeError if self.path wasn't specified yet
|
||||||
logSys.debug("PID lock not removed because not defined yet")
|
logSys.debug("PID lock not removed because not defined yet")
|
||||||
|
|
||||||
def exists(self):
|
def exists(self):
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.1.2.4 $
|
# $Revision: 1.2 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.1.2.4 $"
|
__version__ = "$Revision: 1.2 $"
|
||||||
__date__ = "$Date: 2005/08/04 20:48:30 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import os, logging, signal
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = logging.getLogger("fail2ban")
|
||||||
|
|
||||||
class ExternalError(UserWarning):
|
class ExternalError(UserWarning):
|
||||||
""" Exception to warn about failed command
|
""" Exception to warn about failed fwcheck or fwban command
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.1.2.2 $
|
# $Revision: 1.2 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.1.2.2 $"
|
__version__ = "$Revision: 1.2 $"
|
||||||
__date__ = "$Date: 2005/08/01 16:35:18 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
|
|
||||||
# Author: Cyril Jaquier
|
# Author: Cyril Jaquier
|
||||||
#
|
#
|
||||||
# $Revision: 1.12.2.10 $
|
# $Revision: 1.13 $
|
||||||
|
|
||||||
__author__ = "Cyril Jaquier"
|
__author__ = "Cyril Jaquier"
|
||||||
__version__ = "$Revision: 1.12.2.10 $"
|
__version__ = "$Revision: 1.13 $"
|
||||||
__date__ = "$Date: 2005/09/13 20:43:00 $"
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
version = "0.5.4"
|
version = "0.6.0"
|
||||||
|
|
Loading…
Reference in New Issue