Fail2Banカスタムフィルタは適用されませんでした。

Fail2Banカスタムフィルタは適用されませんでした。

Fail2banのカスタム刑務所ルールしかし、決して適用されません。

私はそのような公式文書を見つけることができませんでした。何か落ちたかもしれません。

/etc/fail2ban/filter.d/expressjs.conf

[Definition]
failregex = .* from ip <HOST>

/etc/fail2ban/jail.conf

[express-js]
enabled  = true
filter   = expressjs
logpath  = /var/log/expressjs/slowin-killer.log
maxretry = 5
bantime  = 3600
findtime = 600

/var/log/expressjs/slowin-killer.log

[20-5-2017 20:49:57] Failed to authentificate user "[email protected]" from ip 127.0.0.1
[20-5-2017 20:57:19] Failed to authentificate user "[email protected]" from ip 127.0.0.1
[20-5-2017 20:59:20] Failed to authentificate user "[email protected]" from ip 127.0.0.1
[20-5-2017 21:12:47] Failed to authentificate user "[email protected]" from ip 127.0.0.1
[20-5-2017 21:16:9] Failed to authentificate user "[email protected]" from ip 127.0.0.1

エラーメッセージはありませんが、刑務所が有効になっているようです...

$ fail2ban-client status expressjs
Status for the jail: expressjs
|- Filter
|  |- Currently failed: 0
|  |- Total failed: 0
|  `- File list:    /var/log/expressjs/slowin-killer.log
`- Actions
   |- Currently banned: 0
   |- Total banned: 0
   `- Banned IP list:   

奇妙なことに、正規表現はうまくいきます...

failure2ban-regex /var/log/expressjs/slowin-killer.log /etc/fail2ban/filter.d/expressjs.conf

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

Use   failregex filter file : expressjs, basedir: /etc/fail2ban
Use         log file : /var/log/expressjs/slowin-killer.log
Use         encoding : UTF-8


Results
=======

Failregex: 27 total
|-  #) [# of hits] regular expression
|   1) [27] .* from ip <HOST>
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [34] Day(?P<_sep>[-/])Month(?P=_sep)(?:Year|Year2) 24hour:Minute:Second
|  [1] (?:DAY )?MON Day Year 24hour:Minute:Second(?:\.Microseconds)?
`-

Lines: 162 lines, 0 ignored, 27 matched, 135 missed
[processed in 0.01 sec]

Missed line(s): too many to print.  Use --print-all-missed to print all 135 lines

ベストアンサー1

フィルタが正しく機能するためには、修正する必要がありません。

  1. 内部的にこれをexpressjs.conf設定しました。つまり、自動ブロック/拒否iptablesルールを作成するには、10分(600秒)期間内に5回の試行失敗(正規表現一致)が必要です。マンページ:findtime = 600maxretry = 5jail.conf
   findtime
          time interval (in seconds) before the current time where failures will count towards a ban.

   maxretry
          number of failures that have to occur in the last findtime seconds to ban then IP.

ログを見ると、ここに貼り付けたログの最初のログエントリと最後のログエントリの間に10分以上があります(5回試行)。最初: 20:49、最後:21:16

  1. すべてのログはから来ます。ブロックの内部を127.0.0.1見ると、基本的な構成が見つかります。これを変更しない限り、localhostアドレスをブロックすると、内部通信にそのアドレスを使用する他のソフトウェアが破損するため、非常に危険です。jail.conf[DEFAULT]ignoreip = 127.0.0.1/8

  2. expressjs.conf構成が設定されていないため、datepattern =Fail2banはログファイルのどの部分が日付かを推測できません。ファイルでいくつかの例を見ると、/etc/fail2ban/filter.d同じ日付正規表現を見つけることができます。ここで別の問題は、ログ日付の「2番目」の部分に秒< 10(最後のログなど)に末尾のゼロがないことです。これは修正する必要があります。datepattern = ^L %%d/%%m/%%Y - %%H:%%M:%%Sdatepattern = ^%%Y:%%m:%%d-%%H:%%M:%%S21:16:9

見てFail2ban公式wiki例を入手してフィルタを改善してください。整理することが多いですね。

おすすめ記事