Topic: fail2ban behind pfsense
I'm using iredmail but fail2ban not work properly cause by default get the wrong ip, i mean the firewall ip, so i had to ignore it or ban everyone.
I'm running iredmail into a server in private lan behind pfsense firewall with SSL offload and haproxy so when guest visit mail.myserver.com to login into roudcube the firewall handle the client ip, offload SSL and redirect in plain HTTP into the internal lan to the VM with iredmail.
I need custom config for the filter in order to grab the right ip.
Here the log entry for roundcube into /var/log/maillog:
Oct 26 10:02:13 mail roundcube: <rf4cvlc1> Failed login for userjohntrytohack from 10.1.0.2 (X-Forwarded-For: 81.47.153.97) in session rf4cvlc1avloqnqc (error: 0):
As you can see the username pop up: userjohntrytohack
the ip of firewall 10.1.0.2 then the real client ip is 81.47.153.97
immediatly after "Forwarded-For: "
So fail2ban see the firewall ip and try to ban it which is not correct and it's into ignoreip variable.
Here the /etc/fail2ban/filter.d/roundcube-auth.conf:
prefregex = ^\s*(\[\])?(%(__hostname)s\s*(?:roundcube(?:\[(\d*)\])?:)?\s*(<[\w]+>)? IMAP Error)?: <F-CONTENT>.+</F-CONTENT>$
failregex = ^(?:FAILED login|Login failed) for <F-USER>.*</F-USER> from <HOST>(?:(?:\([^\)]*\))?\. (?:(?! from ).)*(?: user=(?P=u>
^(?:<[\w]+> )?Failed login for <F-USER>.*</F-USER> from <HOST> in session \w+( \(error: \d\))?$
I need an expert help me to edit thiese 2 values prefregx and failregex in order to grab the real ip after the string "Forwarded-For: "
many thanks for your help.
----
Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.