Outils pour utilisateurs

Outils du site


linux:fail2ban-apache-antibot

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
linux:fail2ban-apache-antibot [2016/06/09 15:00] gdureuillinux:fail2ban-apache-antibot [2020/07/24 22:03] (Version actuelle) – modification externe 127.0.0.1
Ligne 1: Ligne 1:
 ====== Fail2ban et Apache - Bannir les scans d'url d'administration (antibot) ====== ====== Fail2ban et Apache - Bannir les scans d'url d'administration (antibot) ======
  
-<WRAP center round info 60%>+===== Information ===== 
 + 
 +<WRAP center info 100%>
 Testé sur Debian 8 Testé sur Debian 8
 </WRAP> </WRAP>
Ligne 13: Ligne 15:
 Commencer par installer le package fail2ban Commencer par installer le package fail2ban
  
-<code>+<sxh bash;>
 apt install fail2ban apt install fail2ban
-</code>+</sxh>
  
 ===== Configuration ===== ===== Configuration =====
Ligne 21: Ligne 23:
 Créer le fichier ''/etc/fail2ban/jail.local'' avec ce contenu : Créer le fichier ''/etc/fail2ban/jail.local'' avec ce contenu :
  
-<code>+<sxh text; Title: /etc/fail2ban/jail.local>
 [apache-antibot] [apache-antibot]
 enabled = true enabled = true
 filter = apache-antibot filter = apache-antibot
 port = http,https port = http,https
-#Fichier ou dossier de logs à surveiller +#Fichier ou dossier de logs à surveiller (prends en compte logrotate) 
-logpath = /home/www-data/logs/*.log+logpath = /home/www-data/logs/apache2/*.log*
 # Nombre de match dans les logs avant de bannir # Nombre de match dans les logs avant de bannir
-maxretry = 2+maxretry = 3
 # Période max surveillée # Période max surveillée
 findtime = 432000 findtime = 432000
Ligne 37: Ligne 39:
 #mta = mail #mta = mail
 #destemail = user@email.com #destemail = user@email.com
-#action = %(action_mw)s +#Ban, mail avec whois et log 
-</code>+#action = %(action_mwl)s 
 +#Ban 
 +action = %(action_)s   
 +</sxh>
  
 Adapter la ligne ''logpath'' à vos fichiers de logs. Adapter la ligne ''logpath'' à vos fichiers de logs.
Ligne 46: Ligne 51:
 Créer le fichier ''/etc/fail2ban/filter.d/apache-antibot.conf'' avec ce contenu : Créer le fichier ''/etc/fail2ban/filter.d/apache-antibot.conf'' avec ce contenu :
  
-<code>+<sxh text; Title: /etc/fail2ban/filter.d/apache-antibot.conf>
 #Modifier 'badurls' selon votre besoin #Modifier 'badurls' selon votre besoin
 [Definition] [Definition]
-badurls = phpmyadmin|myadmin|mysql|phpadmin|sql|msd|mysqldumper|sqlite|sqlitemanager|webdb|soapCaller|manager|setup\.php|pma|status|jmx-console|HNAP1+badurls = stat|phpmyadmin|myadmin|mysql|phpadmin|sql|msd|mysqldumper|msd1.24.4|msd1.24.4stable|sqlite|sqlitemanager|webdb|soapCaller|manager|setup\.php|shell.\php|pma|status|jmx-console|HNAP1|wp-config\.txt|wp-config\.orig|wp-config\.php\.orig|wp-config\.old|wp-config\.php\.old|wp-config\.bak|wp-config\.php\.bak|wp-config\.php\.save|wp-config\.php_bak
  
 failregex = ^(?i)<HOST> .* "(GET|POST|HEAD) .*(%(badurls)s).* HTTP.*" (403|404) .*$ failregex = ^(?i)<HOST> .* "(GET|POST|HEAD) .*(%(badurls)s).* HTTP.*" (403|404) .*$
Ligne 55: Ligne 60:
  
 ignoreregex = ignoreregex =
-</code>+</sxh>
  
 Adapter la ligne badurls pour les chemins sur lesquels vous voulez provoquer un ban par iptables. Adapter la ligne badurls pour les chemins sur lesquels vous voulez provoquer un ban par iptables.
Ligne 63: Ligne 68:
 Activation Activation
  
-<code>+<sxh bash;>
 fail2ban-client start apache-antibot fail2ban-client start apache-antibot
-</code>+</sxh>
  
 Vérification des jails actives Vérification des jails actives
  
-<code>+<sxh bash;>
 fail2ban-client status fail2ban-client status
-</code>+</sxh>
  
 Vous pouvez aussi ajouter une IP aux exceptions (utile pour vos tests) Vous pouvez aussi ajouter une IP aux exceptions (utile pour vos tests)
  
-<code>+<sxh bash;>
 fail2ban-client set apache-antibot addignoreip <IP> fail2ban-client set apache-antibot addignoreip <IP>
-</code>+</sxh>
  
 Pour l'enlever : Pour l'enlever :
  
-<code>+<sxh bash;>
 fail2ban-client set apache-antibot delignoreip <IP> fail2ban-client set apache-antibot delignoreip <IP>
-</code>+</sxh>
  
 Redémarrage de fail2ban au besoin : Redémarrage de fail2ban au besoin :
  
-<code>+<sxh bash;>
 service fail2ban restart service fail2ban restart
-</code>+</sxh>
  
 En cas de ban intempestif de votre IP, vous pouvez vous débannir : En cas de ban intempestif de votre IP, vous pouvez vous débannir :
  
-<code>+<sxh bash;>
 fail2ban-client set YOURJAILNAMEHERE unbanip IPADDRESSHERE fail2ban-client set YOURJAILNAMEHERE unbanip IPADDRESSHERE
-</code>+</sxh>
  
 Pour voir les ip en ban actuellement : Pour voir les ip en ban actuellement :
  
-<code>+<sxh bash;>
 iptables -L iptables -L
-</code>+</sxh>
  
 ===== Rapport dans un fichier ===== ===== Rapport dans un fichier =====
Ligne 107: Ligne 112:
 Le script suivant permet de créer un fichier listant les IP bannies et le pays associé. Le script suivant permet de créer un fichier listant les IP bannies et le pays associé.
  
-<code>+<sxh bash;>
 #!/bin/bash #!/bin/bash
  
 fail2ban-client status apache-antibot | grep 'IP list' | sed -n 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' | grep ip | sed 's/ip//'| sort | uniq > /dev/shm/f2b.txt fail2ban-client status apache-antibot | grep 'IP list' | sed -n 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' | grep ip | sed 's/ip//'| sort | uniq > /dev/shm/f2b.txt
 fail2ban-client status apache-antibot | grep 'IP list' | sed -n 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' | grep ip | sed 's/ip//'| sort | uniq | xargs -n 1 geoiplookup { } | sed -e 's/GeoIP Country Edition: //g' > /dev/shm/f2bgeo.txt fail2ban-client status apache-antibot | grep 'IP list' | sed -n 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' | grep ip | sed 's/ip//'| sort | uniq | xargs -n 1 geoiplookup { } | sed -e 's/GeoIP Country Edition: //g' > /dev/shm/f2bgeo.txt
-paste /dev/shm/f2b.txt /dev/shm/f2bgeo.txt > /home/www-data/domain.info/f2b-bans.html +paste /dev/shm/f2b.txt /dev/shm/f2bgeo.txt > /home/www-data/domain.info/f2b-bans.txt 
-sed -i 's/$/<br \/>\n/g/home/www-data/domain.info/f2b-bans.html +</sxh> 
-</code>+ 
 +===== Remarques ===== 
 + 
 +<WRAP center important 100%> 
 +Attention si les fichiers de logs analysés sont affectés par ''logrotate''Ne pas ajouter ''compress'' et ''delay compress''. fail2ban ne sais pas lire les fichier compressés par défaut
 +</WRAP> 
 + 
 +===== Sources =====
  
-[[http://fips.at/how-to-get-rid-of-http-bots-with-fail2ban.html|Source 1]] - [[http://www.fail2ban.org/wiki/index.php/Commands|Source 2]]+[[http://fips.at/how-to-get-rid-of-http-bots-with-fail2ban.html|fips.at]] - [[http://www.fail2ban.org/wiki/index.php/Commands|fail2ban.org]]
linux/fail2ban-apache-antibot.1465484438.txt.gz · Dernière modification : 2020/07/24 22:03 (modification externe)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki