![fail2ban が SMTP パスワード ブルート フォース攻撃をキャッチしない](https://rvso.com/image/1554872/fail2ban%20%E3%81%8C%20SMTP%20%E3%83%91%E3%82%B9%E3%83%AF%E3%83%BC%E3%83%89%20%E3%83%96%E3%83%AB%E3%83%BC%E3%83%88%20%E3%83%95%E3%82%A9%E3%83%BC%E3%82%B9%E6%94%BB%E6%92%83%E3%82%92%E3%82%AD%E3%83%A3%E3%83%83%E3%83%81%E3%81%97%E3%81%AA%E3%81%84.png)
スパマーが私のサーバー (Debian の postfix) でブルート フォース パスワード推測攻撃を実行しています。スパマーはすでに 2 人のユーザーのパスワードを推測し、私のサーバーを使用してスパムを送信し始めています。パスワードは変更され、攻撃は軽減されました (今のところ) が、スパマーを完全にブロックしたいと考えています。
fail2ban をインストールしましたが、何らかの理由で攻撃を検出できません。
/etc/fail2ban/fail.conf
含まれるもの:
[sasl]
enabled = true
port = smtp,ssmtp,submission,imap2,imap3,imaps,pop3,pop3s
filter = sasl
# You might consider monitoring /var/log/mail.warn instead if you are
# running postfix since it would provide the same log lines at the
# "warn" level but overall at the smaller filesize.
#logpath = /var/log/mail.log
logpath = /var/log/mail.warn
/etc/fail2ban/filter.d/sasl.conf
含まれるもの:
# Fail2Ban configuration file
#
# Author: Yaroslav Halchenko
#
# $Revision$
#
[Definition]
# 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 "<HOST>" can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
# Values: TEXT
#
failregex = (?i): warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
でフィルターを実行すると/var/log/mail.warn
、次のような結果が生成されます。
# fail2ban-regex /var/log/mail.warn '(?i): warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$'
Running tests
=============
Use regex line : (?i): warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|P...
Use log file : /var/log/mail.warn
Results
=======
Failregex
|- Regular expressions:
| [1] (?i): warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$
|
`- Number of matches:
[1] 15293 match(es)
Ignoreregex
|- Regular expressions:
|
`- Number of matches:
Summary
=======
Addresses found:
[1]
123.169.7.222 (Sun Feb 25 06:40:18 2018)
123.169.7.222 (Sun Feb 25 06:40:21 2018)
...
185.173.176.157 (Fri Mar 02 10:12:46 2018)
185.173.176.157 (Fri Mar 02 10:13:15 2018)
185.173.176.157 (Fri Mar 02 10:13:43 2018)
185.173.176.157 (Fri Mar 02 10:14:11 2018)
185.173.176.157 (Fri Mar 02 10:14:41 2018)
185.173.176.157 (Fri Mar 02 10:15:13 2018)
185.173.176.157 (Fri Mar 02 10:15:42 2018)
185.173.176.157 (Fri Mar 02 10:16:13 2018)
185.173.176.157 (Fri Mar 02 10:16:42 2018)
185.173.176.157 (Fri Mar 02 10:17:10 2018)
Date template hits:
34294 hit(s): MONTH Day Hour:Minute:Second
0 hit(s): WEEKDAY MONTH Day Hour:Minute:Second Year
0 hit(s): WEEKDAY MONTH Day Hour:Minute:Second
0 hit(s): Year/Month/Day Hour:Minute:Second
0 hit(s): Day/Month/Year Hour:Minute:Second
0 hit(s): Day/Month/Year Hour:Minute:Second
0 hit(s): Day/MONTH/Year:Hour:Minute:Second
0 hit(s): Month/Day/Year:Hour:Minute:Second
0 hit(s): Year-Month-Day Hour:Minute:Second
0 hit(s): Year.Month.Day Hour:Minute:Second
0 hit(s): Day-MONTH-Year Hour:Minute:Second[.Millisecond]
0 hit(s): Day-Month-Year Hour:Minute:Second
0 hit(s): TAI64N
0 hit(s): Epoch
0 hit(s): ISO 8601
0 hit(s): Hour:Minute:Second
0 hit(s): <Month/Day/Year@Hour:Minute:Second>
Success, the total number of match is 15293
However, look at the above section 'Running tests' which could contain important
information.
それにもかかわらず、/var/log/fail2ban.log
問題のある IP アドレスがブロックされていることは示されません。
アップデート
提案に従って、ログ レベルを上げました。次のように表示されます。
2018-03-02 12:47:55,920 fail2ban.filter : DEBUG Processing line with time:1519986602.0 and ip:185.173.176.157
2018-03-02 12:47:55,920 fail2ban.filter : DEBUG Ignore line since time 1519986602.0 < 1519987675.92 - 600
2018-03-02 12:47:55,920 fail2ban.filter : DEBUG Processing line with time:1519986635.0 and ip:185.173.176.157
2018-03-02 12:47:55,920 fail2ban.filter : DEBUG Ignore line since time 1519986635.0 < 1519987675.92 - 600
jail.conf には次の内容が含まれています:
bantime = 600
maxretry = 3
答え1
Ignore line since time 1519986602.0 < 1519987675.92 - 600
ログ記録からドキュメント、私は がオプション600
の値であると推測しますfindtime
。つまり、特定の IP からのクラック試行は よりも大きなストライドで行われるようでfindtime
、そのため によって無視されますfail2ban
。
1519987675.92-1519986602.0
1073.92
約18分です。
完璧な解決策としては、インターネットに接続されたインターフェースで TLS の使用を義務付け、クライアントが提示する証明書が信頼できる CA によって発行されたものであることの検証を義務付けることが挙げられます。