2013-10-30 13:02:59 +00:00
# Fail2Ban filter for openssh
2006-07-17 19:26:14 +00:00
#
2014-02-02 04:16:40 +00:00
# If you want to protect OpenSSH from being bruteforced by password
# authentication then get public key authentication working before disabling
2014-02-13 05:20:36 +00:00
# PasswordAuthentication in sshd_config.
#
#
# "Connection from <HOST> port \d+" requires LogLevel VERBOSE in sshd_config
#
2006-07-17 19:26:14 +00:00
2007-09-12 21:38:51 +00:00
[INCLUDES]
# Read common prefixes. If any customizations available -- read them from
# common.local
2008-03-04 00:17:56 +00:00
before = common.conf
2007-09-12 21:38:51 +00:00
2016-11-11 12:23:20 +00:00
[DEFAULT]
2006-06-26 20:05:00 +00:00
2007-09-12 21:38:51 +00:00
_daemon = sshd
2015-10-05 19:18:16 +00:00
# optional prefix (logged from several ssh versions) like "error: ", "error: PAM: " or "fatal: "
__pref = (?:(?:error|fatal): (?:PAM: )?)?
# optional suffix (logged from several ssh versions) like " [preauth]"
2018-03-19 16:28:24 +00:00
#__suff = (?: port \d+)?(?: \[preauth\])?\s*
__suff = (?: (?:port \d+|on \S+|\[preauth\])){0,3}\s*
__on_port_opt = (?: (?:port \d+|on \S+)){0,2}
2015-10-05 19:18:16 +00:00
2017-11-23 21:21:42 +00:00
# for all possible (also future) forms of "no matching (cipher|mac|MAC|compression method|key exchange method|host key type) found",
# see ssherr.c for all possible SSH_ERR_..._ALG_MATCH errors.
__alg_match = (?:(?:\w+ (?!found\b)){0,2}\w+)
2018-03-20 12:09:05 +00:00
# PAM authentication mechanism, can be overridden, e. g. `filter = sshd[__pam_auth='pam_ldap']`:
__pam_auth = pam_[a-z]+
2017-03-10 21:08:03 +00:00
[Definition]
2015-10-05 19:18:16 +00:00
2017-03-10 21:08:03 +00:00
prefregex = ^<F-MLFID>%(__prefix_line)s</F-MLFID>%(__pref)s<F-CONTENT>.+</F-CONTENT>$
2016-11-11 12:23:20 +00:00
2018-03-19 16:28:24 +00:00
cmnfailre = ^[aA]uthentication (?:failure|error|failed) for <F-USER>.*</F-USER> from <HOST>( via \S+)?%(__suff)s$
^User not known to the underlying authentication module for <F-USER>.*</F-USER> from <HOST>%(__suff)s$
2018-03-20 08:09:42 +00:00
^Failed publickey for invalid user <F-USER>(?P<cond_user>\S+)|(?:(?! from ).)*?</F-USER> from <HOST>%(__on_port_opt)s(?: ssh\d*)?(?(cond_user): |(?:(?:(?! from ).)*)$)
2018-01-10 18:07:20 +00:00
^Failed \b(?!publickey)\S+ for (?P<cond_inv>invalid user )?<F-USER>(?P<cond_user>\S+)|(?(cond_inv)(?:(?! from ).)*?|[^:]+)</F-USER> from <HOST>%(__on_port_opt)s(?: ssh\d*)?(?(cond_user): |(?:(?:(?! from ).)*)$)
2018-03-20 17:47:42 +00:00
^<F-USER>ROOT</F-USER> LOGIN REFUSED FROM <HOST>
2018-03-19 16:28:24 +00:00
^[iI](?:llegal|nvalid) user <F-USER>.*?</F-USER> from <HOST>%(__suff)s$
^User <F-USER>.+</F-USER> from <HOST> not allowed because not listed in AllowUsers%(__suff)s$
^User <F-USER>.+</F-USER> from <HOST> not allowed because listed in DenyUsers%(__suff)s$
^User <F-USER>.+</F-USER> from <HOST> not allowed because not in any group%(__suff)s$
^refused connect from \S+ \(<HOST>\)
2017-03-20 23:15:57 +00:00
^Received <F-MLFFORGET>disconnect</F-MLFFORGET> from <HOST>%(__on_port_opt)s:\s*3: .*: Auth fail%(__suff)s$
2018-03-19 16:28:24 +00:00
^User <F-USER>.+</F-USER> from <HOST> not allowed because a group is listed in DenyGroups%(__suff)s$
^User <F-USER>.+</F-USER> from <HOST> not allowed because none of user's groups are listed in AllowGroups%(__suff)s$
2018-03-20 12:09:05 +00:00
^<F-NOFAIL>%(__pam_auth)s\(sshd:auth\):\s+authentication failure;</F-NOFAIL>(?:\s+(?:(?:logname|e?uid|tty)=\S*)){0,4}\s+ruser=<F-ALT_USER>\S*</F-ALT_USER>\s+rhost=<HOST>(?:\s+user=<F-USER>\S*</F-USER>)?%(__suff)s$
2017-03-15 17:00:53 +00:00
^(error: )?maximum authentication attempts exceeded for <F-USER>.*</F-USER> from <HOST>%(__on_port_opt)s(?: ssh\d*)?%(__suff)s$
2017-03-10 21:08:03 +00:00
^User <F-USER>.+</F-USER> not allowed because account is locked%(__suff)s
2018-03-20 17:47:42 +00:00
^<F-MLFFORGET>Disconnecting</F-MLFFORGET>: Too many authentication failures(?: for <F-USER>.+?</F-USER>)?%(__suff)s$
2018-03-02 18:24:47 +00:00
^<F-NOFAIL>Received <F-MLFFORGET>disconnect</F-MLFFORGET></F-NOFAIL> from <HOST>%(__on_port_opt)s:\s*11:
2018-03-20 17:47:42 +00:00
^<F-NOFAIL>Connection <F-MLFFORGET>closed</F-MLFFORGET></F-NOFAIL> by <HOST>
2018-03-20 12:09:05 +00:00
^<F-MLFFORGET><F-NOFAIL>Accepted \w+</F-NOFAIL></F-MLFFORGET> for <F-USER>\S+</F-USER> from <HOST>(?:\s|$)
2017-03-10 21:08:03 +00:00
mdre-normal =
2018-03-19 16:28:24 +00:00
mdre-ddos = ^Did not receive identification string from <HOST>
^Connection <F-MLFFORGET>reset</F-MLFFORGET> by <HOST>
2017-03-10 21:08:03 +00:00
^<F-NOFAIL>SSH: Server;Ltype:</F-NOFAIL> (?:Authname|Version|Kex);Remote: <HOST>-\d+;[A-Z]\w+:
2018-03-19 16:28:24 +00:00
^Read from socket failed: Connection <F-MLFFORGET>reset</F-MLFFORGET> by peer
2017-03-10 21:08:03 +00:00
2018-03-19 16:28:24 +00:00
mdre-extra = ^Received <F-MLFFORGET>disconnect</F-MLFFORGET> from <HOST>%(__on_port_opt)s:\s*14: No supported authentication methods available
2017-11-23 21:21:42 +00:00
^Unable to negotiate with <HOST>%(__on_port_opt)s: no matching <__alg_match> found.
2018-03-19 16:28:24 +00:00
^Unable to negotiate a <__alg_match>
2017-11-23 21:21:42 +00:00
^no matching <__alg_match> found:
2017-03-10 21:08:03 +00:00
mdre-aggressive = %(mdre-ddos)s
%(mdre-extra)s
cfooterre = ^<F-NOFAIL>Connection from</F-NOFAIL> <HOST>
failregex = %(cmnfailre)s
<mdre-<mode>>
%(cfooterre)s
# Parameter "mode": normal (default), ddos, extra or aggressive (combines all)
# Usage example (for jail.local):
# [sshd]
# mode = extra
# # or another jail (rewrite filter parameters of jail):
# [sshd-aggressive]
# filter = sshd[mode=aggressive]
#
mode = normal
2016-11-11 12:23:20 +00:00
2017-03-10 21:08:03 +00:00
#filter = sshd[mode=aggressive]
2006-06-26 20:05:00 +00:00
2006-11-15 18:44:28 +00:00
ignoreregex =
2013-05-27 21:06:49 +00:00
2017-02-22 17:39:44 +00:00
maxlines = 1
2013-06-29 12:00:40 +00:00
2013-05-09 23:15:07 +00:00
journalmatch = _SYSTEMD_UNIT=sshd.service + _COMM=sshd
2013-11-02 04:59:05 +00:00
2016-10-05 17:34:21 +00:00
datepattern = {^LN-BEG}
2013-11-08 22:34:31 +00:00
# DEV Notes:
#
# "Failed \S+ for .*? from <HOST>..." failregex uses non-greedy catch-all because
# it is coming before use of <HOST> which is not hard-anchored at the end as well,
# and later catch-all's could contain user-provided input, which need to be greedily
# matched away first.
#
2017-03-10 21:08:03 +00:00
# Author: Cyril Jaquier, Yaroslav Halchenko, Petr Voralek, Daniel Black and Sergey Brester aka sebres
# Rewritten using prefregex (and introduced "mode" parameter) by Serg G. Brester.