기계

기계

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

수동으로 입력했지만 안타깝게도 여전히 메일 로그인에서 동일한 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그러나 UFW.UFWfirewalld

솔루션

이 줄을/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

자원:Fail2Ban은 Iptables 규칙을 설정할 수 없습니다:

답변2

사용자 수에 따라 임계값을 낮추고 공격 횟수에 따라 금지 시간을 늘릴 수 있다는 점에 유의할 가치가 있습니다.

저는 Postfix를 사용하지 않고 대신 Exim을 사용합니다. 하지만 공격자를 차단하는 과제는 동일합니다. 여기에서 내 Fail2ban 감옥의 상태를 확인하여 거기에 있는 봇넷 크기에 대한 아이디어를 얻을 수 있습니다.

XXXX@XXXX:~#fail2ban-클라이언트 상태 exim

감옥 상태: exim
|- 필터
| |- 현재 실패: 0
| |- 총 실패 횟수: 10380
| - File list: /var/log/exim4/mainlog- 작업
|- 현재 금지된 항목:1763년
|- 금지된 총 개수: 5644
`- 금지된 IP 목록: XXXXXXXXXXXX

관련 정보