Mehr Sicherheit durch fail2ban: Unterschied zwischen den Versionen

K Textersetzung - „</source>“ durch „</syntaxhighlight>“
Keine Bearbeitungszusammenfassung
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>
# JAILS
#


# Next jails corresponds to the standard configuration in Fail2ban 0.6 which
=== Backend ===
# was shipped in Debian. Enable any defined here jail by including
solltet ihr ein neueres Debian Linux / Raspberry Pi OS (Bookworm und neuer) nutzen, muss das Backend von auto, auf systemd geändert werden:
#
# [SECTION_NAME]
# enabled = true


<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.
#
#
# in /etc/fail2ban/jail.local.
# 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.
#
#
# Optionally you may override any other parameter (e.g. banaction,
# Note: if systemd backend is chosen as the default but you enable a jail
# action, port, logpath, etc) in that section within jail.local
#      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
[ssh]
backend = systemd
 
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>''/etc/fail2ban/jail.local''
''/etc/fail2ban/jail.local''
<pre>
<pre>
[ssh]
[ssh]