Axiso

Notes

Fail2ban – Commandes et notes

En vrac — novembre 2011

Identification FTP

Une adresse distante peut tenter de se connecter à de multiples occasions au serveur FTP. Que ce soit volontaire ou non, ceci engendre un cumul d’alertes dans le journal du serveur :

Nov 1 01:02:03 serveur pure-ftpd: (?@111.222.333.444) [WARNING] Sorry, cleartext sessions are not accepted on this server.#012Please reconnect using SSL/TLS security mechanisms.

Pour bloquer ce serveur distant parasite avec Fail2ban :

echo -e '[Definition]

__errmsg = (?:Authentication failed for user|Sorry, cleartext sessions are not accepted on this server)

failregex = pure-ftpd: \(.+?@\) \[WARNING\] %(__errmsg)s.*$

ignoreregex =' > /etc/fail2ban/filter.d/pure-ftpd.conf

echo -e '[pure-ftpd]

enabled  = true
port     = ftp,ftp-data,ftps,ftps-data
filter   = pure-ftpd
logpath  = /var/log/syslog
maxretry = 6' >> /etc/fail2ban/jail.conf
/etc/init.d/fail2ban reload

Une fois que Fail2ban aura détecté des alertes répétées correspondant au filtre mis en place, il activera la protection et l’indiquera dans son propre journal.

tail /var/log/fail2ban.log
fail2ban.actions: WARNING [pure-ftpd] Ban 203.126.99.218

Fail2ban au lancement de Iptables

En vrac — août 2011 ,

Si un arrêt du service Iptables ou un chargement de ses règles est nécessaire alors que Fail2ban est utilisé sur le système, ne pas oublier de relancer ce dernier après Iptables afin qu’il initialise à nouveaux ses propres règles.

Situation initale :

iptables -L
Chain INPUT (policy ACCEPT) target  prot opt source  destination fail2ban-ssh  tcp  --  anywhere  anywhere  multiport dports ssh,10022 ACCEPT  all  --  anywhere  anywhere REJECT  all  --  anywhere  loopback/8  reject-with icmp-port-unreachable ACCEPT  all  --  anywhere  anywhere  state RELATED,ESTABLISHED ACCEPT  all  --  loopback/8  loopback/8 ACCEPT  tcp  --  anywhere  anywhere  tcp dpt:ftp … Chain fail2ban-ssh (1 references) target  prot opt source  destination RETURN  all  --  anywhere  anywhere

Effacement et exemple de chargement des règles de Iptables :

iptables -F
iptables-restore < /etc/iptables/iptables-start-source
iptables -L
Chain INPUT (policy ACCEPT) target  prot opt source  destination ACCEPT  all  --  anywhere  anywhere REJECT  all  --  anywhere  loopback/8  reject-with icmp-port-unreachable ACCEPT  all  --  anywhere  anywhere  state RELATED,ESTABLISHED ACCEPT  all  --  loopback/8  loopback/8 ACCEPT  tcp  --  anywhere  anywhere  tcp dpt:ftp

Fail2ban n’étant plus actif, le charger à nouveau :

/etc/init.d/fail2ban reload
iptables -L
Chain INPUT (policy ACCEPT) target  prot opt source  destination fail2ban-ssh  tcp  --  anywhere  anywhere  multiport dports ssh,10022 ACCEPT  all  --  anywhere  anywhere REJECT  all  --  anywhere  loopback/8  reject-with icmp-port-unreachable ACCEPT  all  --  anywhere  anywhere  state RELATED,ESTABLISHED ACCEPT  all  --  loopback/8  loopback/8 ACCEPT  tcp  --  anywhere  anywhere  tcp dpt:ftp … Chain fail2ban-ssh (1 references) target  prot opt source  destination RETURN  all  --  anywhere  anywhere