Fail2ban reagiert nicht

hafgan

New Member
Hallo,

ich habe das Problem, dass Fail2ban nicht auf fehlerhafte logins reagiert.

In meiner /var/log/mail.log steht z.B. Folgendes:
Code:
...
Nov 23 01:44:28 euve10111 pop3d: LOGIN FAILED, user=web10p5, ip=[::ffff:80.237.153.114]
Nov 23 01:44:33 euve10111 pop3d: Disconnected, ip=[::ffff:80.237.153.114]
Nov 23 01:44:33 euve10111 pop3d: Connection, ip=[::ffff:80.237.153.114]
Nov 23 01:44:33 euve10111 pop3d: LOGIN FAILED, user=web10p5, ip=[::ffff:80.237.153.114]
Nov 23 01:44:38 euve10111 pop3d: Disconnected, ip=[::ffff:80.237.153.114]
Nov 23 01:44:38 euve10111 pop3d: Connection, ip=[::ffff:80.237.153.114]
Nov 23 01:44:38 euve10111 pop3d: Disconnected, ip=[::ffff:80.237.153.114]
...

Im Fail2ban log wird keine Eintrag vorgenommen. Ich gehe davon aus, dass er diesen Vorgang überhaupt nicht erkennt.

Der entsprechende Abschnitt der jail.conf:
Code:
[courierauth]

enabled  = true
port     = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
filter   = courierlogin
logpath  = /var/log/mail.log

Der Filter courierlogin.conf:
Code:
[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 "<HOST>" can
#          be used for standard IP/hostname matching and is only an alias for
#          (?:::f{4,6}:)?(?P<host>\S+)
# Values:  TEXT
#
failregex = LOGIN FAILED, .*, ip=\[<HOST>\]$

# Option:  ignoreregex
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
# Values:  TEXT
#
ignoreregex =

Hat da jemand einen Hinweis, was ich falsch eingestellt habe? Fail2ban hat jedenfalls den jail "courierauth" erfolgreich und fehlerfrei gestartet laut log:
Code:
2010-11-22 20:15:14,869 fail2ban.jail   : INFO   Jail 'courierauth' started

Gruß
hafgan
 
Führe zuerst ein:
Code:
fail2ban-regex /var/log/mail.log /etc/fail2ban/filter.d/courierlogin.conf

Wenn das dann matcht und dir eine Anzahl an Treffer zurückgegeben hat, dann versuche mal in der /etc/fail2ban/fail2ban.conf und stell dort das Logging auf 4, dann restart und gleichzeitg ein tail -f /var/log/failban.log

Wenn es keine Treffer beim testen gab, dann versuch mal folgenden Filter-Eintrag:
Code:
failregex = (.*)LOGIN FAILED, .*, ip=\[(.*):<HOST>\]

da evtl. Fail2ban mit der Regex-Gruppe HOST nicht auf IPv6 matchen kann:
::ffff:....
 
Hallo blocklist!

Danke für Deine Hilfe!
Code:
# fail2ban-regex /var/log/mail.log /etc/fail2ban/filter.d/courierlogin.conf
    165.98.119.118 (Wed Nov 24 01:40:28 2010)
    165.98.119.118 (Wed Nov 24 01:40:33 2010)
    165.98.119.118 (Wed Nov 24 01:40:41 2010)
....

Date template hits:
11825 hit(s): Month Day Hour:Minute:Second
0 hit(s): Weekday Month Day Hour:Minute:Second Year
0 hit(s): Weekday Month Day Hour:Minute:Second
0 hit(s): Year/Month/Day Hour:Minute:Second
0 hit(s): Day/Month/Year Hour:Minute:Second
0 hit(s): Day/Month/Year:Hour:Minute:Second
0 hit(s): Year-Month-Day Hour:Minute:Second
0 hit(s): Day-Month-Year Hour:Minute:Second[.Millisecond]
0 hit(s): TAI64N
0 hit(s): Epoch
0 hit(s): ISO 8601

Success, the total number of match is 1698

However, look at the above section 'Running tests' which could contain important
information.
Der Filter funktioniert also schon mal.

Code:
# cat /var/log/fail2ban.log
...
2010-11-24 17:38:21,681 fail2ban.comm   : DEBUG  Command: ['start', 'courierauth']
2010-11-24 17:38:21,682 fail2ban.jail   : INFO   Jail 'courierauth' started
2010-11-24 17:38:21,682 fail2ban.filter : DEBUG  /var/log/mail.log has been modified
2010-11-24 17:38:21,682 fail2ban.actions.action: DEBUG  iptables -N fail2ban-courierauth
iptables -A fail2ban-courierauth -j RETURN
iptables -I INPUT -p tcp -j fail2ban-courierauth
2010-11-24 17:38:21,694 fail2ban.filter.datedetector: DEBUG  Sorting the template list
2010-11-24 17:38:21,713 fail2ban.actions.action: DEBUG  iptables -N fail2ban-courierauth
iptables -A fail2ban-courierauth -j RETURN
iptables -I INPUT -p tcp -j fail2ban-courierauth returned successfully
2010-11-24 17:38:21,713 fail2ban.actions.action: DEBUG  printf %b "Hi,\n
The jail courierauth has been started successfully.\n
Regards,\n
Fail2Ban"|mail -s "[Fail2Ban] courierauth: started" xyz@xyz.de
...
Aktuell tut sich grad nix. Ich warte mal ab, bis wieder ein Brute-Force kommt. Bis dahin danke schon mal!
 
arrrggsss, das hab ich jetzt erst gesehen.
Du hast bei deiner Anweisung in der /etc/fail2ban/fail.conf gar keine "action" Anweisung drin, wo drin steht, das z.B. per iptables gesperrt werden soll:
Code:
[courierauth]

enabled  = true
filter      = courierauth
logpath  = /var/log/mail.log
maxretry = 15
action   = iptables[name=courierauth, port=110, protocol="tcp"]
Aus iptables, muss evtl. iptables-multiport ersetzt werden, wenn du mehrere Ports blockieren möchtest.
 
Hi,

sorry. Nee, ich habe nur den relevanten Teil aus der jail.conf hier eingestellt. War vielleicht etwas unklug. Die action ist gesetzt. Hier die gesamte jail.conf:

Code:
root:/etc/fail2ban# cat jail.conf 
# Fail2Ban configuration file.
#
# This file was composed for Debian systems from the original one
#  provided now under /usr/share/doc/fail2ban/examples/jail.conf
#  for additional examples.
#
# To avoid merges during upgrades DO NOT MODIFY THIS FILE
# and rather provide your changes in /etc/fail2ban/jail.local
#
# Author: Yaroslav O. Halchenko <debian@onerussian.com>
#
# $Revision: 281 $
#

# The DEFAULT allows a global definition of the options. They can be override
# in each jail afterwards.

[DEFAULT]

# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1
bantime  = 600
maxretry = 3

# "backend" specifies the backend used to get files modification. Available
# options are "gamin", "polling" and "auto".
# yoh: For some reason Debian shipped python-gamin didn't work as expected
#      This issue left ToDo, so polling is default backend for now
backend = polling

#
# Destination email address used solely for the interpolations in
# jail.{conf,local} configuration files.
destemail = xyz@xyz.de

#
# ACTIONS
#

# Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define 
# action_* variables. Can be overriden globally or per 
# section within jail.local file
banaction = iptables-allports

# email action. Since 0.8.1 upstream fail2ban uses sendmail
# MTA for the mailing. Change mta configuration parameter to mail
# if you want to revert to conventional 'mail'.
#mta = sendmail
mta = mail

# Default protocol
protocol = tcp

#
# Action shortcuts. To be used to define action parameter

# The simplest action to take: ban only
action_ = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]

# ban & send an e-mail with whois report to the destemail.
action_mw = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]
              %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s", protocol="%(protocol)s]

# ban & send an e-mail with whois report and relevant log lines
# to the destemail.
action_mwl = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s]
               %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s]
 
# Choose default action.  To change, just override value of 'action' with the
# interpolation to the chosen action shortcut (e.g.  action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section 
[B]action = %(action_mwl)s[/B]

#
# JAILS
#

# Next jails corresponds to the standard configuration in Fail2ban 0.6 which
# was shipped in Debian. Enable any defined here jail by including
#
# [SECTION_NAME] 
# enabled = true

#
# in /etc/fail2ban/jail.local.
#
# Optionally you may override any other parameter (e.g. banaction,
# action, port, logpath, etc) in that section within jail.local

[ssh]

enabled = true
port    = ssh
filter  = sshd
logpath  = /var/log/auth.log
maxretry = 6

# Generic filter for pam. Has to be used with action which bans all ports
# such as iptables-allports, shorewall
[pam-generic]

enabled = false
# pam-generic filter can be customized to monitor specific subset of 'tty's
filter  = pam-generic
# port actually must be irrelevant but lets leave it all for some possible uses
port = all
banaction = iptables-allports
port     = anyport
logpath  = /var/log/auth.log
maxretry = 6

[xinetd-fail]

enabled   = false
filter    = xinetd-fail
port      = all
banaction = iptables-multiport-log
logpath   = /var/log/daemon.log
maxretry  = 2


[ssh-ddos]

enabled = false
port    = ssh
filter  = sshd-ddos
logpath  = /var/log/auth.log
maxretry = 6

#
# HTTP servers
#

[apache]

enabled = true
port    = http,https
filter  = apache-auth
logpath = /var/log/apache*/*error.log
maxretry = 6

# default action is now multiport, so apache-multiport jail was left
# for compatibility with previous (<0.7.6-2) releases
[apache-multiport]

enabled   = false
port      = http,https
filter    = apache-auth
logpath   = /var/log/apache*/*error.log
maxretry  = 6

[apache-noscript]

enabled = true
port    = http,https
filter  = apache-noscript
logpath = /var/log/apache*/*error.log
maxretry = 6

[apache-overflows]

enabled = false
port    = http,https
filter  = apache-overflows
logpath = /var/log/apache*/*error.log
maxretry = 2

#
# FTP servers
#

[vsftpd]

enabled  = false
port     = ftp,ftp-data,ftps,ftps-data
filter   = vsftpd
logpath  = /var/log/vsftpd.log
# or overwrite it in jails.local to be
# logpath = /var/log/auth.log
# if you want to rely on PAM failed login attempts
# vsftpd's failregex should match both of those formats
maxretry = 6


[proftpd]

enabled  = true
port     = ftp,ftp-data,ftps,ftps-data
filter   = proftpd
logpath  = /var/log/proftpd/proftpd.log
maxretry = 6


[wuftpd]

enabled  = false
port     = ftp,ftp-data,ftps,ftps-data
filter   = wuftpd
logpath  = /var/log/auth.log
maxretry = 6


#
# Mail servers
#

[postfix]

enabled  = true
port     = smtp,ssmtp
filter   = postfix
logpath  = /var/log/mail.log


[couriersmtp]

enabled  = false
port     = smtp,ssmtp
filter   = couriersmtp
logpath  = /var/log/mail.log


#
# Mail servers authenticators: might be used for smtp,ftp,imap servers, so
# all relevant ports get banned
#

[courierauth]

enabled  = true
port     = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
filter   = courierlogin
logpath  = /var/log/mail.log


[sasl]

enabled  = true
port     = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
filter   = sasl
logpath  = /var/log/mail.log


# DNS Servers


# These jails block attacks against named (bind9). By default, logging is off
# with bind9 installation. You will need something like this:
#
# logging {
#     channel security_file {
#         file "/var/log/named/security.log" versions 3 size 30m;
#         severity dynamic;
#         print-time yes;
#     };
#     category security {
#         security_file;
#     };
# }
#
# in your named.conf to provide proper logging

# Word of Caution:
# Given filter can lead to DoS attack against your DNS server
# since there is no way to assure that UDP packets come from the
# real source IP
[named-refused-udp]

enabled  = false
port     = domain,953
protocol = udp
filter   = named-refused
logpath  = /var/log/named/security.log

[named-refused-tcp]

enabled  = false
port     = domain,953
protocol = tcp
filter   = named-refused
logpath  = /var/log/named/security.log
 
Also ich hab jetzt selbst einige fehlerhafte logins erzeugt:
Code:
fail2ban-regex /var/log/mail.log /etc/fail2ban/filter.d/courierlogin.conf
Running tests
=============

Use regex file : /etc/fail2ban/filter.d/courierlogin.conf
Use log file   : /var/log/mail.log


Results
=======

Failregex
|- Regular expressions:
|  [1] LOGIN FAILED, .*, ip=\[<HOST>\]$
|
`- Number of matches:
   [1] 7 match(es)

Ignoreregex
|- Regular expressions:
|
`- Number of matches:

Summary
=======

