機械

機械

メール サーバーへの攻撃とログを止めようとしていますSASL LOGIN authentication failed。しかし、1 日試してみましたが、まだ成功していません。ログには、同じ IP による攻撃が引き続き生成されています。

機械

Linux server 5.4.0-109-generic #123-Ubuntu SMP Fri Apr 8 09:10:54 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

メールログイン/var/log/mail.log

Apr 28 20:45:23 server postfix/smtpd[112579]: connect from unknown[5.34.207.81]
Apr 28 20:45:24 server postfix/smtpd[112409]: warning: unknown[5.34.207.81]: SASL LOGIN authentication failed: authentication failure
Apr 28 20:45:25 server postfix/smtpd[112409]: disconnect from unknown[5.34.207.81] ehlo=1 auth=0/1 rset=1 quit=1 commands=3/4
Apr 28 20:45:30 server postfix/smtpd[112599]: connect from unknown[5.34.207.81]
Apr 28 20:45:31 server postfix/smtpd[112579]: warning: unknown[5.34.207.81]: SASL LOGIN authentication failed: authentication failure
Apr 28 20:45:32 server postfix/smtpd[112579]: disconnect from unknown[5.34.207.81] ehlo=1 auth=0/1 rset=1 quit=1 commands=3/4
Apr 28 20:45:36 server postfix/smtpd[112409]: connect from unknown[5.34.207.81]
Apr 28 20:45:38 server postfix/smtpd[112599]: warning: unknown[5.34.207.81]: SASL LOGIN authentication failed: authentication failure
Apr 28 20:45:38 server postfix/smtpd[112599]: disconnect from unknown[5.34.207.81] ehlo=1 auth=0/1 rset=1 quit=1 commands=3/4

IPtables を使用した Fail2Ban

/etc/fail2ban/jail.local

[postfix-sasl]

enabled  = true
port     = smtp,ssmtp,465,submission,imap,imaps,pop3,pop3s

bantime = 10m
filter   = postfix-sasl
#action   = iptables-multiport[name=postfix, port="smtp,ssmtp,465,submission,imap,imaps,pop3,pop3s", protocol=tcp]
logpath  = /var/log/mail.log
maxretry = 15

私はそうしましたsudo service fail2ban restart、そして、ワイヤードなことは、チェーンが見当たらなかったということですf2b-postfix

そこでログから grep を実行したところfail2ban、出力は次のようになりました。

Fail2Banログイン/var/log/fail2ban.log

2022-04-27 16:27:10,133 fail2ban.actions        [567]: NOTICE  [postfix-sasl] Unban 5.34.207.81
2022-04-27 16:27:45,391 fail2ban.actions        [567]: NOTICE  [postfix-sasl] Ban 5.34.207.81
2022-04-27 16:32:17,801 fail2ban.actions        [567]: NOTICE  [postfix-sasl] Unban 212.70.149.72
2022-04-27 22:37:46,299 fail2ban.actions        [567]: NOTICE  [postfix-sasl] Unban 5.34.207.81

UFW による Fail2Ban

調査したところ、Fail2Ban は UFW で動作できることがわかったので、調査を行い、私の設定を次に示します。

/etc/fail2ban/jail.local

[postfix-sasl]

enabled  = true
journalmatch =
backend = polling
bantime = -1    // Permanent ban? Maybe 
filter   = postfix-sasl
logpath  = /var/log/mail.log
maxretry = 15
banaction = ufw
findtime = 120

手動で入力しましたが、残念ながらメールログイン時に同じIPからの攻撃がまだ確認できることに言及する価値がありsudo ufw insert 1 deny from 5.34.207.81 to anyますsudo ufw reload/var/log/mail.log

答え1

アップデート

最終的に、私のFail2Ban作品は期待通りに動作したので、これを回答としてマークします。

解決策は、actionを に設定して複数のポートを禁止することです。ただし、との競合により起動中に が常に有効にならないことを認識しているため、攻撃者を制限するために はiptables-multiport使用しません。UFWUFWfirewalld

ソリューション

この行を/etc/fail2ban/jail.local

action = iptables-multiport[name=postfix, port="smtp,ssmtp,465,submission,imap,imaps,pop3,pop3s"]

次のようになります:

[postfix-sasl]

enabled  = true
filter   = postfix-sasl
action   = iptables-multiport[name=postfix, port="smtp,ssmtp,465,submission,imap,imaps,pop3,pop3s"]
logpath  = /var/log/mail.log
maxretry = 15
bantime  = 12h

以前はテスト目的で に設定していましたmaxretry3これをもっと高い値に変更した方が良いかもしれません。そうしないと、ユーザーがすぐに問題に直面する可能性があります。

Fail2Banステータスを確認する

あなたの刑務所をチェックしてみる価値はあります:

sudo fail2ban-server status postfix-sasl

出力:

Status for the jail: postfix-sasl
|- Filter
|  |- Currently failed: 2
|  |- Total failed:     49
|  `- File list:        /var/log/mail.log
`- Actions
   |- Currently banned: 1
   |- Total banned:     3
   `- Banned IP list:   5.34.207.81

リソース:Fail2Ban は Iptables ルールを設定できません:

答え2

注意すべき点は、ユーザー数に応じてしきい値を下げ、攻撃の数に応じて禁止期間を延長する必要がある場合があることです。

私は Postfix ではなく、Exim を使用しています。ただし、攻撃者をブロックする課題は同じです。ここでは、私の Fail2ban jail の状態を見て、ボットネットの規模を把握することができます。

XXXX@XXXX:~# fail2ban-client ステータス exim

jail のステータス: exim
|- フィルター
| |- 現在失敗: 0
| |- 合計失敗: 10380
| - File list: /var/log/exim4/mainlog- アクション
|- 現在禁止:1763
|- 合計禁止数: 5644
`- 禁止IPリスト: XXXXXXXXXXXX

関連情報