Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 09/07/2013, à 09:37

alfirdaous

[RESOLU]Fail2ban ne bani pas

Bonjour,

J'ai juste configure fail2ban, j'ai trouve qu'il ne bani pas ainsi qu'il n'envoi pas des e-mails alerts, voici les fichiers de configurations:

fichier jail.conf.local:

# Fail2Ban configuration file.
#
# This file was composed for Debian systems from the original one
#  provided now under /usr/share/doc/fail2ban/examples/jail.conf
#  for additional examples.
#
# To avoid merges during upgrades DO NOT MODIFY THIS FILE
# and rather provide your changes in /etc/fail2ban/jail.local
#
# Author: Yaroslav O. Halchenko <debian@onerussian.com>
#
# $Revision$
#

# The DEFAULT allows a global definition of the options. They can be overridden
# in each jail afterwards.

[DEFAULT]

# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1/8
# 100 minutes ban time
bantime  = 6000
maxretry = 3

# "backend" specifies the backend used to get files modification. Available
# options are "gamin", "polling" and "auto".
# yoh: For some reason Debian shipped python-gamin didn't work as expected
#      This issue left ToDo, so polling is default backend for now
backend = polling

#
# Destination email address used solely for the interpolations in
# jail.{conf,local} configuration files.
destemail = alfirdaous@gmail.com

#
# ACTIONS
#
# Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define
# action_* variables. Can be overridden globally or per
# section within jail.local file
banaction = iptables-multiport

# email action. Since 0.8.1 upstream fail2ban uses sendmail
# MTA for the mailing. Change mta configuration parameter to mail
# if you want to revert to conventional 'mail'.
mta = sendmail

# Default protocol
protocol = tcp

# Specify chain where jumps would need to be added in iptables-* actions
chain = INPUT

#
# Action shortcuts. To be used to define action parameter

# The simplest action to take: ban only
action_ = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]

# ban & send an e-mail with whois report to the destemail.
action_mw = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
              %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s"]

# ban & send an e-mail with whois report and relevant log lines
# to the destemail.
action_mwl = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
               %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]

# Choose default action.  To change, just override value of 'action' with the
# interpolation to the chosen action shortcut (e.g.  action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section
action = %(action_)s

#
# JAILS
#
# Next jails corresponds to the standard configuration in Fail2ban 0.6 which
# was shipped in Debian. Enable any defined here jail by including
#
# [SECTION_NAME]
# enabled = true

#
# in /etc/fail2ban/jail.local.
#
# Optionally you may override any other parameter (e.g. banaction,
# action, port, logpath, etc) in that section within jail.local

[ssh]

enabled  = true
port     = 1213
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 3

[dropbear]

enabled  = false
port     = ssh
filter   = sshd
logpath  = /var/log/dropbear
maxretry = 6

# Generic filter for pam. Has to be used with action which bans all ports
# such as iptables-allports, shorewall
[pam-generic]

enabled  = false
# pam-generic filter can be customized to monitor specific subset of 'tty's
filter   = pam-generic
# port actually must be irrelevant but lets leave it all for some possible uses
port     = all
banaction = iptables-allports
port     = anyport
logpath  = /var/log/auth.log
maxretry = 6

[xinetd-fail]

enabled   = false
filter    = xinetd-fail
port      = all
banaction = iptables-multiport-log
logpath   = /var/log/daemon.log
maxretry  = 2


[ssh-ddos]

enabled  = true
port     = 1213
filter   = sshd-ddos
logpath  = /var/log/auth.log
maxretry = 3

#
# HTTP servers
#

[apache]

enabled  = true
port     = http,https
filter   = apache-auth
logpath  = /var/log/apache*/*error.log
maxretry = 3

# default action is now multiport, so apache-multiport jail was left
# for compatibility with previous (<0.7.6-2) releases
[apache-multiport]

enabled   = true
port      = http,https
filter    = apache-auth
logpath   = /var/log/apache*/*error.log
maxretry  = 3

[apache-noscript]

enabled  = true
port     = http,https
filter   = apache-noscript
logpath  = /var/log/apache*/*error.log
maxretry = 3

[apache-overflows]

enabled  = true
port     = http,https
filter   = apache-overflows
logpath  = /var/log/apache*/*error.log
maxretry = 2

#
# FTP servers
#

[vsftpd]

enabled  = false
port     = ftp,ftp-data,ftps,ftps-data
filter   = vsftpd
logpath  = /var/log/vsftpd.log
# or overwrite it in jails.local to be
# logpath = /var/log/auth.log
# if you want to rely on PAM failed login attempts
# vsftpd's failregex should match both of those formats
maxretry = 6


[proftpd]

enabled  = false
port     = ftp,ftp-data,ftps,ftps-data
filter   = proftpd
logpath  = /var/log/proftpd/proftpd.log
maxretry = 6


[pure-ftpd]

enabled  = false
port     = ftp,ftp-data,ftps,ftps-data
filter   = pure-ftpd
logpath  = /var/log/auth.log
maxretry = 6


[wuftpd]

enabled  = false
port     = ftp,ftp-data,ftps,ftps-data
filter   = wuftpd
logpath  = /var/log/auth.log
maxretry = 6


#
# Mail servers
#

[postfix]

enabled  = false
port     = smtp,ssmtp
filter   = postfix
logpath  = /var/log/mail.log


[couriersmtp]

enabled  = true
port     = smtp,ssmtp
filter   = couriersmtp
logpath  = /var/log/mail.log


#
# Mail servers authenticators: might be used for smtp,ftp,imap servers, so
# all relevant ports get banned
#

[courierauth]

enabled  = true
port     = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
filter   = courierlogin
logpath  = /var/log/mail.log


[sasl]

enabled  = false
port     = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
filter   = sasl
# You might consider monitoring /var/log/mail.warn instead if you are
# running postfix since it would provide the same log lines at the
# "warn" level but overall at the smaller filesize.
logpath  = /var/log/mail.log

[dovecot]

enabled = false
port    = smtp,ssmtp,imap2,imap3,imaps,pop3,pop3s
filter  = dovecot
logpath = /var/log/mail.log

# DNS Servers


# These jails block attacks against named (bind9). By default, logging is off
# with bind9 installation. You will need something like this:
#
# logging {
#     channel security_file {
#         file "/var/log/named/security.log" versions 3 size 30m;
#         severity dynamic;
#         print-time yes;
#     };
#     category security {
#         security_file;
#     };
# };
#
# in your named.conf to provide proper logging

# !!! WARNING !!!
#   Since UDP is connection-less protocol, spoofing of IP and imitation
#   of illegal actions is way too simple.  Thus enabling of this filter
#   might provide an easy way for implementing a DoS against a chosen
#   victim. See
#    http://nion.modprobe.de/blog/archives/690-fail2ban-+-dns-fail.html
#   Please DO NOT USE this jail unless you know what you are doing.
#[named-refused-udp]
#
#enabled  = false
#port     = domain,953
#protocol = udp
#filter   = named-refused
#logpath  = /var/log/named/security.log

[named-refused-tcp]

enabled  = false
port     = domain,953
protocol = tcp
filter   = named-refused
logpath  = /var/log/named/security.log

[apache-w00tw00t]
enabled = true
filter = apache-w00tw00t
action = iptables[name=Apache-w00tw00t,port=80,protocol=tcp]
logpath = /var/log/apache2/access*.log
maxretry = 1

[apache-404]
enabled = true
port = http
filter = apache-404
logpath = /var/log/apache*/error*.log
maxretry = 5

Prenons le dernier cas de apache-404, fichier de configuration sur filter.d (apache-404.conf):

# Fail2Ban configuration file
#
# Author: Cyril Jaquier
#
# $Revision: 471 $
#
[Definition]
# Option: failregex
# Notes.: regex to match the password failure messages in the logfile. The
# host must be matched by a group named "host". The tag "" can
# be used for standard IP/hostname matching.
# Values: TEXT
# [client x.x.x.x] File does not exist: /home/www/admin/admin,
failregex = [[]client []] File does not exist: .*
#
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =

var/log/apache2/error.log:

[Tue Jul 09 09:35:15 2013] [error] [client IP] File does not exist: /home/alfirdaous/www/Audio
[Tue Jul 09 09:35:15 2013] [error] [client IP] File does not exist: /home/alfirdaous/www/Audio
[Tue Jul 09 09:35:15 2013] [error] [client IP] File does not exist: /home/alfirdaous/www/Images
[Tue Jul 09 09:35:15 2013] [error] [client IP] File does not exist: /home/alfirdaous/www/Audio
[Tue Jul 09 09:35:15 2013] [error] [client IP] File does not exist: /home/alfirdaous/www/Video
[Tue Jul 09 09:35:18 2013] [error] [client IP] File does not exist: /home/alfirdaous/www/Audio
[Tue Jul 09 09:35:18 2013] [error] [client IP] File does not exist: /home/alfirdaous/www/Audio

Bien sur que fail2ban etait redemarrer et actif.

IPTables:

iptables -L
// les protocoles INPUT ..

Chain fail2ban-ssh (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere  

Merci a vous

Dernière modification par alfirdaous (Le 12/07/2013, à 09:44)

Hors ligne

#2 Le 09/07/2013, à 10:11

tiramiseb

Re : [RESOLU]Fail2ban ne bani pas

Salut,

Je ne connais pas du tout fail2ban, par contre ta regex me semble étrange...

[[]client []] File does not exist: .*

C'est quoi ce "[[]client []]" ?

J'ai l'impression que dans tes fichiers tout ce qui est entre "< ... >" a été perdu (il n'y a rien qu'à voir la description que tu cites : « The tag "" can be used for standard IP/hostname matching. » ça ne veut rien dire).
D'ailleurs si on cherche un peu sur Internet c'est bien ce qu'on retrouve : le même contenu avec des informations entre "< ... >". Tu as copié-collé ce contenu à partir d'un site pourri ?

Ce serait plutôt quelque chose dans ce genre-là :

failregex = [client <HOST>] File does not exist: .*

On retrouve sur Internet la syntaxe suivante, mais je n'en comprends pas l'intérêt :

failregex = [[]client <HOST>[]] File does not exist: .*

Mais bon, comme dit, je ne connais pas fail2ban, cette forme est peut-être indispensable.

Dernière modification par tiramiseb (Le 09/07/2013, à 10:12)

Hors ligne

#3 Le 09/07/2013, à 21:36

tcham

Re : [RESOLU]Fail2ban ne bani pas

Bonsoir,

pour infos  [apache-overflows] fait ce que tu recherche.

failregex = ^%(_apache_error_client)s (Invalid (method|URI) in request|request failed: URI too long|erroneous characters after protocol string)

tu dois changer:

action = %(action_)s
en
action = %(action_mwl)s

la commande sudo fail2ban-client status te donne quoi ?

sinon pour l'envoi de mail j'utilise sendmail (ssmtp) parfois c'est un peu chaotique je cherche actuellement a corriger les envoi de mail vers mon mail perso

j'ai trouvé avec aliasies mais j'attend quelques jours avant de dire que ça marche.

Hors ligne

#4 Le 10/07/2013, à 02:48

alfirdaous

Re : [RESOLU]Fail2ban ne bani pas

meme si j'essai avec ssh de se connecter d'une autre machine avec des donnees erronees, ca ne bani pas:

fail2ban-client status
Status
|- Number of jail:	1
`- Jail list:		ssh

Hors ligne

#5 Le 10/07/2013, à 12:27

pires57

Re : [RESOLU]Fail2ban ne bani pas

c'est peut être simplement que ta syntaxe n'est pas bonne.
moi j'ai ceci, compare avec tes lignes

# SSH 
# 3 retry > Ban 5 minutes
[ssh]
 
enabled = true
port    = ssh
filter    = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
logpath  = /var/log/auth.log
maxretry = 3
bantime = 300

Utilisateur d'Archlinux, Ubuntu et Kali Linux
Administrateur système et réseau spécialisé Linux.
LinkedIn

Hors ligne

#6 Le 12/07/2013, à 07:32

alfirdaous

Re : [RESOLU]Fail2ban ne bani pas

j'ai teste avec l'erreur 404 et la regex donnee par tiramiseb:

jail.conf.local

[apache-404]
enabled = true
port = http
filter = apache-404
logpath = /var/log/apache*/error*.log
maxretry = 3

apache-404:

# Fail2Ban configuration file
#
# Author: Cyril Jaquier
#
# $Revision: 471 $
#
[Definition]
# Option: failregex
# Notes.: regex to match the password failure messages in the logfile. The
# host must be matched by a group named "host". The tag "" can
# be used for standard IP/hostname matching.
# Values: TEXT
# [client x.x.x.x] File does not exist: /home/www/admin/admin,
failregex = [[]client []] File does not exist: .*
#
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =

Toujours ca marche pas
PS: Sachant que jail.conf a ete copie en jail.conf.local

Hors ligne

#7 Le 12/07/2013, à 08:14

bruno

Re : [RESOLU]Fail2ban ne bani pas

Ton fichier doit s’appeler jail.local, avec jail.conf.local je ne suis pas sûr que cela marche…
La regex d'origine était correcte (pour prendre en compte les crochets [] présents dans les logs). Si tu as un doute utilise fail2ban-regex pour tester (-h pour connaître la syntaxe), par exemple  :

fail2ban-regex /var/log/apache2/error.log /etc/fail2ban/filter.d/apache-404.conf

Hors ligne

#8 Le 12/07/2013, à 08:25

alfirdaous

Re : [RESOLU]Fail2ban ne bani pas

ici ils disent que c'est jail.conf.local

quand je fais le nom jail.local, et je fais www.site.com/404, le navigateur passe tout le temps tournant, sans s'arretter, j'ai consule le log: /var/log/fail2ban.log

2013-07-12 08:24:48,409 fail2ban.actions: WARNING [apache-404] Ban MON_IP

Est ce que c'est due au ban??

J'ai essaye de supprimer l'IP:

iptables -A INPUT -s MON_IP -j DROP

Essayer de voir le ban liste: je trouve que MON_IP est toujours la dans

iptables -L
Chain INPUT (policy DROP)
DROP       all  --  41.251.192.124       anywhere            

Chain FORWARD (policy DROP)

Chain fail2ban-apache-404 (1 references)
target     prot opt source               destination         
DROP       all  --  MON_IP       anywhere            

Dernière modification par alfirdaous (Le 12/07/2013, à 08:35)

Hors ligne

#9 Le 12/07/2013, à 08:41

bruno

Re : [RESOLU]Fail2ban ne bani pas

Et tu préfères faire confiance à un blog plutôt qu'à la documentation officielle ?!

Premières lignes du fichier jail.conf fourni par Debian/Ubuntu :

# Fail2Ban configuration file.
#
# This file was composed for Debian systems from the original one
# provided now under /usr/share/doc/fail2ban/examples/jail.conf
# for additional examples.
#
# Comments: use '#' for comment lines and ';' for inline comments
#
# To avoid merges during upgrades DO NOT MODIFY THIS FILE
# and rather provide your changes in /etc/fail2ban/jail.local
#

Je traduit les 2 dernières lignes :

Pour éviter un écrasement lors d'une mise à jour NE MODIFIEZ PAS CE FICHIER, faites plutôt vos modifications dans /etc/fail2ban/jail.local


Et la doc officielle : http://www.fail2ban.org/wiki/index.php/ … figuration

Extrait :

Every .conf file can be overridden with a file named .local. 

Chaque fichier .conf peut être surchargé par un fichier .local.

Autrement dit jail.conf peut être surchargé par jail.local. AMHA ton fichier jail.conf.local n'est pas interprété.

Hors ligne

#10 Le 12/07/2013, à 08:48

bruno

Re : [RESOLU]Fail2ban ne bani pas

Ok c'était donc bien un problème de nom de fichier.

Pour la suite je t'invite à lire les docs sur iptables.

Pour te débloquer supprimes toutes les règles iptables :

sudo iptables -F

et relance fail2ban :

sudo service fail2ban restart

Au final je ne vois pas bien l’intérêt de bloquer les utilisateurs sur l'erreur 404… Je trouve même cela plutôt risqué (la preuve smile)

Dernière modification par bruno (Le 12/07/2013, à 08:48)

Hors ligne

#11 Le 12/07/2013, à 08:55

alfirdaous

Re : [RESOLU]Fail2ban ne bani pas

c'est juste un test efficace de fail2ban, je vais pas la mettre, merci bruno, une toute petite chose, je recois pas de notification en cas de ban:

jail.local:

# Destination email address used solely for the interpolations in
# jail.{conf,local} configuration files.
destemail = alfirdaous@gmail.com

action = %(action_mw)s

Hors ligne

#12 Le 12/07/2013, à 09:18

bruno

Re : [RESOLU]Fail2ban ne bani pas

Pour les notifications par courriel, il faut que tu vérifies que tu as un MTA (sendmail) installé sur ta machine et qu'il peut envoyer des courriels vers l'extérieur (sur ton adresse gmail).

Hors ligne

#13 Le 12/07/2013, à 09:27

alfirdaous

Re : [RESOLU]Fail2ban ne bani pas

merci je vais voir ca, ce n'est pas trop important, peut etre le fait de les ajouter dans une BDD serait mieux

Hors ligne