staging.inyokaproject.org

Problem Konfiguration fail2ban & iptables

Status: Gelöst | Ubuntu-Version: Server 14.04 (Trusty Tahr)
Antworten |

Carroty4Sum

Avatar von Carroty4Sum

Anmeldungsdatum:
13. Februar 2017

Beiträge: Zähle...

Hallo Ubuntuusers,

ich stehe vor einem Problem, welches ich nicht selbst gelöst bekomme.

In meiner Datei jail.local sind Filter aktiviert:

# "backend" specifies the backend used to get files modification.
# Available options are "pyinotify", "gamin", "polling" and "auto".
# This option can be overridden in each jail as well.
#
# pyinotify: requires pyinotify (a file alteration monitor) to be installed.
#            If pyinotify is not installed, Fail2ban will use auto.
# gamin:     requires Gamin (a file alteration monitor) to be installed.
#            If Gamin is not installed, Fail2ban will use auto.
# polling:   uses a polling algorithm which does not require external libraries.
# auto:      will try to use the following backends, in order:
#            pyinotify, gamin, polling.
backend = auto

# "usedns" specifies if jails should trust hostnames in logs,
#   warn when reverse DNS lookups are performed, or ignore all hostnames in logs
#
# yes:   if a hostname is encountered, a reverse DNS lookup will be performed.
# warn:  if a hostname is encountered, a reverse DNS lookup will be performed,
#        but it will be logged as a warning.
# no:    if a hostname is encountered, will not be used for banning,
#        but it will be logged as info.
usedns = warn

#
# Destination email address used solely for the interpolations in
# jail.{conf,local} configuration files.
destemail = xxx@xxx.xxx                   <-- hier anonymisiert
#
# Name of the sender for mta actions
sendername = Fail2Ban

#
# ACTIONS
#

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

# 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 = mail

# Default protocol
protocol = tcp

# Specify chain where jumps would need to be added in iptables-* actions
chain = INPUT

#
# 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", chain="%(chain)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", chain="%(chain)s"]
              %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s", sendername="%(sendername)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", chain="%(chain)s"]
               %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s", sendername="%(sendername)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
# action = %(action_)s
action = %(action_mwl)s

#
# 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
#
# HTTP servers
#

[apache]

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

... usw.

In /etc/fail2ban/filter.d/apache-auth.conf ist definiert:

[Definition]


failregex = ^%(_apache_error_client)s (AH01797: )?client denied by server configuration: (uri )?\S*\s*$
            ^%(_apache_error_client)s (AH01617: )?user .* authentication failure for "\S*": Password Mismatch$
            ^%(_apache_error_client)s (AH01618: )?user .* not found(: )?\S*\s*$
            ^%(_apache_error_client)s (AH01614: )?client used wrong authentication scheme: \S*\s*$
            ^%(_apache_error_client)s (AH\d+: )?Authorization of user \S+ to access \S* failed, reason: .*$
            ^%(_apache_error_client)s (AH0179[24]: )?(Digest: )?user .*: password mismatch: \S*\s*$
            ^%(_apache_error_client)s (AH0179[01]: |Digest: )user `.*' in realm `.+' (not found|denied by provider): \S*\s*$
            ^%(_apache_error_client)s (AH01631: )?user .*: authorization failure for "\S*":\s*$
            ^%(_apache_error_client)s (AH01775: )?(Digest: )?invalid nonce .* received - length is not \S+\s*$
            ^%(_apache_error_client)s (AH01788: )?(Digest: )?realm mismatch - got `.*' but expected `.+'\s*$
            ^%(_apache_error_client)s (AH01789: )?(Digest: )?unknown algorithm `.*' received: \S*\s*$
            ^%(_apache_error_client)s (AH01793: )?invalid qop `.*' received: \S*\s*$
            ^%(_apache_error_client)s (AH01777: )?(Digest: )?invalid nonce .* received - user attempted time travel\s*$

ignoreregex =

In /var/log/apache2/error.log gibt es unter anderem diesen Eintrag:

[Mon Feb 13 13:33:37.089466 2017] [access_compat:error] [pid 25173] [client 92.76.112.232:55278] AH01797: client denied by server configuration: /srv/www/.../index.php

Wenn ich nun aber folgenden Befehl ausführe:

fail2ban-regex /var/log/apache2/error.log /etc/fail2ban/filter.d/apache-auth.conf

Erhalte ich keine Einträge:

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

Use   failregex file : /etc/fail2ban/filter.d/apache-auth.conf
Use         log file : /var/log/apache2/error.log


Results
=======

Failregex: 0 total

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [36] WEEKDAY MONTH Day Hour:Minute:Second[.subsecond] Year
`-

Lines: 36 lines, 0 ignored, 0 matched, 36 missed
Missed line(s):: too many to print.  Use --print-all-missed to print all 36 lines

Zumindest für den einen Eintrag hätte ich das erwartet.

a) Woran liegt das? b) Wie könnte ich den Fehler beheben?

Für ein wenig Hilfe wäre ich sehr dankbar.

Viele Grüße

Carroty4

P. S. Ein anderer von mir selbst erstellter Filter für einen andere Anwendung funktioniert tadellos und Einträge werden angezeigt.

xylit

Anmeldungsdatum:
22. September 2016

Beiträge: 138

Hallo Carroty4Sum,

für was wird bei Dir fail2ban & iptables benötigt? Ohne jetzt eine Lösung für dich zu haben.

gruss

Carroty4Sum

(Themenstarter)
Avatar von Carroty4Sum

Anmeldungsdatum:
13. Februar 2017

Beiträge: Zähle...

xylit schrieb:

Hallo Carroty4Sum,

für was wird bei Dir fail2ban & iptables benötigt? Ohne jetzt eine Lösung für dich zu haben.

gruss

Hallo Xylit,

vielen Dank für dein Interesse an dem Thema.

Fail2ban ist eine weit verbreitete Software, welche einen entscheidenden Einfluss auf die eigene Netzwerksicherheit hat. Sofern ich es richtig verstanden habe, "filtert" Fail2Bans jail.conf (besser: jail.local) Logs wie z.B. das syslog oder /Apache*/*error.log auf bestimmte Zugriffe, die in den .conf-Dateien des Verzeichnis filter.d definiert sind.

Die Kommandozeile

fail2ban-regex /var/log/<Logdatei> /etc/fail2ban/filter.d/<filter>.conf

gibt, sofern ich es richtig verstanden habe, ganz simpel das Ergebnis des Filters (der darin enthaltenen Zeilen failregex = ) an der Logdatei aus.

Bitte hab Verständnis dafür, dass ich aus Sicherheitsgründen Angaben über die Anwendungsart und die Systemarchitektur nur eingeschränkt machen kann.

Trotzdem würde ich es mich freuen, wenn in diesem Forum womöglich ausreichend Exertise vorhanden wäre, um mir in der im Topic genannten Problemstellung, "unter die Arme zu greifen". Bedauerlicherweise ist die Suchmaschinen-Recherche bei diesem Thema wenig ergiebig.

Vielen Dank!

xylit

Anmeldungsdatum:
22. September 2016

Beiträge: 138

Hallo Carroty4Sum.

habe leider noch nicht mit gearbeitet

http://www.laub-home.de/wiki/Mehr_Sicherheit_durch_fail2ban http://linuxwiki.de/Fail2Ban

sorry, dass ich nicht weiterhelfen kann,

gruss

misterunknown Team-Icon

Ehemalige
Avatar von misterunknown

Anmeldungsdatum:
28. Oktober 2009

Beiträge: 4403

Offenbar matched dein Regex nicht richtig. Das müsstest du also debuggen.

Carroty4Sum

(Themenstarter)
Avatar von Carroty4Sum

Anmeldungsdatum:
13. Februar 2017

Beiträge: 9

misterunknown schrieb:

Offenbar matched dein Regex nicht richtig. Das müsstest du also debuggen.

Wie ich finde, eine erstaunliche Notwendigkeit, da es sich um eine frische Installation handelt. Wer weiß wieviele unsichere Konfigurationen dann da draußen noch so herumschwirren ...

Carroty4Sum

(Themenstarter)
Avatar von Carroty4Sum

Anmeldungsdatum:
13. Februar 2017

Beiträge: 9

Also das Debuggen verläuft wenig ergiebig. Sämtliche Zeilen werden nicht erkannt. Hat jemand noch einen Tipp?

Carroty4Sum

(Themenstarter)
Avatar von Carroty4Sum

Anmeldungsdatum:
13. Februar 2017

Beiträge: 9

Thema kann als "solved" markiert werden.

In den Paketen von Ubuntu 14.04 Server ist nur Fail2ban v0.8.1 vorhanden.

Lösung: 1. Deinstallation von Ubuntu und entfernen der Konfigurationsdateien:

sudo apt-get remove fail2ban
rm -R /etc/fail2ban

2. Manuelle Installation der neuen Version (atm 0.10a) via Github

Nun matchen die Filter.

Antworten |