Closed johnassel closed 7 years ago
First you should check the filter will match at all the failures that are logged.
Use fail2ban-regex
to check it, see 2 examples:
fail2ban-regex '... direct log line with failure ...' /etc/fail2ban/filter.d/postfix-sasl.conf
fail2ban-regex /path/to/txt-log-file-or-journald-client-output /etc/fail2ban/filter.d/postfix-sasl.conf
So, check whether the failregex
of postfix-sasl filter is still good (nothing was changed in log format).
Secondly, if you have a parallel operating with any text logging (for example with rsyslog), you can change backend
to polling
(or gamin
or pyinotify
if these are supported) to check the failures will be recognized within a text log files.
If yes, something would be wrong with backend systemd
.
Additionaly, we need some debug info or errors logged from fail2ban.log. Set your loglevel to DEBUG, restart f2b and try it again (caution - it will log very much).
And please provide always more info: general system / fail2ban version, any errors in fail2ban.log, etc. BTW. Here are recommended steps to troubleshoot problems
After experimenting I found a solution: It seemed as if fail2ban didn't use systemd to look for the postfix log at this point. The log showed entries like 2015-06-22 11:52:51,211 fail2ban.jail [21952]: INFO Jail 'postfix-sasl' uses pyinotify 2015-06-22 11:52:51,249 fail2ban.server [21952]: INFO Jail postfix-sasl is not a JournalFilter instance After forcing journald with "backend = systemd" in jail.conf in the postfix-sasl jail it worked. Strange enough the other postfix jails are working without that statement and "backend = systemd" as default had been ignored. Still not sure why he is doing this.
After forcing journald with "backend = systemd" in jail.conf in the postfix-sasl jail
Directly change of jail.conf
is not so good (have to merge all the time by update to new version). All the local changes should be made in jail.local
instead.
and "backend = systemd" as default had been ignored. Still not sure why he is doing this.
Can you provide your f2b-version?
And possible an output of fail2ban-client -vvd > output.txt
if you change your default in jail.local to systemd again, and in jail postfix-sasl back (or comment it temporary with #)...
Yes, I've put all my local changes to a .local file. Fail2Ban is v0.9.2 on Fedora 22.
fail2ban-cliend --vvd gives me:
['set', 'syslogsocket', 'auto']
['set', 'logtarget', '/var/log/fail2ban.log']
['set', 'loglevel', 'INFO']
['set', 'dbpurgeage', 86400]
['set', 'dbfile', '/var/lib/fail2ban/fail2ban.sqlite3']
['add', 'apache-auth', 'auto']
['set', 'apache-auth', 'usedns', 'warn']
['set', 'apache-auth', 'addlogpath', '/var/log/httpd/error_log', 'head']
['set', 'apache-auth', 'addlogpath', '/var/log/httpd/ssl_errorlog', 'head']
['set', 'apache-auth', 'maxretry', 5]
['set', 'apache-auth', 'addignoreip', '127.0.0.1/8']
['set', 'apache-auth', 'logencoding', 'auto']
['set', 'apache-auth', 'bantime', 600]
['set', 'apache-auth', 'ignorecommand', '']
['set', 'apache-auth', 'findtime', 600]
['set', 'apache-auth', 'addfailregex', '^[] [(:?error|\S+:\S+)]( [pid \d+(:\S+ \d+)?])? [client .*?' in realm
.+' (not found|denied by provider): \S._?' but expected
.+'(, referer: \S+)?\s*$"]
['set', 'apache-auth', 'addfailregex', "^\[\] \[(:?error|\S+:\S+)\]( \[pid \d+(:\S+ \d+)?\])? \[client ._?' received: \S_(, referer: \S+)?\s_$"] ['set', 'apache-auth', 'addfailregex', "^\[\] \[(:?error|\S+:\S+)\]( \[pid \d+(:\S+ \d+)?\])? \[client <HOST>(:\d{1,5})?\] (AH01793: )?invalid qop
.?' received: \S(, referer: \S+)?\s$"]
['set', 'apache-auth', 'addfailregex', '^[] [(:?error|\S+:\S+)]( [pid \d+(:\S+ \d+)?])? [client HTTP_._?'(, referer: \S+)?\s_$"] ['set', 'apache-shellshock', 'addaction', 'iptables-multiport'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'actionban', 'iptables -I f2b-<name> 1 -s <ip> -j <blocktype>'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'actionstop', 'iptables -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>\niptables -F f2b-<name>\niptables -X f2b-<name>'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'actionstart', 'iptables -N f2b-<name>\niptables -A f2b-<name> -j RETURN\niptables -I <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'actionunban', 'iptables -D f2b-<name> -s <ip> -j <blocktype>'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'actioncheck', "iptables -n -L <chain> | grep -q 'f2b-<name>[ \t]'"] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'protocol', 'tcp'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'name', 'apache-shellshock'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'chain', 'INPUT'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'known/**name**', 'Init'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'known/protocol', 'tcp'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'known/port', 'ssh'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'known/chain', 'INPUT'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'known/name', 'default'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'known/blocktype', 'REJECT --reject-with icmp-port-unreachable'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'blocktype', 'REJECT --reject-with icmp-port-unreachable'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'port', 'http,https'] ['set', 'apache-shellshock', 'action', 'iptables-multiport', 'bantime', '600'] ['add', 'dovecot', 'systemd'] ['set', 'dovecot', 'usedns', 'warn'] ['set', 'dovecot', 'maxretry', 5] ['set', 'dovecot', 'addignoreip', '127.0.0.1/8'] ['set', 'dovecot', 'logencoding', 'auto'] ['set', 'dovecot', 'bantime', 600] ['set', 'dovecot', 'ignorecommand', ''] ['set', 'dovecot', 'findtime', 600] ['set', 'dovecot', 'addfailregex', '^\s_(<[^.]+\.[^.]+>)?\s_(?:\S+ )?(?:kernel: \[ *\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?(auth|dovecot(-auth)?|auth-worker)(?:\(\S+\))?[\]\)]?:?|[\[\(]?(auth|dovecot(-auth)?|auth-worker)(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)?\s(?:\[ID \d+ \S+\])?\s_(pam_unix(\(dovecot:auth\))?:)?\s+authentication failure; logname=\S\* uid=\S\* euid=\S\* tty=dovecot ruser=\S\* rhost=<HOST>(\s+user=\S_)?\s_$'] ['set', 'dovecot', 'addfailregex', '^\s_(<[^.]+\.[^.]+>)?\s_(?:\S+ )?(?:kernel: \[ _\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?(auth|dovecot(-auth)?|auth-worker)(?:\(\S+\))?[\]\)]?:?|[\[\(]?(auth|dovecot(-auth)?|auth-worker)(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)?\s(?:\[ID \d+ \S+\])?\s_(pop3|imap)-login: (Info: )?(Aborted login|Disconnected)(: Inactivity)? \(((auth failed, \d+ attempts)( in \d+ secs)?|tried to use (disabled|disallowed) \S+ auth)\):( user=<\S_>,)?( method=\S+,)? rip=<HOST>(, lip=(\d{1,3}\.){3}\d{1,3})?(, TLS( handshaking(: SSL_accept\(\) failed: error:[\dA-F]+:SSL routines:[TLS\d]+_GET_CLIENT_HELLO:unknown protocol)?)?(: Disconnected)?)?(, session=<\S+>)?\s_$'] ['set', 'dovecot', 'addfailregex', '^\s_(<[^.]+\.[^.]+>)?\s_(?:\S+ )?(?:kernel: \[ _\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?(auth|dovecot(-auth)?|auth-worker)(?:\(\S+\))?[\]\)]?:?|[\[\(]?(auth|dovecot(-auth)?|auth-worker)(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)?\s(?:\[ID \d+ \S+\])?\s_(Info|dovecot: auth\(default\)|auth-worker\(\d+\)): pam\(\S+,<HOST>\): pam_authenticate\(\) failed: (User not known to the underlying authentication module: \d+ Time\(s\)|Authentication failure \(password mismatch\?\))\s_$'] ['set', 'dovecot', 'addfailregex', '^\s_(<[^.]+\.[^.]+>)?\s_(?:\S+ )?(?:kernel: \[ *\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?(auth|dovecot(-auth)?|auth-worker)(?:\(\S+\))?[\]\)]?:?|[\[\(]?(auth|dovecot(-auth)?|auth-worker)(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)?\s(?:\[ID \d+ \S+\])?\s_auth-worker\(\d+\): pam\(\S+,<HOST>\): unknown user\s_$'] ['set', 'dovecot', 'addjournalmatch', '_SYSTEMD_UNIT=dovecot.service'] ['set', 'dovecot', 'addaction', 'iptables-multiport'] ['set', 'dovecot', 'action', 'iptables-multiport', 'actionban', 'iptables -I f2b-<name> 1 -s <ip> -j <blocktype>'] ['set', 'dovecot', 'action', 'iptables-multiport', 'actionstop', 'iptables -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>\niptables -F f2b-<name>\niptables -X f2b-<name>'] ['set', 'dovecot', 'action', 'iptables-multiport', 'actionstart', 'iptables -N f2b-<name>\niptables -A f2b-<name> -j RETURN\niptables -I <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>'] ['set', 'dovecot', 'action', 'iptables-multiport', 'actionunban', 'iptables -D f2b-<name> -s <ip> -j <blocktype>'] ['set', 'dovecot', 'action', 'iptables-multiport', 'actioncheck', "iptables -n -L <chain> | grep -q 'f2b-<name>[ \t]'"] ['set', 'dovecot', 'action', 'iptables-multiport', 'protocol', 'tcp'] ['set', 'dovecot', 'action', 'iptables-multiport', 'name', 'dovecot'] ['set', 'dovecot', 'action', 'iptables-multiport', 'chain', 'INPUT'] ['set', 'dovecot', 'action', 'iptables-multiport', 'known/**name**', 'Init'] ['set', 'dovecot', 'action', 'iptables-multiport', 'known/protocol', 'tcp'] ['set', 'dovecot', 'action', 'iptables-multiport', 'known/port', 'ssh'] ['set', 'dovecot', 'action', 'iptables-multiport', 'known/chain', 'INPUT'] ['set', 'dovecot', 'action', 'iptables-multiport', 'known/name', 'default'] ['set', 'dovecot', 'action', 'iptables-multiport', 'known/blocktype', 'REJECT --reject-with icmp-port-unreachable'] ['set', 'dovecot', 'action', 'iptables-multiport', 'blocktype', 'REJECT --reject-with icmp-port-unreachable'] ['set', 'dovecot', 'action', 'iptables-multiport', 'port', 'pop3,pop3s,imap,imaps,submission,465,sieve'] ['set', 'dovecot', 'action', 'iptables-multiport', 'bantime', '600'] ['add', 'postfix-sasl', 'systemd'] ['set', 'postfix-sasl', 'usedns', 'warn'] ['set', 'postfix-sasl', 'maxretry', 1] ['set', 'postfix-sasl', 'addignoreip', '127.0.0.1/8'] ['set', 'postfix-sasl', 'logencoding', 'auto'] ['set', 'postfix-sasl', 'bantime', 604800] ['set', 'postfix-sasl', 'ignorecommand', ''] ['set', 'postfix-sasl', 'findtime', 604800] ['set', 'postfix-sasl', 'addignoreregex', 'authentication failed: Connection lost to authentication server$'] ['set', 'postfix-sasl', 'addfailregex', '^\s*(<[^.]+\.[^.]+>)?\s_(?:\S+ )?(?:kernel: \[ _\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?postfix/(submission/)?smtp(d|s)(?:\(\S+\))?[\]\)]?:?|[\[\(]?postfix/(submission/)?smtp(d|s)(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)?\s(?:\[ID \d+ \S+\])?\s_warning: [-._\w]+\[<HOST>\]: SASL ((?i)LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/:]_={0,2})?\s_$'] ['set', 'postfix-sasl', 'addfailregex', '(?i): warning: [-._\w]+\[<HOST>\]: SASL PLAIN authentication failed:'] ['set', 'postfix-sasl', 'addjournalmatch', '_SYSTEMD_UNIT=postfix.service'] ['set', 'postfix-sasl', 'addaction', 'iptables-multiport'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'actionban', 'iptables -I f2b-<name> 1 -s <ip> -j <blocktype>'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'actionstop', 'iptables -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>\niptables -F f2b-<name>\niptables -X f2b-<name>'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'actionstart', 'iptables -N f2b-<name>\niptables -A f2b-<name> -j RETURN\niptables -I <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'actionunban', 'iptables -D f2b-<name> -s <ip> -j <blocktype>'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'actioncheck', "iptables -n -L <chain> | grep -q 'f2b-<name>[ \t]'"] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'protocol', 'tcp'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'name', 'postfix-sasl'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'chain', 'INPUT'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'known/**name**', 'Init'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'known/protocol', 'tcp'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'known/port', 'ssh'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'known/chain', 'INPUT'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'known/name', 'default'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'known/blocktype', 'REJECT --reject-with icmp-port-unreachable'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'blocktype', 'REJECT --reject-with icmp-port-unreachable'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'port', 'smtp,465,submission,imap3,imaps,pop3,pop3s'] ['set', 'postfix-sasl', 'action', 'iptables-multiport', 'bantime', '604800'] ['set', 'postfix-sasl', 'addaction', 'sendmail-whois'] ['set', 'postfix-sasl', 'action', 'sendmail-whois', 'actionban', 'printf %b "Subject: [Fail2Ban] <name>: banned <ip> from
uname -n\nDate:
LC_TIME=C date +"%a, %d %h %Y %T %z"\nFrom: <sendername> <<sender>>\nTo: <dest>\n\nHi,\n\nThe IP <ip> has just been banned by Fail2Ban after\n<failures> attempts against <name>.\n\n\nHere is more information about <ip>:\n\n
/usr/bin/whois \n\nRegards,\n\nFail2Ban" | /usr/sbin/sendmail -f <sender> <dest>'] ['set', 'postfix-sasl', 'action', 'sendmail-whois', 'actionstop', 'printf %b "Subject: [Fail2Ban] <name>: stopped on
uname -n\nDate:
LC_TIME=C date +"%a, %d %h %Y %T %z"\nFrom: <sendername> <<sender>>\nTo: <dest>\n\nHi,\n\nThe jail <name> has been stopped.\n\nRegards,\n\nFail2Ban" | /usr/sbin/sendmail -f <sender> <dest>'] ['set', 'postfix-sasl', 'action', 'sendmail-whois', 'actionstart', 'printf %b "Subject: [Fail2Ban] <name>: started on
uname -n\nDate:
LCTIME=C date +"%a, %d %h %Y %T %z"`\nFrom: uname -n
\nDate: LC_TIME=C date +"%a, %d %h %Y %T %z"
\nFrom: /usr/bin/whois <ip> || echo missing whois program
\n\nRegards,\n\nFail2Ban" | /usr/sbin/sendmail -f uname -n
\nDate: LC_TIME=C date +"%a, %d %h %Y %T %z"
\nFrom: uname -n
\nDate: LC_TIME=C date +"%a, %d %h %Y %T %z"
\nFrom:
Normally fail2ban should block entries about failed logins by postfix like: warning: $host[$ip]: SASL PLAIN authentication failed:
"fail2ban-regex systemd-journal /etc/fail2ban/filter.d/postfix-sasl.conf" finds the specified lines so the filter is working. When fail2ban is starting and loading the jail but it doesn't react on failed logins. Not sure if it is because postfix is logging to journald - other postfix filters work without problems. I tried changing "backend = auto" to "backend = systemd" but that didn't work.
jail.conf: [postfix-sasl] enabled = true port = smtp,465,submission,imap3,imaps,pop3,pop3s filter = postfix-sasl findtime = 6000 bantime = 604800 maxretry = 1
postfix-sasl.conf: [INCLUDES] before = common.conf
[Definition] _daemon = postfix/(submission/)?smtp(d|s) failregex = ^%(__prefixline)swarning: [-.\w]+[]: SASL ((?i)LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/:]={0,2})?\s$
(?i): warning: [-._\w]+[]: SASL PLAIN authentication failed:
ignoreregex = authentication failed: Connection lost to authentication server$
[Init] journalmatch = _SYSTEMD_UNIT=postfix.service
fail2ban-client status postfix-sasl gives me: Status for the jail: postfix-sasl |- Filter | |- Currently failed: 0 | |- Total failed: 0 |
- File list:
- Actions |- Currently banned: 0 |- Total banned: 0 `- Banned IP list:Anyone has a clue on whats going wrong here?