From 840f6cd0520ea842111ebf1b638f96cc5f72f096 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sun, 20 Nov 2005 17:07:47 +0000 Subject: [PATCH] - Merged FAIL2BAN-0_5 with HEAD git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@216 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 106 +++- MANIFEST | 12 +- README | 70 ++- TODO | 22 +- config/debian-initd | 73 +++ config/fail2ban.conf.default | 256 ++++++-- config/gentoo-confd | 2 +- config/gentoo-initd | 6 +- config/redhat-initd | 8 +- confreader/configreader.py | 43 +- fail2ban | 66 ++ fail2ban.py | 790 ++++++++++++------------ firewall/firewall.py | 144 ++++- firewall/ipfw.py | 72 --- firewall/iptables.py | 48 -- log-test/apache | 10 +- log-test/current | 6 + logreader/logreader.py | 101 +-- man/fail2ban.8 | 61 ++ man/fail2ban.conf.5 | 20 + setup.py | 58 +- utils/dns.py | 33 +- utils/mail.py | 79 +++ utils/pidlock.py | 109 ++++ utils/process.py | 137 ++++ firewall/ipfwadm.py => utils/strings.py | 32 +- version.py | 2 +- 27 files changed, 1619 insertions(+), 747 deletions(-) create mode 100644 config/debian-initd create mode 100755 fail2ban delete mode 100644 firewall/ipfw.py delete mode 100644 firewall/iptables.py create mode 100644 man/fail2ban.8 create mode 100644 man/fail2ban.conf.5 create mode 100644 utils/mail.py create mode 100644 utils/pidlock.py create mode 100644 utils/process.py rename firewall/ipfwadm.py => utils/strings.py (60%) diff --git a/CHANGELOG b/CHANGELOG index a05b6cbd..99e4402e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,15 +4,103 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.?.?) ??/??/2005 +Fail2Ban (version 0.6.0) 2005/11/20 ============================================================= -ver. 0.?.? (??/??/2005) - ??? +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
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. +- Propagated patches introduced by Debian maintainer + (Yaroslav Halchenko): + * Fixed handling of SYSLOG logging target. Now it can log + to any SYSLOG target and facility as directed by the + config + * Format of SYSLOG entries fixed to look closer to standard + * Fixed errata in config/gentoo-confd + * Introduced findtime configuration variable to control the + lifetime of caught "failed" log entries + +ver. 0.5.3 (2005/09/08) - beta +---------- +- Fixed a bug when overriding "maxfailures" or "bantime". + Thanks to Yaroslav Halchenko +- Added more debug output if an error occurs when sending + mail. Thanks to Stephen Gildea +- Renamed "maxretry" to "maxfailures" and changed default + value to 5. Thanks to Stephen Gildea +- Hopefully fixed bug #1256075 +- Fixed bug #1262345 +- Fixed exception handling in PIDLock +- Removed warning when using "-V" or "-h" with no config + file. Thanks to Yaroslav Halchenko +- Removed "-i eth0" from config file. Thanks to Yaroslav + Halchenko + +ver. 0.5.2 (2005/08/06) - beta +---------- +- Better PID lock file handling. Should close #1239562 +- Added man pages +- Removed log4py dependency. Use logging module instead +- "maxretry" and "bantime" can be overridden in each section +- Fixed bug #1246278 (excessive memory usage) +- Fixed crash on wrong option value in configuration file +- Changed custom chains to lowercase + +ver. 0.5.1 (2005/07/23) - beta +---------- +- Fixed bugs #1241756, #1239557 +- Added log targets in configuration file. Removed -l option +- Changed iptables rules in order to create a separated chain + for each section +- Fixed static banList in firewall.py +- Added an initd script for Debian. Thanks to Yaroslav + Halchenko +- Check for obsolete files after install + +ver. 0.5.0 (2005/07/12) - beta +---------- +- Added support for CIDR mask in ignoreip +- Added mail notification support +- Fixed bug #1234699 +- Added tags replacement in rules definition. Should allow a + clean solution for Feature Request #1229479 +- Removed "interface" and "firewall" options +- Added start and end commands in the configuration file. + Thanks to Yaroslav Halchenko +- Added firewall rules definition in the configuration file +- Cleaned fail2ban.py - Added an initd script for RedHat/Fedora. Thanks to Andrey G. Grozin -ver. 0.4.1 (06/30/2005) - stable +ver. 0.4.1 (2005/06/30) - stable ---------- - Fixed textToDNS method which generated wrong matches for "rhost=12-xyz...". Thanks to Tom Pike @@ -21,19 +109,19 @@ ver. 0.4.1 (06/30/2005) - stable - Changed default PID lock file location from /tmp to /var/run -ver. 0.4.0 (04/24/2005) - stable +ver. 0.4.0 (2005/04/24) - stable ---------- - Fixed textToDNS which did not recognize strings like "12-345-67-890.abcd.mnopqr.xyz" -ver. 0.3.1 (03/31/2005) - beta +ver. 0.3.1 (2005/03/31) - beta ---------- - Corrected level of messages - Added DNS lookup support - Improved parsing speed. Only parse the new log messages - Added a second verbose level (-vv) -ver. 0.3.0 (02/24/2005) - beta +ver. 0.3.0 (2005/02/24) - beta ---------- - Re-writting of parts of the code in order to handle several log files with different rules @@ -44,7 +132,7 @@ ver. 0.3.0 (02/24/2005) - beta - Added ipfw-start-rule option (thanks to Robert Edeker) - Added -k option which kills a currently running Fail2Ban -ver. 0.1.2 (11/21/2004) - beta +ver. 0.1.2 (2004/11/21) - beta ---------- - Add ipfw and ipfwadm support. The rules are taken from BlockIt. Thanks to Robert Edeker @@ -52,7 +140,7 @@ ver. 0.1.2 (11/21/2004) - beta Robert Edeker who reminded me this - Small code cleaning -ver. 0.1.1 (10/23/2004) - beta +ver. 0.1.1 (2004/10/23) - beta ---------- - Add SIGTERM handler in order to exit nicely when in daemon mode @@ -66,6 +154,6 @@ ver. 0.1.1 (10/23/2004) - beta - Code documentation -ver. 0.1.0 (10/12/2004) - alpha +ver. 0.1.0 (2004/10/12) - alpha ---------- - Initial release diff --git a/MANIFEST b/MANIFEST index 330728f8..b56a8b73 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4,18 +4,24 @@ TODO setup.cfg setup.py version.py +fail2ban fail2ban.py firewall/__init__.py firewall/firewall.py -firewall/iptables.py -firewall/ipfw.py -firewall/ipfwadm.py logreader/__init__.py logreader/logreader.py confreader/__init__.py confreader/configreader.py utils/__init__.py utils/dns.py +utils/process.py +utils/mail.py +utils/strings.py +utils/pidlock.py config/fail2ban.conf.default config/gentoo-initd config/gentoo-confd +config/redhat-initd +config/debian-initd +man/fail2ban.8 +man/fail2ban.conf.5 diff --git a/README b/README index 7882c60d..915304bb 100644 --- a/README +++ b/README @@ -4,14 +4,14 @@ |_| \__,_|_|_/___|_.__/\__,_|_||_| ============================================================= -Fail2Ban (version 0.4.1) 06/30/2005 +Fail2Ban (version 0.6.0) 2005/11/20 ============================================================= Fail2Ban scans log files like /var/log/pwdfail and bans IP that makes too many password failures. It updates firewall -rules to reject the IP address. Currently iptables, ipfw and -ipfwadm are supported. Fail2Ban can read multiple log files -such as sshd or Apache web server ones. It needs log4py. +rules to reject the IP address. These rules can be defined by +the user. Fail2Ban can read multiple log files such as sshd +or Apache web server ones. This is my first Python program. Moreover, English is not my mother tongue... @@ -36,51 +36,55 @@ tries to find lines which match the failregex. Then it retrieves the message time using timeregex and timepattern. It finally gets the ip and if it has already done 3 or more password failures in the last banTime, the ip is banned for -banTime using a firewall rule. After banTime, the rule is -deleted. Notice that if no "plain" ip is available, Fail2Ban -try to do DNS lookup in order to found one or several ip's to -ban. +banTime using a firewall rule. This rule is set by the user +in the configuration file. Thus, Fail2Ban can be adapted for +lots of firewall. After banTime, the rule is deleted. Notice +that if no "plain" ip is available, Fail2Ban try to do DNS +lookup in order to found one or several ip's to ban. Sections can be freely added so it is possible to monitor several daemons at the same time. Runs on my server and does its job rather well :-) The idea is to make fail2ban usable with daemons and services that -require a login (sshd, telnetd, ...). It should also support -others firewalls than iptables. +require a login (sshd, telnetd, ...) and with different +firewalls. Installation: ------------- -Require: python-2.3 (http://www.python.org) - log4py-1.1 (http://sourceforge.net/projects/log4py) +Require: python-2.4 (http://www.python.org) To install, just do: -> tar xvfj fail2ban-0.4.1.tar.bz2 -> cd fail2ban-0.4.1 +> 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.py executable is placed into /usr/bin. +This will install Fail2Ban into /usr/lib/fail2ban. The fail2ban +executable is placed into /usr/bin. -For Gentoo users, an ebuild is available on the website. +Gentoo: ebuilds are available on the website. +Debian: Fail2Ban is in Debian unstable. +RedHat: packages are available on the website. Fail2Ban should now be correctly installed. Just type: -> fail2ban.py -h +> 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. -Gentoo users can use the initd script available in config/. -Copy gentoo-initd to /etc/init.d/fail2ban and gentoo-confd -to /etc/conf.d/fail2ban. You can start fail2ban and add it -to your default runlevel: +You can use the initd script available in config/. Copy +-initd to /etc/init.d/fail2ban. Gentoo users must copy +gentoo-confd to /etc/conf.d/fail2ban. You can start fail2ban: > /etc/init.d/fail2ban start + +Gentoo users can add it to the default runlevel: + > rc-update add fail2ban default Configuration: @@ -91,20 +95,18 @@ or using command line options. Command line options override the value stored in fail2ban.conf. Here are the command line options: - -b start fail2ban in background - -d start fail2ban in debug mode - -e ban IP on the INTF interface + -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 -i IP(s) to ignore - -k kill a currently running Fail2Ban instance - -l log message in FILE - -r allow a max of VALUE password failure - -t