Addresses found:
[1]
    79.212.140.120 (Wed Nov 24 17:16:22 2010)
    79.212.140.120 (Wed Nov 24 18:35:47 2010)
    79.212.140.120 (Wed Nov 24 18:36:00 2010)
    79.212.140.120 (Wed Nov 24 18:37:01 2010)
    79.212.140.120 (Wed Nov 24 18:37:09 2010)
    79.212.140.120 (Wed Nov 24 18:37:17 2010)
    79.212.140.120 (Wed Nov 24 18:37:25 2010)

Date template hits:
1441 hit(s): Month Day Hour:Minute:Second
0 hit(s): Weekday Month Day Hour:Minute:Second Year
0 hit(s): Weekday Month Day Hour:Minute:Second
0 hit(s): Year/Month/Day Hour:Minute:Second
0 hit(s): Day/Month/Year Hour:Minute:Second
0 hit(s): Day/Month/Year:Hour:Minute:Second
0 hit(s): Year-Month-Day Hour:Minute:Second
0 hit(s): Day-Month-Year Hour:Minute:Second[.Millisecond]
0 hit(s): TAI64N
0 hit(s): Epoch
0 hit(s): ISO 8601

Success, the total number of match is 7

However, look at the above section 'Running tests' which could contain important
information.
Wird also wieder erkannt. Allerdings nicht gebannt:
Code:
....
2010-11-24 19:45:10,671 fail2ban.filter : DEBUG  /var/log/mail.log has been modified
2010-11-24 19:45:10,671 fail2ban.filter.datedetector: DEBUG  Sorting the template list
2010-11-24 19:45:11,097 fail2ban.filter : DEBUG  /var/log/mail.log has been modified
2010-11-24 19:45:11,097 fail2ban.filter.datedetector: DEBUG  Sorting the template list
2010-11-24 19:45:11,401 fail2ban.filter : DEBUG  /var/log/mail.log has been modified
2010-11-24 19:45:11,401 fail2ban.filter.datedetector: DEBUG  Sorting the template list
 
mhhhh.
Was ist, wenn du die Action-Anweisung noch mal in dem jail-Part einträgst?

was sagt iptables?
Code:
iptables -L -n

Ich weiss von einem Kollegen, wo er z.B. iptables bei seinem V-Server zwar verwenden konnte, diese aber keine Auswirkungen hatte, da dies irgendwie vom Provider blockiert war, bzw. dadurch nicht gegriffen hat.
 
Morgen,

iptables läuft:
Code:
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
fail2ban-proftpd  tcp  --  anywhere             anywhere            
fail2ban-courierauth  tcp  --  anywhere             anywhere            
fail2ban-apache  tcp  --  anywhere             anywhere            
fail2ban-sasl  tcp  --  anywhere             anywhere            
fail2ban-postfix  tcp  --  anywhere             anywhere            
fail2ban-ssh  tcp  --  anywhere             anywhere            
fail2ban-apache-noscript  tcp  --  anywhere             anywhere            
ISPCP_INPUT  all  --  anywhere             anywhere            
ip-62.75.240.223-INPUT  all  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ISPCP_OUTPUT  all  --  anywhere             anywhere            

Chain ISPCP_INPUT (1 references)
target     prot opt source               destination         
           tcp  --  anywhere             anywhere            tcp spt:submission 
           tcp  --  anywhere             anywhere            tcp spt:ssmtp 
           tcp  --  anywhere             anywhere            tcp spt:smtp 
           tcp  --  anywhere             anywhere            tcp dpt:imaps 
           tcp  --  anywhere             anywhere            tcp dpt:pop3s 
           tcp  --  anywhere             anywhere            tcp dpt:submission 
           tcp  --  anywhere             anywhere            tcp dpt:ssmtp 
           tcp  --  anywhere             anywhere            tcp dpt:smtp 
           tcp  --  anywhere             anywhere            tcp dpt:imap2 
           tcp  --  anywhere             anywhere            tcp dpt:pop3 
           tcp  --  anywhere             anywhere            tcp dpt:https 
           tcp  --  anywhere             anywhere            tcp dpt:www 
RETURN     all  --  anywhere             anywhere            

Chain ISPCP_OUTPUT (1 references)
target     prot opt source               destination                                                                                                                                                                                         
           tcp  --  anywhere             anywhere            tcp dpt:submission                                                                                                                                                              
           tcp  --  anywhere             anywhere            tcp dpt:ssmtp                                                                                                                                                                   
           tcp  --  anywhere             anywhere            tcp dpt:smtp                                                                                                                                                                    
           tcp  --  anywhere             anywhere            tcp spt:imaps                                                                                                                                                                   
           tcp  --  anywhere             anywhere            tcp spt:pop3s                                                                                                                                                                   
           tcp  --  anywhere             anywhere            tcp spt:submission                                                                                                                                                              
           tcp  --  anywhere             anywhere            tcp spt:ssmtp                                                                                                                                                                   
           tcp  --  anywhere             anywhere            tcp spt:smtp                                                                                                                                                                    
           tcp  --  anywhere             anywhere            tcp spt:imap2                                                                                                                                                                   
           tcp  --  anywhere             anywhere            tcp spt:pop3                                                                                                                                                                    
           tcp  --  anywhere             anywhere            tcp spt:https                                                                                                                                                                   
           tcp  --  anywhere             anywhere            tcp spt:www                                                                                                                                                                     
RETURN     all  --  anywhere             anywhere                                                                                                                                                                                            
                                                                                                                                                                                                                                             
Chain fail2ban-apache (1 references)                                                                                                                                                                                                         
target     prot opt source               destination                                                                                                                                                                                         
RETURN     all  --  anywhere             anywhere                                                                                                                                                                                            
                                                                                                                                                                                                                                             
Chain fail2ban-apache-noscript (1 references)                                                                                                                                                                                                
target     prot opt source               destination                                                                                                                                                                                         
RETURN     all  --  anywhere             anywhere                                                                                                                                                                                            

Chain fail2ban-courierauth (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

Chain fail2ban-postfix (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

Chain fail2ban-proftpd (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

Chain fail2ban-sasl (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

Chain fail2ban-ssh (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

Chain ip-62.75.240.223-INPUT (1 references)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             euve10111.vserver.de tcp dpt:ssh 
ACCEPT     tcp  --  anywhere             euve10111.vserver.de tcp dpt:www 
ACCEPT     tcp  --  anywhere             euve10111.vserver.de tcp dpt:https 
ACCEPT     tcp  --  anywhere             euve10111.vserver.de tcp dpt:smtp 
ACCEPT     tcp  --  anywhere             euve10111.vserver.de tcp dpt:pop3 
ACCEPT     tcp  --  anywhere             euve10111.vserver.de tcp dpt:imap2 
ACCEPT     tcp  --  anywhere             euve10111.vserver.de tcp dpt:ssmtp 
ACCEPT     tcp  --  anywhere             euve10111.vserver.de tcp dpts:ftp-data:ftp 
ACCEPT     tcp  --  anywhere             euve10163.vserver.de tcp dpt:imaps

Heute nacht wieder jede Menge Login-Versuche. Kein Hinweis in der fail2ban.log. Das gibts doch nicht. Ich habe jahrelang gute Erfahrungen mit fail2ban gemacht!!
 
Hi,
mmmmmhhhhh, also ich weiss so grad nicht weiter.

Ist die IP evtl. bei Fail2Ban immer noch als gesperrt gelistet?
Arbeitet Fail2Ban bei z.B. SSH korrekt?
Wenn ja, dann liegts wohl an den Einstellungen im jail....
 
Hi,

nein, fail2ban arbeitet überhaupt nicht. Im Log-Eintrag ist halt nur der Start einzelner Jails gelistet. Danach nichts mehr. (Eine IP war auch nicht gebant...)

Ich habe jetzt noch einmal alles von vorne gemacht:
Code:
apt-get purge fail2ban
apt-get install fail2ban

Ich habe nur ein einzigen Jail aktiviert (courierauth) und sonst nichts umkonfiguriert! Dann einige fehlerhafte logins erzeugt. ==> Wieder wurde nichts gebant.

Ich verstehe das nicht. Sonst klappt das immer auf Anhieb!
 
Fehler gefunden:

Die Zeitzonen haben nicht gepasst! Die Logfiles in mail.log waren eine Stunde zu spät. Somit hatte fail2ban diese Daten nicht mehr ausgewertet!

Code:
dpkg-reconfigure tzdata
Hat das Problem gelöst!

Trotzdem, danke für Deine Hilfe!
 
Back
Top