Jetzt will ich endlich mal das nachholen was ich im Thread
pdAdmin-Server schützen
versprochen habe und erstelle hiermit eine kurzes HowTo um einen pdAdmin-Server mithilfe von "fail2ban" ein wenig abzusichern.
Auf CentOS können wir das „Atomic“-Repository nutzen um „fail2ban“ zu installieren.
Um das Repository zu installieren genügt folgende Zeile:
Selbstverständlich kann auch jedes andere repository genutzt werden das "fail2ban" zur installation zur Verfügung stellt.
Anschliessend kann „fail2ban“ per
Installiert werden.
Fail2Ban wird über folgende Dateien eingerichtet:
- jail.conf
- filter.d/<filtername>.conf
Zudem ist es wichtig zu wissen welche LogFiles von fail2ban durchsucht werden müssen damit ein bestimmter Filter greifen kann!
Wenn eine Regel greift, wird/kann eine eMail an den Admin erfolgen das einen bestimmte Aktion von fail2ban ausgelöst wurde bzw. ein Filter gerade gegriffen hat.
vi /etc/fail2ban/jail.conf
Die folgenden Zeilen einfach am Ende der Datei einfügen:
# Hier gehts um pdAdmin
[pdqmail-imap]
enabled = true
port = 143
filter = pdqmail-imap
action = iptables[name=IMAP-Banned, port=143, protocol=tcp]
sendmail-whois[name=IMAP-Banned,dest=root, sender=fail2ban@mein.server.local]Empfäger der eMail angeben.
logpath = /var/log/messages
maxretry = 5
[pdqmail-pop]
enabled = true
port = 110
filter = pdqmail-pop
action = iptables[name=POP-Banned, port=110, protocol=tcp]
sendmail-whois[name=POP-Banned,dest=root, sender=fail2ban@mein.server.local]Empfäger der eMail angeben.
logpath = /var/log/maillog
findtime = 10
maxretry = 5
[pdqmail-smtp]
enabled = true
port = 25
filter = pdqmail-smtp
action = iptables[name=SMTP-Banned, port=25, protocol=tcp]
sendmail-whois[name=SMTP-Banned,dest=root, sender=fail2ban@mein.server.local]Empfäger der eMail angeben.
logpath = /var/log/maillog
findtime = 10
maxretry = 5
Alles anzeigen
Nachdem die jail.conf nun fertig eingerichtet ist, müssen die entsprechenden Filterregeln noch erstellt werden. Diese werden im verzeichnis /etc/fail2ban/filder.d/ erstellt und heissen:
vi /etc/fail2ban/filter.d/pdqmail-imap.conf
# Fail2Ban configuration file
# qmail IMAP from pdAdmin
# to catch IMAP-Login with too much login-trys
[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, user=[-/\w]+.*(?:[a-z]{2,6}), ip=\[<HOST>\]
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
Alles anzeigen
vi /etc/fail2ban/filter.d/pdqmail-pop.conf
# Fail2Ban configuration file for
# qMail POP3 from pdAdmin
# to catch POP3-Logins with too much login-trys
[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 = User [-/\w]+.*(?:[a-z]{2,6}): login failure from <HOST>
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
Alles anzeigen
vi /etc/fail2ban/filter.d/pdqmail-smtp.conf
# Fail2Ban configuration file
# qmail IMAP from pdAdmin
# to catch invalid SMTP logins
[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 = User [-/\w]+.*(?:[a-z]{2,6}): smtp-auth login failed from <HOST> \(no such user\)
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
Alles anzeigen
Die Default-ProFTP-Regel von fail2Ban muss ein wenig angepasst werden (Fett markiert):
vi /etc/fail2ban/filter.d/proftpd.conf
# Fail2Ban configuration file
#
# Author: Yaroslav Halchenko
#
# $Revision: 677 $
#
[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 = \(\S+\[<HOST>\]\)[: -]+ USER \S+: no such user found from \S+ \[\S+\] to \S+:\S+$
\(\S+\[<HOST>\]\)[: -]+ USER \S+ \(Login failed\): Incorrect password\.$
\(\S+\[<HOST>\]\)[: -]+ SECURITY VIOLATION: \S+ login attempted\.$
[B]\(\S+\[<HOST>\]\) \- Maximum login attempts \(3\) exceeded, connection refused[/B]
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
Alles anzeigen
Anschliessend starten wir das ganze mit /etc/init.d/fail2ban restart bzw. start und sorgen per chkconfig fail2ban on dafür das dieser auch beim Booten gestartet wird.
Mit „fail2ban-client –d“ kann man prüfen ob die Configs in Ordnung sind. Etwaige Fehler werden zu Begin mit „Error“ eingeleitet.