Bug 1059498 - fail2ban misses a bunch of ssh attack vectors and does not ban failed attempts
Summary: fail2ban misses a bunch of ssh attack vectors and does not ban failed attempts
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: fail2ban
Version: 20
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: Orion Poplawski
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-01-30 00:38 UTC by Derek Atkins
Modified: 2015-06-30 00:52 UTC (History)
5 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2015-06-30 00:52:46 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
/var/log/secure of log failures that were not banned (36.15 KB, text/plain)
2014-01-30 00:38 UTC, Derek Atkins
no flags Details

Description Derek Atkins 2014-01-30 00:38:51 UTC
Created attachment 857314 [details]
/var/log/secure of log failures that were not banned

Description of problem:

I had a string of ssh "attacks" which, IMHO, should've been banned by fail2ban, but apparently there needs to be some additional failregex work in ssh.conf because this wasn't stopped.

Version-Release number of selected component (if applicable):

fail2ban-0.9-0.3.git1f1a561.fc20.noarch


How reproducible:

It's hard to say.  I don't know which ssh script is testing me.  However a bunch of failed attempts to login as root SHOULD have tickled fail2ban!

Steps to Reproduce:
1. run fail2ban
2. wait for an ssh attack
3. see that fail2ban doesn't actually stop it

Actual results:

nothing.  I got a bunch of log messages like:

Jan 29 17:57:51 mail2 sshd[2204]: Failed password for root from 61.160.194.121 port 1647 ssh2

But nothing was banned:

$ fail2ban-client status sshd
Status for the jail: sshd
|- filter
|  |- File list:	/var/log/secure 
|  |- Currently failed:	0
|  `- Total failed:	0
`- action
   |- Currently banned:	0
   |  `- IP list:	
   `- Total banned:	0
$ grep 61.160.194.121 /var/log/messages
$ 

Expected results:

fail2ban should actually ban on failures (and ban on the FIRST failure, if that's the desire).

Additional info:

See the attached "login failures" log, from /var/log/secure, showing all the login failures that fail2ban didn't catch.  It LOOKS like this regex should catch it:

            ^%(__prefix_line)sFailed \S+ for .* from <HOST>(?: port \d*)?(?: ssh\d*)?\s*$

but it didn't.

Comment 1 Orion Poplawski 2014-01-30 19:13:12 UTC
The regex seems to work for me:

# fail2ban-regex /data/sw/tmp/login-failures.txt /etc/fail2ban/filter.d/sshd.conf

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

Use   failregex file : /etc/fail2ban/filter.d/sshd.conf
Use         maxlines : 10
Use         log file : /data/sw/tmp/login-failures.txt
Use         encoding : UTF-8


Results
=======

Failregex: 131 total
|-  #) [# of hits] regular expression
|   3) [131] ^\s*(<[^.]+\.[^.]+>)?\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:?)?\s(?:\[ID \d+ \S+\])?\s*Failed \S+ for .* from <HOST>(?: port \d*)?(?: ssh\d*)?\s*$


What backend are you using?  Perhaps try running with debugging log level for a bit?

Comment 2 Derek Atkins 2014-01-30 19:33:37 UTC
I'm using the firewallcmd-ipset banaction.

I had more failures this morning, but then I restarted fail2ban manually and it started working.  That doesn't make any sense to me (and does not instill confidence that a freshly-rebooted system isn't properly monitoring).

Comment 3 Orion Poplawski 2014-01-30 19:37:18 UTC
Yeah, that's why I asked what your "backend" (not action) setting is (auto, pyinotify, etc..).

My guess at the moment is that it stops monitoring after the logs are rotated each week.

Comment 4 Derek Atkins 2014-01-30 19:39:29 UTC
Oops, sorry, misread (or misunderstood) what you were asking.

I don't think I changed the default.  Looks like it is set to auto in jail.conf

Comment 5 Orion Poplawski 2014-11-03 03:24:11 UTC
Is this still a problem?

Comment 6 Rok Papez 2015-01-19 10:08:39 UTC
Had the same problem; fail2ban didn't monitor log file. Had backend = auto in jail.conf. After installing gamin, setting backend=gamin and reloading the service it started working.

Working config:

# cat /etc/fail2ban/jail.local
[DEFAULT]
bantime = 3600
ignoreip = <deleted>
destemail = <deleted>
sender = <deleted>
banaction = iptables-multiport
backend = gamin

[sshd]
enabled = true
logpath = /var/log/secure

Comment 7 Fedora End Of Life 2015-05-29 10:44:27 UTC
This message is a reminder that Fedora 20 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 20. 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 '20'.

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 20 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 8 Fedora End Of Life 2015-06-30 00:52:46 UTC
Fedora 20 changed to end-of-life (EOL) status on 2015-06-23. Fedora 20 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


Note You need to log in before you can comment on or make changes to this bug.