동일한 IP에서 매일 postfix 서버에서 수백 개의 SMTP AUTH 요청을 수신하는 Ubuntu 20.04 서버가 있습니다. Fail2ban을 설치했는데 아이러니하게도 IP 차단에 실패하고 있습니다.
내 /etc/fail2ban/jail.local
파일은 다음과 같습니다(<snip>'된 비트는 개인 및 비즈니스 IP입니다).
[postfix-flood-attack]
enabled = true
bantime = 1h
filter = postfix-flood-attack
action = iptables-multiport[name=postfix, port="http,https,smtp,submission,pop3,pop3s,imap,imaps,sieve", protocol=tcp]
logpath = /var/log/mail.log
ignoreip = <snip> 127.0.0.1/8
maxretry = 3
[postfix]
enabled = true
maxretry = 3
bantime = 1h
filter = postfix[mode=aggressive]
logpath = /var/log/mail.log
ignoreip = <snip> 127.0.0.1/8
[dovecot]
enabled = true
port = pop3,pop3s,imap,imaps
filter = dovecot
logpath = /var/log/mail.log
maxretry = 3
ignoreip = <snip> 127.0.01/8
문제의 감옥 postfix-flood-attack
은 에서 가져온 것입니다.이 튜토리얼의 맨 아래. 파일 /etc/fail2ban/filter.d/postfix-flood-attack.conf
은 다음과 같습니다
[Definition]
failregex = lost connection after AUTH from (.*)\[<HOST>\]
ignoreregex =
내 로그 메시지는 다음과 같습니다
Aug 15 13:54:45 ikana postfix/smtps/smtpd[268729]: connect from unknown[193.35.48.18]
Aug 15 13:54:46 ikana postfix/smtps/smtpd[268729]: Anonymous TLS connection established from unknown[193.35.48.18]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Aug 15 13:54:50 ikana postfix/smtps/smtpd[268729]: warning: unknown[193.35.48.18]: SASL PLAIN authentication failed:
Aug 15 13:54:50 ikana postfix/smtps/smtpd[268729]: lost connection after AUTH from unknown[193.35.48.18]
Aug 15 13:54:50 ikana postfix/smtps/smtpd[268729]: disconnect from unknown[193.35.48.18] ehlo=1 auth=0/1 commands=1/2
Aug 15 13:54:50 ikana postfix/smtps/smtpd[268729]: connect from unknown[193.35.48.18]
Aug 15 13:54:51 ikana postfix/smtps/smtpd[268729]: Anonymous TLS connection established from unknown[193.35.48.18]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Aug 15 13:54:57 ikana postfix/smtps/smtpd[268729]: lost connection after AUTH from unknown[193.35.48.18]
Aug 15 13:54:57 ikana postfix/smtps/smtpd[268729]: disconnect from unknown[193.35.48.18] ehlo=1 auth=0/1 commands=1/2
Aug 15 13:54:57 ikana postfix/smtps/smtpd[268729]: connect from unknown[193.35.48.18]
Aug 15 13:54:58 ikana postfix/smtps/smtpd[268729]: Anonymous TLS connection established from unknown[193.35.48.18]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Aug 15 13:55:04 ikana postfix/smtps/smtpd[268729]: lost connection after AUTH from unknown[193.35.48.18]
Aug 15 13:55:04 ikana postfix/smtps/smtpd[268729]: disconnect from unknown[193.35.48.18] ehlo=1 auth=0/1 commands=1/2
Aug 15 13:55:04 ikana postfix/smtps/smtpd[268734]: connect from unknown[193.35.48.18]
Aug 15 13:55:05 ikana postfix/smtps/smtpd[268734]: Anonymous TLS connection established from unknown[193.35.48.18]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Aug 15 13:55:09 ikana postfix/smtps/smtpd[268734]: warning: unknown[193.35.48.18]: SASL PLAIN authentication failed:
Aug 15 13:55:09 ikana postfix/smtps/smtpd[268734]: lost connection after AUTH from unknown[193.35.48.18]
Aug 15 13:55:09 ikana postfix/smtps/smtpd[268734]: disconnect from unknown[193.35.48.18] ehlo=1 auth=0/1 commands=1/2
에 따르면 fail2ban-regex
이것이 작동해야 하지만 IP가 금지되지는 않습니다. 명령의 출력은 다음 fail2ban-regex /var/log/mail.log /etc/fail2ban/filter.d/postfix-flood-attack.conf
과 같습니다.
Running tests
=============
Use failregex filter file : postfix-flood-attack, basedir: /etc/fail2ban
Use log file : /var/log/mail.log
Use encoding : UTF-8
Results
=======
Failregex: 5356 total
|- #) [# of hits] regular expression
| 1) [5356] lost connection after AUTH from (.*)\[<HOST>\]
`-
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
| [37949] {^LN-BEG}(?:DAY )?MON Day %k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
`-
Lines: 37949 lines, 0 ignored, 5356 matched, 32593 missed
[processed in 1.43 sec]
Missed line(s): too many to print. Use --print-all-missed to print all 32593 lines
따라서 5,356개의 로그와 일치하는 항목을 찾고 어떠한 것도 차단하지 않습니다. 일반적으로 기본 10분 조회 시간 내에 8번의 시도가 있습니다. -v
with 옵션을 사용하는 스니펫은 fail2ban-regex
타임스탬프와 다음과 같은 일치 항목을 보여줍니다.
...
193.35.48.18 Thu Aug 15 13:50:55 2019
193.35.48.18 Thu Aug 15 13:51:02 2019
193.35.48.18 Thu Aug 15 13:51:10 2019
193.35.48.18 Thu Aug 15 13:51:15 2019
193.35.48.18 Thu Aug 15 13:54:50 2019
193.35.48.18 Thu Aug 15 13:54:57 2019
193.35.48.18 Thu Aug 15 13:55:04 2019
193.35.48.18 Thu Aug 15 13:55:09 2019
193.35.48.18 Thu Aug 15 13:58:40 2019
193.35.48.18 Thu Aug 15 13:58:48 2019
193.35.48.18 Thu Aug 15 13:58:54 2019
193.35.48.18 Thu Aug 15 13:58:59 2019
...
답변1
구성은 좋아 보이지만 다음 출력에서 주목해야 할 중요한 세부 사항이 하나 있습니다 fail2ban-regex
. 날짜가 2019년으로 결정되었습니다. 질문의 로그 모양을 고려하면 처음에는 다소 어리석은 것처럼 보였습니다. 이는 Fail2ban의 알려진 문제인 것으로 밝혀졌습니다.TZ 문제. 특정 시간대를 사용하도록 서버를 구성한 후에는 여러 서비스를 다시 시작하거나 전체 시스템을 다시 시작해야 제대로 적용됩니다. 시간이 얼마나 지났는지는 기억나지 않지만, 시간대를 구성한 이후로 서버를 다시 시작한 적이 없는 것 같습니다.
를 통해 syslog 서비스를 다시 시작한 후 systemctl restart syslog
, fall2ban은 올바른 시간대의 로그 줄을 인식했습니다.
Fail2ban은 설정된 찾기 시간에 로그 메시지를 즉시 인식하고, 며칠 동안 내 서버를 괴롭히던 IP를 차단했습니다. Fail2ban은 Fail2ban-server가 시작된 이후 시스템에 설정된 정보를 사용하는 대신 syslog에 시간대 정보를 요청하는 것 같습니다.
비슷한 문제가 있는 다른 사람에게 도움이 되기를 바랍니다.
답변2
Fail2ban이 해당 날짜를 2019년으로 가정하게 만든 모호함은 표준 날짜 형식을 사용할 때 발생할 수 없습니다. 문제를 완전히 피할 수 있습니다.ISO 8601을 사용하여- 2020년에는 이전 버전과 호환되는 로그 형식을 고수해야 할 타당한 이유가 남아 있지 않을 수도 있습니다.
또한 우분투에서는 시간대 정보 없이 에포크의 일반 오프셋을 제공하는 시스템 저널을 직접 사용하도록 FAIL2BAN에 지시하여 날짜 형식 지정/구문 분석을 완전히 건너뛸 수 있습니다( 로컬 감옥 구성의 블록 backend = systemd
에서 시도).[DEFAULT]