Bug 1329919

Summary: sendmail-auth.conf filter never matchs on failregex condition
Product: [Fedora] Fedora Reporter: dan
Component: fail2banAssignee: Orion Poplawski <orion>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 25CC: athmanem, axel.thimm, dan, jonathan.underwood, orion, vonsch
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: fail2ban-0.9.6-2.fc25 fail2ban-0.9.6-2.fc24 fail2ban-0.9.6-2.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-01-14 01:27:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description dan 2016-04-24 23:45:47 UTC
Description of problem:

A number of SMTP auth attacks were noticed in my journal but fail2ban is not triggering the specified action.  _daemon does not include a match for "sendmail" and the failregex seems to not match on the journal entries.

jail.local contents:

[DEFAULT]
banTime = 86400
findtime = 14400
maxRetry = 3
ignoreip = 127.0.0.0/8 192.168.0.0/24
banaction = firewallcmd-ipset
action = %(action_mwl)s
sender = fail2ban
destemail = dan

[sshd]
enabled = true

[sendmail]
enabled  = true
filter   = sendmail-auth

Some sample journal entries:

Jan 12 06:03:04 ears.private sendmail[26592]: u0CB32qX026592: [203.92.90.154]: possible SMTP attack: command=AUTH, count=5
Jan 12 06:03:04 ears.private sendmail[26593]: u0CB32f9026593: [203.92.90.154]: possible SMTP attack: command=AUTH, count=5
Jan 12 06:03:04 ears.private sendmail[26594]: u0CB32pQ026594: [203.92.90.154]: possible SMTP attack: command=AUTH, count=5
Jan 12 06:03:04 ears.private sendmail[26596]: u0CB321R026596: [203.92.90.154]: possible SMTP attack: command=AUTH, count=5
Jan 12 06:03:04 ears.private sendmail[26595]: u0CB32IA026595: [203.92.90.154]: possible SMTP attack: command=AUTH, count=5
Jan 21 07:06:57 ears.private sendmail[16035]: u0LC6tox016035: [179.43.141.238]: possible SMTP attack: command=AUTH, count=5
Jan 21 07:06:57 ears.private sendmail[16037]: u0LC6tah016037: [179.43.141.238]: possible SMTP attack: command=AUTH, count=5
Jan 21 07:06:57 ears.private sendmail[16036]: u0LC6t4s016036: [179.43.141.238]: possible SMTP attack: command=AUTH, count=5
Jan 21 07:06:57 ears.private sendmail[16039]: u0LC6tl1016039: [179.43.141.238]: possible SMTP attack: command=AUTH, count=5
Jan 21 07:06:57 ears.private sendmail[16038]: u0LC6tbp016038: [179.43.141.238]: possible SMTP attack: command=AUTH, count=5

Comment 1 dan 2016-04-25 18:49:21 UTC
Results of fail2ban-regex check:

fail2ban-regex "systemd-journal" -m _SYSTEMD_UNIT=sendmail.service /etc/fail2ban/filter.d/sendmail-auth.conf

Running tests
=============

Use   failregex filter file : sendmail-auth, basedir: /etc/fail2ban
Use    journal match : _SYSTEMD_UNIT=sendmail.service


Results
=======

Failregex: 298 total
|-  #) [# of hits] regular expression
|   1) [298] ^\s*(<[^.]+\.[^.]+>)?\s*(?:\S+ )?(?:kernel: \[ *\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?(?:sm-(mta|acceptingconnections)|sendmail)(?:\(\S+\))?[\]\)]?:?|[\[\(]?(?:sm-(mta|acceptingconnections)|sendmail)(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)?\s(?:\[ID \d+ \S+\])?\s*\w{14}: (\S+ )?\[<HOST>\]( \(may be forged\))?: possible SMTP attack: command=AUTH, count=\d+$
`-

Ignoreregex: 0 total

Lines: 232074 lines, 0 ignored, 298 matched, 231776 missed [processed in 33.38 sec]
Missed line(s): too many to print.  Use --print-all-missed to print all 231776 lines

Comment 2 dan 2016-04-25 18:56:29 UTC
Update: works fine when logpath = /var/log/maillog.

Fails to properly start when logpath is removed to go against journal:

Apr 25 14:54:42 ears.private systemd[1]: Starting Fail2Ban Service...
-- Subject: Unit fail2ban.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit fail2ban.service has begun starting up.
Apr 25 14:54:42 ears.private fail2ban-client[12630]: ERROR  Failed during configuration: Bad value substitution:
Apr 25 14:54:42 ears.private fail2ban-client[12630]: section: [sendmail]
Apr 25 14:54:42 ears.private fail2ban-client[12630]: option : action
Apr 25 14:54:42 ears.private fail2ban-client[12630]: key    : logpath
Apr 25 14:54:42 ears.private fail2ban-client[12630]: rawval : , chain="%(chain)s"]
Apr 25 14:54:42 ears.private systemd[1]: fail2ban.service: Control process exited, code=exited status=255
Apr 25 14:54:42 ears.private systemd[1]: Failed to start Fail2Ban Service.
-- Subject: Unit fail2ban.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit fail2ban.service has failed.
--
-- The result is failed.
Apr 25 14:54:42 ears.private systemd[1]: fail2ban.service: Unit entered failed state.
Apr 25 14:54:42 ears.private audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:in
Apr 25 14:54:42 ears.private systemd[1]: fail2ban.service: Failed with result 'exit-code'.
Apr 25 14:54:43 ears.private systemd[1]: fail2ban.service: Service hold-off time over, scheduling restart.
Apr 25 14:54:43 ears.private systemd[1]: fail2ban.service: Start request repeated too quickly.
Apr 25 14:54:43 ears.private audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:in
Apr 25 14:54:43 ears.private systemd[1]: Failed to start Fail2Ban Service.
-- Subject: Unit fail2ban.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit fail2ban.service has failed.
--
-- The result is failed.
Apr 25 14:54:43 ears.private audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:ini
Apr 25 14:54:43 ears.private systemd[1]: fail2ban.service: Unit entered failed state.

Comment 3 dan 2016-04-25 19:38:06 UTC
sendmail-auth.conf needed a journalmatch line.

However, to get around the failure to start, the jail.local section for [sendmail] needs the logpath variable to be present, even if it is null:

[DEFAULT]
banTime = 86400
findtime = 14400
maxRetry = 3
ignoreip = 127.0.0.0/8 192.168.0.0/24
banaction = firewallcmd-ipset
action = %(action_mwl)s
sender = fail2ban
destemail = dan

[sshd]
enabled = true

[sendmail]
enabled  = true
port = 25,465
filter = sendmail-auth
logpath =

Comment 4 Fedora Update System 2016-10-04 14:22:33 UTC
fail2ban-0.9.5-3.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-07310f15dc

Comment 5 dan 2016-10-20 12:21:23 UTC
I tested this and there is still an issue with the filter.

As distributed, sendmail-auth.conf contains:

 _daemon = (?:sm-(mta|acceptingconnections))

This does not provide a match against my journal.  Changing the line to read:

 _daemon = sendmail

provides numerous matches.

Here is a sample journal line:

Oct 18 22:14:39 zzzz.private sendmail[15989]: u9J2ER37015989: 108.61.191.82.vultr.com [108.61.191.82] (may be forged): possible SMTP attack: command=AUTH, count=7

As you can see, the distributed "_daemon =" line will never match.

Comment 6 Fedora End Of Life 2016-11-25 07:27:44 UTC
This message is a reminder that Fedora 23 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 23. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '23'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 23 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 7 dan 2016-11-25 17:48:09 UTC
Also applies to FC24, bumping version.

Comment 8 Orion Poplawski 2016-12-02 21:42:40 UTC
Filed upstream

Comment 9 dan 2017-01-07 00:57:48 UTC
Bug verified in FC25, bumping version.

Comment 10 Fedora Update System 2017-01-07 03:03:25 UTC
fail2ban-0.9.6-1.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-33e3a599fa

Comment 11 Fedora Update System 2017-01-07 03:03:35 UTC
fail2ban-0.9.6-1.el7 has been submitted as an update to Fedora EPEL 7. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2017-57b616d0bb

Comment 12 Fedora Update System 2017-01-07 03:03:40 UTC
fail2ban-0.9.6-1.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2017-4cccf70ef9

Comment 13 Fedora Update System 2017-01-08 00:47:19 UTC
fail2ban-0.9.6-1.el7 has been pushed to the Fedora EPEL 7 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2017-57b616d0bb

Comment 14 Fedora Update System 2017-01-08 01:19:41 UTC
fail2ban-0.9.6-1.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-4cccf70ef9

Comment 15 Fedora Update System 2017-01-08 02:21:55 UTC
fail2ban-0.9.6-1.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-33e3a599fa

Comment 16 Fedora Update System 2017-01-10 21:52:12 UTC
fail2ban-0.9.6-2.el7 has been submitted as an update to Fedora EPEL 7. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2017-fc9588cf24

Comment 17 Fedora Update System 2017-01-10 21:52:22 UTC
fail2ban-0.9.6-2.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-bb1e01ca29

Comment 18 Fedora Update System 2017-01-10 21:52:28 UTC
fail2ban-0.9.6-2.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2017-fc4bbe2631

Comment 19 Fedora Update System 2017-01-11 03:23:10 UTC
fail2ban-0.9.6-2.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-bb1e01ca29

Comment 20 Fedora Update System 2017-01-11 03:49:43 UTC
fail2ban-0.9.6-2.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-fc4bbe2631

Comment 21 Fedora Update System 2017-01-11 07:47:45 UTC
fail2ban-0.9.6-2.el7 has been pushed to the Fedora EPEL 7 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2017-fc9588cf24

Comment 22 dan 2017-01-14 01:27:42 UTC
This is now working under 0.9.6-2 and may be closed.

fail2ban-regex "systemd-journal" /etc/fail2ban/filter.d/sendmail-auth.conf

Running tests
=============

Use   failregex filter file : sendmail-auth, basedir: /etc/fail2ban
Use         systemd journal
Use         encoding : UTF-8
Use    journal match : _SYSTEMD_UNIT=sendmail.service


Results
=======

Failregex: 66 total
|-  #) [# of hits] regular expression
|   1) [66] ^(?:\[\])?\s*(?:<[^.]+\.[^.]+>\s+)?(?:\S+\s+)?(?:kernel: \[ *\d+\.\d+\]\s+)?(?:@vserver_\S+\s+)?(?:(?:(?:\[\d+\])?:\s+[\[\(]?(?:sendmail|sm-(?:mta|acceptingconnections))(?:\(\S+\))?[\]\)]?:?|[\[\(]?(?:sendmail|sm-(?:mta|acceptingconnections))(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)\s+)?(?:\[ID \d+ \S+\]\s+)?\w{14}: (\S+ )?\[<HOST>\]( \(may be forged\))?: possible SMTP attack: command=AUTH, count=\d+$
`-

Ignoreregex: 0 total

Lines: 273223 lines, 0 ignored, 66 matched, 273157 missed
[processed in 51.81 sec]

Comment 23 Fedora Update System 2017-01-19 05:54:33 UTC
fail2ban-0.9.6-2.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.

Comment 24 Fedora Update System 2017-01-25 00:20:37 UTC
fail2ban-0.9.6-2.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.

Comment 25 Fedora Update System 2017-02-15 00:19:49 UTC
fail2ban-0.9.6-2.el7 has been pushed to the Fedora EPEL 7 stable repository. If problems still persist, please make note of it in this bug report.