Late reply, I know - sorry… and long post
I’ve been running crowdsec in parallel to fail2ban and probably will leave them both running for now. I like crowdsec, although not totally sure yet that I am as across what it is doing as I am for fail2ban.
For Postfix I run the following in my fail2ban jail.local file:
[postfix]
enabled = true
mode = normal
port = smtp,465,submission
logpath = %(postfix_log)s
backend = %(postfix_backend)s
[postfix-rbl]
enabled = true
filter = postfix[mode=rbl]
port = smtp,465,submission
logpath = %(postfix_log)s
backend = %(postfix_backend)s
maxretry = 1
[postfix-sasl]
enabled = true
filter = postfix[mode=auth]
port = smtp,465,submission,imap,imaps,pop3,pop3s
logpath = %(postfix_log)s
backend = %(postfix_backend)s
maxretry = 1
[postscreen]
enabled=true
port = smtp,465,submission
logpath = %(postfix_log)s
backend = %(postfix_backend)s
bantime = 2592000
maxretry = 1
This means that a single externally-initiated rbl fail, sasl password fail, or postscreen fail results in a ban. The postfix filter and jail works very well, the postscreen filter catches is ‘ylmf-pc’ botnet, so it bans for a month.
The postscreen filter contains:
[INCLUDES]
before = common.conf
[Definition]
_daemon = postfix/postscreen
failregex = ^%(__prefix_line)sPREGREET \d+ after \d+\.\d+ from \[<HOST>\]:\d+: EHLO ylmf-pc\\r\\n
NOQUEUE: reject: RCPT from (.*)\[<HOST>\]:([0-9]{4,5}:)? 454 4.7.1.*Relay access denied
ignoreregex =
[Init]
journalmatch = _SYSTEMD_UNIT=postfix.service
The postfix rbl lists I use are tested over years of use and work well for me, so I have an aggressive “one strike” ban policy on postfix-rbl. Sasl fails are the same - my users don’t normally come in that way, so zero tolerance for auth fails.
My fail2ban postfix filter is out of the box, no changes - just enabled in ‘normal’ mode, ‘rbl’ mode (1 strike) by the second call, and ‘auth’ mode (1 strike) by the third call.
And I can see fail2ban fails coming through and getting entered into firewall rules:
]# cat /var/log/fail2ban.log | grep "Ban "
2021-02-10 07:00:47,719 fail2ban.actions [923]: NOTICE [postfix-rbl] Ban 168.245.28.80
2021-02-10 08:43:30,799 fail2ban.actions [923]: NOTICE [postfix] Ban 91.134.231.66
2021-02-10 20:05:38,296 fail2ban.actions [923]: NOTICE [postfix-sasl] Ban 82.177.122.227
2021-02-11 01:33:10,259 fail2ban.actions [923]: NOTICE [postfix-sasl] Ban 45.167.11.3
Crowdsec appears to be catching stuff:
]# cscli hub list
INFO[0000] Loaded 13 collecs, 18 parsers, 21 scenarios, 3 post-overflow parsers
INFO[0000] unmanaged items : 55 local, 0 tainted
INFO[0000] PARSERS:
--------------------------------------------------------------------------------------------------------------
NAME 📦 STATUS VERSION LOCAL PATH
--------------------------------------------------------------------------------------------------------------
crowdsecurity/sshd-logs ✔️ enabled 0.1 /etc/crowdsec/parsers/s01-parse/sshd-logs.yaml
crowdsecurity/whitelists ✔️ enabled 0.1 /etc/crowdsec/parsers/s02-enrich/whitelists.yaml
crowdsecurity/geoip-enrich ✔️ enabled 0.2 /etc/crowdsec/parsers/s02-enrich/geoip-enrich.yaml
crowdsecurity/syslog-logs ✔️ enabled 0.1 /etc/crowdsec/parsers/s00-raw/syslog-logs.yaml
crowdsecurity/iptables-logs ✔️ enabled 0.1 /etc/crowdsec/parsers/s01-parse/iptables-logs.yaml
crowdsecurity/postfix-logs ✔️ enabled 0.2 /etc/crowdsec/parsers/s01-parse/postfix-logs.yaml
crowdsecurity/postscreen-logs ✔️ enabled 0.1 /etc/crowdsec/parsers/s01-parse/postscreen-logs.yaml
crowdsecurity/dateparse-enrich ✔️ enabled 0.1 /etc/crowdsec/parsers/s02-enrich/dateparse-enrich.yaml
--------------------------------------------------------------------------------------------------------------
INFO[0000] SCENARIOS:
-----------------------------------------------------------------------------------------------------------------------
NAME 📦 STATUS VERSION LOCAL PATH
-----------------------------------------------------------------------------------------------------------------------
crowdsecurity/iptables-scan-multi_ports ✔️ enabled 0.1 /etc/crowdsec/scenarios/iptables-scan-multi_ports.yaml
crowdsecurity/ssh-bf ✔️ enabled 0.1 /etc/crowdsec/scenarios/ssh-bf.yaml
crowdsecurity/postfix-spam ✔️ enabled 0.2 /etc/crowdsec/scenarios/postfix-spam.yaml
-----------------------------------------------------------------------------------------------------------------------
INFO[0000] COLLECTIONS:
---------------------------------------------------------------------------------------
NAME 📦 STATUS VERSION LOCAL PATH
---------------------------------------------------------------------------------------
crowdsecurity/postfix ✔️ enabled 0.2 /etc/crowdsec/collections/postfix.yaml
crowdsecurity/sshd ✔️ enabled 0.1 /etc/crowdsec/collections/sshd.yaml
crowdsecurity/iptables ✔️ enabled 0.1 /etc/crowdsec/collections/iptables.yaml
crowdsecurity/linux ✔️ enabled 0.2 /etc/crowdsec/collections/linux.yaml
---------------------------------------------------------------------------------------
INFO[0000] POSTOVERFLOWS:
--------------------------------------
NAME 📦 STATUS VERSION LOCAL PATH
--------------------------------------
--------------------------------------
Metrics:
]# cscli metrics
INFO[0000] Buckets Metrics:
+------------------------------+---------------+-----------+--------------+--------+---------+
| BUCKET | CURRENT COUNT | OVERFLOWS | INSTANCIATED | POURED | EXPIRED |
+------------------------------+---------------+-----------+--------------+--------+---------+
| crowdsecurity/postfix-spam | - | - | 499 | 504 | 499 |
| crowdsecurity/postscreen-rbl | - | 5294 | 5294 | - | - |
+------------------------------+---------------+-----------+--------------+--------+---------+
INFO[0000] Acquisition Metrics:
+-------------------+------------+--------------+----------------+------------------------+
| SOURCE | LINES READ | LINES PARSED | LINES UNPARSED | LINES POURED TO BUCKET |
+-------------------+------------+--------------+----------------+------------------------+
| /var/log/maillog | 143706 | 5923 | 137783 | 504 |
| /var/log/messages | 6969 | - | 6969 | - |
| /var/log/secure | 115 | 27 | 88 | - |
+-------------------+------------+--------------+----------------+------------------------+
INFO[0000] Parser Metrics:
+-------------------------------------+--------+--------+----------+
| PARSERS | HITS | PARSED | UNPARSED |
+-------------------------------------+--------+--------+----------+
| child-crowdsecurity/postfix-logs | 43999 | 629 | 43370 |
| child-crowdsecurity/postscreen-logs | 30097 | 5294 | 24803 |
| child-crowdsecurity/sshd-logs | 526 | 27 | 499 |
| crowdsecurity/dateparse-enrich | 5950 | 5950 | - |
| crowdsecurity/geoip-enrich | 5950 | 5950 | - |
| crowdsecurity/postfix-logs | 14989 | 629 | 14360 |
| crowdsecurity/postscreen-logs | 30097 | 5294 | 24803 |
| crowdsecurity/sshd-logs | 111 | 27 | 84 |
| crowdsecurity/syslog-logs | 150790 | 150790 | - |
| crowdsecurity/whitelists | 5950 | 5950 | - |
+-------------------------------------+--------+--------+----------+
And bans:
]# cscli decisions list
+-------+----------+-------------------+------------------------------+--------+---------+--------------------------------+--------+-------------------+----------+
| ID | SOURCE | SCOPE:VALUE | REASON | ACTION | COUNTRY | AS | EVENTS | EXPIRATION | ALERT ID |
+-------+----------+-------------------+------------------------------+--------+---------+--------------------------------+--------+-------------------+----------+
| 60496 | crowdsec | Ip:103.149.12.29 | crowdsecurity/postscreen-rbl | ban | | | 1 | 1h15m36.21447193s | 11385 |
| 60488 | crowdsec | Ip:193.239.147.98 | crowdsecurity/postscreen-rbl | ban | | | 1 | 39m1.481871957s | 11377 |
| 60485 | crowdsec | Ip:103.114.105.83 | crowdsecurity/postscreen-rbl | ban | | VIETNAM POSTS AND | 1 | 22m56.888637507s | 11374 |
| | | | | | | TELECOMMUNICATIONS GROUP | | | |
| 60483 | crowdsec | Ip:103.207.38.234 | crowdsecurity/postscreen-rbl | ban | VN | VNPT Corp | 1 | 16m9.504475056s | 11372 |
| 60481 | crowdsec | Ip:141.98.10.143 | crowdsecurity/postscreen-rbl | ban | | | 1 | 7m2.063749882s | 11370 |
| 60480 | crowdsec | Ip:45.148.10.69 | crowdsecurity/postscreen-rbl | ban | | | 1 | 2m10.204645422s | 11369 |
+-------+----------+-------------------+------------------------------+--------+---------+--------------------------------+--------+-------------------+----------+
But, those IPs don’t match what fail2ban is catching:
]# cat /var/log/fail2ban.log | grep "Ban "
2021-02-10 07:00:47,719 fail2ban.actions [923]: NOTICE [postfix-rbl] Ban 168.245.28.80
2021-02-10 08:43:30,799 fail2ban.actions [923]: NOTICE [postfix] Ban 91.134.231.66
2021-02-10 20:05:38,296 fail2ban.actions [923]: NOTICE [postfix-sasl] Ban 82.177.122.227
2021-02-11 01:33:10,259 fail2ban.actions [923]: NOTICE [postfix-sasl] Ban 45.167.11.3
It may well be that crowdsec is catching those also, and it’s passed them back out?
These are the events that triggered the above fail2ban bans:
Immediate ban under postfix-sasl filter:
Feb 11 01:33:10 emp07 postfix/submission/smtpd[31878]: warning: unknown[45.167.11.3]: SASL PLAIN authentication failed: authentication failure
Immediate ban under postfix-sasl filter:
Feb 10 20:05:38 emp07 postfix/submission/smtpd[19706]: warning: unknown[82.177.122.227]: SASL PLAIN authentication failed: authentication failure
Three strikes, then ban under normal postfix filter:
Feb 10 08:43:28 emp07 postfix/postscreen[25723]: CONNECT from [91.134.231.66]:52643 to [192.168.1.235]:25
Feb 10 08:43:28 emp07 postfix/dnsblog[25725]: addr 91.134.231.66 listed by domain hostkarma.junkemailfilter.com as 127.0.1.1
Feb 10 08:43:28 emp07 postfix/dnsblog[25725]: addr 91.134.231.66 listed by domain hostkarma.junkemailfilter.com as 127.0.0.4
Feb 10 08:43:28 emp07 postfix/postscreen[25723]: PASS OLD [91.134.231.66]:52643
Feb 10 08:43:28 emp07 postfix/smtpd[25735]: warning: hostname jan.leacloud.us does not resolve to address 91.134.231.66
Feb 10 08:43:28 emp07 postfix/smtpd[25735]: connect from unknown[91.134.231.66]
Feb 10 08:43:29 emp07 postfix/smtpd[25735]: Anonymous TLS connection established from unknown[91.134.231.66]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Feb 10 08:43:30 emp07 postfix/smtpd[25735]: NOQUEUE: reject: RCPT from unknown[91.134.231.66]: 450 4.1.8 <bounce@fulfillteam.us>: Sender address rejected: Domain not found; from=<bounce@fulfillteam.us> to=<aaaa@aaaa.net> proto=ESMTP helo=<jan.leacloud.us>
Immediate ban under postfix-rbl filter
Feb 10 07:00:38 emp07 postfix/postscreen[21746]: CONNECT from [168.245.28.80]:7788 to [192.168.1.235]:25
Feb 10 07:00:38 emp07 postfix/dnsblog[21753]: addr 168.245.28.80 listed by domain zen.spamhaus.org as 127.0.0.2
Feb 10 07:00:38 emp07 postfix/dnsblog[21756]: addr 168.245.28.80 listed by domain hostkarma.junkemailfilter.com as 127.0.1.1
Feb 10 07:00:38 emp07 postfix/dnsblog[21756]: addr 168.245.28.80 listed by domain hostkarma.junkemailfilter.com as 127.0.0.1
Feb 10 07:00:39 emp07 postfix/dnsblog[21757]: addr 168.245.28.80 listed by domain wl.mailspike.net as 127.0.0.17
Feb 10 07:00:44 emp07 postfix/postscreen[21746]: PASS NEW [168.245.28.80]:7788
Feb 10 07:00:45 emp07 postfix/smtpd[21758]: connect from o15.sg.m.dripemail2.com[168.245.28.80]
Feb 10 07:00:46 emp07 postfix/smtpd[21758]: Anonymous TLS connection established from o15.sg.m.dripemail2.com[168.245.28.80]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Feb 10 07:00:47 emp07 postfix/smtpd[21758]: NOQUEUE: reject: RCPT from o15.sg.m.dripemail2.com[168.245.28.80]: 554 5.7.1 Service unavailable; Client host [168.245.28.80] blocked using zen.spamhaus.org; https://www.spamhaus.org/sbl/query/SBL509183; from=<bounces+2693180-aea9-aaaa=aaaa.net@m.dripemail2.com> to=<aaaa@aaaa.net> proto=ESMTP helo=<o15.sg.m.dripemail2.com>
Feb 10 07:00:47 emp07 postfix/smtpd[21758]: disconnect from o15.sg.m.dripemail2.com[168.245.28.80]