Effectivement, je sais plus ou j'avais lu ça mais vu que mon fichier /etc/hosts.deny était absent de mon système j'en avais déduit qu'il n'existait pas dans freebsd 6.2
Je te montre le script que j'utilise sur un autre serveur basé sur Debian GNU/Linux et qui fonctionne parfaitement:
Code:#!/bin/sh
#on commence par récupérer l'ip des vilains méchants a partir du log, et on la met dans un fichier
cat /var/log/auth.log | grep "Failed" | awk -F "from" '{ print $2 }' | awk '{ print $1 }' | sort -u >/var/log/blacklist.log
cat /var/log/auth.log | grep "Illegal" | awk -F "from" '{ print $2 }' | awk '{ print $1 }' | sort -u >>/var/log/blacklist.log
#pour chaque ip on compte combien il y a eu d'erreurs d'authentification
for i in `cat /var/log/blacklist.log` ; do
nberreurs1=`cat /var/log/auth.log | grep "Failed" | grep $i | wc -l`
nberreurs2=`cat /var/log/auth.log | grep "Illegal" | grep $i | wc -l`
let nberreurs=$nberreurs1+$nberreurs2
#s'il y a eu plus de 3 erreurs et que l'ip n'est pas déjà blacklistée et bien on la blackliste !
if [ "$nberreurs" -ge "3" ]
then
if [ "`cat /etc/hosts.deny | grep $i`" = "" ]
then
echo "ALL: $i" >>/etc/hosts.deny
fi
fi
done
je te montre enfin le fichier /etc/hosts.deny de la distribe une fois le script lancé:
Code:# See the manual pages hosts_access(5), hosts_options(5)
# and /usr/doc/netbase/portmapper.txt.gz
#
# Example: ALL: some.host.name, .some.domain
# ALL EXCEPT in.fingerd: other.host.name, .other.domain
#
# If you're going to protect the portmapper use the name "portmap" for the
# daemon name. Remember that you can only use the keyword "ALL" and IP
# addresses (NOT host or domain names) for the portmapper. See portmap(8)
# and /usr/doc/portmap/portmapper.txt.gz for further information.
#
# The PARANOID wildcard matches any host whose name does not match its
# address.
# You may wish to enable this to ensure any programs that don't
# validate looked up hostnames still leave understandable logs. In past
# versions of Debian this has been the default.
# ALL: PARANOID
ALL: 201.14.47.146
ALL: 202.54.130.157
ALL: 211.66.128.125
ALL: 216.47.142.239
ALL: 217.117.141.179
ALL: 217.20.175.55
ALL: 217.73.102.225
ALL: 218.189.207.134
ALL: 62.68.203.206
ALL: 70.85.166.250
ALL: 71.180.57.79
ALL: 74.86.131.195
ALL: 77.92.146.10
Mais en discutant ici je pense avoir trouver l'astuce:
remplacer ça:
Code:if [ "`cat /etc/hosts.deny | grep $i`" = "" ]
then
echo "ALL: $i" >>/etc/hosts.deny
par ça:
Code:if [ "`cat /etc/hosts.allow | grep $i`" = "" ]
then
echo "ALL : $i : deny" >>/etc/hosts.allow
Et remplacer "Illegal" par "Invalid" et rajout de 'invalid"
Voici donc le script final si ça intéresse:
Code:#!/bin/sh
#on commence par récupérer l'ip des vilains méchants a partir du log, et on met dans un fichier
cat /var/log/auth.log | grep "illegal" | awk -F "from" '{ print $2 }' | awk '{ print $1 }' | sort -u >/var/log/blacklist.log
cat /var/log/auth.log | grep "invalid" | awk -F "from" '{ print $2 }' | awk '{ print $1 }' | sort -u >>/var/log/blacklist.log
cat /var/log/auth.log | grep "Invalid" | awk -F "from" '{ print $2 }' | awk '{ print $1 }' | sort -u >/var/log/blacklist.log
#pour chaque ip on compte combien il y a eu d'erreurs d'authentification
for i in `cat /var/log/blacklist.log` ; do
nberreurs1=`cat /var/log/auth.log | grep "illegal" | grep $i | wc -l`
nberreurs2=`cat /var/log/auth.log | grep "invalid" | grep $i | wc -l`
nberreurs3=`cat /var/log/auth.log | grep "Invalid" | grep $i | wc -l`
let nberreurs=$nberreurs1+$nberreurs2+$nberreurs3
#si il y a eu plus de 3 erreurs et que l'ip n'est pas déjà blacklistée et bien on la blackliste !
if [ "$nberreurs" -ge "3" ]
then
if [ "`cat /etc/hosts.allow | grep $i`" = "" ]
then
echo "ALL : $i : deny" >>/etc/hosts.allow
fi
fi
done
J'aimerais avoir votre avis.