diff --git a/.gitignore b/.gitignore index b697c3dc..76a33e60 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ htmlcov *.orig *.rej *.bak +__pycache__ diff --git a/ChangeLog b/ChangeLog index 2df538e5..ad2e9a3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -77,7 +77,7 @@ ver. 0.8.12 (2013/12/XX) - things-can-only-get-better - allow for ",milliseconds" in the custom date format of proftpd.log - allow for ", referer ..." in apache-* filter for apache error logs. - allow for spaces at the beginning of kernel messages. Closes gh-448 - - recidive jail to block all protocols. Closes gh-440. Thanks Ioan Indreias + - recidive jail to block all protocols. Closes gh-440. Thanksg Ioan Indreias - smtps not a IANA standard and has been removed from Arch. Replaced with 465. Thanks Stefan. Closes gh-447 - mysqld-syslog-iptables rule was too long. Part of gh-447. @@ -86,6 +86,8 @@ ver. 0.8.12 (2013/12/XX) - things-can-only-get-better - complain action - ensure where not matching other IPs in log sample. Closes gh-467 - Fix firewall-cmd actioncheck - patch from Adam Tkac. Redhat Bug #979622 + - Fix apache-common for apache-2.4 log file format. Thanks Mark White. + Closes gh-516 - Enhancements: - long names on jails documented based on iptables limit of 30 less @@ -93,11 +95,16 @@ ver. 0.8.12 (2013/12/XX) - things-can-only-get-better - remove indentation of name and loglevel while logging to SYSLOG to resolve syslog(-ng) parsing problems. Closes Debian bug #730202. - added squid filter. Thanks Roman Gelfand. + - updated check_fail2ban to return performance data for all jails. + - filter apache-noscript now includes php cgi scripts. + Thanks dani. Closes gh-503 - New Features: Daniel Black * filter.d/solid-pop3d -- added thanks to Jacques Lav!gnotte on mailinglist. + Bas van den Dikkenberg & Steven Hiscocks + * filter.d/nsd.conf -- also amended Unix date template to match nsd format - Enhancements: - loglines now also report "[PID]" after the name portion diff --git a/MANIFEST b/MANIFEST index 0d0f3e89..0b339b89 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5,13 +5,14 @@ TODO THANKS COPYING DEVELOP -doc/run-rootless.txt fail2ban-2to3 +fail2ban-testcases-all fail2ban-testcases-all-python3 bin/fail2ban-client bin/fail2ban-server bin/fail2ban-testcases bin/fail2ban-regex +doc/run-rootless.txt fail2ban/client/configreader.py fail2ban/client/configparserinc.py fail2ban/client/jailreader.py @@ -61,23 +62,26 @@ fail2ban/tests/sockettestcase.py fail2ban/tests/utils.py fail2ban/tests/misctestcase.py fail2ban/tests/databasetestcase.py -fail2ban/tests/config/apache-auth/digest/.htaccess -fail2ban/tests/config/apache-auth/digest/.htpasswd -fail2ban/tests/config/apache-auth/digest_time/.htaccess -fail2ban/tests/config/apache-auth/digest_time/.htpasswd -fail2ban/tests/config/apache-auth/basic/authz_owner/.htaccess -fail2ban/tests/config/apache-auth/basic/authz_owner/cant_get_me.html -fail2ban/tests/config/apache-auth/basic/authz_owner/.htpasswd -fail2ban/tests/config/apache-auth/basic/file/.htaccess -fail2ban/tests/config/apache-auth/basic/file/.htpasswd -fail2ban/tests/config/apache-auth/digest.py -fail2ban/tests/config/apache-auth/digest_wrongrelm/.htaccess -fail2ban/tests/config/apache-auth/digest_wrongrelm/.htpasswd -fail2ban/tests/config/apache-auth/digest_anon/.htaccess -fail2ban/tests/config/apache-auth/digest_anon/.htpasswd -fail2ban/tests/config/apache-auth/README -fail2ban/tests/config/apache-auth/noentry/.htaccess +fail2ban/tests/files/config/apache-auth/digest/.htaccess +fail2ban/tests/files/config/apache-auth/digest/.htpasswd +fail2ban/tests/files/config/apache-auth/digest_time/.htaccess +fail2ban/tests/files/config/apache-auth/digest_time/.htpasswd +fail2ban/tests/files/config/apache-auth/basic/authz_owner/.htaccess +fail2ban/tests/files/config/apache-auth/basic/authz_owner/cant_get_me.html +fail2ban/tests/files/config/apache-auth/basic/authz_owner/.htpasswd +fail2ban/tests/files/config/apache-auth/basic/file/.htaccess +fail2ban/tests/files/config/apache-auth/basic/file/.htpasswd +fail2ban/tests/files/config/apache-auth/digest.py +fail2ban/tests/files/config/apache-auth/digest_wrongrelm/.htaccess +fail2ban/tests/files/config/apache-auth/digest_wrongrelm/.htpasswd +fail2ban/tests/files/config/apache-auth/digest_anon/.htaccess +fail2ban/tests/files/config/apache-auth/digest_anon/.htpasswd +fail2ban/tests/files/config/apache-auth/README +fail2ban/tests/files/config/apache-auth/noentry/.htaccess fail2ban/tests/files/database_v1.db +fail2ban/tests/files/ignorecommand.py +fail2ban/tests/files/filter.d/testcase-common.conf +fail2ban/tests/files/filter.d/testcase01.conf fail2ban/tests/files/testcase01.log fail2ban/tests/files/testcase02.log fail2ban/tests/files/testcase03.log @@ -88,54 +92,58 @@ fail2ban/tests/files/testcase-multiline.log fail2ban/tests/files/logs/bsd/syslog-plain.txt fail2ban/tests/files/logs/bsd/syslog-v.txt fail2ban/tests/files/logs/bsd/syslog-vv.txt +fail2ban/tests/files/logs/3proxy +fail2ban/tests/files/logs/apache-auth +fail2ban/tests/files/logs/apache-badbots +fail2ban/tests/files/logs/apache-modsecurity +fail2ban/tests/files/logs/apache-nohome +fail2ban/tests/files/logs/apache-noscript fail2ban/tests/files/logs/apache-overflows fail2ban/tests/files/logs/assp fail2ban/tests/files/logs/asterisk +fail2ban/tests/files/logs/courier-auth +fail2ban/tests/files/logs/courier-smtp +fail2ban/tests/files/logs/cyrus-imap fail2ban/tests/files/logs/dovecot +fail2ban/tests/files/logs/dropbear +fail2ban/tests/files/logs/ejabberd-auth fail2ban/tests/files/logs/exim -fail2ban/tests/files/logs/nginx-http-auth +fail2ban/tests/files/logs/exim-spam +fail2ban/tests/files/logs/gssftpd +fail2ban/tests/files/logs/guacamole fail2ban/tests/files/logs/lighttpd-auth +fail2ban/tests/files/logs/mysqld-auth +fail2ban/tests/files/logs/nsd +fail2ban/tests/files/logs/perdition +fail2ban/tests/files/logs/php-url-fopen +fail2ban/tests/files/logs/postfix-sasl fail2ban/tests/files/logs/named-refused +fail2ban/tests/files/logs/nginx-http-auth fail2ban/tests/files/logs/pam-generic fail2ban/tests/files/logs/postfix fail2ban/tests/files/logs/proftpd fail2ban/tests/files/logs/pure-ftpd +fail2ban/tests/files/logs/qmail +fail2ban/tests/files/logs/recidive fail2ban/tests/files/logs/roundcube-auth +fail2ban/tests/files/logs/selinux-ssh +fail2ban/tests/files/logs/sendmail-spam +fail2ban/tests/files/logs/sieve +fail2ban/tests/files/logs/squid +fail2ban/tests/files/logs/suhosin fail2ban/tests/files/logs/sogo-auth fail2ban/tests/files/logs/solid-pop3d fail2ban/tests/files/logs/sshd fail2ban/tests/files/logs/sshd-ddos fail2ban/tests/files/logs/vsftpd fail2ban/tests/files/logs/webmin-auth -fail2ban/tests/files/logs/3proxy -fail2ban/tests/files/logs/apache-auth -fail2ban/tests/files/logs/apache-badbots -fail2ban/tests/files/logs/apache-nohome -fail2ban/tests/files/logs/apache-noscript -fail2ban/tests/files/logs/courier-auth -fail2ban/tests/files/logs/courier-smtp -fail2ban/tests/files/logs/cyrus-imap -fail2ban/tests/files/logs/dropbear -fail2ban/tests/files/logs/ejabberd-auth -fail2ban/tests/files/logs/exim-spam -fail2ban/tests/files/logs/gssftpd -fail2ban/tests/files/logs/guacamole -fail2ban/tests/files/logs/lighttpd-auth -fail2ban/tests/files/logs/mysqld-auth -fail2ban/tests/files/logs/perdition -fail2ban/tests/files/logs/php-url-fopen -fail2ban/tests/files/logs/postfix-sasl -fail2ban/tests/files/logs/qmail -fail2ban/tests/files/logs/recidive -fail2ban/tests/files/logs/selinux-ssh -fail2ban/tests/files/logs/sendmail-spam -fail2ban/tests/files/logs/sieve -fail2ban/tests/files/logs/suhosin -fail2ban/tests/files/logs/uwimap-auth fail2ban/tests/files/logs/wuftpd +fail2ban/tests/files/logs/uwimap-auth fail2ban/tests/files/logs/xinetd-fail -fail2ban/tests/files/filter.d/testcase-common.conf -fail2ban/tests/files/filter.d/testcase01.conf +fail2ban/tests/config/jail.conf +fail2ban/tests/config/fail2ban.conf +fail2ban/tests/config/filter.d/simple.conf +fail2ban/tests/config/action.d/brokenaction.conf setup.py setup.cfg fail2ban/__init__.py @@ -262,7 +270,3 @@ files/fail2ban-tmpfiles.conf files/fail2ban.service files/ipmasq-ZZZzzz_fail2ban.rul files/gen_badbots -testcases/config/jail.conf -testcases/config/fail2ban.conf -testcases/config/filter.d/simple.conf -testcases/config/action.d/brokenaction.conf diff --git a/THANKS b/THANKS index d62b3150..bb479cc8 100644 --- a/THANKS +++ b/THANKS @@ -10,11 +10,13 @@ Adam Tkac Adrien Clerc ache ag4ve (Shawn) +Alasdair D. Campbell Amir Caspi Andrey G. Grozin Andy Fragen Arturo 'Buanzo' Busleiman Axel Thimm +Bas van den Dikkenberg Beau Raines Bill Heaton Carlos Alberto Lopez Perez @@ -24,6 +26,7 @@ Christoph Haas Christos Psonis Cyril Jaquier Daniel B. Cid +Daniel B. Daniel Black David Nutter Eric Gerbier @@ -47,10 +50,12 @@ Justin Shore Kévin Drapel kjohnsonecl kojiro +Lee Clemens Manuel Arostegui Ramirez Marcel Dopita Mark Edgington Mark McKinstry +Mark White Markus Hoffmann Marvin Rouge mEDI diff --git a/config/filter.d/apache-common.conf b/config/filter.d/apache-common.conf index 85ce7af5..c843c92e 100644 --- a/config/filter.d/apache-common.conf +++ b/config/filter.d/apache-common.conf @@ -8,12 +8,13 @@ after = apache-common.local [DEFAULT] -_apache_error_client = \[\] \[(error|\S+:\S+)\]( \[pid \d+:\S+ \d+\])? \[client (:\d{1,5})?\] +_apache_error_client = \[\] \[(:?error|\S+:\S+)\]( \[pid \d+(:\S+ \d+)?\])? \[client (:\d{1,5})?\] # Common prefix for [error] apache messages which also would include # Depending on the version it could be # 2.2: [Sat Jun 01 11:23:08 2013] [error] [client 1.2.3.4] # 2.4: [Thu Jun 27 11:55:44.569531 2013] [core:info] [pid 4101:tid 2992634688] [client 1.2.3.4:46652] +# 2.4 (perfork): [Mon Dec 23 07:49:01.981912 2013] [:error] [pid 3790] [client 204.232.202.107:46301] script '/var/www/timthumb.php' not found or unable to # # Reference: https://github.com/fail2ban/fail2ban/issues/268 # diff --git a/config/filter.d/apache-noscript.conf b/config/filter.d/apache-noscript.conf index 7ea257b2..9a591ca3 100644 --- a/config/filter.d/apache-noscript.conf +++ b/config/filter.d/apache-noscript.conf @@ -9,8 +9,8 @@ before = apache-common.conf [Definition] -failregex = ^%(_apache_error_client)s ((AH001(28|30): )?File does not exist|(AH01264: )?script not found or unable to stat): /\S*(\.php|\.asp|\.exe|\.pl)(, referer: \S+)?\s*$ - ^%(_apache_error_client)s script '/\S*(\.php|\.asp|\.exe|\.pl)\S*' not found or unable to stat(, referer: \S+)?\s*$ +failregex = ^%(_apache_error_client)s ((AH001(28|30): )?File does not exist|(AH01264: )?script not found or unable to stat): /\S*(php([45]|[.-]cgi)?|\.asp|\.exe|\.pl)(, referer: \S+)?\s*$ + ^%(_apache_error_client)s script '/\S*(php([45]|[.-]cgi)?|\.asp|\.exe|\.pl)\S*' not found or unable to stat(, referer: \S+)?\s*$ ignoreregex = diff --git a/config/filter.d/nsd.conf b/config/filter.d/nsd.conf new file mode 100644 index 00000000..cd4ce35f --- /dev/null +++ b/config/filter.d/nsd.conf @@ -0,0 +1,26 @@ +# Fail2Ban configuration file +# +# Author: Bas van den Dikkenberg +# +# + +[INCLUDES] + +# Read common prefixes. If any customizations available -- read them from +# common.local +before = common.conf + + +[Definition] + +_daemon = nsd + +# Option: failregex +# Notes.: regex to match the password failures messages in the logfile. The +# host must be matched by a group named "host". The tag "" can +# be used for standard IP/hostname matching and is only an alias for +# (?:::f{4,6}:)?(?P[\w\-.^_]+) +# Values: TEXT + +failregex = ^\[\]%(__prefix_line)sinfo: ratelimit block .* query TYPE255$ + ^\[\]%(__prefix_line)sinfo: .* refused, no acl matches\.$ diff --git a/config/jail.conf b/config/jail.conf index faf5cdca..acec2c5b 100644 --- a/config/jail.conf +++ b/config/jail.conf @@ -44,6 +44,12 @@ # defined using space separator. ignoreip = 127.0.0.1/8 +# External command that will take an tagged arguments to ignore, e.g. , +# and return true if the IP is to be ignored. False otherwise. +# +# ignorecommand = /path/to/command +ignorecommand = + # "bantime" is the number of seconds that a host is banned. bantime = 600 diff --git a/fail2ban/client/configreader.py b/fail2ban/client/configreader.py index d3e22474..ddbc48db 100644 --- a/fail2ban/client/configreader.py +++ b/fail2ban/client/configreader.py @@ -138,12 +138,13 @@ class DefinitionInitConfigReader(ConfigReader): def __init__(self, file_, jailName, initOpts, **kwargs): ConfigReader.__init__(self, **kwargs) - self._file = file_ - self._jailName = jailName + self.setFile(file_) + self.setJailName(jailName) self._initOpts = initOpts def setFile(self, fileName): self._file = fileName + self._initOpts = {} def getFile(self): return self._file diff --git a/fail2ban/client/filterreader.py b/fail2ban/client/filterreader.py index d8a6dbe8..7366ee47 100644 --- a/fail2ban/client/filterreader.py +++ b/fail2ban/client/filterreader.py @@ -35,6 +35,7 @@ class FilterReader(DefinitionInitConfigReader): _configOpts = [ ["string", "ignoreregex", ""], ["string", "failregex", ""], + ["string", "ignorecommand", ""], ] def read(self): diff --git a/fail2ban/client/jailreader.py b/fail2ban/client/jailreader.py index 1fcce4bb..df59bee0 100644 --- a/fail2ban/client/jailreader.py +++ b/fail2ban/client/jailreader.py @@ -89,6 +89,7 @@ class JailReader(ConfigReader): ["string", "usedns", "warn"], ["string", "failregex", None], ["string", "ignoreregex", None], + ["string", "ignorecommand", None], ["string", "ignoreip", None], ["string", "filter", ""], ["string", "action", ""]] @@ -179,6 +180,8 @@ class JailReader(ConfigReader): stream.append(["set", self.__name, "usedns", self.__opts[opt]]) elif opt == "failregex": stream.append(["set", self.__name, "addfailregex", self.__opts[opt]]) + elif opt == "ignorecommand": + stream.append(["set", self.__name, "ignorecommand", self.__opts[opt]]) elif opt == "ignoreregex": for regex in self.__opts[opt].split('\n'): # Do not send a command if the rule is empty. diff --git a/fail2ban/protocol.py b/fail2ban/protocol.py index 0361fcc3..f0b41786 100644 --- a/fail2ban/protocol.py +++ b/fail2ban/protocol.py @@ -65,6 +65,7 @@ protocol = [ ["set deljournalmatch ", "removes from the journal filter of "], ["set addfailregex ", "adds the regular expression which must match failures for "], ["set delfailregex ", "removes the regular expression at for failregex"], +["set ignorecommand ", "sets ignorecommand of "], ["set addignoreregex ", "adds the regular expression which should match pattern to exclude for "], ["set delignoreregex ", "removes the regular expression at for ignoreregex"], ["set findtime