Re: Attaque réseau ?
Publié : 03 nov. 2015, 19:24
Donc voilà la solution :
[Post edit ]
Au préalable, installer fail2ban sur le RPI :
Il faut également mettre un fichier de log pour domoticz :
Dans le fichier /etc/init.d/domoticz.sh changer :
et relancer domoticz :
[/Post edit ]
1 - modifier le fichier jail.local dans /etc/fail2ban/ en y ajoutant la section suivante :
Modifier le port et le logpath selon votre configuration.
2 - ajouter le filtre domoticz.conf dans /etc/fail2ban/filter.d
3 - relancer fail2ban
C'est fini !
Pour tester :
puis lancer la commande suivante :
confirmation :
J'ai également fait un test depuis mon tel portable en 3G. Après 3 tentatives, mon ip est bannie :
- retirer le ban de l'ip :
Mon ip n'est plus bannie :
Voilà, j'espère que c'est clair et que cela vous a aidé. N'hésitez pas à me dire si j'ai oublié un truc.
[Post edit ]
Au préalable, installer fail2ban sur le RPI :
Code : Tout sélectionner
sudo apt-get install fail2banDans le fichier /etc/init.d/domoticz.sh changer :
Code : Tout sélectionner
DAEMON_ARGS="$DAEMON_ARGS -log /var/log//domoticz.log"Code : Tout sélectionner
sudo /etc/init.d/domoticz.sh restart1 - modifier le fichier jail.local dans /etc/fail2ban/ en y ajoutant la section suivante :
Code : Tout sélectionner
[domoticz]
enabled = true
port = 8080
filter = domoticz
logpath = /var/log/domoticz.log
maxretry = 3
findtime = 36002 - ajouter le filtre domoticz.conf dans /etc/fail2ban/filter.d
Code : Tout sélectionner
vi /etc/fail2ban/filter.d/domoticz.conf
# Fail2Ban configuration file for domoticz
#
# Author: Emmanuel Chanteloup
#
# $Revision$
#
[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>[\w\-.^_]+)
# Values: TEXT
#
failregex = .* Error: Failed login attempt from <HOST> for user '.*' !
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
Code : Tout sélectionner
sudo /etc/init.d/fail2ban restartPour tester :
Code : Tout sélectionner
vi toto.txt :
2015-11-03 18:35:51.908 Error: Failed login attempt from 37.130.158.115 for user 'toto' !Code : Tout sélectionner
fail2ban-regex toto.txt /etc/fail2ban/filter.d/domoticz.confconfirmation :
Code : Tout sélectionner
Success, the total number of match is 1Code : Tout sélectionner
root@raspberrypi:/etc/fail2ban# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
fail2ban-domoticz tcp -- anywhere anywhere multiport dports 8080
fail2ban-ssh tcp -- anywhere anywhere multiport dports ssh
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain fail2ban-domoticz (1 references)
target prot opt source destination
DROP all -- 37.140.158.148 anywhere
RETURN all -- anywhere anywhere
Code : Tout sélectionner
root@raspberrypi:/etc/fail2ban/filter.d# iptables -D fail2ban-domoticz -s VOTRE_IP(ici 37.140.158.148) -j DROP
Code : Tout sélectionner
root@raspberrypi:/etc/fail2ban# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
fail2ban-domoticz tcp -- anywhere anywhere multiport dports 8080
fail2ban-ssh tcp -- anywhere anywhere multiport dports ssh
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain fail2ban-domoticz (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Chain fail2ban-ssh (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere