[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[fail2ban][Argh!] bidouiller les fichiers système



Une question qui a en réalité plus à voir avec le système qu'avec fail2ban…

Comme ça se produit dans fail2ban, je me lance quand même ici sans HS ;-)

J'ai un paquet de lignes qui ne servent à rien dans mes logs :
# cat fail2ban.log
2015-02-08 06:28:58,509 fail2ban.server : INFO Changed logging target to /var/log/fail2ban.log for Fail2ban v0.8.6 2015-02-08 06:29:04,215 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:04,263 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/access.log 2015-02-08 06:29:04,293 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.error.log 2015-02-08 06:29:04,296 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/error.log 2015-02-08 06:29:04,451 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:04,548 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.error.log 2015-02-08 06:29:04,569 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.error.log 2015-02-08 06:29:04,681 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.error.log 2015-02-08 06:29:04,720 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:04,751 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:04,844 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:04,896 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:04,957 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:27,477 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:38,540 fail2ban.filter : INFO Log rotation detected for /var/log/mail.log 2015-02-08 06:29:38,717 fail2ban.filter : INFO Log rotation detected for /var/log/mail.log 2015-02-08 06:29:38,722 fail2ban.filter : INFO Log rotation detected for /var/log/mail.log 2015-02-08 06:29:39,720 fail2ban.filter : INFO Log rotation detected for /var/log/mail.log 2015-02-08 06:29:39,725 fail2ban.filter : INFO Log rotation detected for /var/log/mail.log 2015-02-08 06:29:39,994 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:29:40,544 fail2ban.filter : INFO Log rotation detected for /var/log/mail.log 2015-02-08 06:31:16,397 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/access.log 2015-02-08 06:31:16,435 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/error.log 2015-02-08 06:33:25,121 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:33:25,976 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:33:26,022 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:33:53,507 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 06:33:54,193 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.access.log 2015-02-08 07:06:44,456 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.error.log 2015-02-08 07:06:44,880 fail2ban.filter : INFO Log rotation detected for /var/log/nginx/$log*.error.log ======================================================================== ================== J'ai un certain nombre de fichiers de logs HTTP différents que j'ai renommés $log*, ça ne vous étonne pas.

Ces lignes d'info ne servent à rien et sont redondantes, la question a été posée et résolue sur Internet :
https://github.com/fail2ban/fail2ban/issues/129

On a un lien vers le correctif dans le tropique du GitHub, et j'ai comparé avec ce que j'ai chez moi :
# locate filter.py
/usr/lib/python2.7/lib2to3/fixes/fix_filter.py
/usr/lib/python2.7/lib2to3/fixes/fix_filter.pyc
/usr/share/fail2ban/server/filter.py

# vi /usr/share/fail2ban/server/filter.py

class FileContainer:

        def __init__(self, filename, tail = False):
                self.__filename = filename
                self.__tail = tail
                self.__handler = None
# Try to open the file. Raises an exception if an error occured.
                handler = open(filename)
                stats = os.fstat(handler.fileno())
                self.__ino = stats.st_ino
                try:
                        firstLine = handler.readline()
                        # Computes the MD5 of the first line.
                        self.__hash = md5sum(firstLine).digest()
# Start at the beginning of file if tail mode is off.
                        if tail:
                                handler.seek(0, 2)
                                self.__pos = handler.tell()
                        else:
                                self.__pos = 0
                finally:
                        handler.close()

        def getFileName(self):
                return self.__filename

        def open(self):
                self.__handler = open(self.__filename)
                # Set the file descriptor to be FD_CLOEXEC
                fd = self.__handler.fileno()
                fcntl.fcntl(fd, fcntl.F_SETFD, fd | fcntl.FD_CLOEXEC)
                firstLine = self.__handler.readline()
                # Computes the MD5 of the first line.
                myHash = md5sum(firstLine).digest()
                stats = os.fstat(self.__handler.fileno())
                # Compare hash and inode
                if self.__hash != myHash or self.__ino != stats.st_ino:
logSys.info("Log rotation detected for %s" % self.__filename)
                        self.__hash = myHash
                        self.__ino = stats.st_ino
                        self.__pos = 0
                # Sets the file pointer to the last position.
                self.__handler.seek(self.__pos)

        def readline(self):
                if self.__handler == None:
                        return ""
                return self.__handler.readline()

        def close(self):
                if not self.__handler == None:
                        # Saves the last position.
                        self.__pos = self.__handler.tell()
                        # Closes the file.
                        self.__handler.close()
                        self.__handler = None
======================================================================== ====================

Apparemment, le correctif n'a pas été implémenté partout, notamment chez moi :
# aptitude show fail2ban
Paquet : fail2ban
Nouveau: oui
État: installé
Automatiquement installé: non
Version : 0.8.6-3wheezy3
Priorité : optionnel
Section : net
Responsable : Yaroslav Halchenko <debian@onerussian.com>
Architecture : all
Taille décompressée : 349 k
Dépend: python (>= 2.4), python-central (>= 0.6.11), lsb-base (>= 2.0-7)
Recommande: iptables, whois, python-gamin
Suggère: mailx
Description : bannit des hôtes qui provoquent plusieurs erreurs d'authentification

# service fail2ban -V
service ver. 0.91-ubuntu1
======================================================================== ===================== … et en plus, je ne comprends pas pourquoi j'ai un bidule Ubuntu pour un paquet téléchargé chez Debian…

L'un des autres fichier est compilé et l'autre ne contient pas la mention qui passe dans mes logs, mais j'imagine qu'ils sont
tous plus ou moins liés entre eux.

Ma question, au fait ? Je redoute de modifier des trucs à l'arrache dans les fichiers système, alors je préfère demander…

Merci d'avance pour vos lumières :-)

Reply to: