fail2ban을 통한 postfix + dovecot auth 보안 강화

메일 서버 오픈 이후 불특정 사용자의 접근이 많아지기 시작해서 아래와 같이

차단 방법을 사용해서 차단을 진행함

구성환경 - ubuntu 20.04

 

fail2ban 설치

# apt install fail2ban

 

아래와 같은 filter 생성 - /etc/fail2ban/filter.d/postfix-sasl.conf

# Fail2Ban filter for postfix authentication failures
[INCLUDES]
before = common.conf
[Definition]
#_daemon = postfix/smtpd <- comment this line, "postfix/smtps/smtpd" not detected
failregex = ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$

 

jail 설정 파일 생성 - /etc/fail2ban/jail.local

[DEFAULT]
ignoreip = 127.0.0.0/16

[postfix-sasl]
enabled  = true
port     = 25,465,587
filter   = postfix-sasl
logpath  = /var/log/mail.log
maxretry = 5
bantime  = 600

 

이후 fail2ban 서비스를 재시작한다.

# systemctl restart fail2ban.service

 

fail2ban 상태확인

# fail2ban-client status
Status
|- Number of jail:	1
`- Jail list:	postfix-sasl

 

postfix-sasl jail에 대한 세부 상태 확인

# fail2ban-client status postfix-sasl
Status for the jail: postfix-sasl
|- Filter
|  |- Currently failed:	0
|  |- Total failed:	14
|  `- File list:	/var/log/mail.log
`- Actions
   |- Currently banned:	26
   |- Total banned:	26
   `- Banned IP list:	173.211.232.202 2.56.57.142 2.56.57.153 2.56.57.170 212.192.241.186 212.192.241.55 212.192.241.73 212.192.246.11 212.192.246.120 212.192.246.133 212.192.246.145 212.192.246.167 212.192.246.17 212.192.246.191 212.192.246.226 212.192.246.237 212.192.246.28 212.192.246.36 212.192.246.64 212.192.246.73 212.192.246.81 212.192.246.82 212.192.246.9 5.34.205.62 136.144.41.253 37.0.10.176