From 8710bcfdbd3277996f52c33a2dede32f4e67fb08 Mon Sep 17 00:00:00 2001 From: bms8197 Date: Fri, 14 Apr 2023 01:32:52 +0300 Subject: [PATCH] committing changes in /etc made by "-bash" Package changes: --- .etckeeper | 56 ++- fail2ban/action.d/apprise.conf | 49 +++ fail2ban/action.d/badips.conf | 19 - fail2ban/action.d/badips.py | 392 ------------------ fail2ban/action.d/cloudflare-token.conf | 92 ++++ fail2ban/action.d/cloudflare.conf | 9 +- fail2ban/action.d/dshield.conf | 2 +- fail2ban/action.d/firewallcmd-ipset.conf | 47 ++- fail2ban/action.d/firewallcmd-multiport.conf | 4 +- fail2ban/action.d/firewallcmd-new.conf | 4 +- fail2ban/action.d/firewallcmd-rich-rules.conf | 4 +- fail2ban/action.d/iptables-allports.conf | 46 +- fail2ban/action.d/iptables-common.conf | 92 ---- fail2ban/action.d/iptables-ipset-proto4.conf | 9 +- .../iptables-ipset-proto6-allports.conf | 68 +-- fail2ban/action.d/iptables-ipset-proto6.conf | 68 +-- fail2ban/action.d/iptables-ipset.conf.rpmnew | 90 ++++ fail2ban/action.d/iptables-multiport-log.conf | 2 +- fail2ban/action.d/iptables-multiport.conf | 44 +- fail2ban/action.d/iptables-new.conf | 45 +- .../action.d/iptables-xt_recent-echo.conf | 20 +- fail2ban/action.d/iptables.conf | 132 +++++- fail2ban/action.d/ipthreat.conf | 107 +++++ fail2ban/action.d/nginx-block-map.conf | 11 +- .../symbiosis-blacklist-allports.conf | 7 +- fail2ban/fail2ban.conf | 10 +- fail2ban/filter.d/apache-fakegooglebot.conf | 4 +- fail2ban/filter.d/apache-overflows.conf | 2 +- fail2ban/filter.d/asterisk.conf | 2 +- fail2ban/filter.d/common.conf | 2 +- fail2ban/filter.d/courier-auth.conf | 2 +- fail2ban/filter.d/dovecot.conf | 15 +- fail2ban/filter.d/drupal-auth.conf | 2 +- fail2ban/filter.d/exim-common.conf | 2 +- .../ignorecommands/apache-fakegooglebot | 25 +- fail2ban/filter.d/lighttpd-auth.conf | 2 +- fail2ban/filter.d/monitorix.conf | 25 ++ fail2ban/filter.d/mssql-auth.conf | 15 + fail2ban/filter.d/named-refused.conf | 9 +- fail2ban/filter.d/nginx-bad-request.conf | 16 + fail2ban/filter.d/nginx-botsearch.conf | 4 +- fail2ban/filter.d/nginx-http-auth.conf | 19 +- fail2ban/filter.d/nginx-limit-req.conf | 3 + fail2ban/filter.d/nsd.conf | 6 +- fail2ban/filter.d/postfix.conf | 19 +- fail2ban/filter.d/scanlogd.conf | 17 + fail2ban/filter.d/sendmail-auth.conf | 2 +- fail2ban/filter.d/sendmail-reject.conf | 6 +- fail2ban/filter.d/sshd.conf | 8 +- fail2ban/filter.d/zoneminder.conf | 16 +- fail2ban/jail.conf | 54 ++- fail2ban/jail.d/00-firewalld.conf | 4 +- fail2ban/paths-common.conf | 3 - httpd/conf.d/ssl.conf | 203 +++++++++ selinux/targeted/.policy.sha512 | 2 +- selinux/targeted/policy/policy.31 | Bin 8800699 -> 8801419 bytes 56 files changed, 1011 insertions(+), 907 deletions(-) create mode 100644 fail2ban/action.d/apprise.conf delete mode 100644 fail2ban/action.d/badips.conf delete mode 100644 fail2ban/action.d/badips.py create mode 100644 fail2ban/action.d/cloudflare-token.conf delete mode 100644 fail2ban/action.d/iptables-common.conf create mode 100644 fail2ban/action.d/iptables-ipset.conf.rpmnew create mode 100644 fail2ban/action.d/ipthreat.conf create mode 100644 fail2ban/filter.d/monitorix.conf create mode 100644 fail2ban/filter.d/mssql-auth.conf create mode 100644 fail2ban/filter.d/nginx-bad-request.conf create mode 100644 fail2ban/filter.d/scanlogd.conf create mode 100644 httpd/conf.d/ssl.conf diff --git a/.etckeeper b/.etckeeper index 027ce23..4b3282f 100755 --- a/.etckeeper +++ b/.etckeeper @@ -734,11 +734,11 @@ maybe chmod 0755 'fail2ban' maybe chmod 0755 'fail2ban/action.d' maybe chmod 0644 'fail2ban/action.d/abuseipdb.conf' maybe chmod 0644 'fail2ban/action.d/apf.conf' -maybe chmod 0644 'fail2ban/action.d/badips.conf' -maybe chmod 0640 'fail2ban/action.d/badips.py' +maybe chmod 0644 'fail2ban/action.d/apprise.conf' maybe chmod 0644 'fail2ban/action.d/badips.py.rpmnew' maybe chmod 0640 'fail2ban/action.d/badips.py.rpmsave' maybe chmod 0644 'fail2ban/action.d/blocklist_de.conf' +maybe chmod 0644 'fail2ban/action.d/cloudflare-token.conf' maybe chmod 0644 'fail2ban/action.d/cloudflare.conf' maybe chmod 0644 'fail2ban/action.d/dshield.conf' maybe chmod 0644 'fail2ban/action.d/dummy.conf' @@ -751,17 +751,18 @@ maybe chmod 0644 'fail2ban/action.d/firewallcmd-rich-logging.conf' maybe chmod 0644 'fail2ban/action.d/firewallcmd-rich-rules.conf' maybe chmod 0644 'fail2ban/action.d/helpers-common.conf' maybe chmod 0644 'fail2ban/action.d/iptables-allports.conf' -maybe chmod 0640 'fail2ban/action.d/iptables-common.conf' maybe chmod 0640 'fail2ban/action.d/iptables-common.conf.rpmsave' maybe chmod 0644 'fail2ban/action.d/iptables-ipset-proto4.conf' maybe chmod 0644 'fail2ban/action.d/iptables-ipset-proto6-allports.conf' maybe chmod 0644 'fail2ban/action.d/iptables-ipset-proto6.conf' maybe chmod 0640 'fail2ban/action.d/iptables-ipset.conf' +maybe chmod 0644 'fail2ban/action.d/iptables-ipset.conf.rpmnew' maybe chmod 0644 'fail2ban/action.d/iptables-multiport-log.conf' maybe chmod 0644 'fail2ban/action.d/iptables-multiport.conf' maybe chmod 0644 'fail2ban/action.d/iptables-new.conf' maybe chmod 0644 'fail2ban/action.d/iptables-xt_recent-echo.conf' maybe chmod 0644 'fail2ban/action.d/iptables.conf' +maybe chmod 0644 'fail2ban/action.d/ipthreat.conf' maybe chmod 0644 'fail2ban/action.d/mail-whois-common.conf' maybe chmod 0644 'fail2ban/action.d/mail.conf.rpmsave' maybe chmod 0644 'fail2ban/action.d/mynetwatchman.conf' @@ -783,12 +784,12 @@ maybe chmod 0644 'fail2ban/action.d/sendmail-whois-matches.conf' maybe chmod 0644 'fail2ban/action.d/sendmail-whois.conf' maybe chmod 0644 'fail2ban/action.d/sendmail.conf' maybe chmod 0644 'fail2ban/action.d/shorewall-ipset-proto6.conf' -maybe chmod 0640 'fail2ban/action.d/smtp.py' +maybe chmod 0644 'fail2ban/action.d/smtp.py' maybe chmod 0644 'fail2ban/action.d/smtp.py.rpmnew' maybe chmod 0640 'fail2ban/action.d/smtp.py.rpmsave' maybe chmod 0644 'fail2ban/action.d/symbiosis-blacklist-allports.conf' maybe chmod 0644 'fail2ban/action.d/xarf-login-attack.conf' -maybe chmod 0640 'fail2ban/fail2ban.conf' +maybe chmod 0644 'fail2ban/fail2ban.conf' maybe chmod 0640 'fail2ban/fail2ban.conf.rpmsave' maybe chmod 0755 'fail2ban/fail2ban.d' maybe chmod 0755 'fail2ban/filter.d' @@ -817,7 +818,7 @@ maybe chmod 0644 'fail2ban/filter.d/courier-smtp.conf' maybe chmod 0644 'fail2ban/filter.d/cyrus-imap.conf' maybe chmod 0644 'fail2ban/filter.d/directadmin.conf' maybe chmod 0644 'fail2ban/filter.d/domino-smtp.conf' -maybe chmod 0640 'fail2ban/filter.d/dovecot.conf' +maybe chmod 0644 'fail2ban/filter.d/dovecot.conf' maybe chmod 0644 'fail2ban/filter.d/dovecot.conf.rpmnew' maybe chmod 0640 'fail2ban/filter.d/dovecot.conf.rpmsave' maybe chmod 0644 'fail2ban/filter.d/dropbear.conf' @@ -836,19 +837,22 @@ maybe chmod 0644 'fail2ban/filter.d/guacamole.conf' maybe chmod 0644 'fail2ban/filter.d/haproxy-http-auth.conf' maybe chmod 0644 'fail2ban/filter.d/horde.conf' maybe chmod 0755 'fail2ban/filter.d/ignorecommands' -maybe chmod 0750 'fail2ban/filter.d/ignorecommands/apache-fakegooglebot' +maybe chmod 0755 'fail2ban/filter.d/ignorecommands/apache-fakegooglebot' maybe chmod 0750 'fail2ban/filter.d/ignorecommands/apache-fakegooglebot.rpmsave' maybe chmod 0644 'fail2ban/filter.d/kerio.conf' maybe chmod 0644 'fail2ban/filter.d/lighttpd-auth.conf' maybe chmod 0644 'fail2ban/filter.d/mongodb-auth.conf' maybe chmod 0644 'fail2ban/filter.d/monit.conf' +maybe chmod 0644 'fail2ban/filter.d/monitorix.conf' +maybe chmod 0644 'fail2ban/filter.d/mssql-auth.conf' maybe chmod 0644 'fail2ban/filter.d/murmur.conf' maybe chmod 0644 'fail2ban/filter.d/mysqld-auth.conf' maybe chmod 0644 'fail2ban/filter.d/nagios.conf' -maybe chmod 0640 'fail2ban/filter.d/named-refused.conf' +maybe chmod 0644 'fail2ban/filter.d/named-refused.conf' maybe chmod 0644 'fail2ban/filter.d/named-refused.conf.rpmnew' maybe chmod 0640 'fail2ban/filter.d/named-refused.conf.rpmsave' -maybe chmod 0640 'fail2ban/filter.d/nginx-botsearch.conf' +maybe chmod 0644 'fail2ban/filter.d/nginx-bad-request.conf' +maybe chmod 0644 'fail2ban/filter.d/nginx-botsearch.conf' maybe chmod 0640 'fail2ban/filter.d/nginx-botsearch.conf.rpmsave' maybe chmod 0640 'fail2ban/filter.d/nginx-forbidden.conf' maybe chmod 0644 'fail2ban/filter.d/nginx-http-auth.conf' @@ -871,9 +875,10 @@ maybe chmod 0644 'fail2ban/filter.d/postfix.conf' maybe chmod 0644 'fail2ban/filter.d/proftpd.conf' maybe chmod 0644 'fail2ban/filter.d/pure-ftpd.conf' maybe chmod 0644 'fail2ban/filter.d/qmail.conf' -maybe chmod 0640 'fail2ban/filter.d/recidive.conf' +maybe chmod 0644 'fail2ban/filter.d/recidive.conf' maybe chmod 0640 'fail2ban/filter.d/recidive.conf.rpmsave' maybe chmod 0644 'fail2ban/filter.d/roundcube-auth.conf' +maybe chmod 0644 'fail2ban/filter.d/scanlogd.conf' maybe chmod 0644 'fail2ban/filter.d/screensharingd.conf' maybe chmod 0644 'fail2ban/filter.d/selinux-common.conf' maybe chmod 0644 'fail2ban/filter.d/selinux-ssh.conf' @@ -886,7 +891,7 @@ maybe chmod 0644 'fail2ban/filter.d/sogo-auth.conf' maybe chmod 0644 'fail2ban/filter.d/solid-pop3d.conf' maybe chmod 0644 'fail2ban/filter.d/squid.conf' maybe chmod 0644 'fail2ban/filter.d/squirrelmail.conf' -maybe chmod 0640 'fail2ban/filter.d/sshd.conf' +maybe chmod 0644 'fail2ban/filter.d/sshd.conf' maybe chmod 0644 'fail2ban/filter.d/stunnel.conf' maybe chmod 0644 'fail2ban/filter.d/suhosin.conf' maybe chmod 0644 'fail2ban/filter.d/tine20.conf' @@ -898,7 +903,7 @@ maybe chmod 0644 'fail2ban/filter.d/wuftpd.conf' maybe chmod 0644 'fail2ban/filter.d/xinetd-fail.conf' maybe chmod 0644 'fail2ban/filter.d/znc-adminlog.conf' maybe chmod 0644 'fail2ban/filter.d/zoneminder.conf' -maybe chmod 0640 'fail2ban/jail.conf' +maybe chmod 0644 'fail2ban/jail.conf' maybe chmod 0640 'fail2ban/jail.conf.rpmsave' maybe chmod 0755 'fail2ban/jail.d' maybe chmod 0644 'fail2ban/jail.d/00-firewalld.conf' @@ -991,6 +996,7 @@ maybe chmod 0644 'httpd/conf.d/perl.conf.rpmnew' maybe chmod 0644 'httpd/conf.d/php.conf' maybe chmod 0644 'httpd/conf.d/phpmyadmin.conf' maybe chmod 0644 'httpd/conf.d/squid.conf' +maybe chmod 0644 'httpd/conf.d/ssl.conf' maybe chmod 0640 'httpd/conf.d/ssl.conf_disabled' maybe chmod 0644 'httpd/conf.d/userdir.conf' maybe chmod 0644 'httpd/conf.d/welcome.conf' @@ -3188,7 +3194,7 @@ maybe chmod 0644 'logrotate.d/btmp' maybe chmod 0644 'logrotate.d/chrony' maybe chmod 0644 'logrotate.d/clamav-unofficial-sigs' maybe chmod 0644 'logrotate.d/dnf' -maybe chmod 0640 'logrotate.d/fail2ban' +maybe chmod 0644 'logrotate.d/fail2ban' maybe chmod 0640 'logrotate.d/fail2ban.rpmsave' maybe chmod 0644 'logrotate.d/firewalld' maybe chmod 0644 'logrotate.d/httpd' @@ -4144,9 +4150,7 @@ maybe chmod 0600 'nftables/nat.nft' maybe chmod 0700 'nftables/osf' maybe chmod 0600 'nftables/osf/pf.os' maybe chmod 0600 'nftables/router.nft' -maybe chown 'nginx' 'nginx' -maybe chgrp 'nginx' 'nginx' -maybe chmod 0750 'nginx' +maybe chmod 0755 'nginx' maybe chown 'nginx' 'nginx/.anaf' maybe chgrp 'nginx' 'nginx/.anaf' maybe chmod 0640 'nginx/.anaf' @@ -4159,9 +4163,7 @@ maybe chmod 0640 'nginx/.passwd-madalin' maybe chown 'nginx' 'nginx/allowed_clients.config' maybe chgrp 'nginx' 'nginx/allowed_clients.config' maybe chmod 0640 'nginx/allowed_clients.config' -maybe chown 'nginx' 'nginx/conf.d' -maybe chgrp 'nginx' 'nginx/conf.d' -maybe chmod 0750 'nginx/conf.d' +maybe chmod 0755 'nginx/conf.d' maybe chown 'nginx' 'nginx/conf.d/_zira.go.ro.conf' maybe chgrp 'nginx' 'nginx/conf.d/_zira.go.ro.conf' maybe chmod 0640 'nginx/conf.d/_zira.go.ro.conf' @@ -4679,9 +4681,7 @@ maybe chmod 0644 'nginx/default.d/php.conf' maybe chown 'nginx' 'nginx/fastcgi.conf' maybe chgrp 'nginx' 'nginx/fastcgi.conf' maybe chmod 0640 'nginx/fastcgi.conf' -maybe chown 'nginx' 'nginx/fastcgi_params' -maybe chgrp 'nginx' 'nginx/fastcgi_params' -maybe chmod 0640 'nginx/fastcgi_params' +maybe chmod 0644 'nginx/fastcgi_params' maybe chown 'nginx' 'nginx/html' maybe chgrp 'nginx' 'nginx/html' maybe chmod 0750 'nginx/html' @@ -4697,9 +4697,7 @@ maybe chmod 0640 'nginx/lb_maint_5x.config' maybe chown 'nginx' 'nginx/lb_maintenance.config' maybe chgrp 'nginx' 'nginx/lb_maintenance.config' maybe chmod 0640 'nginx/lb_maintenance.config' -maybe chown 'nginx' 'nginx/mime.types' -maybe chgrp 'nginx' 'nginx/mime.types' -maybe chmod 0640 'nginx/mime.types' +maybe chmod 0644 'nginx/mime.types' maybe chown 'nginx' 'nginx/nginx.conf' maybe chgrp 'nginx' 'nginx/nginx.conf' maybe chmod 0640 'nginx/nginx.conf' @@ -4712,9 +4710,7 @@ maybe chmod 0640 'nginx/off' maybe chown 'nginx' 'nginx/proxy.inc' maybe chgrp 'nginx' 'nginx/proxy.inc' maybe chmod 0640 'nginx/proxy.inc' -maybe chown 'nginx' 'nginx/scgi_params' -maybe chgrp 'nginx' 'nginx/scgi_params' -maybe chmod 0640 'nginx/scgi_params' +maybe chmod 0644 'nginx/scgi_params' maybe chown 'nginx' 'nginx/sites-available' maybe chgrp 'nginx' 'nginx/sites-available' maybe chmod 0750 'nginx/sites-available' @@ -4757,9 +4753,7 @@ maybe chmod 0640 'nginx/ssl/demo1.cpuburnin.com.pem' maybe chown 'nginx' 'nginx/ssl/dhparam.pem' maybe chgrp 'nginx' 'nginx/ssl/dhparam.pem' maybe chmod 0640 'nginx/ssl/dhparam.pem' -maybe chown 'nginx' 'nginx/uwsgi_params' -maybe chgrp 'nginx' 'nginx/uwsgi_params' -maybe chmod 0640 'nginx/uwsgi_params' +maybe chmod 0644 'nginx/uwsgi_params' maybe chmod 0644 'npmrc' maybe chmod 0755 'nrpe.d' maybe chmod 0644 'nsswitch.conf' diff --git a/fail2ban/action.d/apprise.conf b/fail2ban/action.d/apprise.conf new file mode 100644 index 0000000..37c42ea --- /dev/null +++ b/fail2ban/action.d/apprise.conf @@ -0,0 +1,49 @@ +# Fail2Ban configuration file +# +# Author: Chris Caron +# +# + +[Definition] + +# Option: actionstart +# Notes.: command executed once at the start of Fail2Ban. +# Values: CMD +# +actionstart = printf %%b "The jail as been started successfully." | -t "[Fail2Ban] : started on `uname -n`" + +# Option: actionstop +# Notes.: command executed once at the end of Fail2Ban +# Values: CMD +# +actionstop = printf %%b "The jail has been stopped." | -t "[Fail2Ban] : stopped on `uname -n`" + +# Option: actioncheck +# Notes.: command executed once before each actionban command +# Values: CMD +# +actioncheck = + +# Option: actionban +# Notes.: command executed when banning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: See jail.conf(5) man page +# Values: CMD +# +actionban = printf %%b "The IP has just been banned by Fail2Ban after attempts against " | -n "warning" -t "[Fail2Ban] : banned from `uname -n`" + +# Option: actionunban +# Notes.: command executed when unbanning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: See jail.conf(5) man page +# Values: CMD +# +actionunban = + +[Init] + +# Define location of the default apprise configuration file to use +# +config = /etc/fail2ban/apprise.conf +# +apprise = apprise -c "" diff --git a/fail2ban/action.d/badips.conf b/fail2ban/action.d/badips.conf deleted file mode 100644 index 6f9513f..0000000 --- a/fail2ban/action.d/badips.conf +++ /dev/null @@ -1,19 +0,0 @@ -# Fail2ban reporting to badips.com -# -# Note: This reports an IP only and does not actually ban traffic. Use -# another action in the same jail if you want bans to occur. -# -# Set the category to the appropriate value before use. -# -# To get see register and optional key to get personalised graphs see: -# http://www.badips.com/blog/personalized-statistics-track-the-attackers-of-all-your-servers-with-one-key - -[Definition] - -actionban = curl --fail --user-agent "" http://www.badips.com/add// - -[Init] - -# Option: category -# Notes.: Values are from the list here: http://www.badips.com/get/categories -category = diff --git a/fail2ban/action.d/badips.py b/fail2ban/action.d/badips.py deleted file mode 100644 index d57b4e3..0000000 --- a/fail2ban/action.d/badips.py +++ /dev/null @@ -1,392 +0,0 @@ -# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- -# vi: set ft=python sts=4 ts=4 sw=4 noet : - -# This file is part of Fail2Ban. -# -# Fail2Ban is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# Fail2Ban is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Fail2Ban; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -import sys -if sys.version_info < (2, 7): # pragma: no cover - raise ImportError("badips.py action requires Python >= 2.7") -import json -import threading -import logging -if sys.version_info >= (3, ): # pragma: 2.x no cover - from urllib.request import Request, urlopen - from urllib.parse import urlencode - from urllib.error import HTTPError -else: # pragma: 3.x no cover - from urllib.request import Request, urlopen - from urllib.error import HTTPError - from urllib.parse import urlencode - -from fail2ban.server.actions import Actions, ActionBase, BanTicket -from fail2ban.helpers import splitwords, str2LogLevel - - - -class BadIPsAction(ActionBase): # pragma: no cover - may be unavailable - """Fail2Ban action which reports bans to badips.com, and also - blacklist bad IPs listed on badips.com by using another action's - ban method. - - Parameters - ---------- - jail : Jail - The jail which the action belongs to. - name : str - Name assigned to the action. - category : str - Valid badips.com category for reporting failures. - score : int, optional - Minimum score for bad IPs. Default 3. - age : str, optional - Age of last report for bad IPs, per badips.com syntax. - Default "24h" (24 hours) - banaction : str, optional - Name of banaction to use for blacklisting bad IPs. If `None`, - no blacklist of IPs will take place. - Default `None`. - bancategory : str, optional - Name of category to use for blacklisting, which can differ - from category used for reporting. e.g. may want to report - "postfix", but want to use whole "mail" category for blacklist. - Default `category`. - bankey : str, optional - Key issued by badips.com to retrieve personal list - of blacklist IPs. - updateperiod : int, optional - Time in seconds between updating bad IPs blacklist. - Default 900 (15 minutes) - loglevel : int/str, optional - Log level of the message when an IP is (un)banned. - Default `DEBUG`. - Can be also supplied as two-value list (comma- or space separated) to - provide level of the summary message when a group of IPs is (un)banned. - Example `DEBUG,INFO`. - agent : str, optional - User agent transmitted to server. - Default `Fail2Ban/ver.` - - Raises - ------ - ValueError - If invalid `category`, `score`, `banaction` or `updateperiod`. - """ - - TIMEOUT = 10 - _badips = "https://www.badips.com" - def _Request(self, url, **argv): - return Request(url, headers={'User-Agent': self.agent}, **argv) - - def __init__(self, jail, name, category, score=3, age="24h", - banaction=None, bancategory=None, bankey=None, updateperiod=900, - loglevel='DEBUG', agent="Fail2Ban", timeout=TIMEOUT): - super(BadIPsAction, self).__init__(jail, name) - - self.timeout = timeout - self.agent = agent - self.category = category - self.score = score - self.age = age - self.banaction = banaction - self.bancategory = bancategory or category - self.bankey = bankey - loglevel = splitwords(loglevel) - self.sumloglevel = str2LogLevel(loglevel[-1]) - self.loglevel = str2LogLevel(loglevel[0]) - self.updateperiod = updateperiod - - self._bannedips = set() - # Used later for threading.Timer for updating badips - self._timer = None - - @staticmethod - def isAvailable(timeout=1): - try: - response = urlopen(Request("/".join([BadIPsAction._badips]), - headers={'User-Agent': "Fail2Ban"}), timeout=timeout) - return True, '' - except Exception as e: # pragma: no cover - return False, e - - def logError(self, response, what=''): # pragma: no cover - sporadical (502: Bad Gateway, etc) - messages = {} - try: - messages = json.loads(response.read().decode('utf-8')) - except: - pass - self._logSys.error( - "%s. badips.com response: '%s'", what, - messages.get('err', 'Unknown')) - - def getCategories(self, incParents=False): - """Get badips.com categories. - - Returns - ------- - set - Set of categories. - - Raises - ------ - HTTPError - Any issues with badips.com request. - ValueError - If badips.com response didn't contain necessary information - """ - try: - response = urlopen( - self._Request("/".join([self._badips, "get", "categories"])), timeout=self.timeout) - except HTTPError as response: # pragma: no cover - self.logError(response, "Failed to fetch categories") - raise - else: - response_json = json.loads(response.read().decode('utf-8')) - if not 'categories' in response_json: - err = "badips.com response lacked categories specification. Response was: %s" \ - % (response_json,) - self._logSys.error(err) - raise ValueError(err) - categories = response_json['categories'] - categories_names = set( - value['Name'] for value in categories) - if incParents: - categories_names.update(set( - value['Parent'] for value in categories - if "Parent" in value)) - return categories_names - - def getList(self, category, score, age, key=None): - """Get badips.com list of bad IPs. - - Parameters - ---------- - category : str - Valid badips.com category. - score : int - Minimum score for bad IPs. - age : str - Age of last report for bad IPs, per badips.com syntax. - key : str, optional - Key issued by badips.com to fetch IPs reported with the - associated key. - - Returns - ------- - set - Set of bad IPs. - - Raises - ------ - HTTPError - Any issues with badips.com request. - """ - try: - url = "?".join([ - "/".join([self._badips, "get", "list", category, str(score)]), - urlencode({'age': age})]) - if key: - url = "&".join([url, urlencode({'key': key})]) - self._logSys.debug('badips.com: get list, url: %r', url) - response = urlopen(self._Request(url), timeout=self.timeout) - except HTTPError as response: # pragma: no cover - self.logError(response, "Failed to fetch bad IP list") - raise - else: - return set(response.read().decode('utf-8').split()) - - @property - def category(self): - """badips.com category for reporting IPs. - """ - return self._category - - @category.setter - def category(self, category): - if category not in self.getCategories(): - self._logSys.error("Category name '%s' not valid. " - "see badips.com for list of valid categories", - category) - raise ValueError("Invalid category: %s" % category) - self._category = category - - @property - def bancategory(self): - """badips.com bancategory for fetching IPs. - """ - return self._bancategory - - @bancategory.setter - def bancategory(self, bancategory): - if bancategory != "any" and bancategory not in self.getCategories(incParents=True): - self._logSys.error("Category name '%s' not valid. " - "see badips.com for list of valid categories", - bancategory) - raise ValueError("Invalid bancategory: %s" % bancategory) - self._bancategory = bancategory - - @property - def score(self): - """badips.com minimum score for fetching IPs. - """ - return self._score - - @score.setter - def score(self, score): - score = int(score) - if 0 <= score <= 5: - self._score = score - else: - raise ValueError("Score must be 0-5") - - @property - def banaction(self): - """Jail action to use for banning/unbanning. - """ - return self._banaction - - @banaction.setter - def banaction(self, banaction): - if banaction is not None and banaction not in self._jail.actions: - self._logSys.error("Action name '%s' not in jail '%s'", - banaction, self._jail.name) - raise ValueError("Invalid banaction") - self._banaction = banaction - - @property - def updateperiod(self): - """Period in seconds between banned bad IPs will be updated. - """ - return self._updateperiod - - @updateperiod.setter - def updateperiod(self, updateperiod): - updateperiod = int(updateperiod) - if updateperiod > 0: - self._updateperiod = updateperiod - else: - raise ValueError("Update period must be integer greater than 0") - - def _banIPs(self, ips): - for ip in ips: - try: - ai = Actions.ActionInfo(BanTicket(ip), self._jail) - self._jail.actions[self.banaction].ban(ai) - except Exception as e: - self._logSys.error( - "Error banning IP %s for jail '%s' with action '%s': %s", - ip, self._jail.name, self.banaction, e, - exc_info=self._logSys.getEffectiveLevel()<=logging.DEBUG) - else: - self._bannedips.add(ip) - self._logSys.log(self.loglevel, - "Banned IP %s for jail '%s' with action '%s'", - ip, self._jail.name, self.banaction) - - def _unbanIPs(self, ips): - for ip in ips: - try: - ai = Actions.ActionInfo(BanTicket(ip), self._jail) - self._jail.actions[self.banaction].unban(ai) - except Exception as e: - self._logSys.error( - "Error unbanning IP %s for jail '%s' with action '%s': %s", - ip, self._jail.name, self.banaction, e, - exc_info=self._logSys.getEffectiveLevel()<=logging.DEBUG) - else: - self._logSys.log(self.loglevel, - "Unbanned IP %s for jail '%s' with action '%s'", - ip, self._jail.name, self.banaction) - finally: - self._bannedips.remove(ip) - - def start(self): - """If `banaction` set, blacklists bad IPs. - """ - if self.banaction is not None: - self.update() - - def update(self): - """If `banaction` set, updates blacklisted IPs. - - Queries badips.com for list of bad IPs, removing IPs from the - blacklist if no longer present, and adds new bad IPs to the - blacklist. - """ - if self.banaction is not None: - if self._timer: - self._timer.cancel() - self._timer = None - - try: - ips = self.getList( - self.bancategory, self.score, self.age, self.bankey) - # Remove old IPs no longer listed - s = self._bannedips - ips - m = len(s) - self._unbanIPs(s) - # Add new IPs which are now listed - s = ips - self._bannedips - p = len(s) - self._banIPs(s) - if m != 0 or p != 0: - self._logSys.log(self.sumloglevel, - "Updated IPs for jail '%s' (-%d/+%d)", - self._jail.name, m, p) - self._logSys.debug( - "Next update for jail '%' in %i seconds", - self._jail.name, self.updateperiod) - finally: - self._timer = threading.Timer(self.updateperiod, self.update) - self._timer.start() - - def stop(self): - """If `banaction` set, clears blacklisted IPs. - """ - if self.banaction is not None: - if self._timer: - self._timer.cancel() - self._timer = None - self._unbanIPs(self._bannedips.copy()) - - def ban(self, aInfo): - """Reports banned IP to badips.com. - - Parameters - ---------- - aInfo : dict - Dictionary which includes information in relation to - the ban. - - Raises - ------ - HTTPError - Any issues with badips.com request. - """ - try: - url = "/".join([self._badips, "add", self.category, str(aInfo['ip'])]) - self._logSys.debug('badips.com: ban, url: %r', url) - response = urlopen(self._Request(url), timeout=self.timeout) - except HTTPError as response: # pragma: no cover - self.logError(response, "Failed to ban") - raise - else: - messages = json.loads(response.read().decode('utf-8')) - self._logSys.debug( - "Response from badips.com report: '%s'", - messages['suc']) - -Action = BadIPsAction diff --git a/fail2ban/action.d/cloudflare-token.conf b/fail2ban/action.d/cloudflare-token.conf new file mode 100644 index 0000000..8c5c37d --- /dev/null +++ b/fail2ban/action.d/cloudflare-token.conf @@ -0,0 +1,92 @@ +# +# Author: Logic-32 +# +# IMPORTANT +# +# Please set jail.local's permission to 640 because it contains your CF API token. +# +# This action depends on curl. +# +# To get your Cloudflare API token: https://developers.cloudflare.com/api/tokens/create/ +# +# Cloudflare Firewall API: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/endpoints/ + +[Definition] + +# Option: actionstart +# Notes.: command executed on demand at the first ban (or at the start of Fail2Ban if actionstart_on_demand is set to false). +# Values: CMD +# +actionstart = + +# Option: actionstop +# Notes.: command executed at the stop of jail (or at the end of Fail2Ban) +# Values: CMD +# +actionstop = + +# Option: actioncheck +# Notes.: command executed once before each actionban command +# Values: CMD +# +actioncheck = + +# Option: actionban +# Notes.: command executed when banning an IP. Take care that the +# command is executed with Fail2Ban user rights. +# Tags: IP address +# number of failures +#