我正在嘗試阻止攻擊並登入SASL LOGIN authentication failed
我的郵件伺服器。然而,我已經嘗試了一天,但仍然無法實現。日誌繼續產生具有相同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
值得一提的是,我已經手動輸入了sudo ufw insert 1 deny from 5.34.207.81 to any
,sudo ufw reload
但不幸的是我仍然能夠在郵件登入時看到來自同一IP的攻擊/var/log/mail.log
答案1
更新
最後,我的Fail2Ban
作品符合預期,我將此標記為答案!
解決辦法就是設定action
等於iptables-multiport
禁止多個連接埠!但是,我不使用UFW
限制攻擊者,因為我意識到UFW
由於與firewalld
.
解決方案
將此行新增至您的/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
之前我設定maxretry
為3
用於測試目的。您可能想將其更改為更高的值。否則您的用戶可能很快就會遇到麻煩。
檢查 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
答案2
值得注意的是,根據您擁有的用戶數量,您可能需要降低閾值,並且根據攻擊數量可能會增加禁止時間。
我不使用 Postfix,而是使用 Exim。您可以在此處查看我的 Fail2ban 監獄的狀態,以便您了解殭屍網路的規模:
XXXX@XXXX:~#fail2ban-客戶端狀態 exim
監獄狀態:exim
|- 過濾器
| |- 當前失敗:0
| |- 失敗總數:10380
| - File list: /var/log/exim4/mainlog
- 行動
|- 目前禁止:第1763章
|- 禁止總數: 5644
`- 禁止 IP 清單:XXXXXXXXXXXX