Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
elearning:workbooks:centos:6:avance:l107 [2023/02/15 15:48] – removed admin | elearning:workbooks:centos:6:avance:l107 [2023/02/15 15:56] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ~~PDF: | ||
+ | Version : **2021.01** | ||
+ | |||
+ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
+ | |||
+ | ======LCF306 - Gestion de l' | ||
+ | |||
+ | =====Contenu du Module===== | ||
+ | |||
+ | * **LCF306 - Gestion de l' | ||
+ | * Contenu du Module | ||
+ | * Le Problématique | ||
+ | * LAB #1 - John the Ripper | ||
+ | * Surveillance Sécuritaire | ||
+ | * La commande last | ||
+ | * La commande lastlog | ||
+ | * La Commande lastb | ||
+ | * / | ||
+ | * Les Contre-Mesures | ||
+ | * LAB #2 - Renforcer la sécurité des comptes | ||
+ | * LAB #3 - PAM sous RHEL/CentOS 7 | ||
+ | * Bloquer un Compte après N Echecs de Connexion | ||
+ | * Configuration | ||
+ | * LAB #4 - Mise en place du Système de Prévention d' | ||
+ | * Installation | ||
+ | * Configuration | ||
+ | * Le répertoire / | ||
+ | * Le fichier fail2ban.conf | ||
+ | * Le répertoire / | ||
+ | * Le répertoire / | ||
+ | * Commandes | ||
+ | * Activer et Démarrer le Serveur | ||
+ | * Utiliser la Commande Fail2Ban-server | ||
+ | * Ajouter un Prison | ||
+ | |||
+ | =====Le Problématique===== | ||
+ | |||
+ | Un pirate peut utiliser un logiciel de **crackage** pour tenter de découvrir un mot de passe. Le plus connu est **[[http:// | ||
+ | |||
+ | Le principe de ces logiciels est simples - le logiciel utilise des dictionnaires de mots de passe qui sont utilisés le uns après les autres à une vitesse qui peut atteindre des milliers par seconde. | ||
+ | |||
+ | ====LAB #1 - John the Ripper==== | ||
+ | |||
+ | ===Installation=== | ||
+ | |||
+ | Créez le script suivant dans un terminal de RHEL/CentOS 7 en tant que root : | ||
+ | |||
+ | < | ||
+ | [trainee@centos7 ~]$ su - | ||
+ | Password: fenestros | ||
+ | Last login: Mon Apr 23 17:23:14 CEST 2018 on tty1 | ||
+ | [root@centos7 ~]# vi john.sh | ||
+ | [root@centos7 ~]# cat john.sh | ||
+ | #!/bin/bash | ||
+ | # Centos 7 John the Ripper Installation | ||
+ | yum -y install wget gpgme | ||
+ | yum -y group install " | ||
+ | cd | ||
+ | wget http:// | ||
+ | wget http:// | ||
+ | wget http:// | ||
+ | gpg --import openwall-signatures.asc | ||
+ | gpg --verify john-1.8.0.tar.xz.sign | ||
+ | tar xvfJ john-1.8.0.tar.xz | ||
+ | cd john-1.8.0/ | ||
+ | make clean linux-x86-64 | ||
+ | cd ../run/ | ||
+ | ./john --test | ||
+ | #password dictionnary download | ||
+ | wget -O - http:// | ||
+ | </ | ||
+ | |||
+ | Rendez-le exécutable : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# chmod u+x john.sh | ||
+ | </ | ||
+ | |||
+ | Exécutez le script : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# ./ | ||
+ | </ | ||
+ | |||
+ | ===Utilisation=== | ||
+ | |||
+ | Placez-vous dans le répertoire **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# cd john-1.8.0/ | ||
+ | </ | ||
+ | |||
+ | Utilisez l' | ||
+ | |||
+ | < | ||
+ | [root@centos7 run]# ./unshadow /etc/passwd /etc/shadow > mypasswd | ||
+ | </ | ||
+ | |||
+ | Consultez le fichier **mypasswd** : | ||
+ | |||
+ | < | ||
+ | [root@centos7 run]# cat mypasswd | ||
+ | root: | ||
+ | bin: | ||
+ | daemon: | ||
+ | adm: | ||
+ | lp: | ||
+ | sync: | ||
+ | shutdown: | ||
+ | halt: | ||
+ | mail: | ||
+ | operator: | ||
+ | games: | ||
+ | ftp: | ||
+ | nobody: | ||
+ | avahi-autoipd: | ||
+ | systemd-bus-proxy: | ||
+ | systemd-network: | ||
+ | dbus: | ||
+ | polkitd: | ||
+ | abrt: | ||
+ | usbmuxd: | ||
+ | colord: | ||
+ | libstoragemgmt: | ||
+ | setroubleshoot: | ||
+ | rpc: | ||
+ | rtkit: | ||
+ | chrony: | ||
+ | unbound: | ||
+ | tss: | ||
+ | geoclue: | ||
+ | ntp: | ||
+ | sssd: | ||
+ | rpcuser: | ||
+ | nfsnobody: | ||
+ | pulse: | ||
+ | gdm: | ||
+ | gnome-initial-setup: | ||
+ | avahi: | ||
+ | postfix: | ||
+ | sshd: | ||
+ | tcpdump: | ||
+ | trainee: | ||
+ | vboxadd: | ||
+ | </ | ||
+ | |||
+ | Lancez **john** pour craquer le fichier **mypasswd** : | ||
+ | |||
+ | < | ||
+ | [root@centos7 run]# ./john mypasswd | ||
+ | Loaded 2 password hashes with 2 different salts (crypt, generic crypt(3) [?/64]) | ||
+ | Press ' | ||
+ | trainee | ||
+ | 1g 0:00:00:26 4% 2/3 0.03831g/s 230.1p/s 230.2c/s 230.2C/s Hanson..Kristine | ||
+ | 1g 0:00:00:27 4% 2/3 0.03658g/s 230.3p/s 230.4c/s 230.4C/s Ruthless..Tanner | ||
+ | 1g 0:00:00:28 4% 2/3 0.03549g/s 230.3p/s 230.3c/s 230.3C/s Bonjour..Blessing | ||
+ | 1g 0:00:00:36 5% 2/3 0.02775g/s 230.6p/s 230.7c/s 230.7C/s dances..olivias | ||
+ | 1g 0:00:01:14 10% 2/3 0.01348g/s 231.2p/s 231.2c/s 231.2C/s rabbitrabbit..dennisdennis | ||
+ | 1g 0:00:01:16 11% 2/3 0.01311g/s 231.1p/s 231.2c/s 231.2C/s grahamgraham..sharkshark | ||
+ | 1g 0:00:01:18 11% 2/3 0.01277g/s 231.2p/s 231.2c/s 231.2C/s reggiereggie..vickivicki | ||
+ | 1g 0:00:01:19 11% 2/3 0.01263g/s 231.1p/s 231.1c/s 231.1C/s javierjavier..melvinmelvin | ||
+ | 1g 0:00:01:20 12% 2/3 0.01244g/s 231.2p/s 231.2c/s 231.2C/s goldengolden..dixondixon | ||
+ | 1g 0:00:01:21 12% 2/3 0.01231g/s 231.2p/s 231.2c/s 231.2C/s obiwanobiwan..bytemebyteme | ||
+ | 1g 0:00:01:22 12% 2/3 0.01218g/s 231.1p/s 231.1c/s 231.1C/s suzysuzy..raeb | ||
+ | 1g 0:00:01:23 12% 2/3 0.01200g/s 231.1p/s 231.2c/s 231.2C/s xilef..ognimalf | ||
+ | 1g 0:00:01:24 12% 2/3 0.01188g/s 231.1p/s 231.2c/s 231.2C/s auhsoj..trebreh | ||
+ | 1g 0:00:01:25 12% 2/3 0.01171g/s 231.2p/s 231.2c/s 231.2C/s namgib..lareneg | ||
+ | 1g 0:00:02:34 21% 2/3 0.006482g/s 231.2p/s 231.2c/s 231.2C/s tinker3..ashraf3 | ||
+ | [q] < | ||
+ | Use the " | ||
+ | Session aborted | ||
+ | </ | ||
+ | |||
+ | Consultez la liste des mots de passe craqués : | ||
+ | |||
+ | < | ||
+ | [root@centos7 run]# ./john --show mypasswd | ||
+ | trainee: | ||
+ | |||
+ | 1 password hash cracked, 1 left | ||
+ | </ | ||
+ | |||
+ | =====Surveillance Sécuritaire===== | ||
+ | |||
+ | ====La commande last==== | ||
+ | |||
+ | Cette commande indique les dates et heures des connexions des utilisateurs à partir du contenu du fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# last | ||
+ | trainee | ||
+ | trainee | ||
+ | trainee | ||
+ | trainee | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | reboot | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | trainee | ||
+ | (unknown :0 : | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | (unknown :0 : | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | (unknown :0 : | ||
+ | reboot | ||
+ | trainee | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | (unknown :0 : | ||
+ | reboot | ||
+ | trainee | ||
+ | trainee | ||
+ | trainee | ||
+ | trainee | ||
+ | trainee | ||
+ | (unknown :0 : | ||
+ | reboot | ||
+ | |||
+ | wtmp begins Sat Apr 30 11:43:38 2016 | ||
+ | </ | ||
+ | |||
+ | ====La commande lastlog==== | ||
+ | |||
+ | Cette commande indique les dates et heures de la connexion au système la plus récente des utilisateurs : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# lastlog | ||
+ | Username | ||
+ | root | ||
+ | bin **Never logged in** | ||
+ | daemon | ||
+ | adm **Never logged in** | ||
+ | lp | ||
+ | sync | ||
+ | shutdown | ||
+ | halt | ||
+ | mail | ||
+ | operator | ||
+ | games **Never logged in** | ||
+ | ftp **Never logged in** | ||
+ | nobody | ||
+ | avahi-autoipd | ||
+ | systemd-bus-proxy | ||
+ | systemd-network | ||
+ | dbus | ||
+ | polkitd | ||
+ | abrt | ||
+ | usbmuxd | ||
+ | colord | ||
+ | libstoragemgmt | ||
+ | setroubleshoot | ||
+ | rpc **Never logged in** | ||
+ | rtkit **Never logged in** | ||
+ | chrony | ||
+ | unbound | ||
+ | tss **Never logged in** | ||
+ | geoclue | ||
+ | ntp **Never logged in** | ||
+ | sssd | ||
+ | rpcuser | ||
+ | nfsnobody | ||
+ | pulse **Never logged in** | ||
+ | gdm :0 Sat Apr 30 15:22:30 +0200 2016 | ||
+ | gnome-initial-setup | ||
+ | avahi **Never logged in** | ||
+ | postfix | ||
+ | sshd | ||
+ | tcpdump | ||
+ | trainee | ||
+ | vboxadd | ||
+ | snort **Never logged in** | ||
+ | apache | ||
+ | </ | ||
+ | |||
+ | ====La Commande lastb==== | ||
+ | |||
+ | Cette commande indique les dates et heures des connexions infructueueses des utilisateurs à partir du contenu du fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# lastb | ||
+ | root | ||
+ | |||
+ | btmp begins Tue Jun 19 16:37:18 2018 | ||
+ | </ | ||
+ | |||
+ | ====/ | ||
+ | |||
+ | Sous RHEL/CentOS ce fichier contient la journalisation des opérations de gestion des authentifications : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# tail -n 15 / | ||
+ | Jun 19 22:03:57 centos7 polkitd[532]: | ||
+ | Jun 19 22:04:06 centos7 polkitd[532]: | ||
+ | Jun 19 22:04:07 centos7 polkitd[532]: | ||
+ | Jun 19 23:45:43 centos7 su: pam_unix(su-l: | ||
+ | Jun 19 23:46:13 centos7 su: pam_unix(su-l: | ||
+ | Jun 19 23:48:25 centos7 su: pam_unix(su-l: | ||
+ | Jun 19 23:48:25 centos7 su: pam_unix(su-l: | ||
+ | Jun 19 23:52:22 centos7 su: pam_unix(su-l: | ||
+ | Jun 19 23:52:27 centos7 su: pam_unix(su-l: | ||
+ | Jun 19 23:54:35 centos7 su: pam_unix(su-l: | ||
+ | Jun 19 23:55:33 centos7 su: pam_unix(su-l: | ||
+ | Jun 20 00:01:21 centos7 su: pam_unix(su-l: | ||
+ | Jun 20 00:01:50 centos7 su: pam_unix(su-l: | ||
+ | Jun 20 00:01:53 centos7 su: pam_unix(su-l: | ||
+ | Jun 20 00:02:19 centos7 su: pam_unix(su-l: | ||
+ | </ | ||
+ | |||
+ | =====Les Contre-Mesures===== | ||
+ | |||
+ | Les contre-mesures incluent le renforcement de la sécurité des comptes et l' | ||
+ | |||
+ | ====LAB #2 - Renforcer la sécurité des comptes==== | ||
+ | |||
+ | Passez en revue le fichier **/ | ||
+ | |||
+ | < | ||
+ | root: | ||
+ | bin: | ||
+ | daemon: | ||
+ | adm: | ||
+ | lp: | ||
+ | sync: | ||
+ | shutdown: | ||
+ | halt: | ||
+ | mail: | ||
+ | uucp: | ||
+ | operator: | ||
+ | games: | ||
+ | gopher: | ||
+ | ftp: | ||
+ | nobody: | ||
+ | dbus: | ||
+ | usbmuxd: | ||
+ | avahi-autoipd: | ||
+ | vcsa: | ||
+ | rpc: | ||
+ | rtkit: | ||
+ | abrt: | ||
+ | nscd: | ||
+ | tcpdump: | ||
+ | haldaemon: | ||
+ | apache: | ||
+ | nslcd: | ||
+ | saslauth: | ||
+ | postfix: | ||
+ | avahi: | ||
+ | ntp: | ||
+ | rpcuser: | ||
+ | nfsnobody: | ||
+ | sshd: | ||
+ | pulse: | ||
+ | gdm: | ||
+ | trainee: | ||
+ | vboxadd: | ||
+ | prison: | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** : Notez que la valeur de l'UID de root est toujours de 0. Notez cependant que sous RHEL 5 et 6 les UID des utilisateurs normaux commencent à **500** et les UID des comptes système sont inclus entre 1 et 99 par convention. Sous RHEL 7, les UID des utilisateurs normaux commencent à **1000** et les UID des comptes système sont inclus entre 201 et 999. Sous Debian 6, 7 et 8 les UID des utilisateurs normaux commencent à **1000** et les UID des comptes système sont inclus entre 100 et 999 par convention. Sous openSUSE, les UID des utilisateurs normaux commencent à **1000** et les UID des comptes système sont inclus entre 100 et 499. Sous Ubuntu 14.04 les UID des utilisateurs normaux commencent à **1000** et les UID des comptes système sont inclus entre 100 et 999. | ||
+ | </ | ||
+ | |||
+ | Chaque ligne est constituée de 7 champs : | ||
+ | |||
+ | * Le nom d' | ||
+ | * Le mot de passe. Une valeur de **x** dans ce champs indique que le système utilise le fichier **/ | ||
+ | * L'UID. Une valeur unique qui est utilisée pour déterminée les droits aux fichiers et aux répertoires. | ||
+ | * Le GID. Une valeur indiquant le groupe **principal** de l' | ||
+ | * Le nom complet. Ce champs optionnel est aussi appelé **GECOS** | ||
+ | * Le répertoire personnel de l' | ||
+ | * Le shell de l' | ||
+ | |||
+ | Notez d' | ||
+ | |||
+ | < | ||
+ | lp: | ||
+ | </ | ||
+ | |||
+ | Supprimez donc les utilisateurs et groupes inutiles en utilisant des commandes telles: | ||
+ | |||
+ | # userdel -r lp [Entree] | ||
+ | |||
+ | # groupdel lp [Entree] | ||
+ | |||
+ | Pour les utilisateurs restants, utilisez le système de shadowing : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# cat /etc/shadow | ||
+ | root: | ||
+ | bin: | ||
+ | daemon: | ||
+ | adm: | ||
+ | lp: | ||
+ | sync: | ||
+ | shutdown: | ||
+ | halt: | ||
+ | mail: | ||
+ | operator: | ||
+ | games: | ||
+ | ftp: | ||
+ | nobody: | ||
+ | avahi-autoipd: | ||
+ | systemd-bus-proxy: | ||
+ | systemd-network: | ||
+ | dbus: | ||
+ | polkitd: | ||
+ | abrt: | ||
+ | usbmuxd: | ||
+ | colord: | ||
+ | libstoragemgmt: | ||
+ | setroubleshoot: | ||
+ | rpc: | ||
+ | rtkit: | ||
+ | chrony: | ||
+ | unbound: | ||
+ | tss: | ||
+ | geoclue: | ||
+ | ntp: | ||
+ | sssd: | ||
+ | rpcuser: | ||
+ | nfsnobody: | ||
+ | pulse: | ||
+ | gdm: | ||
+ | gnome-initial-setup: | ||
+ | avahi: | ||
+ | postfix: | ||
+ | sshd: | ||
+ | tcpdump: | ||
+ | trainee: | ||
+ | vboxadd: | ||
+ | </ | ||
+ | |||
+ | Chaque ligne est constituée de 8 champs : | ||
+ | |||
+ | * Le nom de l' | ||
+ | * Le mot de passe **crypté** de l' | ||
+ | * **!!** - Le mot de passe n'a pas encore été défini et l' | ||
+ | * ***** - L' | ||
+ | * **vide** - aucun mot de passe sera demandé pour l' | ||
+ | * Le nombre de jours entre le **01/ | ||
+ | * Le nombre de jours que le mot de passe est encore valide. Une valeur de **0** dans ce champs indique sue le mot de passe n' | ||
+ | * Le nombre de jours après lequel le mot de passe doit être changé, | ||
+ | * Le nombre de jours avant la date de modification forcée que l' | ||
+ | * Le nombre de jours après l' | ||
+ | * Le **numéro** du jour après le **01/ | ||
+ | |||
+ | =====LAB #3 - PAM sous RHEL/CentOS 7===== | ||
+ | |||
+ | **PAM** ( //Pluggable Authentification Modules// ou Modules d' | ||
+ | |||
+ | Les fichiers de configuration se trouvent dans le répertoire **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# ls /etc/pam.d | ||
+ | atd | ||
+ | chfn other smtp.postfix | ||
+ | chsh passwd | ||
+ | config-util | ||
+ | crond | ||
+ | cups pluto sudo-i | ||
+ | fingerprint-auth | ||
+ | fingerprint-auth-ac | ||
+ | gdm-autologin | ||
+ | gdm-fingerprint | ||
+ | gdm-launch-environment | ||
+ | gdm-password | ||
+ | gdm-pin | ||
+ | gdm-smartcard | ||
+ | ksu | ||
+ | liveinst | ||
+ | </ | ||
+ | |||
+ | Ces fichiers ont une structure spécifique et sont nommés d' | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# ls / | ||
+ | pam_access.so | ||
+ | pam_cap.so | ||
+ | pam_chroot.so | ||
+ | pam_console.so | ||
+ | pam_cracklib.so | ||
+ | pam_debug.so | ||
+ | pam_deny.so | ||
+ | pam_echo.so | ||
+ | pam_env.so | ||
+ | pam_exec.so | ||
+ | pam_faildelay.so | ||
+ | pam_faillock.so | ||
+ | pam_filter | ||
+ | pam_filter.so | ||
+ | pam_fprintd.so | ||
+ | pam_ftp.so | ||
+ | pam_gnome_keyring.so | ||
+ | pam_group.so | ||
+ | pam_issue.so | ||
+ | pam_keyinit.so | ||
+ | pam_krb5 | ||
+ | </ | ||
+ | |||
+ | Les modules les plus importants sont : | ||
+ | |||
+ | ^ Module ^ Description ^ | ||
+ | | pam_access.so | Ce module est utilisé pour interdire l' | ||
+ | | pam_echo.so | Ce module présente le contenu du fichier passé en argument à tout utilisateur lors de sa connexion. | | ||
+ | | pam_limits.so | Ce module implémente les limites des ressources détaillées dans le fichier **/ | ||
+ | | pam_listfile.so | Ce module est utilisé pour consulter un fichier spécifique pour vérifier les authiorisations. Par exemple, le service ftp utilise ce module pour consulter le fichier **/ | ||
+ | | pam_nologin.so | Ce module interdit les connexions d' | ||
+ | | pam_pwquality.so | Ce module est utilisé pour vérifier la qualité du mot de passe d'un utilisateur | | ||
+ | | pam_securetty.so | Ce module interdit des connexions de root à partir des périphériques tty qui ne sont pas listés dans le fichier **/ | ||
+ | | pam_unix.so | Ce module est utilisé pour vérifier les informations suivantes ; expire, last_change, | ||
+ | |||
+ | Chaque fichier dans /etc/pam.d contient les règles PAM utilisées pendant l' | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# cat / | ||
+ | #%PAM-1.0 | ||
+ | auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so | ||
+ | auth | ||
+ | auth | ||
+ | account | ||
+ | account | ||
+ | password | ||
+ | # pam_selinux.so close should be the first session rule | ||
+ | session | ||
+ | session | ||
+ | session | ||
+ | # pam_selinux.so open should only be followed by sessions to be executed in the user context | ||
+ | session | ||
+ | session | ||
+ | session | ||
+ | session | ||
+ | session | ||
+ | -session | ||
+ | </ | ||
+ | |||
+ | La première ligne de ce fichier est un commentaire qui spécifie que le fichier est conforme à la spécification PAM 1.0. | ||
+ | |||
+ | Ce fichier, tout comme les autres, est ensuite structuré de la façon suivante : | ||
+ | |||
+ | * Une module par ligne, | ||
+ | * Quatre champs séparés par un espace dans chaque règle dont les trois premières sont obligatoires. | ||
+ | |||
+ | Le **premier champs** est le //**type de module**//. Il en existe quatre : | ||
+ | |||
+ | ^ Type ^ Description ^ | ||
+ | | **auth** | Utilisé pour authentifier un utilisateur ou les pré-requis système ( par exemple / | ||
+ | | **account** | Utilisé pour vérifier si l' | ||
+ | | **password** | Utilisé pour vérifier si l' | ||
+ | | **session** | Utilisé pour gérer la session après l' | ||
+ | |||
+ | Le **deuxième champs** est le // | ||
+ | |||
+ | ^ Control-flag ^ Description ^ | ||
+ | | **required** | La réussite de ce module est indispensable. L' | ||
+ | | **requisite** | La réussite de ce module est indispensable. L' | ||
+ | | **sufficient** | La réussite de ce module est suffisant pour authoriser l' | ||
+ | | **optional** | La réussite ou l' | ||
+ | | **include** | Ce control-flag permet d' | ||
+ | |||
+ | Le **troisième champs** stipule le // | ||
+ | |||
+ | Le **quatrième champs** contient éventuellement les **arguments**. | ||
+ | |||
+ | Ouvrez maintenant le fichier **password-auth-ac** : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# cat / | ||
+ | #%PAM-1.0 | ||
+ | # This file is auto-generated. | ||
+ | # User changes will be destroyed the next time authconfig is run. | ||
+ | auth required | ||
+ | auth sufficient | ||
+ | auth requisite | ||
+ | auth required | ||
+ | |||
+ | account | ||
+ | account | ||
+ | account | ||
+ | account | ||
+ | |||
+ | password | ||
+ | password | ||
+ | password | ||
+ | |||
+ | session | ||
+ | session | ||
+ | -session | ||
+ | session | ||
+ | session | ||
+ | </ | ||
+ | |||
+ | Dans ce fichier, si la règle **sufficient** réussit, les modules suivants ne sont pas invoqués. | ||
+ | |||
+ | ===Bloquer un Compte après N Echecs de Connexion=== | ||
+ | |||
+ | Le module PAM **pam_tally.so** permet de bloquer un compte après N échecs de connexion. Afin d' | ||
+ | |||
+ | < | ||
+ | auth required pam_tally.so onerr=fail deny=3 unlock_time=300 | ||
+ | </ | ||
+ | |||
+ | Dans ce cas, après trois tentatives infructueuses de connexion, le compte sera bloquer pendant 5 minutes. | ||
+ | |||
+ | ===Configuration=== | ||
+ | |||
+ | Certains modules de PAM peuvent être configurés grâce aux fichiers présents dans le répertoire **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# ls / | ||
+ | access.conf | ||
+ | chroot.conf | ||
+ | console.apps | ||
+ | console.handlers | ||
+ | </ | ||
+ | |||
+ | Parmi les fichiers cités on note ceux qui peuvent être utilisés pour configurer les modules suivants : | ||
+ | |||
+ | ^ Fichier/// | ||
+ | | **access.conf** | Utilisé par le module pam_access.so | | ||
+ | | **// | ||
+ | | **console.perms** | Utilisé par le module pam_console.so | | ||
+ | | **// | ||
+ | | **group.conf** | Utilisés par le module pam_group.so | | ||
+ | | **limits.conf** | Utilisé par le module pam_limits.so | | ||
+ | | **pam_env.conf** | Utilisé par le module pam_env.so | | ||
+ | | **time.conf** | Utilisé par le module pam_time.so | | ||
+ | |||
+ | <WRAP center round todo 50%> | ||
+ | **A faire** : Passez en revue chacun de ces fichiers. | ||
+ | </ | ||
+ | |||
+ | Dernièrement, | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# cat / | ||
+ | #%PAM-1.0 | ||
+ | auth | ||
+ | account | ||
+ | password required | ||
+ | session | ||
+ | </ | ||
+ | |||
+ | =====LAB #4 - Mise en place du Système de Prévention d' | ||
+ | |||
+ | Fail2Ban est un **S**ystème de **P**révention d' | ||
+ | |||
+ | ====Installation==== | ||
+ | |||
+ | Sous RHEL/CentOS 7, beaucoup d' | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# yum -y install epel-release | ||
+ | </ | ||
+ | |||
+ | Ensuite installez Fail2Ban : | ||
+ | |||
+ | < | ||
+ | [root@centos6 ~]# yum install fail2ban | ||
+ | </ | ||
+ | |||
+ | ====Configuration==== | ||
+ | |||
+ | La configuration de Fail2Ban se trouve dans le fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# more / | ||
+ | # | ||
+ | # WARNING: heavily refactored in 0.9.0 release. | ||
+ | # customize settings for your setup. | ||
+ | # | ||
+ | # Changes: | ||
+ | # file, but provide customizations in jail.local file, | ||
+ | # or separate .conf files under jail.d/ directory, e.g.: | ||
+ | # | ||
+ | # HOW TO ACTIVATE JAILS: | ||
+ | # | ||
+ | # YOU SHOULD NOT MODIFY THIS FILE. | ||
+ | # | ||
+ | # It will probably be overwritten or improved in a distribution update. | ||
+ | # | ||
+ | # Provide customizations in a jail.local file or a jail.d/ | ||
+ | # For example to change the default bantime for all jails and to enable the | ||
+ | # ssh-iptables jail the following (uncommented) would appear in the .local file. | ||
+ | # See man 5 jail.conf for details. | ||
+ | # | ||
+ | # [DEFAULT] | ||
+ | # bantime = 3600 | ||
+ | # | ||
+ | # [sshd] | ||
+ | # enabled = true | ||
+ | # | ||
+ | # See jail.conf(5) man page for more information | ||
+ | |||
+ | |||
+ | |||
+ | # Comments: use '#' | ||
+ | |||
+ | |||
+ | [INCLUDES] | ||
+ | |||
+ | #before = paths-distro.conf | ||
+ | --More--(4%) | ||
+ | </ | ||
+ | |||
+ | Dans ce fichier se trouvent des sections pour configurer l' | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | [sshd] | ||
+ | |||
+ | port = ssh | ||
+ | logpath = %(sshd_log)s | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Ces sections, appelées des Prisons (//Jails// en anglais), peuvent contenir des directives telles que : | ||
+ | |||
+ | ^ Directive ^ Description ^ | ||
+ | | enabled | Indique si oui (true) ou non (false) le prison est activé. | | ||
+ | | port | Le port à bloquer dans iptables. | | ||
+ | | filter | Le nom du filtre, une expression régulière, | ||
+ | | logpath | Le nom et le chemin du journal à examiner. | | ||
+ | | maxretry | Le nombre maximal de tentatives. | | ||
+ | | action | Spécifie l' | ||
+ | |||
+ | Il n'est pas recommendé de modifier ce fichier afin de ne pas voir ses modifications ecrasées lors de la prochaine mise-à-jour de Fail2Ban. Fail2Ban nous donne la possibilité de créer le fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# vi / | ||
+ | [root@centos7 ~]# cat / | ||
+ | [DEFAULT] | ||
+ | ignoreip = 127.0.0.1 172.YY+20.0.3 | ||
+ | findtime = 3600 | ||
+ | bantime = 86400 | ||
+ | maxretry = 5 | ||
+ | |||
+ | [sshd] | ||
+ | enabled = true | ||
+ | </ | ||
+ | |||
+ | Il est à noter que les directives dans le fichier **jail.conf** sont surchargées par celles dans les fichiers suivantes et dans l' | ||
+ | |||
+ | * **/ | ||
+ | * **/ | ||
+ | * **/ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Notez que la définition des variables dans la section **[DEFAULT]** du fichier **/ | ||
+ | </ | ||
+ | |||
+ | Dans ce fichier, les directives sont donc : | ||
+ | |||
+ | ^ Directive ^ Description ^ | ||
+ | | ignoreip | Liste des adresses IP, séparées par un **espace**, qui ne sont pas concernées par l' | ||
+ | | findtime | L' | ||
+ | | bantime | La durée de vie des règles, en secondes, inscrites dans le pare-feu iptables. | | ||
+ | | maxretry | Le nombre maximal de tentatives. La règle sera donc inscrite dans le pare-feu lors de la sixième tentative. | | ||
+ | |||
+ | ===Le répertoire / | ||
+ | |||
+ | Le répertoire **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# ls -l / | ||
+ | total 68 | ||
+ | drwxr-xr-x. 2 root root 4096 Jun 8 22:51 action.d | ||
+ | -rw-r--r--. 1 root root 2328 May 11 2017 fail2ban.conf | ||
+ | drwxr-xr-x. 2 root root 6 Jul 13 2017 fail2ban.d | ||
+ | drwxr-xr-x. 3 root root 4096 Jun 8 22:51 filter.d | ||
+ | -rw-r--r--. 1 root root 21502 Jul 13 2017 jail.conf | ||
+ | drwxr-xr-x. 2 root root 30 Jun 8 22:51 jail.d | ||
+ | -rw-r--r--. 1 root root 110 Jun 8 22:54 jail.local | ||
+ | -rw-r--r--. 1 root root 2375 May 11 2017 paths-common.conf | ||
+ | -rw-r--r--. 1 root root 642 May 11 2017 paths-debian.conf | ||
+ | -rw-r--r--. 1 root root 1070 May 11 2017 paths-fedora.conf | ||
+ | -rw-r--r--. 1 root root 1156 May 11 2017 paths-freebsd.conf | ||
+ | -rw-r--r--. 1 root root 975 May 11 2017 paths-opensuse.conf | ||
+ | -rw-r--r--. 1 root root 290 May 11 2017 paths-osx.conf | ||
+ | </ | ||
+ | |||
+ | ==Le fichier fail2ban.conf== | ||
+ | |||
+ | Ce fichier définit les configurations globales de Fail2Ban, telles le **pidfile**, | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# cat / | ||
+ | # Fail2Ban main configuration file | ||
+ | # | ||
+ | # Comments: use '#' | ||
+ | # | ||
+ | # Changes: | ||
+ | # file, but provide customizations in fail2ban.local file, e.g.: | ||
+ | # | ||
+ | # [Definition] | ||
+ | # loglevel = DEBUG | ||
+ | # | ||
+ | |||
+ | [Definition] | ||
+ | |||
+ | # Option: loglevel | ||
+ | # Notes.: Set the log level output. | ||
+ | # | ||
+ | # ERROR | ||
+ | # | ||
+ | # | ||
+ | # INFO | ||
+ | # DEBUG | ||
+ | # Values: [ LEVEL ] Default: ERROR | ||
+ | # | ||
+ | loglevel = INFO | ||
+ | |||
+ | # Option: logtarget | ||
+ | # Notes.: Set the log target. This could be a file, SYSLOG, STDERR or STDOUT. | ||
+ | # Only one log target can be specified. | ||
+ | # If you change logtarget from the default value and you are | ||
+ | # using logrotate -- also adjust or disable rotation in the | ||
+ | # | ||
+ | # (e.g. / | ||
+ | # Values: [ STDOUT | STDERR | SYSLOG | FILE ] Default: STDERR | ||
+ | # | ||
+ | logtarget = / | ||
+ | |||
+ | # Option: syslogsocket | ||
+ | # Notes: Set the syslog socket file. Only used when logtarget is SYSLOG | ||
+ | # auto uses platform.system() to determine predefined paths | ||
+ | # Values: [ auto | FILE ] Default: auto | ||
+ | syslogsocket = auto | ||
+ | |||
+ | # Option: socket | ||
+ | # Notes.: Set the socket file. This is used to communicate with the daemon. Do | ||
+ | # not remove this file when Fail2ban runs. It will not be possible to | ||
+ | # | ||
+ | # Values: [ FILE ] Default: / | ||
+ | # | ||
+ | socket = / | ||
+ | |||
+ | # Option: pidfile | ||
+ | # Notes.: Set the PID file. This is used to store the process ID of the | ||
+ | # | ||
+ | # Values: [ FILE ] Default: / | ||
+ | # | ||
+ | pidfile = / | ||
+ | |||
+ | # Options: dbfile | ||
+ | # Notes.: Set the file for the fail2ban persistent data to be stored. | ||
+ | # A value of ": | ||
+ | # and data is lost when fail2ban is stopped. | ||
+ | # A value of " | ||
+ | # Values: [ None :memory: FILE ] Default: / | ||
+ | dbfile = / | ||
+ | |||
+ | # Options: dbpurgeage | ||
+ | # Notes.: Sets age at which bans should be purged from the database | ||
+ | # Values: [ SECONDS ] Default: 86400 (24hours) | ||
+ | dbpurgeage = 86400 | ||
+ | </ | ||
+ | |||
+ | ==Le répertoire / | ||
+ | |||
+ | Ce répertoire contient les fichiers appelés par les directives **filter** dans les sections des prisons : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# ls -l / | ||
+ | total 344 | ||
+ | -rw-r--r--. 1 root root 442 May 11 2017 3proxy.conf | ||
+ | -rw-r--r--. 1 root root 3241 May 11 2017 apache-auth.conf | ||
+ | -rw-r--r--. 1 root root 2745 May 11 2017 apache-badbots.conf | ||
+ | -rw-r--r--. 1 root root 1273 May 11 2017 apache-botsearch.conf | ||
+ | -rw-r--r--. 1 root root 813 May 11 2017 apache-common.conf | ||
+ | -rw-r--r--. 1 root root 268 May 11 2017 apache-fakegooglebot.conf | ||
+ | -rw-r--r--. 1 root root 487 May 11 2017 apache-modsecurity.conf | ||
+ | -rw-r--r--. 1 root root 596 May 11 2017 apache-nohome.conf | ||
+ | -rw-r--r--. 1 root root 1187 May 11 2017 apache-noscript.conf | ||
+ | -rw-r--r--. 1 root root 2000 May 11 2017 apache-overflows.conf | ||
+ | -rw-r--r--. 1 root root 346 May 11 2017 apache-pass.conf | ||
+ | -rw-r--r--. 1 root root 1014 May 11 2017 apache-shellshock.conf | ||
+ | -rw-r--r--. 1 root root 3418 May 11 2017 assp.conf | ||
+ | -rw-r--r--. 1 root root 2443 May 11 2017 asterisk.conf | ||
+ | -rw-r--r--. 1 root root 520 May 11 2017 botsearch-common.conf | ||
+ | -rw-r--r--. 1 root root 1863 May 11 2017 common.conf | ||
+ | -rw-r--r--. 1 root root 252 May 11 2017 counter-strike.conf | ||
+ | -rw-r--r--. 1 root root 393 May 11 2017 courier-auth.conf | ||
+ | -rw-r--r--. 1 root root 490 May 11 2017 courier-smtp.conf | ||
+ | -rw-r--r--. 1 root root 444 May 11 2017 cyrus-imap.conf | ||
+ | -rw-r--r--. 1 root root 345 May 11 2017 directadmin.conf | ||
+ | -rw-r--r--. 1 root root 1942 May 11 2017 domino-smtp.conf | ||
+ | -rw-r--r--. 1 root root 1875 May 11 2017 dovecot.conf | ||
+ | -rw-r--r--. 1 root root 1696 May 11 2017 dropbear.conf | ||
+ | -rw-r--r--. 1 root root 557 May 11 2017 drupal-auth.conf | ||
+ | -rw-r--r--. 1 root root 1282 May 11 2017 ejabberd-auth.conf | ||
+ | -rw-r--r--. 1 root root 516 May 11 2017 exim-common.conf | ||
+ | -rw-r--r--. 1 root root 1847 May 11 2017 exim.conf | ||
+ | -rw-r--r--. 1 root root 2158 May 11 2017 exim-spam.conf | ||
+ | -rw-r--r--. 1 root root 963 May 11 2017 freeswitch.conf | ||
+ | -rw-r--r--. 1 root root 1209 May 11 2017 froxlor-auth.conf | ||
+ | -rw-r--r--. 1 root root 236 May 11 2017 groupoffice.conf | ||
+ | -rw-r--r--. 1 root root 322 May 11 2017 gssftpd.conf | ||
+ | -rw-r--r--. 1 root root 512 May 11 2017 guacamole.conf | ||
+ | -rw-r--r--. 1 root root 1158 May 11 2017 haproxy-http-auth.conf | ||
+ | -rw-r--r--. 1 root root 404 May 11 2017 horde.conf | ||
+ | drwxr-xr-x. 2 root root 33 Jun 8 22:51 ignorecommands | ||
+ | -rw-r--r--. 1 root root 482 May 11 2017 kerio.conf | ||
+ | -rw-r--r--. 1 root root 323 May 11 2017 lighttpd-auth.conf | ||
+ | -rw-r--r--. 1 root root 2279 May 11 2017 mongodb-auth.conf | ||
+ | -rw-r--r--. 1 root root 773 May 11 2017 monit.conf | ||
+ | -rw-r--r--. 1 root root 652 May 11 2017 murmur.conf | ||
+ | -rw-r--r--. 1 root root 890 May 11 2017 mysqld-auth.conf | ||
+ | -rw-r--r--. 1 root root 400 May 11 2017 nagios.conf | ||
+ | -rw-r--r--. 1 root root 1594 May 11 2017 named-refused.conf | ||
+ | -rw-r--r--. 1 root root 528 May 11 2017 nginx-botsearch.conf | ||
+ | -rw-r--r--. 1 root root 442 May 11 2017 nginx-http-auth.conf | ||
+ | -rw-r--r--. 1 root root 1427 May 11 2017 nginx-limit-req.conf | ||
+ | -rw-r--r--. 1 root root 707 May 11 2017 nsd.conf | ||
+ | -rw-r--r--. 1 root root 459 May 11 2017 openhab.conf | ||
+ | -rw-r--r--. 1 root root 495 May 11 2017 openwebmail.conf | ||
+ | -rw-r--r--. 1 root root 1905 May 11 2017 oracleims.conf | ||
+ | -rw-r--r--. 1 root root 814 May 11 2017 pam-generic.conf | ||
+ | -rw-r--r--. 1 root root 568 May 11 2017 perdition.conf | ||
+ | -rw-r--r--. 1 root root 834 May 11 2017 php-url-fopen.conf | ||
+ | -rw-r--r--. 1 root root 188 May 11 2017 portsentry.conf | ||
+ | -rw-r--r--. 1 root root 1289 May 11 2017 postfix.conf | ||
+ | -rw-r--r--. 1 root root 454 May 11 2017 postfix-rbl.conf | ||
+ | -rw-r--r--. 1 root root 482 May 11 2017 postfix-sasl.conf | ||
+ | -rw-r--r--. 1 root root 1216 May 11 2017 proftpd.conf | ||
+ | -rw-r--r--. 1 root root 2409 May 11 2017 pure-ftpd.conf | ||
+ | -rw-r--r--. 1 root root 795 May 11 2017 qmail.conf | ||
+ | -rw-r--r--. 1 root root 1286 May 11 2017 recidive.conf | ||
+ | -rw-r--r--. 1 root root 1367 May 11 2017 roundcube-auth.conf | ||
+ | -rw-r--r--. 1 root root 821 May 11 2017 screensharingd.conf | ||
+ | -rw-r--r--. 1 root root 517 May 11 2017 selinux-common.conf | ||
+ | -rw-r--r--. 1 root root 570 May 11 2017 selinux-ssh.conf | ||
+ | -rw-r--r--. 1 root root 396 Jul 13 2017 sendmail-auth.conf | ||
+ | -rw-r--r--. 1 root root 2472 Jul 13 2017 sendmail-reject.conf | ||
+ | -rw-r--r--. 1 root root 371 May 11 2017 sieve.conf | ||
+ | -rw-r--r--. 1 root root 706 May 11 2017 slapd.conf | ||
+ | -rw-r--r--. 1 root root 472 May 11 2017 sogo-auth.conf | ||
+ | -rw-r--r--. 1 root root 1094 May 11 2017 solid-pop3d.conf | ||
+ | -rw-r--r--. 1 root root 206 May 11 2017 squid.conf | ||
+ | -rw-r--r--. 1 root root 199 May 11 2017 squirrelmail.conf | ||
+ | -rw-r--r--. 1 root root 186 May 11 2017 sshd-aggressive.conf | ||
+ | -rw-r--r--. 1 root root 4487 May 11 2017 sshd.conf | ||
+ | -rw-r--r--. 1 root root 476 May 11 2017 sshd-ddos.conf | ||
+ | -rw-r--r--. 1 root root 363 May 11 2017 stunnel.conf | ||
+ | -rw-r--r--. 1 root root 649 May 11 2017 suhosin.conf | ||
+ | -rw-r--r--. 1 root root 821 May 11 2017 tine20.conf | ||
+ | -rw-r--r--. 1 root root 374 May 11 2017 uwimap-auth.conf | ||
+ | -rw-r--r--. 1 root root 637 May 11 2017 vsftpd.conf | ||
+ | -rw-r--r--. 1 root root 444 May 11 2017 webmin-auth.conf | ||
+ | -rw-r--r--. 1 root root 520 May 11 2017 wuftpd.conf | ||
+ | -rw-r--r--. 1 root root 503 May 11 2017 xinetd-fail.conf | ||
+ | </ | ||
+ | |||
+ | ==Le répertoire / | ||
+ | |||
+ | Ce répertoire contient les fichiers appelés par les directives **action** dans les sections des prisons : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# ls -l / | ||
+ | total 244 | ||
+ | -rw-r--r--. 1 root root 587 May 11 2017 apf.conf | ||
+ | -rw-r--r--. 1 root root 629 May 11 2017 badips.conf | ||
+ | -rw-r--r--. 1 root root 10620 May 11 2017 badips.py | ||
+ | -rw-r--r--. 2 root root 11791 Jul 13 2017 badips.pyc | ||
+ | -rw-r--r--. 2 root root 11791 Jul 13 2017 badips.pyo | ||
+ | -rw-r--r--. 1 root root 2631 May 11 2017 blocklist_de.conf | ||
+ | -rw-r--r--. 1 root root 1931 May 11 2017 cloudflare.conf | ||
+ | -rw-r--r--. 1 root root 7524 May 11 2017 dshield.conf | ||
+ | -rw-r--r--. 1 root root 1133 May 11 2017 dummy.conf | ||
+ | -rw-r--r--. 1 root root 1538 May 11 2017 firewallcmd-allports.conf | ||
+ | -rw-r--r--. 1 root root 1530 May 11 2017 firewallcmd-ipset.conf | ||
+ | -rw-r--r--. 1 root root 2088 May 11 2017 firewallcmd-multiport.conf | ||
+ | -rw-r--r--. 1 root root 2005 May 11 2017 firewallcmd-new.conf | ||
+ | -rw-r--r--. 1 root root 3223 May 11 2017 firewallcmd-rich-logging.conf | ||
+ | -rw-r--r--. 1 root root 2689 May 11 2017 firewallcmd-rich-rules.conf | ||
+ | -rw-r--r--. 1 root root 1437 May 11 2017 iptables-allports.conf | ||
+ | -rw-r--r--. 1 root root 1868 May 11 2017 iptables-common.conf | ||
+ | -rw-r--r--. 1 root root 1350 May 11 2017 iptables.conf | ||
+ | -rw-r--r--. 1 root root 1828 May 11 2017 iptables-ipset-proto4.conf | ||
+ | -rw-r--r--. 1 root root 1755 May 11 2017 iptables-ipset-proto6-allports.conf | ||
+ | -rw-r--r--. 1 root root 1798 May 11 2017 iptables-ipset-proto6.conf | ||
+ | -rw-r--r--. 1 root root 1431 May 11 2017 iptables-multiport.conf | ||
+ | -rw-r--r--. 1 root root 1910 May 11 2017 iptables-multiport-log.conf | ||
+ | -rw-r--r--. 1 root root 1508 May 11 2017 iptables-new.conf | ||
+ | -rw-r--r--. 1 root root 2282 May 11 2017 iptables-xt_recent-echo.conf | ||
+ | -rw-r--r--. 1 root root 1556 May 11 2017 mail.conf | ||
+ | -rw-r--r--. 1 root root 5233 May 11 2017 mynetwatchman.conf | ||
+ | -rw-r--r--. 1 root root 1493 May 11 2017 netscaler.conf | ||
+ | -rw-r--r--. 1 root root 489 May 11 2017 nftables-allports.conf | ||
+ | -rw-r--r--. 1 root root 3680 May 11 2017 nftables-common.conf | ||
+ | -rw-r--r--. 1 root root 496 May 11 2017 nftables-multiport.conf | ||
+ | -rw-r--r--. 1 root root 1436 May 11 2017 npf.conf | ||
+ | -rw-r--r--. 1 root root 3146 May 11 2017 nsupdate.conf | ||
+ | -rw-r--r--. 1 root root 1023 May 11 2017 route.conf | ||
+ | -rw-r--r--. 1 root root 2762 May 11 2017 sendmail-buffered.conf | ||
+ | -rw-r--r--. 1 root root 1818 May 11 2017 sendmail-common.conf | ||
+ | -rw-r--r--. 1 root root 798 May 11 2017 sendmail.conf | ||
+ | -rw-r--r--. 1 root root 1692 May 11 2017 sendmail-geoip-lines.conf | ||
+ | -rw-r--r--. 1 root root 918 May 11 2017 sendmail-whois.conf | ||
+ | -rw-r--r--. 1 root root 993 May 11 2017 sendmail-whois-ipjailmatches.conf | ||
+ | -rw-r--r--. 1 root root 974 May 11 2017 sendmail-whois-ipmatches.conf | ||
+ | -rw-r--r--. 1 root root 1207 May 11 2017 sendmail-whois-lines.conf | ||
+ | -rw-r--r--. 1 root root 938 May 11 2017 sendmail-whois-matches.conf | ||
+ | -rw-r--r--. 1 root root 2981 May 11 2017 shorewall-ipset-proto6.conf | ||
+ | -rw-r--r--. 1 root root 6021 May 11 2017 smtp.py | ||
+ | -rw-r--r--. 2 root root 5921 Jul 13 2017 smtp.pyc | ||
+ | -rw-r--r--. 2 root root 5921 Jul 13 2017 smtp.pyo | ||
+ | -rw-r--r--. 1 root root 1330 May 11 2017 symbiosis-blacklist-allports.conf | ||
+ | -rw-r--r--. 1 root root 6018 May 11 2017 xarf-login-attack.conf | ||
+ | </ | ||
+ | |||
+ | ====Commandes==== | ||
+ | |||
+ | Fail2Ban est constitué de deux commandes : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# which fail2ban-client | ||
+ | / | ||
+ | [root@centos7 ~]# which fail2ban-server | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | L' | ||
+ | |||
+ | Les options de la commande **fail2ban-server** sont : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# fail2ban-server --help | ||
+ | Usage: / | ||
+ | |||
+ | Fail2Ban v0.9.7 reads log file that contains password failure report | ||
+ | and bans the corresponding IP addresses using firewall rules. | ||
+ | |||
+ | Only use this command for debugging purpose. Start the server with | ||
+ | fail2ban-client instead. The default behaviour is to start the server | ||
+ | in background. | ||
+ | |||
+ | Options: | ||
+ | -b start in background | ||
+ | -f start in foreground | ||
+ | -s < | ||
+ | -p < | ||
+ | -x force execution of the server (remove socket file) | ||
+ | -h, --help | ||
+ | -V, --version | ||
+ | |||
+ | Report bugs to https:// | ||
+ | </ | ||
+ | |||
+ | Les options de la commande **fail2ban-client** sont : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# fail2ban-client --help | ||
+ | Usage: / | ||
+ | |||
+ | Fail2Ban v0.9.7 reads log file that contains password failure report | ||
+ | and bans the corresponding IP addresses using firewall rules. | ||
+ | |||
+ | Options: | ||
+ | -c < | ||
+ | -s < | ||
+ | -p < | ||
+ | -d dump configuration. For debugging | ||
+ | -i interactive mode | ||
+ | -v increase verbosity | ||
+ | -q decrease verbosity | ||
+ | -x force execution of the server (remove socket file) | ||
+ | -b start server in background (default) | ||
+ | -f start server in foreground (note that the client forks once itself) | ||
+ | -h, --help | ||
+ | -V, --version | ||
+ | |||
+ | Command: | ||
+ | BASIC | ||
+ | start starts the server and the jails | ||
+ | reload | ||
+ | reload < | ||
+ | stop stops all jails and terminate the | ||
+ | | ||
+ | status | ||
+ | | ||
+ | ping tests if the server is alive | ||
+ | help | ||
+ | version | ||
+ | |||
+ | | ||
+ | set loglevel < | ||
+ | | ||
+ | | ||
+ | get loglevel | ||
+ | set logtarget < | ||
+ | Can be STDOUT, STDERR, SYSLOG or a | ||
+ | file | ||
+ | get logtarget | ||
+ | set syslogsocket auto|< | ||
+ | auto or < | ||
+ | | ||
+ | get syslogsocket | ||
+ | flushlogs | ||
+ | and reopens it. For log rotation. | ||
+ | |||
+ | | ||
+ | set dbfile < | ||
+ | | ||
+ | " | ||
+ | get dbfile | ||
+ | | ||
+ | set dbpurgeage < | ||
+ | | ||
+ | get dbpurgeage | ||
+ | | ||
+ | |||
+ | JAIL CONTROL | ||
+ | add < | ||
+ | start < | ||
+ | stop < | ||
+ | | ||
+ | status < | ||
+ | with optional flavor or extended | ||
+ | info | ||
+ | |||
+ | JAIL CONFIGURATION | ||
+ | set < | ||
+ | set < | ||
+ | < | ||
+ | set < | ||
+ | of < | ||
+ | set < | ||
+ | of < | ||
+ | the ' | ||
+ | ' | ||
+ | set < | ||
+ | list of < | ||
+ | set < | ||
+ | files for < | ||
+ | set < | ||
+ | of < | ||
+ | set < | ||
+ | | ||
+ | set < | ||
+ | < | ||
+ | for < | ||
+ | set < | ||
+ | < | ||
+ | set < | ||
+ | set < | ||
+ | < | ||
+ | to exclude for < | ||
+ | set < | ||
+ | < | ||
+ | set < | ||
+ | for which the filter will look | ||
+ | back for < | ||
+ | set < | ||
+ | a host will be banned for < | ||
+ | set < | ||
+ | | ||
+ | set < | ||
+ | set < | ||
+ | set < | ||
+ | set < | ||
+ | < | ||
+ | for < | ||
+ | set < | ||
+ | | ||
+ | set < | ||
+ | adds a new action named <ACT> for | ||
+ | < | ||
+ | based action, a < | ||
+ | < | ||
+ | else will be a Command Action | ||
+ | set < | ||
+ | < | ||
+ | |||
+ | | ||
+ | set < | ||
+ | sets the start command <CMD> of | ||
+ | the action <ACT> for < | ||
+ | set < | ||
+ | | ||
+ | set < | ||
+ | sets the check command <CMD> of | ||
+ | the action <ACT> for < | ||
+ | set < | ||
+ | | ||
+ | set < | ||
+ | sets the unban command <CMD> of | ||
+ | the action <ACT> for < | ||
+ | set < | ||
+ | sets < | ||
+ | | ||
+ | < | ||
+ | |||
+ | | ||
+ | set < | ||
+ | sets the < | ||
+ | the action <ACT> for < | ||
+ | set < | ||
+ | calls the < | ||
+ | < | ||
+ | for < | ||
+ | |||
+ | JAIL INFORMATION | ||
+ | get < | ||
+ | files for < | ||
+ | get < | ||
+ | for < | ||
+ | get < | ||
+ | < | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | get < | ||
+ | | ||
+ | | ||
+ | get < | ||
+ | | ||
+ | to ignore for < | ||
+ | get < | ||
+ | will look back for failures for | ||
+ | < | ||
+ | get < | ||
+ | < | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | for < | ||
+ | get < | ||
+ | |||
+ | | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | | ||
+ | < | ||
+ | |||
+ | | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | | ||
+ | get < | ||
+ | the action <ACT> for < | ||
+ | |||
+ | Report bugs to https:// | ||
+ | </ | ||
+ | |||
+ | ===Activer et Démarrer le Serveur=== | ||
+ | |||
+ | Pour prendre en compte la configuration dans le fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# systemctl status fail2ban | ||
+ | ● fail2ban.service - Fail2Ban Service | ||
+ | | ||
+ | | ||
+ | Docs: man: | ||
+ | |||
+ | [root@centos7 ~]# systemctl enable fail2ban | ||
+ | |||
+ | Created symlink from / | ||
+ | |||
+ | [root@centos7 ~]# systemctl start fail2ban | ||
+ | |||
+ | [[root@centos7 ~]# ps aux | grep fail2ban-server | ||
+ | root | ||
+ | root | ||
+ | </ | ||
+ | |||
+ | ===Utiliser la Commande Fail2Ban-server== | ||
+ | |||
+ | Pour connaître le status de Fail2Ban-server, | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# fail2ban-client status | ||
+ | Status | ||
+ | |- Number of jail: 1 | ||
+ | `- Jail list: sshd | ||
+ | </ | ||
+ | |||
+ | Il est aussi possible de se renseigner sur le statut d'un prison particulier : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# fail2ban-client status sshd | ||
+ | Status for the jail: sshd | ||
+ | |- Filter | ||
+ | | |- Currently failed: 0 | ||
+ | | |- Total failed: 0 | ||
+ | | `- Journal matches: | ||
+ | `- Actions | ||
+ | |- Currently banned: 0 | ||
+ | |- Total banned: 0 | ||
+ | `- Banned IP list: | ||
+ | </ | ||
+ | |||
+ | La commande **fail2ban-client** peut être utilisée pour contrôler un prison : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# fail2ban-client stop sshd | ||
+ | Jail stopped | ||
+ | |||
+ | [root@centos7 ~]# fail2ban-client status sshd | ||
+ | ERROR NOK: (' | ||
+ | Sorry but the jail ' | ||
+ | |||
+ | [root@centos7 ~]# fail2ban-client reload | ||
+ | |||
+ | [root@centos7 ~]# fail2ban-client status sshd | ||
+ | Status for the jail: sshd | ||
+ | |- Filter | ||
+ | | |- Currently failed: 0 | ||
+ | | |- Total failed: 0 | ||
+ | | `- Journal matches: | ||
+ | `- Actions | ||
+ | |- Currently banned: 0 | ||
+ | |- Total banned: 0 | ||
+ | `- Banned IP list: | ||
+ | </ | ||
+ | |||
+ | ===Ajouter un Prison=== | ||
+ | |||
+ | Installez maintenant le serveur Apache si ce n'est pas déjà fait : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# yum install httpd | ||
+ | </ | ||
+ | |||
+ | Activez et démarrez le service Apache si ce n'est pas déjà lancé : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# systemctl status httpd | ||
+ | ● httpd.service - The Apache HTTP Server | ||
+ | | ||
+ | | ||
+ | Docs: man: | ||
+ | | ||
+ | |||
+ | [root@centos7 ~]# systemctl enable httpd | ||
+ | |||
+ | Created symlink from / | ||
+ | |||
+ | [root@centos7 ~]# systemctl start httpd | ||
+ | </ | ||
+ | |||
+ | Modifiez maintenant votre fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# vi / | ||
+ | [root@centos7 ~]# cat / | ||
+ | [DEFAULT] | ||
+ | ignoreip = 127.0.0.1 10.0.2.15 | ||
+ | findtime = 3600 | ||
+ | bantime = 86400 | ||
+ | maxretry = 5 | ||
+ | |||
+ | [sshd] | ||
+ | enabled = true | ||
+ | |||
+ | [apache-auth] | ||
+ | enabled = true | ||
+ | </ | ||
+ | |||
+ | Appliquez la nouvelle configuration et constatez le résultat : | ||
+ | |||
+ | < | ||
+ | [root@centos7 ~]# fail2ban-client reload | ||
+ | [root@centos7 ~]# fail2ban-client status | ||
+ | Status | ||
+ | |- Number of jail: 2 | ||
+ | `- Jail list: | ||
+ | </ | ||
+ | |||
+ | ----- | ||
+ | |||
+ | Copyright © 2023 Hugh Norris. |