Mehr Sicherheit durch fail2ban: Unterschied zwischen den Versionen

K Textersetzung - „</source>“ durch „</syntaxhighlight>“
Keine Bearbeitungszusammenfassung
 
(5 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
==Fail2Ban==
Das kleine Programm fail2ban lässt sich so konfigurieren, dass es einen Angreifer erkennt, wenn dieser versucht sich einzuloggen und er das Kennwort nicht weiß oder einen falschen SSH Key verwendet. Standardmäßig schließt dann fail2ban, mittels Firewall Regel (iptables), den Zugang für das angreifende System für x Minuten. Das ist eine der besten Waffen gegen BruteForce Angriffe.
Dieses kleine Programm lässt sich so konfigurieren, dass es einen Angreifer erkennt, wenn dieser versucht sich einzuloggen und er das Kennwort nicht weiß. Standardmäßig schließt dann fail2ban, mittels Firewall Regel (iptables), den Zugang für das angreifende System für 10 Minuten.


==Installation==
==Installation==
Debian/Ubuntu Linux
Debian/Ubuntu Linux
<pre>
<pre>
aptitude install fail2ban
apt install fail2ban
</pre>
</pre>
==Konfiguration==
==Konfiguration==
Alle Änderungen des Users können in folgender Datei konfiguriert werden, diese Überschreiben die Datei ''jail.conf''<br>
 
''/etc/fail2ban/jail.local''
=== Actions ===
<pre>
möchte man eine E-Mail erhalten, wenn es zu einer fail2ban Aktion kommt, kann man dies einfach durch das anlegen dieser Konfiguration machen. Die anderen Parameter setzten die Blockierungszeit und die Versuche bis eine Blockierung ausgelöst wird:
 
<code>/etc/fail2ban/jail.d/action.conf</code><pre>
[DEFAULT]
[DEFAULT]


# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1
bantime  = 3600
maxretry = 3
#
# Destination email address used solely for the interpolations in
# Destination email address used solely for the interpolations in
# jail.{conf,local} configuration files.
# jail.{conf,local,d/*} configuration files.
destemail = mymail@mydomain.de
destemail = YOURMAILADDRESS


# Choose default action.  To change, just override value of 'action' with the
# 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
# interpolation to the chosen action shortcut (e.g.  action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section
# globally (section [DEFAULT]) or per specific section
#action = %(action_)s
action = %(action_mwl)s
action = %(action_mw)s
 
# "bantime" is the number of seconds that a host is banned.
bantime  = 30m
 
# "maxretry" is the number of failures before a host get banned.
maxretry = 3


</pre>
=== Backend ===
solltet ihr ein neueres Debian Linux / Raspberry Pi OS (Bookworm und neuer) nutzen, muss das Backend von auto, auf systemd geändert werden:
<code>/etc/fail2ban/jail.d/backend.conf</code><pre>
[DEFAULT]
# "backend" specifies the backend used to get files modification.
# Available options are "pyinotify", "gamin", "polling", "systemd" and "auto".
# This option can be overridden in each jail as well.
#
#
# JAILS
# 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.
# systemd:  uses systemd python library to access the systemd journal.
#              Specifying "logpath" is not valid for this backend.
#              See "journalmatch" in the jails associated filter config
# auto:      will try to use the following backends, in order:
#              pyinotify, gamin, polling.
#
#
# Note: if systemd backend is chosen as the default but you enable a jail
#      for which logs are present only in its own log files, specify some other
#      backend for that jail (e.g. polling) and provide empty value for
#      journalmatch. See https://github.com/fail2ban/fail2ban/issues/959#issuecomment-74901200
backend = systemd


# Next jails corresponds to the standard configuration in Fail2ban 0.6 which
</pre>Dann kann man auch noch das eigene Logging konfigurieren, damit es auch nach systemd-journal loggt:
# was shipped in Debian. Enable any defined here jail by including
 
<code>/etc/fail2ban/fail2ban.d/logging.conf</code><pre>
[DEFAULT]
# Option: logtarget
# Notes.: Set the log target. This could be a file, SYSTEMD-JOURNAL, SYSLOG, STDERR or STDOUT.
#        Only one 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: [ STDOUT | STDERR | SYSLOG | SYSOUT | SYSTEMD-JOURNAL | FILE ]  Default: STDERR
#
#
# [SECTION_NAME]
logtarget = SYSTEMD-JOURNAL
# enabled = true


#
</pre>
# 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


=== allowipv6 Warning ===
um das auftauchende Warning <pre>
fail2ban-server[3538]: 2024-01-03 19:21:18,823 fail2ban.configreader  [3538]: WARNING 'allowipv6' not defined in 'Definition'. Using default one: 'auto'
</pre>loszuwerden, einfach diese Datei anlegen:


[ssh]
<code>/etc/fail2ban/fail2ban.d/ipv6.conf</code><pre>
DEFAULT]
# Option: allowipv6
# Notes.: Allows IPv6 interface:
#        Default: auto
# Values: [ auto yes (on, true, 1) no (off, false, 0) ] Default: auto
allowipv6 = no


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


</pre>
</pre>


===Konfiguration für SSH===
===Konfiguration für SSH===
Folgendes der Datei hinzufügen:<br>
Folgendes der Datei hinzufügen:<br><code>/etc/fail2ban/jail.local</code>
''/etc/fail2ban/jail.local''
<pre>
<pre>
[ssh]
[ssh]
Zeile 79: Zeile 112:


===Konfiguration für Pure-FTPd===
===Konfiguration für Pure-FTPd===
Folgendes der Datei hinzufügen:<br>
Folgendes der Datei hinzufügen:<br><code>/etc/fail2ban/jail.local</code>
''/etc/fail2ban/jail.local''
<pre>
<pre>
#
#
Zeile 95: Zeile 127:
</pre>
</pre>


''/etc/fail2ban/filter.d/pure-ftpd.conf''
<code>/etc/fail2ban/filter.d/pure-ftpd.conf</code>
<pre>
<pre>
# Fail2Ban configuration file
# Fail2Ban configuration file
Zeile 382: Zeile 414:
[[Kategorie:Ubuntu]]
[[Kategorie:Ubuntu]]
[[Kategorie:Security]]
[[Kategorie:Security]]
[[Kategorie:RaspberryPiOS]]
{{#related:Fail2ban-Dockerized: SSH und andere Dienste absichern per Docker Compose}}