From 16f55d2d56f65e730c72f88aff32670ea01982bd Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 6 Jan 2014 23:30:13 -0500 Subject: [PATCH 01/13] DOC: pass through jail.conf.5 -- unification and some restructuring/shortening --- man/jail.conf.5 | 249 +++++++++++++++++++++++++----------------------- 1 file changed, 132 insertions(+), 117 deletions(-) diff --git a/man/jail.conf.5 b/man/jail.conf.5 index 4f1ae6b5..20408a4d 100644 --- a/man/jail.conf.5 +++ b/man/jail.conf.5 @@ -12,15 +12,25 @@ jail.conf \- configuration for the fail2ban server .I filter.d/*.conf filter.d/*.local .SH DESCRIPTION -Fail2ban has four configuration file types. Failban configuration files that contain global configuration items, Action configuration files are the commands for banning and unbanning of IP address, Filter configuration files tell fail2ban how to detect authentication failures, and Jail configuration files combine filters with actions into jails. +Fail2ban has four configuration file types: -.SH "CONFIGUATION FILES" +.TP +\fIfail2ban.conf\fR +Fail2Ban global configuration (such as logging) +.TP +\fIfilter.d/*.conf\fR +Filters specifying how to detect authentication failures +.TP +\fIaction.d/*.conf\fR +Actions defining the commands for banning and unbanning of IP address +.TP +\fIjail.conf\fR +Jails defining combinations of Filters with Actions. -There are *.conf files that are distributed by fail2ban and *.local file that contain user customizations. -It is recommended that *.conf files should remain unchanged. If needed, customizations should be provided in *.local files. -For instance, if you would like to customize the [ssh-iptables-ipset] jail, create a jail.local to extend jail.conf -(the configuration for the fail2ban server). The jail.local file will be the following if you only need to enable -it as follows: + +.SH "CONFIGUATION FILES FORMAT" + +\fI*.conf\fR files are distributed by Fail2Ban. It is recommended that *.conf files should remain unchanged to ease upgrades. If needed, customizations should be provided in \fI*.local\fR files. For example, if you would like to enable the [ssh-iptables-ipset] jail specified in jail.conf, create jail.local containing .TP \fIjail.local\fR @@ -29,132 +39,156 @@ it as follows: enabled = true .PP -Override only the settings you need to change and the rest of the configuration will come from the corresponding -*.conf file. +In .local files specify only the settings you would like to change and the rest of the configuration will then come from the corresponding .conf file which is parsed first. -\fIfilter.d/\fR and \fIaction.d/\fR -These directories contains \fI*.conf\fR and \fI*.local\fR files that contain filter and action configurations. -\fI.local\fR files are read first and only need to set the directives that are different from the \fI.conf\fR file. -Directives not overwritten are read from the \fI.conf\fR file. -.RS +.TP \fIjail.d/\fR and \fIfail2ban.d/\fR -.RS -In addition to .local, for any jail.conf or fail2ban.conf file there can be a corresponding -\fI.d/\fR directory to contain additional .conf files that will be read after the -appropriate .local file. Last parsed file will take precidence over -identical entries, parsed alphabetically, e.g. +In addition to .local, for jail.conf or fail2ban.conf file there can +be a corresponding \fI.d/\fR directory containining additional .conf +files. The order e.g. for \fIjail\fR configuration would be: + +.RS +jail.conf +.RE +.RS +jail.d/*.conf (in alphabetical order) +.RE +.RS +jail.local +.RE +.RS +jail.d/*.local (in alphabetical order). + +i.e. all .local files are parsed after .conf files in the original +configuration file and files under .d directory. Settings in the file +parsed later take precedence over identical entries in previously +parsed files. Files are ordered alphabetically, e.g. + +\fIfail2ban.d/01_custom_log.conf\fR - to use a different log path +.RE .RS \fIjail.d/01_enable.conf\fR - to enable a specific jail .RE .RS -\fIjail.d/02_custom_port.conf\fR - containing specific configuration entry to change the port of the jail specified in the configuration +\fIjail.d/02_custom_port.conf\fR - to change the port(s) of a jail. +.RE +.RE + +Configuration files have sections, those specified with [section name], and name = value pairs. For those name items that can accept multiple values, specify the values separated by spaces, or in separate lines space indented at the beginning of the line before the second value. + +.PP +Configuration files can include other (defining common variables) configuration files, which is often used in Filters and Actions. Such inclusions are defined in a section called [INCLUDES]: + +.TP +.B before +indicates that the specified file is to be parsed before the current file. +.TP +.B after +indicates that the specified file is to be parsed after the current file. +.RE + +Using Python "string interpolation" mechanisms, other definitions are allowed and can later be used within other definitions as %(name)s. For example. + +.RS +baduseragents = IE|wget .RE .RS -\fIfail2ban.d/01_custom_log.conf\fR - containing specific configuration entry to use a different log path. -.RE +failregex = useragent=%(baduseragents)s .RE -The order \fIjail\fR configuration is parsed is: +Comments: use '#' for comment lines and '; ' (space is important) for inline comments. When using Python2.X '; ' can only be used on the first line due to an Python library bug. -jail.conf , -jail.d/*.conf (in alphabetical order), -jail.local, followed by -jail.d/*.local (in alphabetical order). - -Likewise for fail2ban configuration except the filenames/directories begin with "fail2ban" and not "jail". - -Configuration files have sections, those specified with [section name], and name = value pairs. For those name items that can accept multiple values, specify the values separated by spaces, or new lines between the values which also requires space at the beginning of the line before the second value.. - -Comments: use '#' for comment lines and ';' (following a space) for inline comments. When using Python2.X ';' can only be used on the first line due to an Python library bug. - -.SH "FAIL2BAN CONFIGURATION FILES" +.SH "FAIL2BAN CONFIGURATION FILE(S) (\fIfail2ban.conf\fR)" These files have one section, [Definition]. The items that can be set are: .TP -\fBloglevel\fR -Set the log level output. , 1 = ERROR, 2 = WARN, 3 = INFO, 4 = DEBUG. Default: 1 +.B loglevel +verbosity level of log output: 1 = ERROR, 2 = WARN, 3 = INFO, 4 = DEBUG. Default: 1 .TP -\fBlogtarget\fR -Set the log target. This could be a file, SYSLOG, STDERR or STDOUT. Only one log target can be specified. +.B logtarget +log target: filename, SYSLOG, STDERR or STDOUT. Default: STDERR . Only a single log target can be specified. If you change logtarget from the default value and you are using logrotate -- also adjust or disable rotation in the -corresponding configuration file (e.g. /etc/logrotate.d/fail2ban on Debian systems). Values can be [ STDOUT | STDERR | SYSLOG | FILE ] Default: STDERR. +corresponding configuration file (e.g. /etc/logrotate.d/fail2ban on Debian systems). .TP -\fBsocket\fR -Set the socket file. This is used to communicate with the fail2ban server daemon. Do not remove this file when Fail2ban runs. It will not be possible to communicate with the server afterwards. Default: /var/run/fail2ban/fail2ban.sock +.B socket +socket filename. Default: /var/run/fail2ban/fail2ban.sock . +This is used for communication with the fail2ban server daemon. Do not remove this file when Fail2ban is running. It will not be possible to communicate with the server afterwards. .TP -\fBpidfile\fR -Set the PID file. This is used to store the process ID of the fail2ban server. -# Values: [ FILE ] Default: /var/run/fail2ban/fail2ban.pid +.B pidfile +PID filename. Default: /var/run/fail2ban/fail2ban.pid. +This is used to store the process ID of the fail2ban server. -.SH "JAIL CONFIGURATION FILES" -The following options are applicable to all jails. They appear in a section specifing the jail name or in the \fI[DEFAULT]\fR section which is used if individual sections don't have a value specified. +.SH "JAIL CONFIGURATION FILE(S) (\fIjail.conf\fR)" +The following options are applicable to any jail. They appear in a section specifying the jail name or in the \fI[DEFAULT]\fR section which defines default values to be used if not specified in the individual section. .TP -\fBfilter\fR -The filename of the filter in /etc/fail2ban/filter.d/ without the .conf/.local extension. Only one filter can be specified. +.B filter +name of the filter -- filename of the filter in /etc/fail2ban/filter.d/ without the .conf/.local extension. Only one filter can be specified. .TP -\fBlogpath\fR -This is the log filename(s). Globs, like paths containing * and ? or [0-9], can be used however only the files that exist at startup matching this glob pattern will be read. +.B logpath +filename(s) of the log files to be monitored. Globs -- paths containing * and ? or [0-9] -- can be used however only the files that exist at startup matching this glob pattern will be considered. .TP -\fBaction\fR -action(s) from \fI/etc/fail2ban/action.d/\fR without the \fI.conf\fR/\fI.local\fR extension. Arguements can be passed to actions to override the default values from the [Init] section. Arguements are specified by [name=value,name2=value]. Values can also be quoted. More that one action can be specified. +.B action +action(s) from \fI/etc/fail2ban/action.d/\fR without the \fI.conf\fR/\fI.local\fR extension. Arguments can be passed to actions to override the default values from the [Init] section in the action file. Arguments are specified by [name=value,name2=value]. Values can also be quoted. More that one action can be specified (in separate lines). .TP -\fBignoreip\fR -A list of IPs not to ban. These can include a CIDR mask too. +.B ignoreip +list of IPs not to ban. They can include a CIDR mask too. .TP -\fBignorecommand\fR -A command that is executed to determine if the current ban's actionban is to be executed. This command will return true if the current ban should be ignored. A false return value will result in the ban's actionban executed. -Like ACTION FILES, tags like are can be included in the ignore command value and will be substitued before execution. Currently only is supported however more will be added later. +.B ignorecommand +command that is executed to determine if the current candidate IP for banning should not be banned. IP will not be banned if command returns successfully (exit code 0). +Like ACTION FILES, tags like are can be included in the ignorecommand value and will be substituted before execution. Currently only is supported however more will be added later. .TP -\fBbantime\fR -effective ban duration (measured in seconds). +.B bantime +effective ban duration (in seconds). .TP -\fBfindtime\fR +.B findtime time interval (in seconds) before the current time where failures will count towards a ban. .TP -\fBmaxretry\fR -number of failures that can occur in the last \fBfindtime\fR seconds before a ban of that IP will result. +.B maxretry +number of failures that have to occur in the last \fBfindtime\fR seconds to ban then IP. .TP -\fBbackend\fR -This is the backend used to detect changes in the logpath. It defaults to "auto" which will try "pyinotify", "gamin" before "polling". Any of these can be specified. "pyinotify" is only valid on Linux systems with the "pyinotify" Python libraries. "gamin" requires the "gamin" libraries. +.B backend +backend to be used to detect changes in the logpath. It defaults to "auto" which will try "pyinotify", "gamin" before "polling". Any of these can be specified. "pyinotify" is only valid on Linux systems with the "pyinotify" Python libraries. "gamin" requires the "gamin" libraries. .TP -\fBusedns\fR -This tells fail2ban to use DNS to resolve HOST names that appear in the logs. By default it is "warn" which will preform the resolving hostnames to IPs however it will also log a warning. If you are using DNS here you could be blocking the wrong IPs due to the asymetric nature of reverse DNS (that the application used to write the domain name to log) compared to forward DNS that fail2ban uses to resolve this back to an IP (but not necessarly the same one). Idealy configure your applications to log a real IP. This can be set to "yes" to prevent warnings in the log or "no" to disable DNS resolution. +.B usedns +use DNS to resolve HOST names that appear in the logs. By default it is "warn" which will resolve hostnames to IPs however it will also log a warning. If you are using DNS here you could be blocking the wrong IPs due to the asymmetric nature of reverse DNS (that the application used to write the domain name to log) compared to forward DNS that fail2ban uses to resolve this back to an IP (but not necessarily the same one). Ideally you should configure your applications to log a real IP. This can be set to "yes" to prevent warnings in the log or "no" to disable DNS resolution altogether (thus ignoring entries where hostname, not an IP is logged).. .TP -\fBfailregex\fR -Here a failregex can be added which is effectively added to the filter's failregexes. If this is useful for others using your application please tell the fail2ban developers by reporting an issue (REPORTING BUGS below). +.B failregex +regex (Python \fBreg\fRular \fBex\fRpression) to be added to the filter's failregexes. If this is useful for others using your application please share you regular expression with the fail2ban developers by reporting an issue (see REPORTING BUGS below). .TP -\fBignoreregex\fR -Here you can specify a Python regex that when applied to a log file line will be ignored. This will be ignored even if it matches a failregex of the jail or any of its filters. +.B ignoreregex +regex which, if the log line matches, would cause Fail2Ban not consider that line. This line will be ignored even if it matches a failregex of the jail or any of its filters. -.SH "ACTION CONFIGURATION FILES" -Action files specify which commands are executed to ban and unban an IP address. They are located under \fI/etc/fail2ban/action.d\fR. + +.SH "ACTION CONFIGURATION FILES (\fIaction.d/*.conf\fR)" +Action files specify which commands are executed to ban and unban an IP address. Like with jail.conf files, if you desire local changes create an \fI[actionname].local\fR file in the \fI/etc/fail2ban/action.d\fR directory and override the required settings. -Action files are ini files that have two sections, \fBDefinition\fR and \fBInit\fR . +Action files have two sections, \fBDefinition\fR and \fBInit\fR . -The [Init] section allows for action-specific settings. In \fIjail.conf/jail.local\fR these can be overwritten for a particular jail as options to the jail. +The [Init] section enables action-specific settings. In \fIjail.conf/jail.local\fR these can be overridden for a particular jail as options of the action's specification in that jail. The following commands can be present in the [Definition] section. .TP -\fBactionstart\fR +.B actionstart command(s) executed when the jail starts. .TP -\fBactionstop\fR +.B actionstop command(s) executed when the jail stops. .TP -\fBactioncheck\fR -the command ran before any other action. It aims to verify if the environment is still ok. +.B actioncheck +command(s) ran before any other action. It aims to verify if the environment is still ok. .TP -\fBactionban\fR +.B actionban command(s) that bans the IP address after \fBmaxretry\fR log lines matches within last \fBfindtime\fR seconds. .TP -\fBactionunban\fR +.B actionunban command(s) that unbans the IP address after \fBbantime\fR. +.RE Commands specified in the [Definition] section are executed through a system shell so shell redirection and process control is allowed. The commands should return 0, otherwise error would be logged. Moreover if \fBactioncheck\fR exits with non-0 status, it is taken as indication that firewall status has changed and fail2ban needs to reinitialize itself (i.e. issue \fBactionstop\fR and \fBactionstart\fR commands). @@ -162,7 +196,7 @@ return 0, otherwise error would be logged. Moreover if \fBactioncheck\fR exits Tags are enclosed in <>. All the elements of [Init] are tags that are replaced in all action commands. Tags can be added by the \fBfail2ban-client\fR using the setctag command. \fB
\fR is a tag that is always a new line (\\n). -More than a single command is allowed to be specified. Each command needs to be on a separate line and indented with whitespaces without blank lines. The following example defines +More than a single command is allowed to be specified. Each command needs to be on a separate line and indented with whitespace(s) without blank lines. The following example defines two commands to be executed. actionban = iptables -I fail2ban- --source -j DROP @@ -171,53 +205,34 @@ two commands to be executed. .SS "Action Tags" The following tags are substituted in the actionban, actionunban and actioncheck (when called before actionban/actionunban) commands. .TP -\fBip\fR -An IPv4 ip address to be banned. e.g. 192.168.0.2 +.B ip +IPv4 IP address to be banned. e.g. 192.168.0.2 .TP -\fBfailures\fR -The number of times the failure occurred in the log file. e.g. 3 +.B failures +number of times the failure occurred in the log file. e.g. 3 .TP -\fBtime\fR -The unix (epoch) time of the ban. e.g. 1357508484 +.B time +UNIX (epoch) time of the ban. e.g. 1357508484 .TP -\fBmatches\fR -The concatenated string of the log file lines of the matches that generated the ban. Many characters interpreted by shell get escaped. +.B matches +concatenated string of the log file lines of the matches that generated the ban. Many characters interpreted by shell get escaped to prevent injection, nevertheless use with caution. -.SH FILTER FILES +.SH FILTER FILES (\fIfilter.d/*.conf\fR) Filter definitions are those in \fI/etc/fail2ban/filter.d/*.conf\fR and \fIfilter.d/*.local\fR. -These are used to identify failed authentication attempts in logs and to extract the host IP address (or hostname if \fBusedns\fR is \fBtrue\fR). +These are used to identify failed authentication attempts in log files and to extract the host IP address (or hostname if \fBusedns\fR is \fBtrue\fR). Like action files, filter files are ini files. The main section is the [Definition] section. There are two filter definitions used in the [Definition] section: - .TP -\fBfailregex\fR -is the regex (\fBreg\fRular \fBex\fRpression) that will match failed attempts. The tag is used as part of the regex and is itself a regex -for IPv4 addresses and hostnames. fail2ban will work out which one of these it actually is. - +.B failregex +regex that will match failed attempts. The tag is used as part of the regex and is itself a regex +for IPv4 addresses (and hostnames if \fBusedns\fR). Fail2Ban will work out which one of these it actually is. .TP -\fBignoreregex\fR -is the regex to identify log entries that should be ignored by fail2ban, even if they match failregex. - - -Using Python "string interpolation" mechanisms, other definitions are allowed and can later be used within other definitions as %(defnname)s. For example. - - baduseragents = IE|wget - failregex = useragent=%(baduseragents)s - -.PP -Filters can also have a section called [INCLUDES]. This is used to read other configuration files. - -.TP -\fBbefore\fR -indicates that this file is read before the [Definition] section. - -.TP -\fBafter\fR -indicates that this file is read after the [Definition] section. +.B ignoreregex +regex to identify log entries that should be ignored by Fail2Ban, even if they match failregex. .SH AUTHOR Fail2ban was originally written by Cyril Jaquier . @@ -227,7 +242,7 @@ Manual page written by Daniel Black and Yaroslav Halchenko. .SH "REPORTING BUGS" Report bugs to https://github.com/fail2ban/fail2ban/issues .SH COPYRIGHT -Copyright \(co 2013 Daniel Black +Copyright \(co 2013 Daniel Black and the Fail2Ban Team .br Copyright of modifications held by their respective authors. Licensed under the GNU General Public License v2 (GPL). From 9a8b449086a80e57da88c9f7e57b111e6bdf4981 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 6 Jan 2014 23:38:52 -0500 Subject: [PATCH 02/13] DOC: some typos, fixes from Vincent Lefevre --- config/action.d/iptables-new.conf | 2 +- config/action.d/osx-ipfw.conf | 2 +- config/filter.d/roundcube-auth.conf | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/action.d/iptables-new.conf b/config/action.d/iptables-new.conf index 38927442..f35f387c 100644 --- a/config/action.d/iptables-new.conf +++ b/config/action.d/iptables-new.conf @@ -2,7 +2,7 @@ # # Author: Cyril Jaquier # Copied from iptables.conf and modified by Yaroslav Halchenko -# to fullfill the needs of bugreporter dbts#350746. +# to fulfill the needs of bugreporter dbts#350746. # # diff --git a/config/action.d/osx-ipfw.conf b/config/action.d/osx-ipfw.conf index 8423f003..abe4009c 100644 --- a/config/action.d/osx-ipfw.conf +++ b/config/action.d/osx-ipfw.conf @@ -79,7 +79,7 @@ blocktype = unreach port setnum = 10 # Option: number for ipfw rule -# Notes: This is meant to be automaticly generated and not overwritten +# Notes: This is meant to be automatically generated and not overwritten # Values: Random value between 10000 and 12000 rulenum="`echo $((RANDOM%%2000+10000))`" diff --git a/config/filter.d/roundcube-auth.conf b/config/filter.d/roundcube-auth.conf index b093f69c..e3e78588 100644 --- a/config/filter.d/roundcube-auth.conf +++ b/config/filter.d/roundcube-auth.conf @@ -22,8 +22,8 @@ ignoreregex = # DoS resistance: # # Assume that the user can inject "from " into the imap response -# somehow. Write test cases around this to ensure that the combination of -# arbitary user input and IMAP response doesn't inject the wrong IP for +# somehow. Write test cases around this to ensure that the combination of +# arbitrary user input and IMAP response doesn't inject the wrong IP for # fail2ban # # Author: Teodor Micu & Yaroslav Halchenko & terence namusonge & Daniel Black From e6627185b0ebf5fbf5ad41fe056fcd179b184804 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 7 Jan 2014 13:41:16 -0500 Subject: [PATCH 03/13] DOC: fixing formatting in the section names of the manpage - \fB to return into bold --- man/jail.conf.5 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/man/jail.conf.5 b/man/jail.conf.5 index 20408a4d..8d1cd6da 100644 --- a/man/jail.conf.5 +++ b/man/jail.conf.5 @@ -99,7 +99,7 @@ failregex = useragent=%(baduseragents)s Comments: use '#' for comment lines and '; ' (space is important) for inline comments. When using Python2.X '; ' can only be used on the first line due to an Python library bug. -.SH "FAIL2BAN CONFIGURATION FILE(S) (\fIfail2ban.conf\fR)" +.SH "FAIL2BAN CONFIGURATION FILE(S) (\fIfail2ban.conf\fB)" These files have one section, [Definition]. @@ -121,7 +121,7 @@ This is used for communication with the fail2ban server daemon. Do not remove th PID filename. Default: /var/run/fail2ban/fail2ban.pid. This is used to store the process ID of the fail2ban server. -.SH "JAIL CONFIGURATION FILE(S) (\fIjail.conf\fR)" +.SH "JAIL CONFIGURATION FILE(S) (\fIjail.conf\fB)" The following options are applicable to any jail. They appear in a section specifying the jail name or in the \fI[DEFAULT]\fR section which defines default values to be used if not specified in the individual section. .TP .B filter @@ -162,7 +162,7 @@ regex (Python \fBreg\fRular \fBex\fRpression) to be added to the filter's failre regex which, if the log line matches, would cause Fail2Ban not consider that line. This line will be ignored even if it matches a failregex of the jail or any of its filters. -.SH "ACTION CONFIGURATION FILES (\fIaction.d/*.conf\fR)" +.SH "ACTION CONFIGURATION FILES (\fIaction.d/*.conf\fB)" Action files specify which commands are executed to ban and unban an IP address. Like with jail.conf files, if you desire local changes create an \fI[actionname].local\fR file in the \fI/etc/fail2ban/action.d\fR directory @@ -217,7 +217,7 @@ UNIX (epoch) time of the ban. e.g. 1357508484 .B matches concatenated string of the log file lines of the matches that generated the ban. Many characters interpreted by shell get escaped to prevent injection, nevertheless use with caution. -.SH FILTER FILES (\fIfilter.d/*.conf\fR) +.SH "FILTER FILES (\fIfilter.d/*.conf\fB)" Filter definitions are those in \fI/etc/fail2ban/filter.d/*.conf\fR and \fIfilter.d/*.local\fR. From 4d4060930bbacca501773cd4454b128be41b31e5 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 8 Jan 2014 21:46:32 +1100 Subject: [PATCH 04/13] DOC: spelling + GPL2+ for license --- man/jail.conf.5 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/man/jail.conf.5 b/man/jail.conf.5 index 8d1cd6da..e79ecd14 100644 --- a/man/jail.conf.5 +++ b/man/jail.conf.5 @@ -28,7 +28,7 @@ Actions defining the commands for banning and unbanning of IP address Jails defining combinations of Filters with Actions. -.SH "CONFIGUATION FILES FORMAT" +.SH "CONFIGURATION FILES FORMAT" \fI*.conf\fR files are distributed by Fail2Ban. It is recommended that *.conf files should remain unchanged to ease upgrades. If needed, customizations should be provided in \fI*.local\fR files. For example, if you would like to enable the [ssh-iptables-ipset] jail specified in jail.conf, create jail.local containing @@ -45,7 +45,7 @@ In .local files specify only the settings you would like to change and the rest \fIjail.d/\fR and \fIfail2ban.d/\fR In addition to .local, for jail.conf or fail2ban.conf file there can -be a corresponding \fI.d/\fR directory containining additional .conf +be a corresponding \fI.d/\fR directory containing additional .conf files. The order e.g. for \fIjail\fR configuration would be: .RS @@ -128,7 +128,7 @@ The following options are applicable to any jail. They appear in a section speci name of the filter -- filename of the filter in /etc/fail2ban/filter.d/ without the .conf/.local extension. Only one filter can be specified. .TP .B logpath -filename(s) of the log files to be monitored. Globs -- paths containing * and ? or [0-9] -- can be used however only the files that exist at startup matching this glob pattern will be considered. +filename(s) of the log files to be monitored. Globs -- paths containing * and ? or [0-9] -- can be used however only the files that exist at start up matching this glob pattern will be considered. .TP .B action action(s) from \fI/etc/fail2ban/action.d/\fR without the \fI.conf\fR/\fI.local\fR extension. Arguments can be passed to actions to override the default values from the [Init] section in the action file. Arguments are specified by [name=value,name2=value]. Values can also be quoted. More that one action can be specified (in separate lines). @@ -242,10 +242,13 @@ Manual page written by Daniel Black and Yaroslav Halchenko. .SH "REPORTING BUGS" Report bugs to https://github.com/fail2ban/fail2ban/issues .SH COPYRIGHT -Copyright \(co 2013 Daniel Black and the Fail2Ban Team +Copyright \(co 2013 the Fail2Ban Team .br Copyright of modifications held by their respective authors. -Licensed under the GNU General Public License v2 (GPL). +.br +Licensed under the GNU General Public License v2 (GPL) or +(at your option) any later version. +. .SH "SEE ALSO" .br fail2ban-server(1) From cd5aab5ff144ed2da58368ec524de435be9b1419 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 10 Jan 2014 08:39:39 +1100 Subject: [PATCH 05/13] TST: for tag substition, multiple on same line --- testcases/actiontestcase.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testcases/actiontestcase.py b/testcases/actiontestcase.py index e0587b3d..62a486f4 100644 --- a/testcases/actiontestcase.py +++ b/testcases/actiontestcase.py @@ -60,6 +60,13 @@ class ExecuteAction(LogCaptureTestCase): self.assertEqual(Action.substituteRecursiveTags({'A': ''}), {'A': ''}) self.assertEqual(Action.substituteRecursiveTags({'A': ' ','X':'fun'}), {'A': ' fun', 'X':'fun'}) self.assertEqual(Action.substituteRecursiveTags({'A': ' ', 'B': 'cool'}), {'A': ' cool', 'B': 'cool'}) + # Multiple stuff on same line is ok + self.assertEqual(Action.substituteRecursiveTags({'failregex': 'to= fromip= evilperson=', 'honeypot': 'pokie', 'ignoreregex': ''}), + { 'failregex': "to=pokie fromip= evilperson=pokie", + 'honeypot': 'pokie', + 'ignoreregex': '', + }) + # rest is just cool self.assertEqual(Action.substituteRecursiveTags(aInfo), { 'HOST': "192.0.2.0", From 128112d51c73ea43050ed749093fdb540e7fe344 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Thu, 9 Jan 2014 22:44:50 +0000 Subject: [PATCH 06/13] ENH: ejabberd filter --- ChangeLog | 1 + config/filter.d/ejabberd-auth.conf | 19 +++++++++++++++++++ testcases/files/logs/ejabberd-auth | 2 ++ 3 files changed, 22 insertions(+) create mode 100644 config/filter.d/ejabberd-auth.conf create mode 100644 testcases/files/logs/ejabberd-auth diff --git a/ChangeLog b/ChangeLog index 42d357fc..a286cf0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -52,6 +52,7 @@ ver. 0.8.12 (2013/12/XX) - things-can-only-get-better Closes gh-566 - Added to sshd filter expression for "Received disconnect from : 3: ...: Auth fail". Thanks Marcel Dopita. Closes gh-289 + - Added filter.d/ejabberd-auth - New Features: diff --git a/config/filter.d/ejabberd-auth.conf b/config/filter.d/ejabberd-auth.conf new file mode 100644 index 00000000..1e15ebc4 --- /dev/null +++ b/config/filter.d/ejabberd-auth.conf @@ -0,0 +1,19 @@ +# Fail2Ban configuration file +# +# Author: Steven Hiscocks +# +# + +[Definition] + +# Option: failregex +# Notes.: regex to match the password failures messages in the logfile. The +# host must be matched by a group named "host". The tag "" can +# be used for standard IP/hostname matching and is only an alias for +# (?:::f{4,6}:)?(?P[\w\-.^_]+) +# Multiline regexs should use tag "" to separate lines. +# This allows lines between the matching lines to continue to be +# searched for other failures. This tag can be used multiple times. +# Values: TEXT +# +failregex = ^(?:\.\d+)? \[info\] <0\.\d+\.\d>@ejabberd_c2s:wait_for_feature_request:\d+ \([^\)]+\) Failed authentication for \S+ from IP $ diff --git a/testcases/files/logs/ejabberd-auth b/testcases/files/logs/ejabberd-auth new file mode 100644 index 00000000..c67538da --- /dev/null +++ b/testcases/files/logs/ejabberd-auth @@ -0,0 +1,2 @@ +# failJSON: { "time": "2014-01-07T18:09:08", "match": true , "host": "1.2.3.4" } +2014-01-07 18:09:08.512 [info] <0.22741.1>@ejabberd_c2s:wait_for_feature_request:662 ({socket_state,p1_tls,{tlssock,#Port<0.24718>,#Port<0.24720>},<0.22740.1>}) Failed authentication for test@example.com from IP 1.2.3.4 From 0dd65336808a82a9b15f97338e99bb77b6c0fb5d Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Thu, 9 Jan 2014 23:22:12 +0000 Subject: [PATCH 07/13] BF: Add ejabberd-auth to jail.conf --- config/jail.conf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/jail.conf b/config/jail.conf index fc9a6c17..5dcce02c 100644 --- a/config/jail.conf +++ b/config/jail.conf @@ -559,6 +559,12 @@ maxretry = 10 action = iptables-multiport[name=freeswitch-tcp, port="5060,5061,5080,5081", protocol=tcp] iptables-multiport[name=freeswitch-udp, port="5060,5061,5080,5081", protocol=udp] +[ejabberd-auth] + +enabled = false +filter = ejabberd-auth +logpath = /var/log/ejabberd/ejabberd.log +action = iptables[name=ejabberd, port=xmpp-client, protocol=tcp] # Historical support (before https://github.com/fail2ban/fail2ban/issues/37 was fixed ) # use [asterisk] for new jails From b52a4441fda6eed0dcb5c0a344e4802024f02fc4 Mon Sep 17 00:00:00 2001 From: Tomas Pihl Date: Sat, 11 Jan 2014 15:10:02 +0100 Subject: [PATCH 08/13] Support ACL-events without AccountID. Typically happens when a registration from an unknown domain is performed. Add credits --- ChangeLog | 1 + THANKS | 1 + config/filter.d/asterisk.conf | 2 +- testcases/files/logs/asterisk | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a286cf0f..2ca227ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -53,6 +53,7 @@ ver. 0.8.12 (2013/12/XX) - things-can-only-get-better - Added to sshd filter expression for "Received disconnect from : 3: ...: Auth fail". Thanks Marcel Dopita. Closes gh-289 - Added filter.d/ejabberd-auth + - Improved ACL-handling for Asterisk - New Features: diff --git a/THANKS b/THANKS index efbcbe75..38e29fe6 100644 --- a/THANKS +++ b/THANKS @@ -80,6 +80,7 @@ Stefan Tatschner Stephen Gildea Steven Hiscocks Tom Pike +Tomas Pihl Tyler Vaclav Misek Vincent Deffontaines diff --git a/config/filter.d/asterisk.conf b/config/filter.d/asterisk.conf index 3c1a97df..7bb2c709 100644 --- a/config/filter.d/asterisk.conf +++ b/config/filter.d/asterisk.conf @@ -15,7 +15,7 @@ failregex = ^%(log_prefix)s Registration from '[^']*' failed for '(:\d+)?' ^%(log_prefix)s Host failed MD5 authentication for '[^']*' \([^)]+\)$ ^%(log_prefix)s Failed to authenticate (user|device) [^@]+@\S*$ ^%(log_prefix)s (?:handle_request_subscribe: )?Sending fake auth rejection for (device|user) \d*>;tag=\w+\S*$ - ^%(log_prefix)s SecurityEvent="(FailedACL|InvalidAccountID|ChallengeResponseFailed|InvalidPassword)",EventTV="[\d-]+",Severity="[\w]+",Service="[\w]+",EventVersion="\d+",AccountID="\d+",SessionID="0x[\da-f]+",LocalAddress="IPV[46]/(UD|TC)P/[\da-fA-F:.]+/\d+",RemoteAddress="IPV[46]/(UD|TC)P//\d+"(,Challenge="\w+",ReceivedChallenge="\w+")?(,ReceivedHash="[\da-f]+")?$ + ^%(log_prefix)s SecurityEvent="(FailedACL|InvalidAccountID|ChallengeResponseFailed|InvalidPassword)",EventTV="[\d-]+",Severity="[\w]+",Service="[\w]+",EventVersion="\d+",AccountID="\d*",SessionID="0x[\da-f]+",LocalAddress="IPV[46]/(UD|TC)P/[\da-fA-F:.]+/\d+",RemoteAddress="IPV[46]/(UD|TC)P//\d+"(,Challenge="\w+",ReceivedChallenge="\w+")?(,ReceivedHash="[\da-f]+")?(,ACLName="\w+")?$ ^\[\]\s*WARNING%(__pid_re)s:?(?:\[C-[\da-f]*\])? Ext\. s: "Rejecting unknown SIP connection from "$ ignoreregex = diff --git a/testcases/files/logs/asterisk b/testcases/files/logs/asterisk index 60c89d5f..a2535156 100644 --- a/testcases/files/logs/asterisk +++ b/testcases/files/logs/asterisk @@ -40,6 +40,8 @@ [2009-12-22 16:35:24] NOTICE[14916]: chan_sip.c:15644 handle_request_subscribe: Sending fake auth rejection for user ;tag=6pwd6erg54 # failJSON: { "time": "2013-07-06T09:09:25", "match": true , "host": "141.255.164.106" } [2013-07-06 09:09:25] SECURITY[3308] res_security_log.c: SecurityEvent="InvalidPassword",EventTV="1373098165-824497",Severity="Error",Service="SIP",EventVersion="2",AccountID="972592891005",SessionID="0x88aab6c",LocalAddress="IPV4/UDP/92.28.73.180/5060",RemoteAddress="IPV4/UDP/141.255.164.106/5084",Challenge="41d26de5",ReceivedChallenge="41d26de5",ReceivedHash="7a6a3a2e95a05260aee612896e1b4a39" +# failJSON: { "time": "2014-01-10T16:39:06", "match": true , "host": "50.30.42.14" } +[2014-01-10 16:39:06] SECURITY[1503] res_security_log.c: SecurityEvent="FailedACL",EventTV="1389368346-880526",Severity="Error",Service="SIP",EventVersion="1",AccountID="",SessionID="0x7ff408103b18",LocalAddress="IPV4/UDP/83.11.20.23/5060",RemoteAddress="IPV4/UDP/50.30.42.14/5066",ACLName="domain_must_match" # failJSON: { "time": "2013-11-11T14:33:38", "match": true , "host": "192.168.55.152" } [2013-11-11 14:33:38] WARNING[6756][C-0000001d] Ext. s: "Rejecting unknown SIP connection from 192.168.55.152" From 7b6ee64b9e2960506b5bfcc802ff2a92f938eb41 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 12 Jan 2014 21:43:11 +1100 Subject: [PATCH 09/13] DOC: add over pruned bits of jail.conf.5 --- man/jail.conf.5 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/man/jail.conf.5 b/man/jail.conf.5 index 30baa9eb..5101e3b8 100644 --- a/man/jail.conf.5 +++ b/man/jail.conf.5 @@ -162,6 +162,30 @@ regex (Python \fBreg\fRular \fBex\fRpression) to be added to the filter's failre .B ignoreregex regex which, if the log line matches, would cause Fail2Ban not consider that line. This line will be ignored even if it matches a failregex of the jail or any of its filters. +.SS Backends +Available options are listed below. +.TP +.B pyinotify +requires pyinotify (a file alteration monitor) to be installed. If pyinotify is not installed, Fail2ban will use auto. +.TP +.B gamin +requires Gamin (a file alteration monitor) to be installed. If Gamin is not installed, Fail2ban will use auto. +.TP +.B polling +uses a polling algorithm which does not require external libraries. +.TP +.B systemd +uses systemd python library to access the systemd journal. Specifying \fBlogpath\fR is not valid for this backend and instead utilises \fBjournalmatch\fR from the jails associated filter config. + +.SS Actions +Each jail can be configured with only a single filter, but may have multiple actions. By default, the name of a action is the action filename, and in the case of Python actions, the ".py" file extension is stripped. Where multiple of the same action are to be used, the \fBactname\fR option can be assigned to the action to avoid duplication e.g.: +.PP +.nf +[ssh-iptables-ipset] +enabled = true +action = smtp.py[dest=chris@example.com, actname=smtp-chris] + smtp.py[dest=sally@example.com, actname=smtp-sally] +.fi .SH "ACTION CONFIGURATION FILES (\fIaction.d/*.conf\fB)" Action files specify which commands are executed to ban and unban an IP address. From a443b8b4d35498f91de6424eccbab7988912bad7 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 12 Jan 2014 21:45:39 +1100 Subject: [PATCH 10/13] BF: remove second jail definition --- config/jail.conf | 6 ------ 1 file changed, 6 deletions(-) diff --git a/config/jail.conf b/config/jail.conf index 0a886c38..838d678e 100644 --- a/config/jail.conf +++ b/config/jail.conf @@ -715,12 +715,6 @@ action = %(banaction)s[name=%(__name__)s-tcp, port="%(port)s", protocol="tcp", logpath = /var/log/freeswitch.log maxretry = 10 -[ejabberd-auth] - -enabled = false -filter = ejabberd-auth -logpath = /var/log/ejabberd/ejabberd.log -action = iptables[name=ejabberd, port=xmpp-client, protocol=tcp] # Historical support (before https://github.com/fail2ban/fail2ban/issues/37 was fixed ) # use [asterisk] for new jails From 6b0e6b9bcacb9c173f082abd4544cf29450ef62f Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 13 Jan 2014 06:59:59 +1100 Subject: [PATCH 11/13] ENH: add improper command pipelining postfix filter --- ChangeLog | 5 ++--- config/filter.d/postfix.conf | 1 + testcases/files/logs/postfix | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ca227ff..aebfa829 100644 --- a/ChangeLog +++ b/ChangeLog @@ -54,6 +54,8 @@ ver. 0.8.12 (2013/12/XX) - things-can-only-get-better ...: Auth fail". Thanks Marcel Dopita. Closes gh-289 - Added filter.d/ejabberd-auth - Improved ACL-handling for Asterisk + - loglines now also report "[PID]" after the name portion + - Added improper command pipelining to postfix filter. - New Features: @@ -65,9 +67,6 @@ ver. 0.8.12 (2013/12/XX) - things-can-only-get-better - Added filter for freeswitch. Thanks Jim and editors and authors of http://wiki.freeswitch.org/wiki/Fail2ban -- Enhancements: - - loglines now also report "[PID]" after the name portion - ver. 0.8.11 (2013/11/13) - loves-unittests-and-tight-DoS-free-filter-regexes ----------- diff --git a/config/filter.d/postfix.conf b/config/filter.d/postfix.conf index fd8519c9..7330f10c 100644 --- a/config/filter.d/postfix.conf +++ b/config/filter.d/postfix.conf @@ -15,6 +15,7 @@ _daemon = postfix/smtpd failregex = ^%(__prefix_line)sNOQUEUE: reject: RCPT from \S+\[\]: 554 5\.7\.1 .*$ ^%(__prefix_line)sNOQUEUE: reject: RCPT from \S+\[\]: 450 4\.7\.1 : Helo command rejected: Host not found; from=<> to=<> proto=ESMTP helo= *$ ^%(__prefix_line)sNOQUEUE: reject: VRFY from \S+\[\]: 550 5\.1\.1 .*$ + ^%(__prefix_line)simproper command pipelining after \S+ from [^[]*\[\]:?$ ignoreregex = diff --git a/testcases/files/logs/postfix b/testcases/files/logs/postfix index 122ad8e5..ccf2f8bc 100644 --- a/testcases/files/logs/postfix +++ b/testcases/files/logs/postfix @@ -10,3 +10,13 @@ Jul 18 23:12:56 xxx postfix/smtpd[8738]: NOQUEUE: reject: RCPT from foo[192.51.1 Jul 18 23:12:56 xxx postfix/smtpd[8738]: NOQUEUE: reject: RCPT from foo[192.51.100.43]: 554 5.7.1 : Sender address rejected: match bad.domain; from= to= proto=SMTP helo=<192.51.100.43> # failJSON: { "time": "2005-08-10T10:55:38", "match": true , "host": "72.53.132.234" } Aug 10 10:55:38 f-vanier-bourgeois postfix/smtpd[2162]: NOQUEUE: reject: VRFY from 72-53-132-234.cpe.distributel.net[72.53.132.234]: 550 5.1.1 : Recipient address rejected: User unknown in local recipient tab + + +# failJSON: { "time": "2005-01-12T11:07:49", "match": true , "host": "181.21.131.88" } +Jan 12 11:07:49 emf1pt2-2-35-70 postfix/smtpd[13767]: improper command pipelining after DATA from unknown[181.21.131.88]: + +# failJSON: { "time": "2004-12-25T02:35:54", "match": true , "host": "173.10.140.217" } +Dec 25 02:35:54 platypus postfix/smtpd[9144]: improper command pipelining after RSET from 173-10-140-217-BusName-washingtonDC.hfc.comcastbusiness.net[173.10.140.217] + +# failJSON: { "time": "2004-12-18T02:05:46", "match": true , "host": "216.245.198.245" } +Dec 18 02:05:46 platypus postfix/smtpd[16349]: improper command pipelining after NOOP from unknown[216.245.198.245] From 9f107403e807093687d65359646f4e6817f3446d Mon Sep 17 00:00:00 2001 From: Ivo Truxa Date: Mon, 13 Jan 2014 01:18:09 +0100 Subject: [PATCH 12/13] Update exim When using Dovecot authentication for Exim, which is relatively common, the current regex for catching authentication failures needs a small tweak. The current plain|login options are too limiting and will only work in the cases when only the Exim's rudimentary built-in authentication is used. There can be not only the dovecot_login shown in this log example, but also dovecot_plain, ntlm, cram, cyrus, md5, and plenty of others. In fact many admins may opt for their own authentication labels, when setting up Exim. For this reason the regex should catch any label. I suggest modifying the regex in the following way:
^%(pid)s \w+ authenticator failed for (\S+ )?\(\S+\) \[\]: 535 Incorrect authentication data( \(set_id=.*\)|: \d+ Time\(s\))?\s*$
--- testcases/files/logs/exim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testcases/files/logs/exim b/testcases/files/logs/exim index 89fa7f87..84aedcfa 100644 --- a/testcases/files/logs/exim +++ b/testcases/files/logs/exim @@ -37,3 +37,6 @@ # failJSON: { "time": "2013-09-02T09:19:07", "match": true , "host": "118.233.20.68" } 2013-09-02 09:19:07 login authenticator failed for (gkzwsoju) [118.233.20.68]: 535 Incorrect authentication data + +# failJSON: { "time": "2014-01-12T02:07:48", "match": true , "host": "85.214.85.40" } +2014-01-12 02:07:48 dovecot_login authenticator failed for h1832461.stratoserver.net (User) [85.214.85.40]: 535 Incorrect authentication data (set_id=scanner) From 2d8c0b26e443b5b91b16019b7a76dbeb09be3f0c Mon Sep 17 00:00:00 2001 From: Ivo Truxa Date: Mon, 13 Jan 2014 01:38:49 +0100 Subject: [PATCH 13/13] Matching any Exim authentication name As explained in https://github.com/grooverdan/fail2ban/pull/4, in Exim there can be used plenty of other standard authentication names, and in fact the names can be custom. The failregex in Exim filter should catch authentication errors regardless of the name of the authentication. Hence replacing the plain|login with the general \w+ --- config/filter.d/exim.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/filter.d/exim.conf b/config/filter.d/exim.conf index 66743390..b5028f0e 100644 --- a/config/filter.d/exim.conf +++ b/config/filter.d/exim.conf @@ -14,7 +14,7 @@ before = exim-common.conf [Definition] failregex = ^%(pid)s %(host_info)ssender verify fail for <\S+>: (?:Unknown user|Unrouteable address|all relevant MX records point to non-existent hosts)\s*$ - ^%(pid)s (plain|login) authenticator failed for (\S+ )?\(\S+\) \[\]: 535 Incorrect authentication data( \(set_id=.*\)|: \d+ Time\(s\))?\s*$ + ^%(pid)s \w+ authenticator failed for (\S+ )?\(\S+\) \[\]: 535 Incorrect authentication data( \(set_id=.*\)|: \d+ Time\(s\))?\s*$ ^%(pid)s %(host_info)sF=(<>|[^@]+@\S+) rejected RCPT [^@]+@\S+: (relay not permitted|Sender verify failed|Unknown user)\s*$ ^%(pid)s SMTP protocol synchronization error \([^)]*\): rejected (connection from|"\S+") %(host_info)s(next )?input=".*"\s*$ ^%(pid)s SMTP call from \S+ \[\](:\d+)? (I=\[\S+\]:\d+ )?dropped: too many nonmail commands \(last was "\S+"\)\s*$