Fail2ban pour Joomla sur Debian10 (Turnkey16) derrière un reverse proxy
Système
⇒ Configuration
⇒ Serveur
: aller tout en bas à Paramétres du proxy
et activer Behind Load Balancer
Privilèges de l'utilisateur: “Diagnostics: PF Table IP addresses”
source: https://linuxize.com/post/install-configure-fail2ban-on-debian-10/
#systemctl status fail2ban
le confirme
whois
pour des infos plus détaillées sur les IPs bloquées # apt-get install whois
# cp /etc/fail2ban/jail.{conf,local}
# nano /etc/fail2ban/jail.{conf,local} ... ignoreip = 127.0.0.1/8 IPs.reseau.lan.local/24 si besoin ... bantime = 60m ... findtime = 10m ... maxretry = 5 ... destemail = admin@domain.tld ... action = %(action_mw)s ...
... enabled = true ...
# systemctl restart fail2ban
Malheureusement les jails de fail2ban ne suffisent pas car ce n'est pas Apache qui logge pas les tentatives d'identification mais Joomla!
Sources: https://www.joomla-security.de/server/joomla-login-mit-fail2ban-schuetzen.html et https://www.andrehotzler.de/de/blog/technology/62-joomla-login-mit-fail2ban-schuetzen.html
# nano /etc/fail2ban/filter.d/joomla-login-errors.conf [Definition] failregex = ^.*INFO <HOST>.*joomlafailure.*(Benutzername|Username|utilisateur).*
# nano /etc/fail2ban/jail.d/joomla-login-errors.conf [joomla-login-errors] enabled = true filter = joomla-login-errors port = http,https logpath = /var/www/joomla/administrator/logs/error.php
# nano /etc/fail2ban/action.d/opnsense.conf # Fail2Ban configuration file # from triumvirat.org [Definition] actionban = /root/fail2ban-IP.sh ban <ip> actionunban = /root/fail2ban-IP.sh unban <ip>
Placer la nouvelle action dans /etc/fail2ban/jail.local
... banaction = opnsense ...
# systemctl restart fail2ban # systemctl status fail2ban
Il faut créer un petit script:
# nano fail2ban-IP.sh
#!/bin/sh KEY="la_clé" SECRET="le_mot_de_passe" FWIP="ip.de.la.OPNSense" FWPORT="n°_de_port" ALIAS="fail2ban_CT_Joomla" if [ $1 = "ban" ]; then TODO="add" elif [ $1 = "unban" ]; then TODO="delete" fi curl -X POST -d '{"address":"'$2'"}' -H "Content-Type: application/json" -k -u $KEY:$SECRET https://$FWIP:$FWPORT/api/firewall/alias_util/$TODO/$ALIAS
# chmod 600 fail2ban-IP.sh # chmod +x fail2ban-IP.sh
Pour tester le script:
# ./fail2ban-IP.sh ban 192.168.1.1 # ./fail2ban-IP.sh unban 192.168.1.1
et pour finir:
# fail2ban-client set joomla-login-errors banip 192.168.1.1 # fail2ban-client set joomla-login-errors unbanip 192.168.1.1
# nano /etc/apache2/sites-available/joomla.conf et ajouter: <Directory /var/www/joomla/administrator> Order Deny,Allow Deny from all Allow from ip1.ou.bien.réseau1/24 ip2.ou.bien.réseau.2/24 </Directory>
# systemctl restart apache2