fail2banの設定について



●インストール

 sshへのブルートフォースアタックの対策として「Denyhostsの設定方法」に記載しているとおり設定済みです。
 DenyhostsでFTPアクセスに対するブルートフォースアタックを拒否したいと思い色々調べたところ、有益な設定情報が無かったため「fail2ban」で設定することにしました。
 fail2banをインストールするためにEPEL(EPELを利用するための設定方法)を設定しておきます。

 参考URL:Fail2banで不正アクセスをブロックする方法!

 準備が出来たらfail2banをインストールします。
※CentOS Stream 8、Rocky 8の場合
# dnf -y --enablerepo=epel install fail2ban

 依存性関連で下記もインストールされました。

  fail2ban-firewalld-0.11.2-1.el8.noarch.rpm
  fail2ban-sendmail-0.11.2-1.el8.noarch.rpm
  fail2ban-server-0.11.2-1.el8.noarch.rpm

# systemctl enable --now fail2ban

※CentOS 7の場合
# yum -y --enablerepo=epel install fail2ban

 依存性関連で下記もインストールされました。

  fail2ban-firewalld.noarch 0:0.9.3-1.el7
  fail2ban-sendmail.noarch 0:0.9.3-1.el7          
  fail2ban-server.noarch 0:0.9.3-1.el7
  ipset.x86_64 0:6.19-4.el7                       
  ipset-libs.x86_64 0:6.19-4.el7

# systemctl start fail2ban
# systemctl enable fail2ban
 定義されているフィルターは/etc/fail2ban/filter.d/ディレクトリにあります。個別に新規作成する場合、作成するフィルタは該当ディレクトリに保存します。

●jail.localの新規作成及び動作確認

 SSHに関するフィルタ(sshd.conf)は設定されていますので、動作確認を兼ねて設定していきます。
 /etc/fail2ban/jail.confは直接編集は推奨されていませんので、/etc/fail2ban/jail.localを新規作成し必要な設定情報を記載します。
 なお、jail.confはソフトウェアのバージョンアップ等で上書きされる可能性があるようです。
 jail.conf → jail.localの順に読み込まれるため、jail.localの記載内容が優先(上書き)されます。

 [DEFAULT]セクションに記載されている内容が、共通設定となります。
 ignoreipには除外するIPアドレスを入力します。
 findtimeで定義した期間内に、maxretryで定義した回数だけ失敗するとbantimeで定義した期間、接続拒否する、という動作になります。

 jail.localの例
[DEFAULT]

ignoreip = 127.0.0.1/8 10.0.0.0/8 192.168.0.0/16
bantime  = 15m
findtime  = 15m
maxretry = 3
backend = auto

filter = %(__name__)s

#
# ACTIONS
#
(fail2banのスタート・ストップ時、BAN実行時にメール通知を受ける場合はメールアドレスを入力)
destemail = root@mail.bigbang.mydns.jp
(banactionをfirewalldに変更)
banaction = firewallcmd-ipset
banaction_allports = firewallcmd-allports
action = %(action_mw)s
※BANしたIPアドレス情報をメール通知する場合追記
(BANしたIPアドレスのみ通知の場合は不要)
action = %(action_mw)s (BANしたIPアドレス+そのIPアドレスのWHOIS情報も通知)
action = %(action_mwl)s (上記+そのIPアドレスが記録されたログの行も転記して通知)
それぞれのサービス毎にメール通知を設定したい場合、[DEFAULT]のaction行を削除し各サービス毎に追記
#
# JAILS
#
#
# SSH servers
#
[sshd]

enabled = true
filetr = sshd
port    = ssh
logpath = %(sshd_log)s
backend = systemd
bantime = 1w
findtime = 1h
maxentry = 3
 設定が完了したらfail2banを再起動します。
# systemctl restart fail2ban
 Firewalldと正常に連携できているか確認するためには、iptablesの内容を表示させます。
# iptables -nvL
Chain INPUT (policy ACCEPT 17M packets, 22G bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            multiport dports 22 match-set f2b-sshd src reject-with icmp-port-unreachable
(以下、省略)
 状態を確認します。
# fail2ban-client status
Status
|- Number of jail:	1
`- Jail list: sshd
 SSHは動作していることが確認できました。

●BANされたパケットを拒否せずにドロップ(破棄)するようにする

 参考URL:Fail2banで不正なアクセスをブロック(BAN)してサーバを守る

 ※下記設定だけでは、ドロップ(破棄)する動作とならないようです。仕方ないので「●ブラックリスト」による設定にしました。

 iptables-common.localを新規作成します。
 [Init] がIPv4用、[Init?family=inet6] がIPv6用です。
# vi /etc/fail2ban/action.d/iptables-common.local
[Init] 
blocktype = DROP

[Init?family=inet6]
blocktype = DROP
 作成後、fail2banを再起動します。

 ※2022.05.19追記
 下記のようにも変更する必要があるようです。

 参考URL:Fail2Ban DROP instead REJECT - gists · GitHub
 参考URL:【linux】fail2banで不正アクセスを止めよう!
# vi /etc/fail2ban/action.d/iptables-common.conf

[Init]
#blocktype = REJECT --reject-with icmp-port-unreachable ← 先頭に「#」を不可
blocktype = DROP ← 追記

※IPv6でも設定する時
[Init?family=inet6]
#blocktype = REJECT --reject-with icmp-port-unreachable ← 先頭に「#」を不可
blocktype = DROP ← 追記
 変更後、fail2banを再起動します。

●ブラックリスト

 GitHubレポジトリmitchellkrogza/Fail2Ban-Blacklist-JAIL-for-Repeat-Offenders-with-Perma-Extended-Banningから設定ファイルをダウンロードします。
/etc/fail2ban/filter.d/blacklist.confの作成
# cd /etc/fail2ban/filter.d
# sudo wget \
https://raw.githubusercontent.com/mitchellkrogza/Fail2Ban-Blacklist-JAIL-for-Repeat-Offenders-with-Perma-Extended-Banning/master/filter.d/blacklist.conf \
-O blacklist.conf

/etc/fail2ban/action.d/blacklist.conf の作成
# cd /etc/fail2ban/action.d
# sudo wget \
https://raw.githubusercontent.com/mitchellkrogza/Fail2Ban-Blacklist-JAIL-for-Repeat-Offenders-with-Perma-Extended-Banning/master/action.d/blacklist.conf \
-O blacklist.conf
 /etc/fail2ban/jail.localの末尾へ追記します。
# vi /etc/fail2ban/jail.local
[blacklist]
enabled = true
logpath  = /var/log/fail2ban.*
filter = blacklist
banaction = blacklist
bantime  = 3mo
findtime = 1w
maxretry = 10

 なお、上記URLに記載している(STEP 5: recidive filter must be disabled (do not run both at same time))とおり、[recidive]を無効化する必要があります。

 blacklistに登録されたipが列挙されるファイル/etc/fail2ban/ip.blacklistを作成します。
# sudo touch /etc/fail2ban/ip.blacklist
# sudo chmod 755 /etc/fail2ban/ip.blacklist
 fail2banを再起動します。

●BANされるか確認

 参考URL:CentOS7+fail2ban+firewalldで不正アクセス対策
 参考URL:fail2ban/Debianへのインストール

 ignoreipで定義されている以外(試験時は192.168.0.0/24は除外しました。)からの端末を使用してProFTPdがBANされるかどうか確認します。Windows 7端末から存在しないアカウントでftp接続します。
 /var/log/secureに下記のようなログが記録されました。
Oct  5 16:34:50 server proftpd[18195]: 192.168.0.1 (192.168.0.100[192.168.0.100]) - USER admin: \
no such user found from  192.168.0.100 [192.168.0.100] to ::ffff:192.168.0.1:21
Oct  5 16:35:08 server proftpd[18519]: 192.168.0.1 (192.168.0.100[192.168.0.100]) - USER admin: \
no such user found from  192.168.0.100 [192.168.0.100] to ::ffff:192.168.0.1:21
Oct  5 16:35:19 server proftpd[19155]: 192.168.0.1 (192.168.0.100[192.168.0.100]) - USER admin: \
no such user found from  192.168.0.100 [192.168.0.100] to ::ffff:192.168.0.1:21
※BANする条件
/etc/fail2ban/filter.d/proftpd.confに記載
※actionの条件
/etc/fail2ban/jail.localの[proftpd]セクションに記載
 BANされているか確認します。BANされるタイミングはmaxentryで定義されている回数に達すると即時です。上記の設定の場合、ログに記録されて(しきい値を超えて)からBANされるまで2~3分程度のタイムラグがありました。
 また、[proftpd]のように個別で定義されいているmaxentryは[DEFAULT]で定義されている回数より少ない場合、[DEFAULT]で定義されている回数が有効になりますので注意が必要です。
# ipset --list fail2ban-proftpd
Name: fail2ban-proftpd
Type: hash:ip
Revision: 1
Header: family inet hashsize 1024 maxelem 65536 timeout 120
Size in memory: 16592
References: 1
Members:
192.168.0.100 timeout 32
 想定どおりBANされました。BANされている間、Windows 7端末からFTPログインしようとすると応答がない状態でした。
 BANされた時にメール送信するように設定していましたので、下記のようなメールが送信されました。
[Fail2Ban] proftpd: banned 192.168.0.100 from server.bigbang.mydns.jp

 また、フィルタで検知した情報及びBANされる、BANの解除等の情報は/var/log/fail2ban.logに記録されます。
2016-10-05 16:36:22,943 fail2ban.filter   [20276]: INFO    [proftpd] Found 192.168.0.100
2016-10-05 16:36:22,944 fail2ban.filter   [20276]: INFO    [proftpd] Found 192.168.0.100
2016-10-05 16:36:22,944 fail2ban.filter   [20276]: INFO    [proftpd] Found 192.168.0.100
2016-10-05 16:36:23,682 fail2ban.actions  [20276]: NOTICE  [proftpd] Ban 192.168.0.100
 ↑ BANされている
2016-10-05 16:38:23,881 fail2ban.actions  [20276]: NOTICE  [proftpd] Unban 192.168.0.100
 ↑ 120秒後BANが解除されている


●再犯対策

 参考URL:fail2banでしつこい攻撃者だけ長期BANする方法

 BANの自動解除後、再度攻撃してくる可能性は十分に考えられます。fail2banはそのあたりも考慮されており下記のような設定で対策できます。

 ただし、[blacklist]を有効化している場合、[recidive]は無効にしてください。

 1日に10回banされたIPアドレスに対し、3ヶ月間アクセス不可にする設定例です。
 jail.localに追記します。
# vi /etc/fail2ban/jail.local
[recidive]

enabled = true
logpath  = /var/log/fail2ban.log
banaction = iptables-allports
bantime  = 3mo
findtime = 1d
maxretry = 10

# systemctl reload fail2ban
 リロード直後、ログには下記のように記録されていました。
2016-12-13 17:01:16,046 fail2ban.jail           [7117]: INFO    Jail 'recidive' started
 正常に設定できたようです。

●Dovecotの不正アクセス対応

 Dovecotの不正アクセスをfail2banで検知できるようにします。
# vi /etc/fail2ban/jail.local

[dovecot]

enabled = true
filter = dovecot
port    = imaps
logpath = /var/log/secure
backend = systemd
bantime = 1w
findtime = 15m
maxentry = 5

# systemctl reload fail2ban

 以上で、fail2banで定義されているフィルターで検知出来るようになります。

●フィルター作成方法

 参考URL:CentOS7にFail2ban導入②フィルタ作成方法

 フィルターを作成するためには、監視対象となるサービスが出力しているログがどこにあるか確認することです。Fail2banはログから文字列をパターンマッチさせて検出します。
 fail2banのフィルターは「/etc/fail2ban/filter.d」に格納されており、そこにデフォルトのフィルターが用意されています。
 デフォルトの設定で機能することもありますが、時々フィルターのパターンと出力されたログのパターンが一致していないことがあり正常に機能しないことがあります。
 その場合、自分でフィルターを作成する必要があります。
 今回は、vsftpdのログで/etc/hosts.allow、/etc/hosts.denyの設定により拒否された場合のパターンを検出するフィルターを作成します。

 手順は下記のとおりとなります。

 ①フィルター定義をする
 ②フィルターでパターンマッチ出来るか確認する
  確認コマンド:fail2ban-regex <ログファイルのパス> <フィルター定義のパス>
  デフォルトのフィルター情報に追記する形で作成します。
# cp -p /etc/fail2ban/filter.d/vsftpd.conf /tmp
 デフォルトの内容は下記のとおりです。
# vi /tmp/vsftpd.conf
[Definition]

__pam_re=\(?%(__pam_auth)s(?:\(\S+\))?\)?:?
_daemon =  vsftpd

failregex = ^%(__prefix_line)s%(__pam_re)s\s+authentication failure; logname=\S* uid=\S* euid=\S* tty=(ftp)? ruser=\S* rhost=<HOST>(?:\s+user=.*)?\s*$
            ^ \[pid \d+\] \[[^\]]+\] FAIL LOGIN: Client "<HOST>"(?:\s*$|,)

ignoreregex =

※補足
failregex    — 指定ログファイル中に出力されている文字列で、検出対象にしたい文字列を正規表現で記述
ignoreregex —  指定ログファイル中に出力されている文字列で、検出対象にしたくない文字列を正規表現で記述
 動作確認のため「failregex =」部分を「^ \[pid \d+\] \[[^\]]+\] FAIL LOGIN: Client "<HOST>"(?:\s*$|,)」だけとしたフィルターでテストします。
# fail2ban-regex /var/log/vsftpd.log-20210202 /tmp/vsftpd.conf

Running tests
=============

Use   failregex file : /tmp/vsftpd.conf
Use         log file : /var/log/vsftpd.log-20210202
Use         encoding : UTF-8


Results
=======

Failregex: 6 total
|-  #) [# of hits] regular expression
|   1) [6] ^ \[pid \d+\] \[[^\]]+\] FAIL LOGIN: Client "<HOST>"(?:\s*$|,)
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [1011] {^LN-BEG}(?:DAY )?MON Day %k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
`-

Lines: 1011 lines, 0 ignored, 6 matched, 1005 missed
[processed in 0.10 sec]

Missed line(s): too many to print.  Use --print-all-missed to print all 1005 lines
 6行マッチし、1005行マッチしなかったことが分かります。
 grepコマンドでマッチした行を確認する方法は下記のとおりです。
# grep "FAIL LOGIN: Client" /var/log/vsftpd.log-20210202|wc-l
6
 新たなフィルターを定義します。

 /etc/hosts.denyでブロックされるとログに下記のように記録されます。
Mon Feb  1 08:13:02 2021 [pid 27398] CONNECT: Client "***.***.***.***", "Connection refused: tcp_wrappers denial."
 このログにマッチさせるフィルターは下記のようになります。
failregex = ^ \[pid \d+\] CONNECT: Client "<HOST>"(?:\s*$|,) "Connection refused: tcp_wrappers denial."
 テスト用フィルタ作成後、テストします。
# fail2ban-regex /var/log/vsftpd.log-20210202 /tmp/vsftpd.conf

Running tests
=============

Use   failregex file : /tmp/vsftpd.conf
Use         log file : /var/log/vsftpd.log-20210202
Use         encoding : UTF-8


Results
=======

Failregex: 980 total
|-  #) [# of hits] regular expression
|   1) [980] ^ \[pid \d+\] CONNECT: Client "<HOST>"(?:\s*$|,) "Connection refused: tcp_wrappers denial."
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [1011] {^LN-BEG}(?:DAY )?MON Day %k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
`-

Lines: 1011 lines, 0 ignored, 980 matched, 31 missed
[processed in 0.11 sec]

Missed line(s): too many to print.  Use --print-all-missed to print all 31 lines
 980行マッチし、31行マッチしなかったことが分かります。
 grepコマンドでマッチした行を確認する方法は下記のとおりです。
# grep "\"Connection refused: tcp_wrappers denial.\"" /var/log/vsftpd.log-20210202|wc -l
980
 最後に忘れずにデフォルトのフィルターに新たなフィルターを追記し、fail2banをリロードします。
# /etc/fail2ban/filter.d/vsftpd.conf

(failregex部分のみ抜粋)
failregex = ^%(__prefix_line)s%(__pam_re)s\s+authentication failure; logname=\S* uid=\S* euid=\S* tty=(ftp)? ruser=\S* rhost=<HOST>(?:\s+user=.*)?\s*$
            ^ \[pid \d+\] \[[^\]]+\] FAIL LOGIN: Client "<HOST>"(?:\s*$|,)
            ^ \[pid \d+\] CONNECT: Client "<HOST>"(?:\s*$|,) "Connection refused: tcp_wrappers denial."


# systemctl reload fail2ban
 これで、追加したフィルターが読み込まれマッチするようになります。

 しかしながら、本番環境ではFAIL LOGINの方はマッチしBanされるのですが、何故かマッチしBanする動作を確認できませんでした。

●Apacheの403、404対策

 参考URL:Apache向けfail2banの簡易構築手順
 参考URL:EC2でnginxの過剰な404|403に対しfail2banをかける

 Apacheのアクセスログに明らかに存在していないファイル等に対するアクセスがあり、不正なアクセス(403と404のリクエストエラー)として対策を実施します。
 事前に下記を確認します。
# cat /etc/sysconfig/iptables or # cat /etc/sysconfig/firewalld ← iptables(または、fiwarelld)の現在のコンフィグを確認
# /etc/init.d/iptables status or # systemctl status firewalld ← iptables(または、fiwarelld)の有効化を確認
# iptables -L  ← iptables(または、fiwarelld)の現在適用されているルールを確認
# mkdir /var/log/fail2ban ← ログディレクトリを新規作成
 fail2ban.confを環境に合わせ編集します。
logtarget = /var/log/fail2ban.log
 jail.localを新規作成または追記します。
# vi /etc/fail2ban/jail.local
#
# Apache
#
[apache-403]

enabled = true
filter = apache-403
logpath = /var/log/httpd/*access_log
action = iptables-multiport[name="403", port="http,https", protocol="tcp"]
maxretry = 3
findtime = 10m
bantime = 1w

[apache-404]

enabled = true
filter = apache-404
logpath = /var/log/httpd/*access_log
action = iptables-multiport[name="404", port="http,https", protocol="tcp"]
maxretry = 3
findtime = 10m
bantime = 1w
 403フィルター新規作成
# vi /etc/fail2ban/filter.d/apache-403.conf
[Definition]
failregex =  ^<HOST>.*"(GET|POST).*" 403 .*$                      # フィルター
ignoreregex = 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 # ホワイトリスト
 404フィルター新規作成
# vi /etc/fail2ban/filter.d/apache-404.conf
[Definition]
failregex =  ^<HOST>.*"(GET|POST).*" 404 .*$                      # フィルター
ignoreregex = 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 # ホワイトリスト
 設定を反映させます。
# systemctl reload fail2ban
 設定されているかどうか確認します。
# fail2ban-client status apache-403
Status for the jail: apache-403
|- Filter
|  |- Currently failed:	0
|  |- Total failed:	0
|  `- File list:	/var/log/httpd/access_log /var/log/httpd/ssl_access_log
`- Actions
   |- Currently banned:	0
   |- Total banned:	0
   `- Banned IP list:	
# fail2ban-client status apache-404
Status for the jail: apache-404
|- Filter
|  |- Currently failed:	0
|  |- Total failed:	0
|  `- File list:	/var/log/fail2ban.log
`- Actions
   |- Currently banned:	0
   |- Total banned:	0
   `- Banned IP list:	
 必要に応じてログローテーションを設定してください。

●ApacheのDos攻撃を防ぐ

 参考URL:fail2banでdos攻撃を防ぐ方法

 Dos用のフィルターを定義します。

設定内容の説明です。

failregex:Jail判定するためのログ行の正規表現。
ignoreregex:failregexの中で除外したい正規表現。
 「(?i)」の部分は、この正規表現では大文字と小文字を区別しないという修飾子。
 この設定内容をまとめると「アセットファイル(画像ファイル、JSファイル、CSSファイルなどの静的ファイル)を除く、全GET,POST,HEADリクエストを監視する」となります。
vi /etc/fail2ban/filter.d/apache-ddos.conf
 
[Definition]
failregex = ^<HOST> -.*"(GET|POST).*
ignoreregex = \.(?i)(jpe?g|gif|png|bmp|pdf|js|css|woff|eot|ttf|ico|txt|xml|swf|xlsx?|docx?|pptx?)
 jailを定義し、fail2banを再起動します。
# vi /etc/fail2ban/jail.d/jail.local
[apache-ddos]

enabled = true
port = http,https
filter = apache-ddos
logpath = /var/log/httpd/*access_log
maxretry = 10
findtime = 1m
bantime = 1w
action = %(action_mwl)s ← 共通項目として設定済みであれば設定不要
destemail = root@mail.bigbnag.mydns.jp ← 共通項目として設定済みであれば設定不要

# systemctl reload fail2ban
 どのくらいBANされているか確認する。
# fail2ban-client status apache-ddos
 BANされるかどうかテストしてみます。ignoreipを一時的に空にし、ローカルから試験します。
ignoreip =

# fail2ban-client reload apache-ddos

# yes 'exec 4<>/dev/tcp/127.0.0.1/80; printf "GET / HTTP/1.0\r\n\r\n" >&4; head -1 <&4' | head -100 | bash
 Banされているかどうか確認します。
# fail2ban-client status apache-ddos
Status for the jail: apache-ddos
|- Filter
|  |- Currently failed:	1
|  |- Total failed:	100
|  `- File list:	/var/log/httpd/access_log /var/log/httpd/ssl_access_log
`- Actions
   |- Currently banned:	1
   |- Total banned:	1
   `- Banned IP list:	127.0.0.1
 jail.localを元の設定に戻し、対象JAILルールを再起動します。
ignoreip =

# fail2ban-client reload apache-ddos
# fail2ban-client status apache-ddos
Status for the jail: apache-ddos
|- Filter
|  |- Currently failed:	0
|  |- Total failed:	0
|  `- File list:	/var/log/httpd/access_log /var/log/httpd/ssl_access_log
`- Actions
   |- Currently banned:	0
   |- Total banned:	0
   `- Banned IP list:	
 BanされていたIPアドレスが無くなっていればOKです。

●/var/log/secureに記録される「POSSIBLE BREAK-IN ATTEMPT!」に対し、不正アクセスとしてブロックする

 参考URL:管理者/sshd への攻撃を撃退
 参考URL:fail2banでSSH攻撃対策を強化する

 /var/log/secureに変なログが残っていたので調査してみました。
# cat /var/log/secure* | grep "POSSIBLE BREAK-IN ATTEMPT" | sed -e "s/.*getaddrinfo for //g" -e "s/ failed - .*//g" | sort | uniq -cd
(抜粋)
     28 1.packets [178.62.0.248]
      2 100.77.178.186.static.anycast.cnt-grms.ec [186.178.77.100]
      6 102.subnet118-98-68.astinet.telkom.net.id [118.98.68.102]
     48 105.251.9.221.adsl-pool.jlccptt.net.cn [221.9.251.105]
      2 105.subnet118-97-188.astinet.telkom.net.id [118.97.188.105]
 のような感じでかなりの攻撃があるようです。
 これらのIPアドレスをアクセスできないように設定します。
 まず、アクセス拒否から除外すべきネットワークアドレス等を設定します。これをやっておかないとリモートアクセスに必要なIPアドレスまでもブロックされてしまいます。
# vi /etc/fail2ban/jail.local
ignoreip = 127.0.0.1/8 10.0.0.0/24 192.168.0.0/24

# systemctl reload fial2ban
 SSH用のフィルタを設定します。
# vi /etc/fail2ban/filter.d/sshd.conf
failregex = ...
                  ^%(__prefix_line)sAddress <HOST> .* POSSIBLE BREAK-IN ATTEMPT!*\s*$
                  ^%(__prefix_line)sreverse mapping checking getaddrinfo .* \[<HOST>\] failed - POSSIBLE BREAK-IN ATTEMPT!\s*$
                  ^%(__prefix_line)s.+Received disconnect from <HOST>: 11: Bye Bye *$
のように追加。

# systemctl reload fial2ban
 これで設定した内容にヒットしたものはbanされるようになります。

●yumによるアップデートの防止

 fail2banを稼働させましたので統合監視ソフト等を導入している場合、プロセス生き死に等の監視対象を設定します。
 yumにより不用意にアップデートさせたくない場合、/etc/yum.confで除外設定をしてください。

●banの解除方法及び代表的なコマンド

 banされているIPアドレスの確認
# fail2ban-client status [Jail名]
 [Jail名]はfail2ban-client statusで表示されるものを使用します。
 解除するには下記のようにします。
# fail2ban-client set [Jail名] unbanip [IPアドレス]
 意外と簡単に解除できました。 

 その他のコマンドも列記しておきます。

・Fail2banサーバ起動(※非推奨 systemctl で起動する方が良い)
# fail2ban-client start
・Fail2banサーバ停止(※非推奨 systemctl で停止する方が良い)
# fail2ban-client stop
・Fail2banの設定ファイルを再読み込み
# fail2ban-client reload
・指定したJAILルールをリロード
# fail2ban-client reload <JAILルール名>
・Fail2banサーバのステータスを表示
# fail2ban-client status
・指定したJAILルールのステータスとBAN状況を表示
# fail2ban-client status <JAILルール名>
・指定したJAILルールで指定したIPアドレスを手動でBAN
# fail2ban-client set <JAILルール名> banip <IPアドレス>
・指定したJAILルールで指定したIPアドレスをBAN解除
# fail2ban-client set <JAILルール名> unbanip <IPアドレス>
・BANされたIPアドレスを含むJAILを簡潔に表示
# fail2ban-client banned


●database disk image is malformed

 /var/log/fail2ban.logに下記のようなログが記録されていましたので、対処しました。
2019-07-22 21:14:59,199 fail2ban.transmitter    \
[18352]: WARNING Command ['start', 'sshd'] has failed. Received DatabaseError('database disk image is malformed',)
 下記のようにすることでログは出力されなくなりました。
# mv /var/lib/fail2ban/fail2ban.sqlite3 /var/lib/fail2ban/fail2ban.sqlite3_20190722
# yum reinstall fail2ban
# systemctl restart fail2ban


●NOTICE Jail started without 'journalmatch' set

 参考URL:Fail2banで不正なアクセスをブロック(BAN)してサーバを守る

 vsftpdの設定を有効にしたところ、下記のようなログが記録されました。
2019-07-22 21:57:43,809 fail2ban.filtersystemd  [26017]: NOTICE  Jail started without 'journalmatch' set. \
Jail regexs will be checked against all journal entries, which is not advised for performance reasons.
2019-07-22 21:57:43,830 fail2ban.jail           [26017]: INFO    Jail 'vsftpd' started
 対処するため下記のように変更します。
# vi /etc/fail2ban/filter.d/vsftpd.conf
[Init] ← 追記
journalmatch = _SYSTEMD_UNIT=proftpd.service ← 追記
# systemctl restart fail2ban
 fail2banの再起動後、解消しました。

●Line with odd timestamp

 参考URL:Some timezone warnings since version 0.11.2 #2882

 fail2banのログ

2022-11-02 05:32:56,608 fail2ban.filter [1525]: WARNING [apache-403] Simulate NOW in operation since found time has too larg e deviation 1667334716 ~ 1667334776.6086128 +/- 60
2022-11-02 05:32:56,609 fail2ban.filter [1525]: WARNING [apache-404] Simulate NOW in operation since found time has too larg e deviation 1667334716 ~ 1667334776.6094935 +/- 60
2022-11-02 05:32:56,609 fail2ban.filter [1525]: WARNING [apache-403] Please check jail has possibly a timezone issue. Line with odd timestamp: 66.***.***.*** - - [02/Nov/2022:05:31:56 +0900] "GET /redmine/issues/gantt?month=7&months=6&year=2091&zoom=1 HTTP/1.1" 200 30371 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.5304.87 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
2022-11-02 05:32:56,610 fail2ban.filter [1525]: WARNING [apache-ddos] Simulate NOW in operation since found time has too large deviation 1667334716 ~ 1667334776.6105652 +/- 60
2022-11-02 05:32:56,724 fail2ban.filter [1525]: WARNING [apache-404] Please check jail has possibly a timezone issue. Line with odd timestamp: 66.***.***.*** - - [02/Nov/2022:05:31:56 +0900] "GET /redmine/issues/gantt?month=7&months=6&year=2091&zoom=1 HTTP/1.1" 200 30371 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.5304.87 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
2022-11-02 05:32:56,726 fail2ban.filter [1525]: WARNING [apache-ddos] Please check jail has possibly a timezone issue. Line with odd timestamp: 66.***.***.*** - - [02/Nov/2022:05:31:56 +0900] "GET /redmine/issues/gantt?month=7&months=6&year=2091&zoom=1 HTTP/1.1" 200 30371 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.5304.87 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"


 httodのログ

66.***.***.*** - - [02/Nov/2022:05:31:56 +0900] "GET /redmine/issues/gantt?month=7&months=6&year=2091&zoom=1 HTTP/1.1" 200 30371 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.5304.87 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"


 上記のリンク先のコメントから抜粋

This warning isn’t an issue to fix in fail2ban. It indicates that there could be a problem with your system, since the message was logged at a particular time and fail2ban only found out about it some seconds later. It could be a sign that your system is overloaded, or your disks are slow, etc. When you see this message, fail2ban processed the log message as normal, but it might have been too late to do much good. For example, if someone is trying to guess an ssh password and fail2ban is notified of the new log messages 5 minutes later, then banning them is still good but it did let them keep guessing for five extra minutes.

この警告はfail2banで修正すべき問題ではありません。このメッセージは特定の時間に記録され、fail2ban はその数秒後にそれを知ったのですから、システムに問題がある可能性を示しているのです。システムが過負荷になっている、ディスクが遅い、などのサインかもしれません。このメッセージを見たとき、fail2ban は通常通りログメッセージを処理しましたが、あまりに遅すぎたため、あまり役に立たなかったかもしれません。例えば、誰かが ssh のパスワードを推測しようとしていて、fail2ban がその 5 分後に新しいログメッセージを通知された場合、その人を禁止することはまだ良いことですが、5 分間余計に推測させ続けることになりました。


 コメントを読むと、「無視すればよい」とのこと。