Installons fail2ban puis copions le fichier de base au cas où et éditons-le !
apt-get install fail2ban cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
vi /etc/fail2ban/jail.local
Les configurations sont les suivantes :
Pour résumer, si quelqu’un rentre plus de X fois un mauvais login / mot de passe pendant x heure, il est banni x heure. Et comme je veux le savoir, je vais ajouter la notification par email.
Dans mon cas :
vi /etc/fail2ban/jail.local
# "bantime" is the number of seconds that a host is banned.
bantime = 86400
...
# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime = 3600
...
# "maxretry" is the number of failures before a host get banned.
maxretry = 3
...
# Destination email address used solely for the interpolations in
# jail.{conf,local,d/*} configuration files.
destemail = xxxxx@xxx.ovh
...
mta = mail
...
action = %(action_mwl)s
...
[sshd]
port = ssh
logpath = journal
backend = systemd
enabled = true
maxretry = 3
findtime = 300
bantime = 86400 #24 heures
ignoreip = 127.0.0.1
...
[proxmox]
enabled = true
port = https,http,8006
filter = proxmox
backend = systemd
maxretry = 3
findtime = 2d
bantime = 1h
Un fichier supplémentaire est nécessaire pour cette prison, les autres existants déjà
vi /etc/fail2ban/filter.d/proxmox.conf [Definition] failregex = pvedaemon\[.*authentication failure; rhost=<HOST> user=.* msg=.* ignoreregex =
systemctl restart fail2ban.service fail2ban-client status
Status |- Number of jail: 2 `- Jail list: proxmox, sshd
pour le filtre Proxmox :
fail2ban-regex /var/log/fail2ban.log /etc/fail2ban/filter.d/proxmox.conf
pour le filtre sshd :
fail2ban-regex /var/log/fail2ban.log /etc/fail2ban/filter.d/sshd.conf