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
elearning:workbooks:redhat:rh134:l103 [2024/10/21 15:20] adminelearning:workbooks:redhat:rh134:l103 [2024/10/22 10:15] (Version actuelle) admin
Ligne 1: Ligne 1:
 ~~PDF:LANDSCAPE~~ ~~PDF:LANDSCAPE~~
  
-Version : **2021.01**+Version : **2024.01**
  
 Dernière mise-à-jour : ~~LASTMOD~~ Dernière mise-à-jour : ~~LASTMOD~~
  
-======LRF607 - Gestion du Durcissement du système======+======RH13404 - Gestion de la Sécurité======
  
 =====Contenu du Module===== =====Contenu du Module=====
  
-  * **LRF607 - Gestion du Durcissement du système**+  * **RH13404 - Gestion de la Sécurité**
     * Contenu du Module     * Contenu du Module
-    * System Hardening Manuel +    * LAB #1 - Les Droits Unix Avancés 
-      * Les compilateurs +      * 1.1 - Les ACL 
-      * Les paquets +      * 1.2 Les Attributs Étendus
-      * Les démons et services +
-      * Les fichiers .rhosts +
-      * Les fichiers et les repertoires sans proprietaire +
-      * Interdire les connexions de root via le réseau +
-      * Limiter le delai d'inactivite d'une session shell +
-      * Renforcer la securite d'init +
-        * Les Distributions SysVInit +
-        * Les Distributions Upstart +
-      * Renforcer la sécurité du Noyau +
-      * La commande sysctl +
-    * LAB #1 - System Hardening à l'aide de l'outil Bastille +
-      * Présentation +
-      * Installation +
-      * Utilisation+
     * LAB #2 - Mise en place de SELinux pour sécuriser le serveur     * LAB #2 - Mise en place de SELinux pour sécuriser le serveur
-      * Introducton +      * 2.1 - Introducton 
-      * Définitions+      * 2.2 - Définitions
         * Security Context         * Security Context
         * Domains et Types         * Domains et Types
Ligne 46: Ligne 32:
         * Booléens         * Booléens
     * LAB #3 - Travailler avec SELinux     * LAB #3 - Travailler avec SELinux
-      * Copier et Déplacer des Fichiers +      * 3.1 - Copier et Déplacer des Fichiers 
-      * Vérifier les SC des Processus +      * 3.2 - Vérifier les SC des Processus 
-      * Visualiser la SC d'un Utilisateur +      * 3.3 - Visualiser la SC d'un Utilisateur 
-      * Vérifier la SC d'un fichier +      * 3.4 - Vérifier la SC d'un fichier 
-      * Troubleshooting SELinux +      * 3.4 - La commande chcon 
-        * La commande chcon +      * 3.5 - La commande restorecon 
-      * La commande restorecon +      * 3.6 - Le fichier /.autorelabel 
-      * Le fichier /.autorelabel +      * 3.7 - La commande semanage 
-      * La commande semanage +      * 3.8 - La commande audit2allow 
-      * La commande audit2allow+    * LAB #4 - Le Pare-feu Netfilter/iptables 
 +      * 4.1 - La Configuration par firewalld 
 +      * 4.2 - La Configuration de Base de firewalld 
 +      * 4.3 - La Commande firewall-cmd 
 +      * 4.4 - La Configuration Avancée de firewalld 
 +      * 4.5 - Le mode Panic de firewalld
  
-=====System Hardening Manuel=====+=====LAB #1 - Les Droits Unix Avancés=====
  
-====Les compilateurs====+====1.1 - Les ACL====
  
-Afin d'empêcher un pirate de créer des exécutables sur le serveur vous devez modifier les permissions sur les compilateurs éventuellement présents afin que seulement root puisse les exécuter.+Au delà des droits étendus d'Unix, Linux utilise un système d'ACL pour permettre une meilleure gestion des droits sur des fichiers.
  
-====Les paquets==== +Pour connaître les ACL positionnés sur un fichier, il convient d'utiliser la commande **getfacl** :
- +
-Il convient dans ce cas de passer en revue la liste des paquets installes puis de supprimer ceux qui sont juges être inutiles :+
  
 <code> <code>
-[root@centos7 ~]# rpm -qa | more +[root@redhat9 ~]# touch tux.jpg 
-libtalloc-2.1.9-1.el7.x86_64 + 
-gnome-contacts-3.22.1-1.el7.x86_64 +[root@redhat9 ~]# getfacl tux.jpg 
-lrzsz-0.12.20-36.el7.x86_64 +# file: tux.jpg 
-NetworkManager-team-1.8.0-11.el7_4.x86_64 +# owner: root 
-opus-1.0.2-6.el7.x86_64 +# group: root 
-libsss_certmap-1.15.2-50.el7_4.11.x86_64 +user::rw
-m17n-db-1.6.4-3.el7.noarch +group::r-- 
-expat-2.1.0-10.el7_3.x86_64 +other::r--
-gvfs-mtp-1.30.4-3.el7.x86_64 +
-hypervfcopyd-0-0.30.20161211git.el7.x86_64 +
-perl-parent-0.225-244.el7.noarch +
-libreport-centos-2.1.11-38.el7.centos.x86_64 +
-pixman-0.34.0-1.el7.x86_64 +
-alsa-plugins-pulseaudio-1.1.1-1.el7.x86_64 +
-libreoffice-graphicfilter-5.0.6.2-15.el7_4.x86_64 +
-libreport-rhel-anaconda-bugzilla-2.1.11-38.el7.centos.x86_64 +
-libXext-1.3.3-3.el7.x86_64 +
-libtool-ltdl-2.4.2-22.el7_3.x86_64 +
-NetworkManager-ppp-1.8.0-11.el7_4.x86_64 +
-osinfo-db-20170423-2.el7.noarch +
-fftw-libs-double-3.3.3-8.el7.x86_64 +
-kernel-tools-libs-3.10.0-693.21.1.el7.x86_64 +
-e2fsprogs-libs-1.42.9-10.el7.x86_64 +
---More--+
 </code> </code>
  
-====Les démons et services====+Pour positionner des ACL sur un fichier, il convient d'utiliser la commande **setfacl** :
  
-Il convient dans ce cas de passer en revue la liste des démons et services actives puis de supprimer ceux qui sont juges être inutiles;+<code> 
 +[root@redhat9 ~]# setfacl --set u::rwx,g::rx,o::-,u:trainee:rw tux.jpg
  
-  * ps aux +[root@redhat9 ~]# getfacl tux.jpg 
-  * chkconfig --list +# filetux.jpg 
-  * systemctl list-unit-files +# owner: root 
- +# group: root 
-<code> +user::rwx 
-[root@centos7 ~]# ps aux | more +user:trainee:rw- 
-USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND +group::r-x 
-root          0.0  0.9 128172  4768 ?        Ss   14:58   0:11 /usr/lib/systemd/systemd --swit +mask::rwx 
-ched-root --system --deserialize 21 +other::---
-root          0.0  0.0      0     0 ?        S    14:58   0:00 [kthreadd] +
-root          0.0  0.0      0     0 ?        S    14:58   0:13 [ksoftirqd/0] +
-root          0.0  0.0      0     0 ?        S<   14:58   0:00 [kworker/0:0H] +
-root         6  0.0  0.0      0     0 ?        S    14:58   0:00 [kworker/u2:0] +
-root          0.0  0.0      0     0 ?        S    14:58   0:00 [migration/0] +
-root         8  0.0  0.0      0     0 ?        S    14:58   0:00 [rcu_bh] +
-root          0.0  0.0      0     0 ?        S    14:58   0:09 [rcu_sched] +
-root        10  0.0  0.0      0     0 ?        S    14:58   0:00 [watchdog/0] +
-root        12  0.0  0.0      0     0 ?        S    14:58   0:00 [kdevtmpfs] +
-root        13  0.0  0.0      0     0 ?        S<   14:58   0:00 [netns] +
-root        14  0.0  0.0      0     0 ?        S    14:58   0:00 [khungtaskd] +
-root        15  0.0  0.0      0     0 ?        S<   14:58   0:00 [writeback] +
-root        16  0.0  0.0      0     0 ?        S<   14:58   0:00 [kintegrityd] +
-root        17  0.0  0.0      0     0 ?        S<   14:58   0:00 [bioset] +
-root        18  0.0  0.0      0     0 ?        S<   14:58   0:00 [kblockd] +
-root        19  0.0  0.0      0     0 ?        S<   14:58   0:00 [md] +
-root        25  0.0  0.0      0     0 ?        S    14:58   0:03 [kswapd0] +
-root        26  0.0  0.0      0     0 ?        SN   14:58   0:00 [ksmd] +
-root        27  0.0  0.0      0     0 ?        S<   14:58   0:00 [crypto] +
-root        35  0.0  0.0      0     0 ?        S<   14:58   0:00 [kthrotld] +
---More--+
 </code> </code>
  
-<code+<WRAP center round important 60%
-[root@centos7 ~]# chkconfig --list+**Important** Veuillez noter l'apparition de la ligne **mask**. Le mask indique les permissions maximales qui peuvent être acccordées à un utilisateur ou un groupe tiers. 
 +</WRAP>
  
-NoteThis output shows SysV services only and does not include native +Regardez maintenant l'effet des ACL sur un répertoire. Créez le répertoire /home/trainee/rep1 :
-      systemd services. SysV configuration data might be overridden by native +
-      systemd configuration.+
  
-      If you want to list systemd services use 'systemctl list-unit-files'. +<code> 
-      To see services enabled on particular target use +[root@redhat9 ~]# mkdir rep1
-      'systemctl list-dependencies [target]'. +
- +
-livesys        0:off 1:off 2:off 3:on 4:on 5:on 6:off +
-livesys-late    0:off 1:off 2:off 3:on 4:on 5:on 6:off +
-netconsole      0:off 1:off 2:off 3:off 4:off 5:off 6:off +
-network        0:off 1:off 2:off 3:off 4:off 5:off 6:off +
-snortd          0:off 1:off 2:on 3:on 4:on 5:on 6:off+
 </code> </code>
 +
 +Positionnez des ACL le répertoire avec la commande **setfacl** :
  
 <code> <code>
-[root@centos7 ~]# systemctl list-unit-files +[root@redhat9 ~]# setfacl --set d:u::r,d:g::-,d:o::rep1
-UNIT FILE                                     STATE    +
-proc-sys-fs-binfmt_misc.automount             static   +
-dev-hugepages.mount                           static   +
-dev-mqueue.mount                              static   +
-proc-fs-nfsd.mount                            static   +
-proc-sys-fs-binfmt_misc.mount                 static   +
-sys-fs-fuse-connections.mount                 static   +
-sys-kernel-config.mount                       static   +
-sys-kernel-debug.mount                        static   +
-tmp.mount                                     enabled  +
-var-lib-nfs-rpc_pipefs.mount                  static   +
-brandbot.path                                 disabled +
-cups.path                                     enabled  +
-systemd-ask-password-console.path             static   +
-systemd-ask-password-plymouth.path            static   +
-systemd-ask-password-wall.path                static   +
-session-33.scope                              static   +
-abrt-ccpp.service                             enabled  +
-abrt-oops.service                             enabled  +
-abrt-pstoreoops.service                       disabled +
-abrt-vmcore.service                           enabled  +
-abrt-xorg.service                             enabled  +
-abrtd.service                                 enabled  +
-lines 1-23+
 </code> </code>
  
-====Les fichiers .rhosts====+Notez l'utilisation de la lettre **d** pour indiquer une permission //par défaut//.
  
-Le systeme rhosts presente une faille de securite importante pour un serveur Linux. Pour cette raison, il convient de supprimer les fichiers **.rhosts** des utilisateurs. Utilisez la commande suivante: +Créez maintenant un fichier appelé fichier1 dans /root/rep1 :
- +
-  # find -name "\.rhosts" -exec rm -f \{\} \; [Entree] +
- +
-====Les fichiers et les repertoires sans proprietaire==== +
- +
-Afin de dresser la liste des fichiers et des groupes sans proprietaires sur le serveur, il convient d'utiliser les deux commandes suivantes: +
- +
-  # find / -nouser -exec ls -l \{\} \; 2> sans_pro.txt [Entree] +
- +
-  # find / -nogroup -exec ls -l \{\} \; 2>> sans_pro.txt[Entree] +
- +
-Ces commandes produiront une liste éventuelle dans le fichier **sans_pro.txt**. +
- +
-L'examen de cette liste pourrait dévoiler des anomalies au quel cas il conviendrait de: +
- +
-  * modifier le propriétaire a root +
-  * modifier le groupe a root +
-  * modifier les permissions a 700 +
- +
-====Interdire les connexions de root via le reseau==== +
- +
-Le fichier de configuration des connexions de root est **/etc/securetty** :+
  
 <code> <code>
-[root@centos7 ~]# cat /etc/securetty +[root@redhat9 ~]# touch rep1/fichier1
-console +
-vc/1 +
-vc/2 +
-vc/3 +
-vc/4 +
-vc/5 +
-vc/6 +
-vc/7 +
-vc/8 +
-vc/9 +
-vc/10 +
-vc/11 +
-tty1 +
-tty2 +
-tty3 +
-tty4 +
-tty5 +
-tty6 +
-tty7 +
-tty8 +
-tty9 +
-tty10 +
-tty11 +
-ttyS0 +
-ttysclp0 +
-sclp_line0 +
-3270/tty1 +
-hvc0 +
-hvc1 +
-hvc2 +
-hvc3 +
-hvc4 +
-hvc5 +
-hvc6 +
-hvc7 +
-hvsi0 +
-hvsi1 +
-hvsi2 +
-xvc0+
 </code> </code>
  
-Afin d'empêcher une connexion de root //directement// via le réseau et donc d'obliger une connexion en utilisant un compte d'utilisateur normal avant de passer en root grâce à la commande **su**, ce fichier ne doit **pas** contenir des entrees du type **ttysX** ou X = 0,1,2 etc. +Utilisez la commande **getfacl** pour visualiser le résultat :
- +
-====Limiter le delai d'inactivite d'une session shell==== +
- +
-Une session de shell laissee ouverte inutilement et d'une maniere sans surveillance est un risque de securite. Verifiez donc le contenu du fichier **/etc/profile** :+
  
 <code> <code>
-[root@centos7 ~]# cat /etc/profile +[root@redhat9 ~]# getfacl rep1 
-/etc/profile+file: rep1 
 +# owner: root 
 +# group: root 
 +user::rwx 
 +group::r-x 
 +other::r-x 
 +default:user::r-- 
 +default:group::--- 
 +default:other::---
  
-System wide environment and startup programs, for login setup +[root@redhat9 ~]getfacl rep1/fichier1 
-Functions and aliases go in /etc/bashrc+file: rep1/fichier1 
 +# owner: root 
 +# group: root 
 +user::r-- 
 +group::--- 
 +other::--- 
 +</code>
  
-# It's NOT a good idea to change this file unless you know what you +Notez que le fichier créé possède les ACL positionnés sur le répertoire rep1.
-# are doing. It's much better to create a custom.sh shell script in +
-# /etc/profile.d/ to make custom changes to your environment, as this +
-# will prevent the need for merging in future updates.+
  
-pathmunge () { +Dernièrement, les systèmes de sauvegarde classiques sous Linux ne peuvent pas sauvegarder les ACL, sauf l'outil **star**. Si vous n'utilisez pas **star**, il convient donc de sauvegarder les ACL dans un fichier grâce à la commande suivante :
-    case ":${PATH}:" in +
-        *:"$1":*+
-            ;; +
-        *+
-            if [ "$2" = "after" ] ; then +
-                PATH=$PATH:$1 +
-            else +
-                PATH=$1:$PATH +
-            fi +
-    esac +
-}+
  
 +<code>
 +[root@redhat9 ~]# cd rep1
  
-if -x /usr/bin/id ]; then +[root@redhat9 rep1]# getfacl ---skip-base . > backup.acl
-    if [ -z "$EUID" ]; then +
-        # ksh workaround +
-        EUID=`/usr/bin/id -u` +
-        UID=`/usr/bin/id -ru` +
-    fi +
-    USER="`/usr/bin/id -un`" +
-    LOGNAME=$USER +
-    MAIL="/var/spool/mail/$USER" +
-fi+
  
-# Path manipulation +[root@redhat9 rep1]# cat backup.acl 
-if "$EUID" = "0" ]; then +file: 
-    pathmunge /usr/sbin +owner: root 
-    pathmunge /usr/local/sbin +group: root 
-else +user::rwx 
-    pathmunge /usr/local/sbin after +group::r-x 
-    pathmunge /usr/sbin after +other::r-
-fi +default:user::r-- 
- +default:group::--
-HOSTNAME=`/usr/bin/hostname 2>/dev/null` +default:other::---
-HISTSIZE=1000 +
-if [ "$HISTCONTROL" = "ignorespace" ] ; then +
-    export HISTCONTROL=ignoreboth +
-else +
-    export HISTCONTROL=ignoredups +
-fi +
- +
-export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL +
- +
-By default, we want umask to get setThis sets it for login shell +
-Current threshold for system reserved uid/gids is 200 +
-You could check uidgid reservation validity in +
-# /usr/share/doc/setup-*/uidgid file +
-if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then +
-    umask 002 +
-else +
-    umask 022 +
-fi +
- +
-for i in /etc/profile.d/*.sh ; do +
-    if [ -r "$i" ]; then +
-        if [ "${-#*i}" != "$-" ]; then  +
-            . "$i" +
-        else +
-            . "$i" >/dev/null +
-        fi +
-    fi +
-done +
- +
-unset i +
-unset -f pathmunge+
 </code> </code>
  
-A ce fichier doivent etre ajoutées les deux lignes suivantes:+La restauration des ACL se fait avec la commande **setfacl** :
  
-<file> +  # setfacl --restore=backup.acl [Entrée]
-Readonly TMOUT=300 +
-Export TMOUT +
-</file>+
  
-Par cette action, vous définissez le délai d’inactivité d'une session shell a une durée de 5 minutes.+==Options des Commandes===
  
-Dernièrement, afin de se protéger contre des permissions trop permissives lors de la création de fichiers et de répertoires, il convient de passer la valeur d'**umask** à **077** dans le fichier **/etc/profile**. +Les options de la commande **getfacl** sont :
- +
-====Renforcer la securite d'init==== +
- +
-===Les Distributions SysVInit=== +
- +
-Le fichier **/etc/inittab** est utilise pour configurer le démarrage de votre serveur.  +
- +
-La première modification à effectuer est de spécifier le niveau d’exécution par défaut a 3 au lieu de 5. Ceci permet de ne pas lancer les sessions graphiques sur une serveur de production. Cherchez donc la ligne suivante: +
- +
-<file> +
-id:5:initdefault: +
-</file> +
- +
-Modifiez-la en: +
- +
-<file> +
-id:3:initdefault: +
-</file> +
- +
-Le mode **single user** de démarrage de Linux n'est pas habituellement protégé par un mot de passe. Afin de remédier a cela, ajoutez les lignes suivantes: +
- +
-<file> +
-# Single user mode +
-~~:S:wait:/sbin/sulogin +
-</file> +
- +
-Dernièrement, afin d'empêcher une personne a redémarrer le serveur à l'aide des touches **ctrl+alt+supp**, il convient de mettre en commentaire la ligne correspondante: +
- +
-<file> +
-# ca::ctrlaltdel:/sbin/shutdown -t3 -r now +
-</file> +
- +
-===Les Distributions Upstart=== +
- +
-Afin d'empêcher une personne à redémarrer le serveur à l'aide des touches **ctrl+alt+supp**, éditez le fichier **/etc/init/control-alt-delete.conf** en modifiant la ligne suivante : +
- +
-<file> +
-exec /sbin/shutdown -r now "Control-Alt-Delete pressed" +
-</file> +
- +
-en  +
- +
-<file> +
-#exec /sbin/shutdown -k now "Control-Alt-Delete pressed" +
-</file> +
- +
-====Renforcer la sécurité du Noyau==== +
- +
-===La commande sysctl=== +
- +
-Les fichiers dans le répertoire **/proc/sys** peuvent être administrés par la commande **sysctl** en temps réel.  +
- +
-La commande **sysctl** applique les règles consignés dans le fichier **/etc/sysctl.conf** au démarrage de la machine. +
- +
-Saisissez la commande :+
  
 <code> <code>
-[root@centos7 ~]# cat /etc/sysctl.conf +[root@redhat9 rep1]# getfacl --help 
-# System default settings live in /usr/lib/sysctl.d/00-system.conf. +getfacl 2.3.1 -- get file access control lists 
-# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file +Usage: getfacl [-aceEsRLPtpndvh] file ... 
-+  -a, --access            display the file access control list only 
-# For more information, see sysctl.conf(5) and sysctl.d(5)+  -d, --default           display the default access control list only 
- +  -c, --omit-header       do not display the comment header 
-[root@centos7 ~]# cat /usr/lib/sysctl.d/00-system.conf +  -e, --all-effective     print all effective rights 
-# Kernel sysctl configuration file +  -E, --no-effective      print no effective rights 
-# +  -s, --skip-base         skip files that only have the base entries 
-# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and +  -R, --recursive         recurse into subdirectories 
-# sysctl.conf(5) for more details. +  -L--logical           logical walk, follow symbolic links 
- +  -P--physical          physical walk, do not follow symbolic links 
-# Disable netfilter on bridges. +  -t, --tabular           use tabular output format 
-net.bridge.bridge-nf-call-ip6tables = 0 +  -n, --numeric           print numeric user/group identifiers 
-net.bridge.bridge-nf-call-iptables = 0 +      --one-file-system   skip files on different filesystems 
-net.bridge.bridge-nf-call-arptables = 0 +  -p--absolute-names    don't strip leading '/' in pathnames 
- +  -v, --version           print version and exit 
-# Controls the maximum shared segment sizein bytes +  -h--help              this help text
-kernel.shmmax = 4294967295 +
- +
-# Controls the maximum number of shared memory segmentsin pages +
- +
-[root@centos7 ~]# ls -l /etc/sysctl.d/ +
-total 0 +
-lrwxrwxrwx. 1 root root 14 Jun  4 09:54 99-sysctl.conf -> ../sysctl.conf +
- +
-[root@centos7 ~]# cat /etc/sysctl.d/99-sysctl.conf  +
-# System default settings live in /usr/lib/sysctl.d/00-system.conf. +
-# To override those settingsenter new settings here, or in an /etc/sysctl.d/<name>.conf file +
-# +
-# For more informationsee sysctl.conf(5) and sysctl.d(5).+
 </code> </code>
  
-==Options de la commande== +Les options de la commande **setfacl** sont :
- +
-Les options de la commande **sysctl** sont :+
  
 <code> <code>
-[root@centos7 ~]# sysctl --help+[root@redhat9 rep1]# setfacl --help 
 +setfacl 2.3.1 -- set file access control lists 
 +Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ... 
 +  -m, --modify=acl        modify the current ACL(s) of file(s) 
 +  -M, --modify-file=file  read ACL entries to modify from file 
 +  -x, --remove=acl        remove entries from the ACL(s) of file(s) 
 +  -X, --remove-file=file  read ACL entries to remove from file 
 +  -b, --remove-all        remove all extended ACL entries 
 +  -k, --remove-default    remove the default ACL 
 +      --set=acl           set the ACL of file(s), replacing the current ACL 
 +      --set-file=file     read ACL entries to set from file 
 +      --mask              do recalculate the effective rights mask 
 +  -n, --no-mask           don't recalculate the effective rights mask 
 +  -d, --default           operations apply to the default ACL 
 +  -R, --recursive         recurse into subdirectories 
 +  -L, --logical           logical walk, follow symbolic links 
 +  -P, --physical          physical walk, do not follow symbolic links 
 +      --restore=file      restore ACLs (inverse of `getfacl -R') 
 +      --test              test mode (ACLs are not modified) 
 +  -v, --version           print version and exit 
 +  -h, --help              this help text 
 +</code>
  
-Usage: +====1.2 - Les Attributs Etendus====
- sysctl [options] [variable[=value] ...]+
  
-Options: +Les attributs s'ajoutent aux caractéristiques classiques d'un fichier dans un système de fichiers Ext2/Ext3/Ext4JFSReiserFSXFS et Btrfs.
-  -a--all            display all variables +
-  -A                   alias of -a +
-  -X                   alias of -a +
-      --deprecated     include deprecated parameters to listing +
-  -b--binary         print value without new line +
-  -e--ignore         ignore unknown variables errors +
-  -N, --names          print variable names without values +
-  -n, --values         print only values of a variables +
-  -p, --load[=<file> read values from file +
-  -f                   alias of -p +
-      --system         read values from all system directories +
-  -r, --pattern <expression> +
-                       select setting that match expression +
-  -q, --quiet          do not echo variable set +
-  -w, --write          enable writing a value to variable +
-  -o                   does nothing +
-  -x                   does nothing +
-  -d                   alias of -h+
  
- -h, --help     display this help and exit +Les principaux attributs sont :
- -V, --version  output version information and exit+
  
-For more details see sysctl(8)+^ Attribut ^ Description ^ 
-</code>+| a | Fichier journal - uniquement l'ajout de données au fichier est permisLe fichier ne peut pas détruit | 
 +| i | Le fichier ne peut ni être modifié, ni être détruit, ni être déplacé. Le placement d'un lien sur le fichier n'est pas permis | 
 +| s | Le fichier sera physiquement détruit lors de sa suppression | 
 +| D | Répertoire synchrone | 
 +| S | Fichier synchrone | 
 +| A | La date et l'heure de dernier accès ne seront pas mises à jour |
  
-<WRAP center round important 50%> +<WRAP center round important 60%> 
-**Important** : Consultez la page de la traduction du manuel de **sysctl** **[[http://www.delafond.org/traducmanfr/man/man8/sysctl.8.html|ici]]** pour comprendre la commande.+**Important** - Un fichier synchrone et un répertoire synchrone impliquent que les modifications seront immédiatement inscrites sur disque.
 </WRAP> </WRAP>
  
-=====LAB #1 - System Hardening à l'aide de l'outil Bastille===== +Les commandes associées avec les attributs sont :
- +
-====Présentation==== +
- +
-Bastille Linux est un script interactif de renforcement de la sécurité pour certaines distributions de Linux dont %%RHEL%%, %%CentOS%% et Debian.+
  
-====Installation====+^ Commande ^ description ^ 
 +| chattr | Modifie les attributs | 
 +| lsattr | Visualise les attributs |
  
-Installez le dépôt EPEL :+Pour mieux comprendre, créez le répertoire **/root/attributs/rep** :
  
 <code> <code>
-[root@centos7 ~]# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm +[root@redhat9 rep1]# cd .. 
-[root@centos7 ~]# rpm -ivh epel-release-latest-7.noarch.rpm+[root@redhat9 ~]# mkdir -p attributs/rep
 </code> </code>
  
-Commencez par installer la dépendance de Bastille :+Créez ensuite les fichier **fichier** et **rep/fichier1** :
  
 <code> <code>
-[root@centos7 ~]# yum install perl-Curses+[root@redhat9 ~]# touch attributs/fichier 
 +[root@redhat9 ~]# touch attributs/rep/fichier1
 </code> </code>
  
-Téléchargez et installez Bastille :+Modifiez les attributs d'une manière récursive sur le répertoire **attributs** :
  
 <code> <code>
-[root@centos7 ~]# wget https://www.dropbox.com/s/sz0ggexdkkduumb/Bastille-3.0.9-1.0.noarch.rpm+[root@redhat9 ~]# chattr +i -R attributs/
 </code> </code>
 +
 +Visualisez les attributs de l'arborescence **attributs** :
  
 <code> <code>
-[root@centos7 ~]# yum localinstall Bastille-3.0.9-1.0.noarch.rpm --nogpgcheck +[root@redhat9 ~]# lsattr -R attributs 
-</code>+----i----------------- attributs/rep
  
-Dernièrement créez un lien symbolique :+attributs/rep: 
 +----i----------------- attributs/rep/fichier1
  
-<code> +----i----------------- attributs/fichier
-[root@centos7 /]# ln -s /usr/lib/Bastille /usr/lib64/+
 </code> </code>
  
-===Utilisation===+<WRAP center round important 60%> 
 +**Important** - Notez que l'attribut **e** sous Ext4 indique l'utilisation des **Extents**. Cet attribut ne peut pas être enlever avec la commande **chattr**. Les Extents seront couverts dans le cours **Gestion des Disques, des Systèmes de Fichiers et le Swap**. 
 +</WRAP>
  
-Pour démarrez bastille en mode texte, saisissez la commande suivante :+Essayez maintenant de déplacer le fichier **fichier**. Vous obtiendrez un résultat similaire à celui-ci :
  
-  # /usr/sbin/bastille -c [Entrée] +<code> 
- +[root@redhat9 ~]cd attributs; mv /root/attributs/fichier /root/attributs/rep/fichier 
-Pour démarrez bastille en mode graphique, saisissez la commande suivante : +mvcannot move '/root/attributs/fichier' to '/root/attributs/rep/fichier': Operation not permitted 
- +</code>
-  # /usr/sbin/bastille -x [Entrée] +
- +
-<WRAP center round todo 50%> +
-**A Faire** - Lancez Bastille et répondez aux questions posées. Ré-amorcez votre machine virtuelle et testez le résultat. +
-</WRAP>+
  
 =====LAB #2 - Mise en place de SELinux pour sécuriser le serveur===== =====LAB #2 - Mise en place de SELinux pour sécuriser le serveur=====
  
-====Introducton====+====2.1 - Introducton====
  
 L'approche %%SELinux%% (//Security Enhanced Linux//) à la sécurité est une approche de type **TE**. Elle essaie aussi d'intégrer les notions des approches de type **RBAC**, **MAC** et **MLS** sous la forme de **MCS** : L'approche %%SELinux%% (//Security Enhanced Linux//) à la sécurité est une approche de type **TE**. Elle essaie aussi d'intégrer les notions des approches de type **RBAC**, **MAC** et **MLS** sous la forme de **MCS** :
Ligne 547: Ligne 298:
 Chaque **//classe d'objet//** possède un jeu de permissions possibles ou **//actions//** qui peuvent être uniques à la classe ou bien **héritées** d'autres classes. Chaque **//classe d'objet//** possède un jeu de permissions possibles ou **//actions//** qui peuvent être uniques à la classe ou bien **héritées** d'autres classes.
  
-====Définitions====+====2.2 - Définitions====
  
 ===Security Context=== ===Security Context===
Ligne 561: Ligne 312:
 | Niveau | Un niveau est un attribut de MLS et MCS. Une plage MLS est une paire de niveaux exprimée en utilisant la syntaxe //niveaubas-niveauhaut//. Chaque niveau est une paire exprimée en tant que sensibilitéhaut-sensibilitébas:catégoriehaut:catégoriebas par exemple s0-s0:c0.c1023. Il est important de noter que s0-s0 s'exprime aussi s0 et c0, c1, c2, c3 est exprimé c0.c3. | | Niveau | Un niveau est un attribut de MLS et MCS. Une plage MLS est une paire de niveaux exprimée en utilisant la syntaxe //niveaubas-niveauhaut//. Chaque niveau est une paire exprimée en tant que sensibilitéhaut-sensibilitébas:catégoriehaut:catégoriebas par exemple s0-s0:c0.c1023. Il est important de noter que s0-s0 s'exprime aussi s0 et c0, c1, c2, c3 est exprimé c0.c3. |
  
-Sous RHEL/CentOS 7, le fichier **/etc/selinux/targeted/setrans.conf** contient la correspondance entre les niveaux et leurs valeurs compréhensibles par l'utilisateur :+Sous RedHat 9, le fichier **/etc/selinux/targeted/setrans.conf** contient la correspondance entre les niveaux et leurs valeurs compréhensibles par l'utilisateur :
  
 <code> <code>
-[root@centos7 /]# cat /etc/selinux/targeted/setrans.conf+[root@redhat9 attributs]# cat /etc/selinux/targeted/setrans.conf
 # #
 # Multi-Category Security translation table for SELinux # Multi-Category Security translation table for SELinux
Ligne 593: Ligne 344:
  
 <code> <code>
-[root@centos7 /]# /usr/sbin/semanage login -l+[root@redhat9 attributs]# /usr/sbin/semanage login -l
  
 Login Name           SELinux User         MLS/MCS Range        Service Login Name           SELinux User         MLS/MCS Range        Service
Ligne 599: Ligne 350:
 __default__          unconfined_u         s0-s0:c0.c1023       * __default__          unconfined_u         s0-s0:c0.c1023       *
 root                 unconfined_u         s0-s0:c0.c1023       * root                 unconfined_u         s0-s0:c0.c1023       *
-system_u             system_u             s0-s0:c0.c1023       *   
 </code> </code>
  
Ligne 628: Ligne 378:
  
 <code> <code>
-[root@centos7 /]# ls -lR /etc/selinux/ | more+[root@redhat9 attributs]# ls -lR /etc/selinux/ | more
 /etc/selinux/: /etc/selinux/:
-total 12 +total 8 
--rw-r--r--. 1 root root  547 Dec 10  2015 config +-rw-r--r--. 1 root root 1187 Oct 19  2023 config 
-drwx------. 2 root root    6 Apr 23 16:24 final +-rw-r--r--. 1 root root 2668 Dec 14  2023 semanage.conf 
--rw-r--r--. 1 root root 2321 Aug  4  2017 semanage.conf +drwxr-xr-x. root root  133 Sep 25 12:04 targeted
-drwxr-xr-x. root root 4096 Apr 23 16:24 targeted +
-drwxr-xr-x. 2 root root    6 Aug  4  2017 tmp+
  
-/etc/selinux/final+/etc/selinux/targeted
-total 0+total 16 
 +-rw-r--r--. 1 root root 2367 Jun  5 11:17 booleans.subs_dist 
 +drwxr-xr-x. 4 root root 4096 Sep 25 11:58 contexts 
 +drwxr-xr-x. 2 root root    6 Jun  5 11:17 logins 
 +drwxr-xr-x. 2 root root   23 Sep 25 12:04 policy 
 +-rw-r--r--. 1 root root  607 Jun  5 11:17 setrans.conf 
 +-rw-r--r--. 1 root root   73 Sep 25 12:04 seusers
  
-/etc/selinux/targeted: +/etc/selinux/targeted/contexts
-total 24 +total 72 
-drwx------. root root 4096 Apr 23 16:24 active +-rw-r--r--. root root  262 Sep 25 11:58 customizable_types 
--rw-r--r--. 1 root root 2623 Mar  7 15:19 booleans.subs_dist +-rw-r--r--. 1 root root  195 Jun  5 11:17 dbus_contexts 
-drwxr-xr-x. 4 root root 4096 Apr 23 16:20 contexts +-rw-r--r--. 1 root root 1111 Jun  5 11:17 default_contexts 
-drwxr-xr-x. 2 root root    6 Mar  7 15:19 logins +-rw-r--r--. 1 root root  114 Jun  5 11:17 default_type 
-drwxr-xr-x. 3 root root   19 Apr 23 16:41 modules +-rw-r--r--. 1 root root   29 Jun  5 11:17 failsafe_context 
-drwxr-xr-x. 2 root root   22 Apr 23 16:41 policy +drwxr-xr-xroot root 4096 Sep 25 12:04 files
--rw-------. 1 root root    0 Mar  7 14:52 semanage.read.LOCK +
--rw-------. 1 root root    0 Mar  7 14:52 semanage.trans.LOCK +
--rw-r--r--. 1 root root  607 Mar  7 15:19 setrans.conf +
--rw-r--r--. root root  176 Apr 23 16:24 seusers+
 --More-- --More--
 </code> </code>
  
-Afin d'utiliser SELinux en ligne de commande sous RHEL/CentOS 7, il est nécessaire d'installer le paquet **setools-console** :+Afin d'utiliser SELinux en ligne de commande sous RedHat 9, il est nécessaire d'installer le paquet **setools-console** :
  
 <code> <code>
-[root@centos7 ~]# yum install setools-console+[root@redhat9 attributs]# dnf install setools-console -y
 </code> </code>
  
Ligne 664: Ligne 414:
  
 <code> <code>
-[root@centos7 ~]# seinfo +[root@redhat9 attributs]# seinfo
 Statistics for policy file: /sys/fs/selinux/policy Statistics for policy file: /sys/fs/selinux/policy
-Policy Version & Typev.28 (binary, mls+Policy Version:             33 (MLS enabled
- +Target Policy:              selinux 
-   Classes:            94    Permissions:       262 +Handle unknown classes:     allow 
-   Sensitivities:       1    Categories:       1024 +  Classes:             135    Permissions:         457 
-   Types:            4747    Attributes:        251 +  Sensitivities:         1    Categories:         1024 
-   Users:               8    Roles:              14 +  Types:              5155    Attributes:          259 
-   Booleans:          307    Cond. Expr.:       356 +  Users:                 8    Roles:                15 
-   Allow:          101746    Neverallow:          +  Booleans:            360    Cond. Expr.:         393 
-   Auditallow:        155    Dontaudit:        8846 +  Allow:             65813    Neverallow:            
-   Type_trans:      17759    Type_change:        74 +  Auditallow:          176    Dontaudit:          8692 
-   Type_member:        35    Role allow:         39 +  Type_trans:       272792    Type_change:          94 
-   Role_trans:        416    Range_trans     5697 +  Type_member:          37    Range_trans:        6164 
-   Constraints      109    Validatetrans:       0 +  Role allow:           40    Role_trans:          419 
-   Initial SIDs:       27    Fs_use:             29 +  Constraints:          70    Validatetrans:         0 
-   Genfscon:          105    Portcon:           602 +  MLS Constrain:        72    MLS Val. Tran        0 
-   Netifcon:            0    Nodecon:             0 +  Permissives          5    Polcap:                6 
-   Permissives:            Polcap:              2+  Defaults:              7    Typebounds:            0 
 +  Allowxperm:            0    Neverallowxperm:       0 
 +  Auditallowxperm:          Dontauditxperm:        0 
 +  Ibendportcon:          0    Ibpkeycon:             0 
 +  Initial SIDs:         27    Fs_use:               35 
 +  Genfscon:            109    Portcon:             665 
 +  Netifcon:              0    Nodecon:               0
 </code> </code>
  
Ligne 794: Ligne 549:
  
 <code> <code>
-[root@centos7 /]# cat /etc/selinux/config+[root@redhat9 attributs]# cat /etc/selinux/config
  
 # This file controls the state of SELinux on the system. # This file controls the state of SELinux on the system.
Ligne 801: Ligne 556:
 #     permissive - SELinux prints warnings instead of enforcing. #     permissive - SELinux prints warnings instead of enforcing.
 #     disabled - No SELinux policy is loaded. #     disabled - No SELinux policy is loaded.
 +# See also:
 +# https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-selinux/#getting-started-with-selinux-selinux-states-and-modes
 +#
 +# NOTE: In earlier Fedora kernel builds, SELINUX=disabled would also
 +# fully disable SELinux during boot. If you need a system with SELinux
 +# fully disabled instead of SELinux running with no policy loaded, you
 +# need to pass selinux=0 to the kernel command line. You can use grubby
 +# to persistently set the bootloader to boot with selinux=0:
 +#
 +#    grubby --update-kernel ALL --args selinux=0
 +#
 +# To revert back to SELinux enabled:
 +#
 +#    grubby --update-kernel ALL --remove-args selinux
 +#
 SELINUX=enforcing SELINUX=enforcing
-# SELINUXTYPE= can take one of three two values:+# SELINUXTYPE= can take one of these three values:
 #     targeted - Targeted processes are protected, #     targeted - Targeted processes are protected,
-#     minimum - Modification of targeted policy. Only selected processes are protected. +#     minimum - Modification of targeted policy. Only selected processes are protected.
 #     mls - Multi Level Security protection. #     mls - Multi Level Security protection.
-SELINUXTYPE=targeted +SELINUXTYPE=targeted
 </code> </code>
  
Ligne 812: Ligne 582:
  
 <code> <code>
-[root@centos7 /]# getenforce+[root@redhat9 attributs]# getenforce
 Enforcing Enforcing
 </code> </code>
Ligne 819: Ligne 589:
  
 <code> <code>
-[root@centos7 /]# setenforce permissive +[root@redhat9 attributs]# setenforce permissive 
-[root@centos7 /]# getenforce+ 
 +[root@redhat9 attributs]# getenforce
 Permissive Permissive
 </code> </code>
Ligne 827: Ligne 598:
  
 <code> <code>
-[root@centos7 /]# sestatus+root@redhat9 attributs]# sestatus
 SELinux status:                 enabled SELinux status:                 enabled
 SELinuxfs mount:                /sys/fs/selinux SELinuxfs mount:                /sys/fs/selinux
Ligne 836: Ligne 607:
 Policy MLS status:              enabled Policy MLS status:              enabled
 Policy deny_unknown status:     allowed Policy deny_unknown status:     allowed
-Max kernel policy version:      28+Memory protection checking:     actual (secure) 
 +Max kernel policy version:      33
 </code> </code>
  
Ligne 844: Ligne 616:
  
 <code> <code>
-[root@centos7 /]# sestatus -v+[root@redhat9 attributs]# sestatus -v
 SELinux status:                 enabled SELinux status:                 enabled
 SELinuxfs mount:                /sys/fs/selinux SELinuxfs mount:                /sys/fs/selinux
Ligne 853: Ligne 625:
 Policy MLS status:              enabled Policy MLS status:              enabled
 Policy deny_unknown status:     allowed Policy deny_unknown status:     allowed
-Max kernel policy version:      28+Memory protection checking:     actual (secure) 
 +Max kernel policy version:      33
  
 Process contexts: Process contexts:
Ligne 870: Ligne 643:
 /sbin/init                      system_u:object_r:bin_t:s0 -> system_u:object_r:init_exec_t:s0 /sbin/init                      system_u:object_r:bin_t:s0 -> system_u:object_r:init_exec_t:s0
 /usr/sbin/sshd                  system_u:object_r:sshd_exec_t:s0 /usr/sbin/sshd                  system_u:object_r:sshd_exec_t:s0
-/lib/libc.so.6                  system_u:object_r:lib_t:s0 -> system_u:object_r:lib_t:s0 
-/lib/ld-linux.so.2              system_u:object_r:lib_t:s0 -> system_u:object_r:ld_so_t:s0 
 </code> </code>
  
Ligne 881: Ligne 652:
  
 <code> <code>
-[root@centos7 /]# getsebool -a | more+[root@redhat9 attributs]# getsebool -a | more
 abrt_anon_write --> off abrt_anon_write --> off
 abrt_handle_event --> off abrt_handle_event --> off
Ligne 902: Ligne 673:
 cobbler_use_nfs --> off cobbler_use_nfs --> off
 collectd_tcp_network_connect --> off collectd_tcp_network_connect --> off
 +colord_use_nfs --> off
 condor_tcp_network_connect --> off condor_tcp_network_connect --> off
 conman_can_network --> off conman_can_network --> off
 +conman_use_nfs --> off
 container_connect_any --> off container_connect_any --> off
 +container_manage_cgroup --> off
 +container_read_certs --> off
 +container_use_cephfs --> off
 +container_use_devices --> off
 +container_use_dri_devices --> on
 +container_use_ecryptfs --> off
 +container_user_exec_content --> on
 +cron_can_relabel --> off
 +cron_system_cronjob_use_shares --> off
 +cron_userdomain_transition --> on
 +cups_execmem --> off
 +cvs_read_shadow --> off
 +daemons_dontaudit_scheduling --> on
 +daemons_dump_core --> off
 +daemons_enable_cluster_mode --> off
 +daemons_use_tcp_wrapper --> off
 +daemons_use_tty --> off
 +dbadm_exec_content --> on
 +dbadm_manage_user_files --> off
 +dbadm_read_user_files --> off
 +deny_bluetooth --> off
 +deny_execmem --> off
 +deny_ptrace --> off
 +dhcpc_exec_iptables --> off
 +dhcpd_use_ldap --> off
 +dnsmasq_use_ipset --> off
 +domain_can_mmap_files --> off
 --More-- --More--
 </code> </code>
Ligne 911: Ligne 711:
  
 <code> <code>
-[root@centos7 /]# sestatus -b | more+[root@redhat9 attributs]# sestatus -b | more
 SELinux status:                 enabled SELinux status:                 enabled
 SELinuxfs mount:                /sys/fs/selinux SELinuxfs mount:                /sys/fs/selinux
Ligne 920: Ligne 720:
 Policy MLS status:              enabled Policy MLS status:              enabled
 Policy deny_unknown status:     allowed Policy deny_unknown status:     allowed
-Max kernel policy version:      28+Memory protection checking:     actual (secure) 
 +Max kernel policy version:      33
  
 Policy booleans: Policy booleans:
Ligne 935: Ligne 736:
 boinc_execmem                               on boinc_execmem                               on
 cdrecord_read_content                       off cdrecord_read_content                       off
 +cluster_can_network_connect                 off
 +cluster_manage_all_files                    off
 +cluster_use_execmem                         off
 +cobbler_anon_write                          off
 +cobbler_can_network_connect                 off
 +cobbler_use_cifs                            off
 +cobbler_use_nfs                             off
 +collectd_tcp_network_connect                off
 +colord_use_nfs                              off
 +condor_tcp_network_connect                  off
 +conman_can_network                          off
 +conman_use_nfs                              off
 +container_connect_any                       off
 +container_manage_cgroup                     off
 +container_read_certs                        off
 +container_use_cephfs                        off
 +container_use_devices                       off
 +container_use_dri_devices                   on
 +container_use_ecryptfs                      off
 +container_user_exec_content                 on
 +cron_can_relabel                            off
 +cron_system_cronjob_use_shares              off
 +cron_userdomain_transition                  on
 +cups_execmem                                off
 +cvs_read_shadow                             off
 +daemons_dontaudit_scheduling                on
 +daemons_dump_core                           off
 +daemons_enable_cluster_mode                 off
 --More-- --More--
 </code> </code>
Ligne 941: Ligne 770:
  
 <code> <code>
-[root@centos7 /]# setsebool antivirus_can_scan_system 1 +[root@redhat9 attributs]# setsebool antivirus_can_scan_system 1 
-[root@centos7 /]# getsebool antivirus_can_scan_system+ 
 +[root@redhat9 attributs]# getsebool antivirus_can_scan_system
 antivirus_can_scan_system --> on antivirus_can_scan_system --> on
-[root@centos7 /]# setsebool antivirus_can_scan_system 0 + 
-[root@centos7 /]# getsebool antivirus_can_scan_system+[root@redhat9 attributs]# setsebool antivirus_can_scan_system 0 
 + 
 +[root@redhat9 attributs]# getsebool antivirus_can_scan_system
 antivirus_can_scan_system --> off antivirus_can_scan_system --> off
 </code> </code>
Ligne 954: Ligne 786:
    
 <code> <code>
-[root@centos7 ~]# semodule -DB+[root@redhat9 attributs]# semodule -DB
 </code> </code>
  
Ligne 960: Ligne 792:
  
 <code> <code>
-[root@centos7 ~]# seinfo +[root@redhat9 attributs]# seinfo
 Statistics for policy file: /sys/fs/selinux/policy Statistics for policy file: /sys/fs/selinux/policy
-Policy Version & Typev.28 (binary, mls+Policy Version:             33 (MLS enabled
- +Target Policy:              selinux 
-   Classes:            94    Permissions:       262 +Handle unknown classes:     allow 
-   Sensitivities:       1    Categories:       1024 +  Classes:             135    Permissions:         457 
-   Types:            4747    Attributes:        251 +  Sensitivities:         1    Categories:         1024 
-   Users:               8    Roles:              14 +  Types:              5145    Attributes:          259 
-   Booleans:          307    Cond. Expr.:       356 +  Users:                 8    Roles:                15 
-   Allow:          101746    Neverallow:          +  Booleans:            356    Cond. Expr.:         385 
-   Auditallow:        155    Dontaudit:           +  Allow:             65504    Neverallow:            
-   Type_trans:      17759    Type_change:        74 +  Auditallow:          176    Dontaudit:             
-   Type_member:        35    Role allow:         39 +  Type_trans:       271770    Type_change:          94 
-   Role_trans:        416    Range_trans     5697 +  Type_member:          37    Range_trans:        5931 
-   Constraints      109    Validatetrans:       0 +  Role allow:           40    Role_trans:          417 
-   Initial SIDs:       27    Fs_use:             29 +  Constraints:          70    Validatetrans:         0 
-   Genfscon:          105    Portcon:           602 +  MLS Constrain:        72    MLS Val. Tran        0 
-   Netifcon:            0    Nodecon:             0 +  Permissives          5    Polcap:                6 
-   Permissives:            Polcap:              2+  Defaults:              7    Typebounds:            0 
 +  Allowxperm:            0    Neverallowxperm:       0 
 +  Auditallowxperm:          Dontauditxperm:        0 
 +  Ibendportcon:          0    Ibpkeycon:             0 
 +  Initial SIDs:         27    Fs_use:               35 
 +  Genfscon:            109    Portcon:             665 
 +  Netifcon:              0    Nodecon:               0
 </code> </code>
  
-====Copier et Déplacer des Fichiers====+====3.1 - Copier et Déplacer des Fichiers====
  
 Créez deux fichiers **file1** et **file2** en tant que l'utilisateur **trainee** puis visualisez les SC des fichiers : Créez deux fichiers **file1** et **file2** en tant que l'utilisateur **trainee** puis visualisez les SC des fichiers :
  
 <code> <code>
-[root@centos7 /]# exit+[root@redhat9 attributs]# exit
 logout logout
-[trainee@centos7 ~]$ touch file1 file2 + 
-[trainee@centos7 ~]$ ls -Z file* +[trainee@redhat9 ~]$ touch file1 file2 
--rw-rw-r--. trainee trainee unconfined_u:object_r:user_home_t:s0 file1 + 
--rw-rw-r--. trainee trainee unconfined_u:object_r:user_home_t:s0 file2+[trainee@redhat9 ~]$ ls -Z file* 
 +unconfined_u:object_r:user_home_t:s0 file1 
 +unconfined_u:object_r:user_home_t:s0 file2
 </code> </code>
  
Ligne 1000: Ligne 839:
  
 <code> <code>
-[trainee@centos7 ~]$ cp file1 /tmp +[trainee@redhat9 ~]$ cp file1 /tmp 
-[trainee@centos7 ~]$ ls -Z /tmp/file1 + 
--rw-rw-r--. trainee trainee unconfined_u:object_r:user_tmp_t:s0 /tmp/file1+[trainee@redhat9 ~]$ ls -Z /tmp/file1 
 +unconfined_u:object_r:user_tmp_t:s0 /tmp/file1
 </code> </code>
  
Ligne 1010: Ligne 850:
  
 <code> <code>
-[trainee@centos7 ~]$ mv file2 /tmp +[trainee@redhat9 ~]$ mv file2 /tmp 
-[trainee@centos7 ~]$ ls -Z /tmp/file2 + 
--rw-rw-r--. trainee trainee unconfined_u:object_r:user_home_t:s0 /tmp/file2+[trainee@redhat9 ~]$ ls -Z /tmp/file2 
 +unconfined_u:object_r:user_home_t:s0 /tmp/file2
 </code> </code>
  
 Notez que la commande **mv** maintient le **type** d'origine. Notez que la commande **mv** maintient le **type** d'origine.
  
-====Vérifier les SC des Processus====+====3.2 - Vérifier les SC des Processus====
  
 Il convient d'utiliser l'option **Z** avec la commande **ps** : Il convient d'utiliser l'option **Z** avec la commande **ps** :
  
 <code> <code>
-[trainee@centos7 ~]$ ps auxZ | more +[trainee@redhat9 ~]$ ps auxZ | more 
-LABEL                           USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND +LABEL                           USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND 
-system_u:system_r:init_t:s0     root         1  0.0  1.2  46140  6456 ?        Ss   juin17   0:27 /usr/lib/systemd/systemd --system -- +system_u:system_r:init_t:s0     root           1  0.0  0.2 175884 21416 ?        Ss   Oct21   0:47 /usr/lib/systemd/systemd rhgb --switched-root -- 
-deserialize 24 +system --deserialize 31 
-system_u:system_r:kernel_t:s0   root         2  0.0  0.0      0     0 ?        S    juin17   0:00 [kthreadd] +system_u:system_r:kernel_t:s0   root           2  0.0  0.0      0     0 ?        S    Oct21   0:00 [kthreadd] 
-system_u:system_r:kernel_t:s0   root         3  0.0  0.0      0     0 ?        S    juin17   0:25 [ksoftirqd/0+system_u:system_r:kernel_t:s0   root           3  0.0  0.0      0     0 ?        I<   Oct21   0:00 [rcu_gp
-system_u:system_r:kernel_t:s0   root         5  0.0  0.0      0     0 ?        S<   juin17   0:00 [kworker/0:0H+system_u:system_r:kernel_t:s0   root           4  0.0  0.0      0     0 ?        I<   Oct21   0:00 [rcu_par_gp
-system_u:system_r:kernel_t:s0   root         6  0.0  0.0      0     0 ?        S    juin17   0:00 [kworker/u2:0+system_u:system_r:kernel_t:s0   root           5  0.0  0.0      0     0 ?        I<   Oct21   0:00 [slub_flushwq
-system_u:system_r:kernel_t:s0   root         7  0.0  0.0      0     0 ?        S    juin17   0:00 [migration/0+system_u:system_r:kernel_t:s0   root           6  0.0  0.0      0     0 ?        I<   Oct21   0:00 [netns
-system_u:system_r:kernel_t:s0   root         8  0.0  0.0      0     0 ?        S    juin17   0:00 [rcu_bh] +system_u:system_r:kernel_t:s0   root           8  0.0  0.0      0     0 ?        I<   Oct21   0:00 [kworker/0:0H-events_highpri
-system_u:system_r:kernel_t:s0   root          0.0  0.0      0     0 ?        S    juin17   0:17 [rcu_sched+system_u:system_r:kernel_t:s0   root          10  0.0  0.0      0     0 ?        I<   Oct21   0:00 [mm_percpu_wq
-system_u:system_r:kernel_t:s0   root        10  0.0  0.0      0     0 ?        S    juin17   0:01 [watchdog/0+system_u:system_r:kernel_t:s0   root          12  0.0  0.0      0     0 ?           Oct21   0:00 [rcu_tasks_kthre
-system_u:system_r:kernel_t:s0   root        12  0.0  0.0      0     0 ?           juin17   0:00 [kdevtmpfs+system_u:system_r:kernel_t:s0   root          13  0.0  0.0      0     0 ?        I    Oct21   0:00 [rcu_tasks_rude_
-system_u:system_r:kernel_t:s0   root        13  0.0  0.0      0     0 ?        S<   juin17   0:00 [netns+system_u:system_r:kernel_t:s0   root          14  0.0  0.0      0     0 ?           Oct21   0:00 [rcu_tasks_trace
-system_u:system_r:kernel_t:s0   root        14  0.0  0.0      0     0 ?           juin17   0:00 [khungtaskd+system_u:system_r:kernel_t:s0   root          15  0.0  0.0      0     0 ?        S    Oct21   0:00 [ksoftirqd/0
-system_u:system_r:kernel_t:s0   root        15  0.0  0.0      0     0 ?        S<   juin17   0:00 [writeback+system_u:system_r:kernel_t:s0   root          16  0.0  0.0      0     0 ?        I    Oct21   0:01 [rcu_preempt
-system_u:system_r:kernel_t:s0   root        16  0.0  0.0      0     0 ?        S<   juin17   0:00 [kintegrityd+system_u:system_r:kernel_t:s0   root          17  0.0  0.0      0     0 ?        S    Oct21   0:00 [migration/0
-system_u:system_r:kernel_t:s0   root        17  0.0  0.0      0     0 ?        S<   juin17   0:00 [bioset+system_u:system_r:kernel_t:s0   root          18  0.0  0.0      0     0 ?        S    Oct21   0:00 [idle_inject/0] 
-system_u:system_r:kernel_t:s0   root        18  0.0  0.0      0     0 ?        S<   juin17   0:00 [kblockd] +system_u:system_r:kernel_t:s0   root          20  0.0  0.0      0     0 ?        S    Oct21   0:00 [cpuhp/0] 
-system_u:system_r:kernel_t:s0   root        19  0.0  0.0      0     0 ?        S<   juin17   0:00 [md+system_u:system_r:kernel_t:s0   root          21  0.0  0.0      0     0 ?        S    Oct21   0:00 [cpuhp/1
-system_u:system_r:kernel_t:s0   root        25  0.0  0.0      0     0 ?        S    juin17   0:05 [kswapd0] +system_u:system_r:kernel_t:s0   root          22  0.0  0.0      0     0 ?        S    Oct21   0:00 [idle_inject/1
-system_u:system_r:kernel_t:s0   root        26  0.0  0.0      0     0 ?        SN   juin17   0:00 [ksmd] +system_u:system_r:kernel_t:s0   root          23  0.0  0.0      0     0 ?        S    Oct21   0:00 [migration/1
-system_u:system_r:kernel_t:s0   root        27  0.0  0.0      0     0 ?        S<   juin17   0:00 [crypto+system_u:system_r:kernel_t:s0   root          24  0.0  0.0      0     0 ?        S    Oct21   0:00 [ksoftirqd/1
-system_u:system_r:kernel_t:s0   root        35  0.0  0.0      0     0 ?        S<   juin17   0:00 [kthrotld+system_u:system_r:kernel_t:s0   root          27  0.0  0.0      0     0 ?        S    Oct21   0:00 [cpuhp/2
-system_u:system_r:kernel_t:s0   root        37  0.0  0.0      0     0 ?        S<   juin17   0:00 [kmpath_rdacd+system_u:system_r:kernel_t:s0   root          28  0.0  0.0      0     0 ?        S    Oct21   0:00 [idle_inject/2
-system_u:system_r:kernel_t:s0   root        38  0.0  0.0      0     0 ?        S<   juin17   0:00 [kpsmoused+system_u:system_r:kernel_t:s0   root          29  0.0  0.0      0     0 ?        S    Oct21   0:00 [migration/2
-system_u:system_r:kernel_t:s0   root        39  0.0  0.0      0     0 ?        S<   juin17   0:00 [ipv6_addrconf+system_u:system_r:kernel_t:s0   root          30  0.0  0.0      0     0 ?        S    Oct21   0:00 [ksoftirqd/2
-system_u:system_r:kernel_t:s0   root        59  0.0  0.0      0     0 ?        S<   juin17   0:00 [deferwq+system_u:system_r:kernel_t:s0   root          32  0.0  0.0      0     0 ?        I<   Oct21   0:00 [kworker/2:0H-events_highpri
-system_u:system_r:kernel_t:s0   root        94  0.0  0.0      0     0 ?        S    juin17   0:00 [kauditd+system_u:system_r:kernel_t:s0   root          33  0.0  0.0      0     0 ?        S    Oct21   0:00 [cpuhp/3
-system_u:system_r:kernel_t:s0   root       226  0.0  0.0      0     0 ?        S<   juin17   0:00 [ata_sff+system_u:system_r:kernel_t:s0   root          34  0.0  0.0      0     0 ?        S    Oct21   0:00 [idle_inject/3
-system_u:system_r:kernel_t:s0   root       238  0.0  0.0      0     0 ?        S    juin17   0:00 [scsi_eh_0+system_u:system_r:kernel_t:s0   root          35  0.0  0.0      0     0 ?        S    Oct21   0:00 [migration/3
-system_u:system_r:kernel_t:s0   root       240  0.0  0.0      0     0 ?        S<   juin17   0:00 [scsi_tmf_0+--More--
-system_u:system_r:kernel_t:s0   root       241  0.0  0.0      0     0 ?        S    juin17   0:00 [scsi_eh_1+
-system_u:system_r:kernel_t:s0   root       242  0.0  0.0      0     0 ?        S    juin17   0:02 [kworker/u2:2+
-system_u:system_r:kernel_t:s0   root       243  0.0  0.0      0     0 ?        S<   juin17   0:00 [scsi_tmf_1] +
-system_u:system_r:kernel_t:s0   root       244  0.0  0.0      0     0 ?        S    juin17   0:00 [scsi_eh_2+
---Plus--+
 </code> </code>
  
-====Visualiser la SC d'un Utilisateur====+====3.3 - Visualiser la SC d'un Utilisateur====
  
 Utilisez l'option **-Z** avec la commande **id** : Utilisez l'option **-Z** avec la commande **id** :
  
 <code> <code>
-[trainee@centos7 ~]$ id -Z+[trainee@redhat9 ~]$ id -Z
 unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
 </code> </code>
Ligne 1073: Ligne 909:
  
 <code> <code>
-[trainee@centos7 ~]$ id root +[trainee@redhat9 ~]$ id root 
-uid=0(root) gid=0(root) groupes=0(root) +uid=0(root) gid=0(root) groups=0(root) 
-[trainee@centos7 ~]$ id -Z root + 
-id: impossible d'afficher le contexte de sécurité quand un utilisateur est indiqué+[trainee@redhat9 ~]$ id -Z root 
 +id: cannot print security context when user specified
 </code> </code>
  
-====Vérifier la SC d'un fichier====+====3.4 - Vérifier la SC d'un fichier====
  
 Il convient d'utiliser la commande ls avec l'option **-Z** : Il convient d'utiliser la commande ls avec l'option **-Z** :
  
 <code> <code>
-[trainee@centos7 ~]$ cd /etc +[trainee@redhat9 ~]$ cd /etc 
-[trainee@centos7 etc]$ ls -Z l* -d + 
--rw-r--r--. root root unconfined_u:object_r:ld_so_cache_t:s0 ld.so.cache +[trainee@redhat9 etc]$ ls -Z l* -d 
--rw-r--r--. root root system_u:object_r:etc_t:s0       ld.so.conf +unconfined_u:object_r:ld_so_cache_t:s0 ld.so.cache                system_u:object_r:etc_t:s0 libssh 
-drwxr-xr-xroot root system_u:object_r:etc_t:s0       ld.so.conf.d +            system_u:object_r:etc_t:s0 ld.so.conf                 system_u:object_r:etc_t:s0 libuser.conf 
--rw-r-----root root system_u:object_r:etc_t:s0       libaudit.conf +            system_u:object_r:etc_t:s0 ld.so.conf.d            system_u:object_r:locale_t:s0 locale.conf 
-drwxr-xr-x. root root system_u:object_r:etc_t:s0       libnl +            system_u:object_r:etc_t:s0 libaudit.conf           system_u:object_r:locale_t:s0 localtime 
-drwxr-xr-x. root root system_u:object_r:etc_t:s0       libreport +            system_u:object_r:etc_t:s0 libblockdev                system_u:object_r:etc_t:s0 login.defs 
--rw-r--r--. root root unconfined_u:object_r:etc_t:s0   libuser.conf +            system_u:object_r:etc_t:s0 libibverbs.d               system_u:object_r:etc_t:s0 logrotate.conf 
--rw-r--r--. root root unconfined_u:object_r:locale_t:s0 locale.conf +            system_u:object_r:etc_t:s0 libnl                      system_u:object_r:etc_t:s0 logrotate.d 
-lrwxrwxrwx. root root unconfined_u:object_r:locale_t:s0 localtime -> ../usr/share/zoneinfo/Europe/Paris +            system_u:object_r:etc_t:s0 libpaper.d                 system_u:object_r:etc_t:s0 lsm 
--rw-r--r--. root root unconfined_u:object_r:etc_t:s0   login.defs +            system_u:object_r:etc_t:s0 libreport              system_u:object_r:lvm_etc_t:s0 lvm
--rw-r--r--. root root system_u:object_r:etc_t:s0       logrotate.conf +
-drwxr-xr-x. root root system_u:object_r:etc_t:s0       logrotate.d +
-drwxr-xr-x. root root system_u:object_r:etc_t:s0       lsm +
-drwxr-xr-x. root root system_u:object_r:lvm_etc_t:s0   lvm+
 </code> </code>
  
-====Troubleshooting SELinux====+====3.5 - Troubleshooting SELinux====
  
 L'interprétation des messages journalisés de %%SELinux%% est souvent la clef d'un dépannage efficace et rapide. L'interprétation des messages journalisés de %%SELinux%% est souvent la clef d'un dépannage efficace et rapide.
Ligne 1108: Ligne 941:
 Si le démon **auditd** est démarré, les messages de %%SELinux%% sont consignés dans le fichier **/var/log/audit/audit.log**. Dans le cas contraire, les mêmes messages sont consignés dans le fichier **/var/log/messages**. Dans les deux cas, chaque message de %%SELinux%% contient le mot clef **AVC** :  Si le démon **auditd** est démarré, les messages de %%SELinux%% sont consignés dans le fichier **/var/log/audit/audit.log**. Dans le cas contraire, les mêmes messages sont consignés dans le fichier **/var/log/messages**. Dans les deux cas, chaque message de %%SELinux%% contient le mot clef **AVC** : 
  
-===La commande chcon===+====3.6 - La commande chcon====
  
 La commande **chcon** permet de modifier //temporairement// une SC. La commande **chcon** permet de modifier //temporairement// une SC.
 +
 +Prenons le cas de la création d'un répertoire à la racine du système de fichiers afin d'y stocker les pages web du serveur apache :
  
 <code> <code>
-[trainee@centos7 etc]$ cd ~ +[trainee@redhat9 etc]$ su 
-[trainee@centos7 ~]$ chcon --help +Passwordfenestros
-Utilisation chcon [OPTION]... CONTEXT FILE... +
-         ou : chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... +
-         ou : chcon [OPTION]... --reference=RFILE FILE... +
-Modifier le contexte de sécurité SELinux de chaque FILE en CONTEXT. +
-Avec --reference, modifier le contexte de sécurité de chaque FILE à +
-celui de RFILE. +
- +
-Les arguments obligatoires pour les options longues le sont aussi pour les +
-options courtes. +
-      --dereference      affecter le référent de chaque lien symbolique (par +
-                           défaut), au lieu du lien symbolique lui-même +
-  -h, --no-dereference   affecter les liens symboliques au lieu des fichiers +
-                           référencés +
-  -u, --user=USER        définir l'utilisateur USER dans le contexte de +
-                           sécurité cible +
-  -r, --role=ROLE        définir le rôle ROLE dans le contexte de sécurité cible +
-  -t, --type=TYPE        définir le type TYPE dans le contexte de sécurité cible +
-  -l, --range=RANGE      définir l'intervalle RANGE dans le contexte de +
-                         sécurité cible +
-      --no-preserve-root ne pas traiter « / » de manière spéciale (par défaut) +
-      --preserve-root    bloquer le traitement récursif sur « / » +
-      --reference=RFILE  utiliser le contexte de sécurité de RFILE au lieu +
-                           d'indiquer une valeur CONTEXT +
-  -R, --recursive        opérer récursivement sur les fichiers et répertoires +
-  -v, --verbose          afficher un diagnostic pour chaque fichier traité +
- +
-Les options suivantes modifient la façon de parcourir la hiérarchie lorsque +
-l'option -R est aussi indiquée. Si plusieurs options sont indiquées, seule la +
-dernière sera prise en compte. +
- +
-  -H                     si l'argument en ligne de commande est un lien +
-                           symbolique vers un répertoire, le parcourir +
-  -L                     parcourir tous les liens symboliques menant à un +
-                           répertoire +
-  -P                     ne parcourir aucun lien symbolique (par défaut) +
- +
-      --help     afficher l'aide et quitter +
-      --version  afficher des informations de version et quitter+
  
-Aide en ligne de GNU coreutils : <http://www.gnu.org/software/coreutils/> +[root@redhat9 ~]# mkdir /www 
-Signalez les problèmes de traduction de « chcon » à : <traduc@traduc.org> +[root@redhat9 ~]# touch /www/index.html
-Utilisez « info coreutils 'chcon invocation' » pour toute la documentation+
 </code> </code>
  
-Prenons le cas de la création d'un répertoire à la racine du système de fichiers afin d'y stocker les pages web du serveur apache :+Installez maintenant le serveur Apache :
  
 <code> <code>
-[trainee@centos7 ~]$ su - +[root@redhat9 ~]# dnf install httpd
-Mot de passe :  +
-Dernière connexion : dimanche 17 juin 2018 à 20:21:42 CEST sur pts/1 +
-[root@centos7 ~]# mkdir /www +
-[root@centos7 ~]# touch /www/index.html+
 </code> </code>
  
-Installez maintenant le serveur Apache :+Activez et démarrez le service **httpd** :
  
 <code> <code>
-[root@centos7 ~]# yum install httpd+[root@redhat9 ~]# systemctl status httpd 
 +○ httpd.service - The Apache HTTP Server 
 +     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled) 
 +     Active: inactive (dead) 
 +       Docs: man:httpd.service(8) 
 +[root@redhat9 ~]# systemctl enable --now httpd 
 +Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. 
 +[root@redhat9 ~]# systemctl status httpd 
 +● httpd.service - The Apache HTTP Server 
 +     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled) 
 +     Active: active (running) since Tue 2024-10-22 10:15:49 CEST; 3s ago 
 +       Docs: man:httpd.service(8) 
 +   Main PID: 101100 (httpd) 
 +     Status: "Started, listening on: port 80" 
 +      Tasks: 177 (limit: 48800) 
 +     Memory: 34.5M 
 +        CPU: 86ms 
 +     CGroup: /system.slice/httpd.service 
 +             ├─101100 /usr/sbin/httpd -DFOREGROUND 
 +             ├─101101 /usr/sbin/httpd -DFOREGROUND 
 +             ├─101102 /usr/sbin/httpd -DFOREGROUND 
 +             ├─101103 /usr/sbin/httpd -DFOREGROUND 
 +             └─101104 /usr/sbin/httpd -DFOREGROUND 
 + 
 +Oct 22 10:15:49 redhat9.ittraining.loc systemd[1]: Starting The Apache HTTP Server... 
 +Oct 22 10:15:49 redhat9.ittraining.loc httpd[101100]: Server configured, listening on: port 80 
 +Oct 22 10:15:49 redhat9.ittraining.loc systemd[1]: Started The Apache HTTP Server.
 </code> </code>
  
 Modifiez ensuite la directive **%%DocumentRoot%%** dans le fichier **/etc/httpd/conf/httpd.conf** : Modifiez ensuite la directive **%%DocumentRoot%%** dans le fichier **/etc/httpd/conf/httpd.conf** :
 +
 +<code>
 +[root@redhat9 ~]# vi /etc/httpd/conf/httpd.conf
 +</code>
  
 <file> <file>
Ligne 1208: Ligne 1030:
  
 <code> <code>
-[root@centos7 ~]# vi /www/index.html +[root@redhat9 ~]# vi /www/index.html 
-[root@centos7 ~]# cat /www/index.html+ 
 +[root@redhat9 ~]# cat /www/index.html
 <html> <html>
 <title> <title>
Ligne 1223: Ligne 1046:
  
 <code> <code>
-[root@centos7 ~]# chown -R apache:apache /www+[root@redhat9 ~]# chown -R apache:apache /www
 </code> </code>
  
Ligne 1229: Ligne 1052:
  
 <code> <code>
-[root@centos7 ~]# touch /var/www/html/index.html+[root@redhat9 ~]# touch /var/www/html/index.html
 </code> </code>
  
Ligne 1235: Ligne 1058:
  
 <code> <code>
-[root@centos7 ~]# systemctl restart httpd.service+[root@redhat9 ~]# systemctl restart httpd.service
 </code> </code>
  
-Consultez le site localhost en utilisant **lynx** : +Installez le paquet **lynx** :
  
 <code> <code>
-[root@centos7 ~]# lynx localhost+[root@redhat9 ~]# dnf install lynx -y
 </code> </code>
  
-Pour consulter les messages d'alerte de %%SELinux%%, vous disposez de la commande **sealert** du paquet **setroubleshoot-server**.  +Consultez le site localhost en utilisant **lynx** : 
- +
-Installez donc ce paquet :+
  
 <code> <code>
-[root@centos7 ~]# yum install setroubleshoot-server+[root@redhat9 ~]# lynx localhost
 </code> </code>
  
Ligne 1255: Ligne 1076:
  
 <code> <code>
-[root@centos7 ~]# sealert -a /var/log/audit/audit.log > /root/mylogfile.txt +[root@redhat9 ~]# sealert -a /var/log/audit/audit.log > /root/mylogfile.txt
-type=AVC msg=audit(1524491216.546:616): avc:  denied  { getattr } for  pid=15389 comm="gssproxy" name="/" dev="sda2" ino=128 scontext=system_u:system_r:gssproxy_t:s0 tcontext=system_u:object_r:fs_t:s0 tclass=filesystem +
-  +
-**** Invalid AVC allowed in current policy *** +
- +
-type=AVC msg=audit(1524491220.766:622): avc:  denied  { getattr } for  pid=15459 comm="gssproxy" name="/" dev="sda2" ino=128 scontext=system_u:system_r:gssproxy_t:s0 tcontext=system_u:object_r:fs_t:s0 tclass=filesystem +
-  +
-**** Invalid AVC allowed in current policy ***+
 </code> </code>
  
Ligne 1268: Ligne 1082:
  
 <code> <code>
-[root@centos7 ~]# more /root/mylogfile.txt +[root@redhat9 ~]# more /root/mylogfile.txt
  
-found alerts in /var/log/audit/audit.log+found 24 alerts in /var/log/audit/audit.log
 -------------------------------------------------------------------------------- --------------------------------------------------------------------------------
  
-SELinux is preventing /usr/libexec/dbus-1/dbus-daemon-launch-helper from using the rlimitinh access on a process.+SELinux is preventing /usr/bin/pkla-check-authorization from using the noatsecure access on a process.
  
 *****  Plugin catchall (100. confidence) suggests   ************************** *****  Plugin catchall (100. confidence) suggests   **************************
  
-you believe that dbus-daemon-launch-helper should be allowed rlimitinh access on processes labeled unconfined_service_t by default.+If you believe that pkla-check-authorization should be allowed noatsecure access on processes labeled policykit_auth_t by default.
 Then you should report this as a bug. Then you should report this as a bug.
 You can generate a local policy module to allow this access. You can generate a local policy module to allow this access.
 Do Do
 allow this access for now by executing: allow this access for now by executing:
-# ausearch -c 'dbus-daemon-lau' --raw | audit2allow -M my-dbusdaemonlau +# ausearch -c 'pkla-check-auth' --raw | audit2allow -M my-pklacheckauth 
-# semodule -i my-dbusdaemonlau.pp+# semodule -X 300 -i my-pklacheckauth.pp
  
  
 Additional Information: Additional Information:
-Source Context                system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 +Source Context                system_u:system_r:policykit_t:s0 
-Target Context                system_u:system_r:unconfined_service_t:s0-s0:c0.c1 +Target Context                system_u:system_r:policykit_auth_t:s0 
-                              023 +Target Objects                /lib64/ld-linux-x86-64.so.2 [ process ] 
-Target Objects                Unknown [ process ] +Source                        pkla-check-auth 
-Source                        dbus-daemon-lau +Source Path                   /usr/bin/pkla-check-authorization
-Source Path                   /usr/libexec/dbus-1/dbus-daemon-launch-helper+
 Port                          <Unknown> Port                          <Unknown>
 Host                          <Unknown> Host                          <Unknown>
-Source RPM Packages           dbus-1.10.24-13.el7_6.x86_64 +Source RPM Packages           polkit-pkla-compat-0.1-21.el9.x86_64 
-Target RPM Packages            +Target RPM Packages           glibc-2.34-100.el9_4.3.x86_64 
-Policy RPM                    selinux-policy-3.13.1-166.el7_4.9.noarch+SELinux Policy RPM            selinux-policy-targeted-38.1.35-2.el9_4.2.noarch 
 +Local Policy RPM              selinux-policy-targeted-38.1.35-2.el9_4.2.noarch
 Selinux Enabled               True Selinux Enabled               True
 Policy Type                   targeted Policy Type                   targeted
 Enforcing Mode                Permissive Enforcing Mode                Permissive
-Host Name                     centos7.fenestros.loc +Host Name                     redhat9.ittraining.loc 
-Platform                      Linux centos7.fenestros.loc +Platform                      Linux redhat9.ittraining.loc 
-                              3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 +                              5.14.0-427.37.1.el9_4.x86_64 #1 SMP 
-                              19:03:37 UTC 2018 x86_64 x86_64 +                              PREEMPT_DYNAMIC Fri Sep 13 12:41:50 EDT 2024 
-Alert Count                   1 +                              x86_64 x86_64 
-First Seen                    2020-01-23 16:04:33 CET +Alert Count                   10 
-Last Seen                     2020-01-23 16:04:33 CET +First Seen                    2024-10-22 10:01:01 CEST 
---More--(4%)+Last Seen                     2024-10-22 10:33:01 CEST 
 +Local ID                      344c2abc-bac6-4064-ae22-411f0ce680cd 
 + 
 +Raw Audit Messages 
 +type=AVC msg=audit(1729585981.217:17543)avc:  denied  { noatsecure } for  pid=102284 comm="polkitd" scontext=system_u:system_r:policykit_t:s0 tco 
 +ntext=system_u:system_r:policykit_auth_t:s0 tclass=process permissive=1 
 + 
 + 
 +type=AVC msg=audit(1729585981.217:17543): avc:  denied  { rlimitinh } for  pid=102284 comm="pkla-check-auth" scontext=system_u:system_r:policykit_t 
 +:s0 tcontext=system_u:system_r:policykit_auth_t:s0 tclass=process permissive=1 
 + 
 + 
 +--More--(1%)
 </code> </code>
  
Ligne 1314: Ligne 1140:
  
 <code> <code>
-*****  Plugin catchall (17.confidence) suggests   **************************+... 
 +*****  Plugin catchall (100. confidence) suggests   **************************
  
-you believe that httpd should be allowed getattr access on the index.html file by default.+If you believe that httpd should have the net_admin capability by default.
 Then you should report this as a bug. Then you should report this as a bug.
 You can generate a local policy module to allow this access. You can generate a local policy module to allow this access.
Ligne 1322: Ligne 1149:
 allow this access for now by executing: allow this access for now by executing:
 # ausearch -c 'httpd' --raw | audit2allow -M my-httpd # ausearch -c 'httpd' --raw | audit2allow -M my-httpd
-# semodule -i my-httpd.pp+# semodule -X 300 -i my-httpd.pp
  
  
 Additional Information: Additional Information:
 Source Context                system_u:system_r:httpd_t:s0 Source Context                system_u:system_r:httpd_t:s0
-Target Context                unconfined_u:object_r:default_t:s0 +Target Context                system_u:system_r:httpd_t:s0 
-Target Objects                /www/index.html file ]+Target Objects                Unknown capability ]
 Source                        httpd Source                        httpd
 Source Path                   /usr/sbin/httpd Source Path                   /usr/sbin/httpd
 Port                          <Unknown> Port                          <Unknown>
 Host                          <Unknown> Host                          <Unknown>
-Source RPM Packages           httpd-2.4.6-90.el7.centos.x86_64 +Source RPM Packages           httpd-core-2.4.57-11.el9_4.1.x86_64 
-Target RPM Packages +Target RPM Packages            
-Policy RPM                    selinux-policy-3.13.1-166.el7_4.9.noarch+SELinux Policy RPM            selinux-policy-targeted-38.1.35-2.el9_4.2.noarch 
 +Local Policy RPM              selinux-policy-targeted-38.1.35-2.el9_4.2.noarch
 Selinux Enabled               True Selinux Enabled               True
 Policy Type                   targeted Policy Type                   targeted
 Enforcing Mode                Permissive Enforcing Mode                Permissive
-Host Name                     centos7.fenestros.loc +Host Name                     redhat9.ittraining.loc 
-Platform                      Linux centos7.fenestros.loc +Platform                      Linux redhat9.ittraining.loc 
-                              3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 +                              5.14.0-427.37.1.el9_4.x86_64 #1 SMP 
-                              19:03:37 UTC 2018 x86_64 x86_64 +                              PREEMPT_DYNAMIC Fri Sep 13 12:41:50 EDT 2024 
-Alert Count                   1 +                              x86_64 x86_64 
-First Seen                    2020-01-23 16:04:30 CET +Alert Count                   9 
-Last Seen                     2020-01-23 16:04:30 CET +First Seen                    2024-10-22 10:15:49 CEST 
-Local ID                      096941d6-1c72-49bd-862b-9bfc3aad32e5+Last Seen                     2024-10-22 10:32:34 CEST 
 +Local ID                      15ae5915-d5a6-4849-b0d1-e4829bfcb57e
  
 Raw Audit Messages Raw Audit Messages
-type=AVC msg=audit(1579791870.276:244): avc:  denied getattr } for  pid=1728 comm="httpd" path="/www/index.html" dev="sda2" ino=2240172 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file+type=AVC msg=audit(1729585954.475:17532): avc:  denied net_admin } for  pid=101828 comm="httpd" capability=12  scontext=system_u:system_r:httpd_ 
 +t:s0 tcontext=system_u:system_r:httpd_t:s0 tclass=capability permissive=1
  
  
-type=SYSCALL msg=audit(1579791870.276:244): arch=x86_64 syscall=stat success=yes exit=0 a0=56255c9727b8 a1=7ffd44466030 a2=7ffd44466030 a3=7f3a4d9ab712 items=0 ppid=1722 pid=1728 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm=httpd exe=/usr/sbin/httpd subj=system_u:system_r:httpd_t:s0 key=(null)+type=SYSCALL msg=audit(1729585954.475:17532): arch=x86_64 syscall=setsockopt success=yes exit=0 a0=a1=a2=20 a3=7ffeb581bbe4 items=0 ppid=pid= 
 +101828 auid=4294967295 uid=gid=euid=suid=fsuid=egid=sgid=fsgid=tty=(none) ses=4294967295 comm=httpd exe=/usr/sbin/httpd subj=system 
 +_u:system_r:httpd_t:s0 key=(null)ARCH=x86_64 SYSCALL=setsockopt AUID=unset UID=root GID=root EUID=root SUID=root FSUID=root EGID=root SGID=root FSG 
 +ID=root
  
-Hash: httpd,httpd_t,default_t,file,getattr+Hash: httpd,httpd_t,httpd_t,capability,net_admin
 </code> </code>
  
Ligne 1360: Ligne 1193:
  
 <code> <code>
-[root@centos6 ~]# ls -Z /www/index.html +[root@redhat9 ~]# ls -Z /www/index.html 
--rw-r--r--. root root unconfined_u:object_r:default_t:s0 /www/index.html+unconfined_u:object_r:default_t:s0 /www/index.html
 </code> </code>
  
 <code> <code>
-[root@centos7 ~]# ls -Z /var/www/html/index.html +[root@redhat9 ~]# ls -Z /var/www/html/index.html 
--rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html+unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html
 </code> </code>
  
Ligne 1374: Ligne 1207:
  
 <code> <code>
-[root@centos7 ~]# chcon -Rv --type=httpd_sys_content_t /www +[root@redhat9 ~]# chcon -Rv --type=httpd_sys_content_t /www 
-changing security context of /www/index.html +changing security context of '/www/index.html' 
-changing security context of /www+changing security context of '/www'
  
-[root@centos7 ~]# ls -Z /www/index.html +[root@redhat9 ~]# ls -Z /www/index.html 
--rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /www/index.html+unconfined_u:object_r:httpd_sys_content_t:s0 /www/index.html
 </code> </code>
  
Ligne 1385: Ligne 1218:
  
 <code> <code>
-[root@centos7 ~]# semanage fcontext -a -t httpd_sys_content_t "/www(/.*)?"+[root@redhat9 ~]# semanage fcontext -a -t httpd_sys_content_t "/www(/.*)?"
 </code> </code>
  
-====La commande restorecon====+Les options de la commande chcon sont :
  
-<file+<code
-usage:  restorecon [-iFnrRv] [-e excludedir ] [-o filename ] [-f filename | pathname... ] +[root@redhat9 ~]# chcon --help 
-</file>+Usagechcon [OPTION]... CONTEXT FILE... 
 +  or:  chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... 
 +  or:  chcon [OPTION]... --reference=RFILE FILE... 
 +Change the SELinux security context of each FILE to CONTEXT. 
 +With --reference, change the security context of each FILE to that of RFILE. 
 + 
 +Mandatory arguments to long options are mandatory for short options too. 
 +      --dereference      affect the referent of each symbolic link (this is 
 +                         the default), rather than the symbolic link itself 
 +  -h, --no-dereference   affect symbolic links instead of any referenced file 
 +  -u, --user=USER        set user USER in the target security context 
 +  -r, --role=ROLE        set role ROLE in the target security context 
 +  -t, --type=TYPE        set type TYPE in the target security context 
 +  -l, --range=RANGE      set range RANGE in the target security context 
 +      --no-preserve-root  do not treat '/' specially (the default) 
 +      --preserve-root    fail to operate recursively on '/' 
 +      --reference=RFILE  use RFILE's security context rather than specifying 
 +                         a CONTEXT value 
 +  -R, --recursive        operate on files and directories recursively 
 +  -v, --verbose          output a diagnostic for every file processed 
 + 
 +The following options modify how a hierarchy is traversed when the -R 
 +option is also specified.  If more than one is specified, only the final 
 +one takes effect. 
 + 
 +  -H                     if a command line argument is a symbolic link 
 +                         to a directory, traverse it 
 +  -L                     traverse every symbolic link to a directory 
 +                         encountered 
 +  -P                     do not traverse any symbolic links (default) 
 + 
 +      --help     display this help and exit 
 +      --version  output version information and exit 
 + 
 +GNU coreutils online help: <https://www.gnu.org/software/coreutils/> 
 +Full documentation <https://www.gnu.org/software/coreutils/chcon> 
 +or available locally via: info '(coreutils) chcon invocation' 
 +</code> 
 + 
 +====3.7 - La commande restorecon====
  
 Pour illustrer l'utilisation de cette commande, créez les fichiers copy.html et move.html dans le répertoire /tmp : Pour illustrer l'utilisation de cette commande, créez les fichiers copy.html et move.html dans le répertoire /tmp :
  
 <code> <code>
-[root@centos7 ~]# cd /tmp ; touch copy.html move.html +[root@redhat9 ~]# cd /tmp ; touch copy.html move.html 
-[root@centos7 tmp]# ls -Z | grep html + 
--rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 copy.html +[root@redhat9 tmp]# ls -Z | grep html 
--rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 move.html+ unconfined_u:object_r:user_tmp_t:s0 copy.html 
 + unconfined_u:object_r:user_tmp_t:s0 move.html
 </code> </code>
  
Ligne 1406: Ligne 1279:
  
 <code> <code>
-[root@centos7 tmp]# cp copy.html /var/www/html/ +[root@redhat9 tmp]# cp copy.html /var/www/html/ 
-[root@centos7 tmp]# mv move.html /var/www/html/ + 
-[root@centos7 tmp]# ls -Z /var/www/html +[root@redhat9 tmp]# mv move.html /var/www/html/ 
--rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 copy.html + 
--rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html +[root@redhat9 tmp]# ls -Z /var/www/html 
--rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 move.html+unconfined_u:object_r:httpd_sys_content_t:s0 copy.html            unconfined_u:object_r:user_tmp_t:s0 move.html 
 +unconfined_u:object_r:httpd_sys_content_t:s0 index.html
 </code> </code>
  
Ligne 1421: Ligne 1295:
  
 <code> <code>
-[root@centos7 tmp]# restorecon -v /var/www/html/move.html +[root@redhat9 tmp]# restorecon -v /var/www/html/move.html 
-restorecon reset /var/www/html/move.html context unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0+Relabeled /var/www/html/move.html from unconfined_u:object_r:user_tmp_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
  
-[root@centos7 tmp]# ls -Z /var/www/html +[root@redhat9 tmp]# ls -Z /var/www/html 
--rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 copy.html +unconfined_u:object_r:httpd_sys_content_t:s0 copy.html   unconfined_u:object_r:httpd_sys_content_t:s0 move.html 
--rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html +unconfined_u:object_r:httpd_sys_content_t:s0 index.html
--rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 move.html+
 </code> </code>
  
-====Le fichier /.autorelabel====+====3.8 - Le fichier /.autorelabel====
  
 En cas de besoin il est intéressant de pouvoir restaurer les SC par défaut sur l'ensemble des objets du système. Cette procédure est très simple à mettre en oeuvre. Il convient de créer le fichier **.autorelabel** à la racine et de redémarrer le système : En cas de besoin il est intéressant de pouvoir restaurer les SC par défaut sur l'ensemble des objets du système. Cette procédure est très simple à mettre en oeuvre. Il convient de créer le fichier **.autorelabel** à la racine et de redémarrer le système :
  
 <code> <code>
-[root@centos7 tmp]# touch /.autorelabel +[root@redhat9 tmp]# touch /.autorelabel 
-[root@centos7 tmp]# shutdown -r now+ 
 +[root@redhat9 tmp]# shutdown -r now
 </code> </code>
  
-====La commande semanage==== +====3.9 - La commande semanage====
- +
-La commande **semanage** peut prendre plusieurs options : +
- +
-<code> +
-[root@centos7 tmp]# semanage --help +
-usage: semanage [-h] +
-                 +
-                {import,export,login,user,port,interface,module,node,fcontext,boolean,permissive,dontaudit} +
-                ... +
- +
-semanage is used to configure certain elements of SELinux policy with-out +
-requiring modification to or recompilation from policy source. +
- +
-positional arguments: +
-  {import,export,login,user,port,interface,module,node,fcontext,boolean,permissive,dontaudit} +
-    import              Import local customizations +
-    export              Output local customizations +
-    login               Manage login mappings between linux users and SELinux +
-                        confined users +
-    user                Manage SELinux confined users (Roles and levels for an +
-                        SELinux user) +
-    port                Manage network port type definitions +
-    interface           Manage network interface type definitions +
-    module              Manage SELinux policy modules +
-    node                Manage network node type definitions +
-    fcontext            Manage file context mapping definitions +
-    boolean             Manage booleans to selectively enable functionality +
-    permissive          Manage process type enforcement mode +
-    dontaudit           Disable/Enable dontaudit rules in policy +
- +
-optional arguments: +
-  -h, --help            show this help message and exit +
-</code>+
  
 Pour illustrer l'utilisation de cette commande, considérez le besoin de mettre le service apache à l'écoute du port **8090** au lieu du port standard. Pour illustrer l'utilisation de cette commande, considérez le besoin de mettre le service apache à l'écoute du port **8090** au lieu du port standard.
Ligne 1479: Ligne 1320:
  
 <code> <code>
-[root@centos7 tmp]# semanage port -l +[trainee@redhat9 ~]$ su 
-SELinux Port Type              Proto    Port Number+Password: fenestros
  
-afs3_callback_port_t           tcp      7001 +[root@redhat9 ~]# semanage port -l | grep http
-afs3_callback_port_t           udp      7001 +
-afs_bos_port_t                 udp      7007 +
-afs_fs_port_t                  tcp      2040 +
-afs_fs_port_t                  udp      7000, 7005 +
-afs_ka_port_t                  udp      7004 +
-afs_pt_port_t                  tcp      7002 +
-afs_pt_port_t                  udp      7002 +
-afs_vl_port_t                  udp      7003 +
-agentx_port_t                  tcp      705 +
-agentx_port_t                  udp      705 +
-amanda_port_t                  tcp      10080-10083 +
-amanda_port_t                  udp      10080-10082 +
-amavisd_recv_port_t            tcp      10024 +
-amavisd_send_port_t            tcp      10025 +
-amqp_port_t                    tcp      15672, 5671-5672 +
-amqp_port_t                    udp      5671-5672 +
-aol_port_t                     tcp      5190-5193 +
-aol_port_t                     udp      5190-5193 +
-apc_port_t                     tcp      3052 +
-apc_port_t                     udp      3052 +
-apcupsd_port_t                 tcp      3551 +
-apcupsd_port_t                 udp      3551 +
-apertus_ldp_port_t             tcp      539 +
-apertus_ldp_port_t             udp      539 +
-asterisk_port_t                tcp      1720 +
-asterisk_port_t                udp      2427, 2727, 4569 +
-audit_port_t                   tcp      60 +
-auth_port_t                    tcp      113 +
-bacula_port_t                  tcp      9103 +
-bacula_port_t                  udp      9103 +
-bctp_port_t                    tcp      8999 +
-bctp_port_t                    udp      8999 +
-bgp_port_t                     tcp      179, 2605 +
-bgp_port_t                     udp      179, 2605 +
-boinc_client_port_t            tcp      1043 +
-boinc_client_port_t            udp      1034 +
-boinc_port_t                   tcp      31416 +
-brlp_port_t                    tcp      4101 +
-certmaster_port_t              tcp      51235 +
-chronyd_port_t                 udp      323 +
-clamd_port_t                   tcp      3310 +
-clockspeed_port_t              udp      4041 +
-cluster_port_t                 tcp      5149, 40040, 50006-50008 +
-cluster_port_t                 udp      5149, 50006-50008 +
-cma_port_t                     tcp      1050 +
-cma_port_t                     udp      1050 +
-cobbler_port_t                 tcp      25151 +
-collectd_port_t                udp      25826 +
-commplex_link_port_t           tcp      4331, 5001 +
-commplex_link_port_t           udp      5001 +
-commplex_main_port_t           tcp      5000 +
-commplex_main_port_t           udp      5000 +
-comsat_port_t                  udp      512 +
-condor_port_t                  tcp      9618 +
-condor_port_t                  udp      9618 +
-conman_port_t                  tcp      7890 +
-conman_port_t                  udp      7890 +
-connlcli_port_t                tcp      1358 +
-connlcli_port_t                udp      1358 +
-couchdb_port_t                 tcp      5984, 6984 +
-couchdb_port_t                 udp      5984, 6984 +
-ctdb_port_t                    tcp      4379 +
-ctdb_port_t                    udp      4379 +
-cvs_port_t                     tcp      2401 +
-cvs_port_t                     udp      2401 +
-cyphesis_port_t                tcp      6767, 6769, 6780-6799 +
-cyphesis_port_t                udp      32771 +
-cyrus_imapd_port_t             tcp      2005 +
-daap_port_t                    tcp      3689 +
-daap_port_t                    udp      3689 +
-dbskkd_port_t                  tcp      1178 +
-dcc_port_t                     udp      6276, 6277 +
-dccm_port_t                    tcp      5679 +
-dccm_port_t                    udp      5679 +
-dey_keyneg_port_t              tcp      8750 +
-dey_keyneg_port_t              udp      8750 +
-dey_sapi_port_t                tcp      4330 +
-dhcpc_port_t                   tcp      68, 546, 5546 +
-dhcpc_port_t                   udp      68, 546, 5546 +
-dhcpd_port_t                   tcp      547, 548, 647, 847, 7911 +
-dhcpd_port_t                   udp      67, 547, 548, 647, 847 +
-dict_port_t                    tcp      2628 +
-distccd_port_t                 tcp      3632 +
-dns_port_t                     tcp      53 +
-dns_port_t                     udp      53 +
-dnssec_port_t                  tcp      8955 +
-dogtag_port_t                  tcp      7390 +
-echo_port_t                    tcp      7 +
-echo_port_t                    udp      7 +
-efs_port_t                     tcp      520 +
-embrace_dp_c_port_t            tcp      3198 +
-embrace_dp_c_port_t            udp      3198 +
-ephemeral_port_t               tcp      32768-61000 +
-ephemeral_port_t               udp      32768-61000 +
-epmap_port_t                   tcp      135 +
-epmap_port_t                   udp      135 +
-epmd_port_t                    tcp      4369 +
-epmd_port_t                    udp      4369 +
-fac_restore_port_t             tcp      5582 +
-fac_restore_port_t             udp      5582 +
-fingerd_port_t                 tcp      79 +
-flash_port_t                   tcp      843, 1935 +
-flash_port_t                   udp      1935 +
-fmpro_internal_port_t          tcp      5003 +
-fmpro_internal_port_t          udp      5003 +
-freeipmi_port_t                tcp      9225 +
-freeipmi_port_t                udp      9225 +
-ftp_data_port_t                tcp      20 +
-ftp_port_t                     tcp      21, 989, 990 +
-ftp_port_t                     udp      989, 990 +
-gatekeeper_port_t              tcp      1721, 7000 +
-gatekeeper_port_t              udp      1718, 1719 +
-gdomap_port_t                  tcp      538 +
-gdomap_port_t                  udp      538 +
-gds_db_port_t                  tcp      3050 +
-gds_db_port_t                  udp      3050 +
-gear_port_t                    tcp      43273 +
-gear_port_t                    udp      43273 +
-geneve_port_t                  tcp      6080 +
-giftd_port_t                   tcp      1213 +
-git_port_t                     tcp      9418 +
-git_port_t                     udp      9418 +
-glance_port_t                  tcp      9292 +
-glance_port_t                  udp      9292 +
-glance_registry_port_t         tcp      9191 +
-glance_registry_port_t         udp      9191 +
-gluster_port_t                 tcp      38465-38469, 24007-24027 +
-gluster_port_t                 udp      24007-24027 +
-gopher_port_t                  tcp      70 +
-gopher_port_t                  udp      70 +
-gpsd_port_t                    tcp      2947 +
-hadoop_datanode_port_t         tcp      50010 +
-hadoop_namenode_port_t         tcp      8020 +
-hddtemp_port_t                 tcp      7634 +
-hi_reserved_port_t             tcp      512-1023 +
-hi_reserved_port_t             udp      512-1023 +
-howl_port_t                    tcp      5335 +
-howl_port_t                    udp      5353 +
-hplip_port_t                   tcp      1782, 2207, 2208, 8290, 8292, 9100, 9101, 9102, 9220, 9221, 9222, 9280, 9281, 9282, 9290, 9291, 50000, 50002+
 http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010 http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010
 http_cache_port_t              udp      3130 http_cache_port_t              udp      3130
 http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000 http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000
-...+pegasus_http_port_t            tcp      5988 
 +pegasus_https_port_t           tcp      5989
 </code> </code>
  
Ligne 1637: Ligne 1340:
  
 <code> <code>
-[root@centos7 ~]# semanage port -a -t http_port_t -p tcp 8090+[root@redhat9 ~]# semanage port -a -t http_port_t -p tcp 8090
 </code> </code>
  
Ligne 1643: Ligne 1346:
  
 <code> <code>
-[root@centos7 tmp]# semanage port -l | grep http+[root@redhat9 ~]# semanage port -l | grep http
 http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010 http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010
 http_cache_port_t              udp      3130 http_cache_port_t              udp      3130
Ligne 1651: Ligne 1354:
 </code> </code>
  
-====La commande audit2allow====+Les options **semanage** sont :
  
-<code> +[root@redhat9 ~]# semanage --help 
-[root@centos7 tmp]# audit2allow --help +usagesemanage [-h{import,export,login,user,port,ibpkey,ibendport,interface,module,node,fcontext,boolean,permissive,dontaudit} ...
-Usageaudit2allow [options]+
  
-Options+semanage is used to configure certain elements of SELinux policy with-out requiring modification or recompilation from policy source. 
-  --version             show program's version number and exit+ 
 +positional arguments
 +  {import,export,login,user,port,ibpkey,ibendport,interface,module,node,fcontext,boolean,permissive,dontaudit} 
 +    import              Import local customizations 
 +    export              Output local customizations 
 +    login               Manage login mappings between linux users and SELinux confined users 
 +    user                Manage SELinux confined users (Roles and levels for an SELinux user) 
 +    port                Manage network port type definitions 
 +    ibpkey              Manage infiniband ibpkey type definitions 
 +    ibendport           Manage infiniband end port type definitions 
 +    interface           Manage network interface type definitions 
 +    module              Manage SELinux policy modules 
 +    node                Manage network node type definitions 
 +    fcontext            Manage file context mapping definitions 
 +    boolean             Manage booleans to selectively enable functionality 
 +    permissive          Manage process type enforcement mode 
 +    dontaudit           Disable/Enable dontaudit rules in policy 
 + 
 +optional arguments:
   -h, --help            show this help message and exit   -h, --help            show this help message and exit
-  -b, --boot            audit messages since last boot conflicts with -i + 
-  -a, --all             read input from audit log - conflicts with -i +====3.10 La commande audit2allow====
-  -p POLICY, --policy=POLICY +
-                        Policy file to use for analysis +
-  -d, --dmesg           read input from dmesg - conflicts with --all and +
-                        --input +
-  -i INPUT, --input=INPUT +
-                        read input from <input> - conflicts with -a +
-  -l, --lastreload      read input only after the last reload +
-  -r, --requires        generate require statements for rules +
-  -m MODULE, --module=MODULE +
-                        set the module name - implies --requires +
-  -M MODULE_PACKAGE, --module-package=MODULE_PACKAGE +
-                        generate a module package - conflicts with -o and -m +
-  -o OUTPUT, --output=OUTPUT +
-                        append output to <filename>, conflicts with -M +
-  -D, --dontaudit       generate policy with dontaudit rules +
-  -R, --reference       generate refpolicy style output +
-  -N, --noreference     do not generate refpolicy style output +
-  -v, --verbose         explain generated output +
-  -e, --explain         fully explain generated output +
-  -t TYPE, --type=TYPE  only process messages with a type that matches this +
-                        regex +
-  --perm-map=PERM_MAP   file name of perm map +
-  --interface-info=INTERFACE_INFO +
-                        file name of interface information +
-  --debug               leave generated modules for -M +
-  -w, --why             Translates SELinux audit messages into a description +
-                        of why the access was denied +
-</code>+
  
 La création d'un module de politique personnalisé se fait en utilisant la commande **audit2allow**. L'administrateur de sécurité à recours à la création de modules quand, et uniquement quand : La création d'un module de politique personnalisé se fait en utilisant la commande **audit2allow**. L'administrateur de sécurité à recours à la création de modules quand, et uniquement quand :
Ligne 1699: Ligne 1391:
  
 <code> <code>
-[root@centos7 tmp]# mkdir /www1 +[root@redhat9 ~]# mkdir /www1 
-[root@centos7 tmp]# touch /www1/index.html+ 
 +[root@redhat9 ~]# touch /www1/index.html
 </code> </code>
  
 Éditez le fichier **/etc/httpd/conf/httpd.conf** : Éditez le fichier **/etc/httpd/conf/httpd.conf** :
 +
 +<code>
 +[root@redhat9 ~]# vi /etc/httpd/conf/httpd.conf
 +</code>
  
 <file> <file>
Ligne 1712: Ligne 1409:
 </file> </file>
  
-Ajoutez les section **<Directory "/www">**:+Ajoutez les section **<Directory "/www1">**:
  
 <file> <file>
Ligne 1736: Ligne 1433:
  
 <code> <code>
-[root@centos7 ~]# cd ~ +[root@redhat9 ~]# vi /www1/index.html 
-[root@centos7 ~]# vi /www1/index.html + 
-[root@centos7 ~]# cat /www1/index.html+[root@redhat9 ~]# cat /www1/index.html
 <html> <html>
 <title> <title>
Ligne 1752: Ligne 1449:
  
 <code> <code>
-[root@centos7 ~]# chown -R apache:apache /www1+[root@redhat9 ~]# chown -R apache:apache /www1
 </code> </code>
  
Ligne 1758: Ligne 1455:
  
 <code> <code>
-[root@centos7 ~]# systemctl restart httpd.service +[root@redhat9 ~]# systemctl restart httpd.service
 </code> </code>
  
Ligne 1764: Ligne 1461:
  
 <code> <code>
-[root@centos7 ~]# lynx localhost+[root@redhat9 ~]# lynx --dump localhost 
 +                                  Red Hat Logo 
 +                       Red Hat Enterprise Linux Test Page 
 + 
 +   This page is used to test the proper operation of the HTTP server after 
 +   it has been installed. If you can read this page, it means that the 
 +   HTTP server installed at this site is working properly. 
 +     __________________________________________________________________ 
 + 
 +If you are a member of the general public: 
 + 
 +   The fact that you are seeing this page indicates that the website you 
 +   just visited is either experiencing problems, or is undergoing routine 
 +   maintenance. 
 + 
 +   If you would like to let the administrators of this website know that 
 +   you've seen this page instead of the page you expected, you should send 
 +   them e-mail. In general, mail sent to the name "webmaster" and directed 
 +   to the website's domain should reach the appropriate person. 
 + 
 +   For example, if you experienced problems while visiting 
 +   www.example.com, you should send e-mail to "webmaster@example.com"
 + 
 +   For information on Red Hat Enterprise Linux, please visit the [1]Red 
 +   Hat, Inc. website. The documentation for Red Hat Enterprise Linux is 
 +   [2]available on the Red Hat, Inc. website. 
 +     __________________________________________________________________ 
 + 
 +If you are the website administrator: 
 + 
 +   You may now add content to the webroot directory. Note that until you 
 +   do so, people visiting your website will see this page, and not your 
 +   content. 
 + 
 +   For systems using the Apache HTTP Server: You may now add content to 
 +   the directory /var/www/html/. Note that until you do so, people 
 +   visiting your website will see this page, and not your content. To 
 +   prevent this page from ever being used, follow the instructions in the 
 +   file /etc/httpd/conf.d/welcome.conf. 
 + 
 +   For systems using NGINX: You should now put your content in a location 
 +   of your choice and edit the root configuration directive in the nginx 
 +   configuration file /etc/nginx/nginx.conf. 
 +   [3][ Powered by Red Hat Enterprise Linux ] [ Powered by Red Hat 
 +   Enterprise Linux ] 
 + 
 +   [4]Apache™ is a registered trademark of [5]the Apache Software 
 +   Foundation in the United States and/or other countries. 
 +   [6]NGINX™ is a registered trademark of [7]F5 Networks, Inc.. 
 + 
 +References 
 + 
 +   1. http://www.redhat.com/ 
 +   2. http://www.redhat.com/docs/manuals/enterprise/ 
 +   3. https://access.redhat.com/products/red-hat-enterprise-linux 
 +   4. https://apache.org/ 
 +   5. https://apache.org/ 
 +   6. https://nginx.com/ 
 +   7. https://www.f5.com/ 
 +</code> 
 + 
 +Notez que cette fois SELinux est en mode enforcing : 
 + 
 +<code> 
 +[root@redhat9 ~]# getenforce 
 +Enforcing
 </code> </code>
  
Ligne 1770: Ligne 1532:
  
 <code> <code>
-[root@centos7 ~]# cat /var/log/audit/audit.log | grep AVC +[root@redhat9 ~]# cat /var/log/audit/audit.log | grep AVC | tail 
-type=USER_AVC msg=audit(1462020229.957:425): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='avc:  received policyload notice (seqno=2)  exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?' +type=AVC msg=audit(1729587121.979:17697): avc:  denied noatsecure } for  pid=102767 comm="polkitd" scontext=system_u:system_r:policykit_t:s0 tcontext=system_u:system_r:policykit_auth_t:s0 tclass=process permissive=1 
-type=AVC msg=audit(1524491216.546:616): avc:  denied getattr } for  pid=15389 comm="gssproxyname="/" dev="sda2" ino=128 scontext=system_u:system_r:gssproxy_t:s0 tcontext=system_u:object_r:fs_t:s0 tclass=filesystem +type=AVC msg=audit(1729587121.979:17697): avc:  denied rlimitinh } for  pid=102767 comm="pkla-check-auth" scontext=system_u:system_r:policykit_t:s0 tcontext=system_u:system_r:policykit_auth_t:s0 tclass=process permissive=1 
-type=AVC msg=audit(1524491220.766:622): avc:  denied getattr } for  pid=15459 comm="gssproxyname="/" dev="sda2" ino=128 scontext=system_u:system_r:gssproxy_t:s0 tcontext=system_u:object_r:fs_t:s0 tclass=filesystem +type=AVC msg=audit(1729587121.979:17697): avc:  denied siginh } for  pid=102767 comm="pkla-check-auth" scontext=system_u:system_r:policykit_t:s0 tcontext=system_u:system_r:policykit_auth_t:s0 tclass=process permissive=1 
-type=AVC msg=audit(1529418883.052:818): avc:  denied getattr } for  pid=10071 comm="httpdpath="/www/index.html" dev="sda2" ino=35670335 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +type=AVC msg=audit(1729587426.204:17741): avc:  denied net_admin } for  pid=102906 comm="systemd-tmpfilecapability=12  scontext=system_u:system_r:systemd_tmpfiles_t:s0 tcontext=system_u:system_r:systemd_tmpfiles_t:s0 tclass=capability permissive=1 
-type=AVC msg=audit(1529418883.052:819): avc:  denied getattr } for  pid=10071 comm="httpdpath="/www/index.html" dev="sda2" ino=35670335 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +type=AVC msg=audit(1729587481.218:17751): avc:  denied noatsecure } for  pid=102921 comm="polkitd" scontext=system_u:system_r:policykit_t:s0 tcontext=system_u:system_r:policykit_auth_t:s0 tclass=process permissive=1 
-type=AVC msg=audit(1529418919.091:822): avc:  denied getattr } for  pid=10385 comm="httpdpath="/www/index.html" dev="sda2" ino=35670335 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +type=AVC msg=audit(1729587481.218:17751): avc:  denied rlimitinh } for  pid=102921 comm="pkla-check-auth" scontext=system_u:system_r:policykit_t:s0 tcontext=system_u:system_r:policykit_auth_t:s0 tclass=process permissive=1 
-type=AVC msg=audit(1529418919.092:823): avc:  denied getattr } for  pid=10385 comm="httpdpath="/www/index.html" dev="sda2" ino=35670335 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +type=AVC msg=audit(1729587481.218:17751): avc:  denied siginh } for  pid=102921 comm="pkla-check-auth" scontext=system_u:system_r:policykit_t:s0 tcontext=system_u:system_r:policykit_auth_t:s0 tclass=process permissive=1 
-type=AVC msg=audit(1529418954.500:826): avc:  denied  { getattr } for  pid=10669 comm="httpd" path="/www/index.html" dev="sda2" ino=35670335 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +type=AVC msg=audit(1729587592.855:17788): avc:  denied siginh } for  pid=102990 comm="bash" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:initrc_t:s0 tclass=process permissive=1 
-type=AVC msg=audit(1529418954.500:827): avc:  denied getattr } for  pid=10669 comm="httpdpath="/www/index.html" dev="sda2" ino=35670335 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +type=AVC msg=audit(1729588933.891:326): avc:  denied  { getattr } for  pid=2749 comm="httpd" path="/www1/index.html" dev="dm-0" ino=34189841 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0 
-type=AVC msg=audit(1529419054.949:865): avc:  denied  { getattr } for  pid=10670 comm="httpd" path="/www/index.html" dev="sda2" ino=35670335 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +type=AVC msg=audit(1729588933.891:327): avc:  denied  { getattr } for  pid=2749 comm="httpd" path="/www1/index.html" dev="dm-0" ino=34189841 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
-type=AVC msg=audit(1529419054.949:866): avc:  denied getattr } for  pid=10670 comm="httpdpath="/www/index.html" dev="sda2" ino=35670335 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +
-type=USER_AVC msg=audit(1529421001.608:919): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='avc:  received policyload notice (seqno=2)  exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?' +
-type=USER_AVC msg=audit(1529421602.007:946): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='avc:  received policyload notice (seqno=3)  exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?' +
-type=AVC msg=audit(1529422368.058:1019): avc:  denied  { getattr } for  pid=1755 comm="httpd" path="/www1/index.html" dev="sda2" ino=53579496 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file +
-type=AVC msg=audit(1529422368.058:1020): avc:  denied  { getattr } for  pid=1755 comm="httpd" path="/www1/index.html" dev="sda2" ino=53579496 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file+
 </code> </code>
  
Ligne 1791: Ligne 1548:
  
 <code> <code>
-[root@centos7 ~]# grep httpd_t /var/log/audit/audit.log | audit2allow -m httpdlocal > httpdlocal.te+[root@redhat9 ~]# grep httpd_t /var/log/audit/audit.log | audit2allow -m httpdlocal > httpdlocal.te
 </code> </code>
  
Ligne 1797: Ligne 1554:
  
 <code> <code>
-[root@centos7 ~]# cat httpdlocal.te+[root@redhat9 ~]# cat httpdlocal.te
  
 module httpdlocal 1.0; module httpdlocal 1.0;
  
 require { require {
- type httpd_t; +        type httpd_t; 
- type default_t; +        type default_t; 
- class file getattr;+        class capability net_admin; 
 +        class file getattr map open read };
 } }
  
 #============= httpd_t ============== #============= httpd_t ==============
 +allow httpd_t default_t:file { getattr open read };
  
-#!!!! WARNING: 'default_tis a base type. +#!!!! This avc can be allowed using the boolean 'domain_can_mmap_files
-#!!!! The file '/www/index.html' is mislabeled on your system.   +allow httpd_t default_t:file map; 
-#!!!! Fix with $ restorecon -R -v /www/index.html + 
-allow httpd_t default_t:file getattr;+#!!!! This avc has a dontaudit rule in the current policy 
 +allow httpd_t self:capability net_admin;
 </code> </code>
  
Ligne 1818: Ligne 1578:
  
 <code> <code>
-[root@centos7 ~]# grep httpd_t /var/log/audit/audit.log | audit2allow -M httpdlocal+[root@redhat9 ~]# grep httpd_t /var/log/audit/audit.log | audit2allow -M httpdlocal
 ******************** IMPORTANT *********************** ******************** IMPORTANT ***********************
 To make this policy package active, execute: To make this policy package active, execute:
Ligne 1828: Ligne 1588:
  
 <code> <code>
-[root@centos7 ~]# semodule -i httpdlocal.pp+[root@redhat9 ~]# semodule -i httpdlocal.pp
 </code> </code>
  
Ligne 1834: Ligne 1594:
  
 <code> <code>
-[root@centos7 ~]# semodule -l | grep httpd +[root@redhat9 ~]# semodule -l | grep httpd 
-httpdlocal 1.0+httpdlocal
 </code> </code>
  
-Redémarrez le service httpd :+Consultez le site localhost en utilisant **lynx** 
  
 <code> <code>
-[root@centos7 ~]# systemctl restart httpd.service +[root@redhat9 ~]# lynx --dump localhost 
 +   www test page
 </code> </code>
  
-Videz le fichier **/var/log/audit/audit.log** :+Les options **audit2allow** sont :
  
 <code> <code>
-[root@centos7 ~]# vi /var/log/audit/audit.log+[root@redhat9 ~]# audit2allow --help 
 +Usage: audit2allow [options] 
 + 
 +Options: 
 +  --version             show program's version number and exit 
 +  -h, --help            show this help message and exit 
 +  -b, --boot            audit messages since last boot conflicts with -i 
 +  -a, --all             read input from audit log - conflicts with -i 
 +  -p POLICY, --policy=POLICY 
 +                        Policy file to use for analysis 
 +  -d, --dmesg           read input from dmesg - conflicts with --all and 
 +                        --input 
 +  -i INPUT, --input=INPUT 
 +                        read input from <input> - conflicts with -a 
 +  -l, --lastreload      read input only after the last reload 
 +  -r, --requires        generate require statements for rules 
 +  -m MODULE, --module=MODULE 
 +                        set the module name - implies --requires 
 +  -M MODULE_PACKAGE, --module-package=MODULE_PACKAGE 
 +                        generate a module package - conflicts with -o and -m 
 +  -o OUTPUT, --output=OUTPUT 
 +                        append output to <filename>, conflicts with -M 
 +  -D, --dontaudit       generate policy with dontaudit rules 
 +  -R, --reference       generate refpolicy style output 
 +  -N, --noreference     do not generate refpolicy style output 
 +  -v, --verbose         explain generated output 
 +  -e, --explain         fully explain generated output 
 +  -t TYPE, --type=TYPE  only process messages with a type that matches this 
 +                        regex 
 +  --perm-map=PERM_MAP   file name of perm map 
 +  --interface-info=INTERFACE_INFO 
 +                        file name of interface information 
 +  -x, --xperms          generate extended permission rules 
 +  -w, --why             Translates SELinux audit messages into a description 
 +                        of why the access was denied
 </code> </code>
  
-Consultez le site localhost :+=====LAB #4 - Le Pare-feu Netfilter/iptables====== 
 + 
 +**Netfilter** est composé de 5 //hooks// : 
 + 
 +  * NF_IP_PRE_ROUTING 
 +  * NF_IP_LOCAL_IN 
 +  * NF_IP_LOCAL_OUT 
 +  * NF_IP_FORWARD 
 +  * NF_IP_POSTROUTING 
 + 
 +Ces hooks sont utilisés par deux branches, la première est celle concernée par les paquets qui entrent vers des services locaux : 
 + 
 +  * NF_IP_PRE_ROUTING > NF_IP_LOCAL_IN > NF_IP_LOCAL_OUT > NF_IP_POSTROUTING 
 + 
 +tandis que la deuxième concerne les paquets qui traversent la passerelle: 
 + 
 +  * NF_IP_PRE_ROUTING > NF_IP_FORWARD > NF_IP_POSTROUTING 
 + 
 +Si IPTABLES a été compilé en tant que module, son utilisation nécessite le chargement de plusieurs modules supplémentaires en fonction de la situation: 
 + 
 +  * iptable_filter 
 +  * iptable_mangle 
 +  * iptable_net 
 +  * etc 
 + 
 +Netfilter est organisé en **tables**. La commande **iptables** de netfilter permet d'insérer des **policies** dans les **chaines**: 
 + 
 +  * La table **FILTER** 
 +    * La chaîne INPUT 
 +      * Concerne les paquets entrants 
 +        * Policies: ACCEPT, DROP, REJECT 
 +    * La chaîne OUTPUT 
 +      * Concerne les paquets sortants 
 +        * Policies: ACCEPT, DROP, REJECT 
 +    * La chaîne FORWARD 
 +      * Concerne les paquets traversant le par-feu. 
 +        * Policies: ACCEPT, DROP, REJECT 
 + 
 +Si aucune table n'est précisée, c'est la table FILTER qui s'applique par défaut. 
 + 
 +  * La table **NAT** 
 +    * La chaîne PREROUTING 
 +      * Permet de faire la translation d'adresse de destination 
 +        * Cibles: SNAT, DNAT, MASQUERADE 
 +    * La chaîne POSTROUTING 
 +      * Permet de faire la translation d'adresse de la source 
 +        * Cibles: SNAT, DNAT, MASQUERADE 
 +    * Le cas spécifique OUTPUT 
 +      * Permet la modification de la destination des paquets générés localement 
 + 
 +  * La table **MANGLE** 
 +    * Permet le marquage de paquets générés localement (OUTPUT) et entrants (PREROUTING) 
 + 
 +Les **policies** sont: 
 + 
 +  * ACCEPT 
 +    * Permet d'accepter le paquet concerné 
 +  * DROP 
 +    * Permet de rejeter le paquet concerné sans générer un message d'erreur 
 +  * REJECT 
 +    * Permet de rejeter le paquet concerné en générant une message d'erreur 
 + 
 +Les **cibles** sont: 
 + 
 +  * SNAT 
 +    * Permet de modifier l'adresse source du paquet concerné 
 +  * DNAT 
 +    * Permet de modifier l'adresse de destination du paquet concerné 
 +  * MASQUERADE 
 +    * Permet de remplacer l'adresse IP privée de l'expéditeur par un socket public de la passerelle. 
 + 
 +IPTABLES peut être configuré soit par des outils tels shorewall, soit en utilisant des lignes de commandes ou un script. Dans ce dernier cas, la ligne prend la forme: 
 + 
 +  # IPTABLES --action CHAINE --option1 --option2 
 + 
 +Les actions sont: 
 + 
 +^  Action  ^  Abréviation  ^  Déscription 
 +| - -append |  -A  | Ajouter une règle à la fin de la chaîne spécifiée |  
 +| - -delete |  -D  | Supprimer une règle en spécifiant son numéro ou la règle à supprimer |  
 +| - -replace |  -R  | Permet de remplacer la règle spécifée par son numéro |  
 +| - -insert |  -I  | Permet d'insérer une règle à l'endroit spécifié |  
 +| - -list |  -L  | Permet d'afficher des règles | 
 +| - -flush |  -F  | Permet de vider toutes les règles d'une chaîne |   
 + 
 +Les options sont: 
 + 
 +^  Option  ^  Abréviation  ^  Déscription 
 +| - -protocol |  -p  | Permet de spécifier un protocol - tcp, udp, icmp, all |  
 +| - -source |  -s  | Permet de spécifier une adresse source |  
 +| - -destination |  -d  | Permet de spécifier une adresse de destination |  
 +| - -in-interface |  -i  | Permet de spécifier une interface réseau d'entrée |  
 +| - -out-interface |  -o  | Permet de spécifier une interface réseau de sortie | 
 +| - -fragment |  -f  | Permet de ne spécifier que les paquets fragmentés |   
 +| - -source-port |  -sport  | Permet de spécifier un port source ou une plage de ports source |  
 +| - -destination-port |  -dport  | Permet de spécifier un port de destination ou une plage de ports de destination |  
 +| - -tcp-flags |  s/o  | Permet de spécifier un flag TCP à matcher - SYN, ACK, FIN, RST, URG, PSH, ALL, NONE |  
 +| - -icmp-type |  s/o  | Permet de spécifier un type de paquet ICMP | 
 +| - -mac-source |  s/o  | Permet de spécifier une adresse MAC |  
 + 
 +Les options spécifiques à NET sont: 
 + 
 +| - -to-destination |  s/o  | Permet de spécifier l'adresse de destination d'une translation |  
 +| - -to-source |  s/o  | Permet spécifier l'adresse source d'une translation |  
 + 
 +Les options spécifiques aux LOGS sont: 
 + 
 +| - -log-level |  s/o  | Permet de spécifier le niveau de logs |  
 +| - -log-prefix |  s/o  | Permet de spécifier un préfix pour les logs | 
 + 
 +L'option spécifique au STATEFUL est: 
 + 
 +| - -state |  s/o  | Permet de spécifier l'état du paquet à vérifier |  
 + 
 +Ce dernier cas fait référence au STATEFUL. Le STATEFUL est la capacité du par-feu à enregistrer dans une table spécifique, l'état des différentes connexions. Cette table s'appelle une **table d'état**. Le principe du fonctionnement de STATEFUL est simple, à savoir, si le paquet entrant appartient à une communication déjà établie, celui-ci n'est pas vérifié. 
 + 
 +Il existe 4 états: 
 + 
 +  * NEW 
 +    * Le paquet concerne une nouvelle connexion et contient donc un flag SYN à 1 
 +  * ESTABLISHED 
 +    * Le paquet concerne une connexion déjà établie. Le paquet ne doit contenir **ni** flag SYN à 1, **ni** flag FIN à 1 
 +  * RELATED 
 +    * Le paquet est d'une connexion qui présente une relation avec une autre connexion 
 +  * INVALID 
 +    * La paquet provient d'une connexion anormale. 
 + 
 +====4.1 - La Configuration par firewalld ==== 
 + 
 +Firewalld utilise des **zones** - des jeux de règles pré-définis dans lesquels sont placés les interfaces : 
 + 
 +  * **trusted** - un réseau fiable. Dans ce cas tous les ports sont autorisés, 
 +  * **work**, **home**, **internal** - un réseau partiellement fiable. Dans ce cas quelques ports sont autorisés, 
 +  * **dmz**, **public**, **external** - un réseau non fiable. Dans ce cas peu de ports sont autorisés, 
 +  * **block**, **drop** - tout est interdit. La zone drop n'envoie pas de messages d'erreurs. 
 + 
 +<WRAP center round important 50%> 
 +**Important** - Une interface ne peut être que dans une zone à la fois tandis que plusieurs interfaces peuvent être dans la même zone. 
 +</WRAP> 
 + 
 +Le service firewalld doit toujours être lancé :
  
 <code> <code>
-[root@centos7 ~]# lynx localhost+[root@redhat9 ~]# systemctl status firewalld.service 
 +● firewalld.service - firewalld - dynamic firewall daemon 
 +     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled) 
 +     Active: active (running) since Tue 2024-10-22 11:02:04 CEST; 32min ago 
 +       Docs: man:firewalld(1) 
 +   Main PID: 795 (firewalld) 
 +      Tasks: 2 (limit: 48800) 
 +     Memory: 44.6M 
 +        CPU: 510ms 
 +     CGroup: /system.slice/firewalld.service 
 +             └─795 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid 
 + 
 +Oct 22 11:02:01 redhat9.ittraining.loc systemd[1]: Starting firewalld - dynamic firewall daemon... 
 +Oct 22 11:02:04 redhat9.ittraining.loc systemd[1]: Started firewalld - dynamic firewall daemon.
 </code> </code>
  
-Constatez que la consultation ne génère plus de messages de type **AVC** :+====4.2 - La Configuration de Base de firewalld==== 
 + 
 +La configuration par défaut de firewalld se trouve dans **/usr/lib/firewalld** :
  
 <code> <code>
-[root@centos7 ~]# cat /var/log/audit/audit.log +[root@redhat9 ~]# ls -l /usr/lib/firewalld/ 
-[root@centos7 ~]# +total 20 
 +drwxr-xr-x. 2 root root 4096 Sep 25 12:05 helpers 
 +drwxr-xr-x. 2 root root 4096 Sep 25 12:05 icmptypes 
 +drwxr-xr-x. 2 root root   23 Sep 25 12:05 ipsets 
 +drwxr-xr-x. 2 root root   33 Sep 25 12:05 policies 
 +drwxr-xr-x. 2 root root 8192 Sep 25 12:06 services 
 +drwxr-xr-x. 2 root root  184 Sep 25 12:05 zones 
 + 
 +[root@redhat9 ~]# ls -l /usr/lib/firewalld/zones/ 
 +total 40 
 +-rw-r--r--. 1 root root 312 Nov  6  2023 block.xml 
 +-rw-r--r--. 1 root root 306 Nov  6  2023 dmz.xml 
 +-rw-r--r--. 1 root root 304 Nov  6  2023 drop.xml 
 +-rw-r--r--. 1 root root 317 Nov  6  2023 external.xml 
 +-rw-r--r--. 1 root root 410 Nov  6  2023 home.xml 
 +-rw-r--r--. 1 root root 425 Nov  6  2023 internal.xml 
 +-rw-r--r--. 1 root root 729 Feb 22  2024 nm-shared.xml 
 +-rw-r--r--. 1 root root 356 Nov  6  2023 public.xml 
 +-rw-r--r--. 1 root root 175 Nov  6  2023 trusted.xml 
 +-rw-r--r--. 1 root root 352 Nov  6  2023 work.xml 
 + 
 +[root@redhat9 ~]# ls -l /usr/lib/firewalld/services/ 
 +total 884 
 +-rw-r--r--. 1 root root 352 Nov  6  2023 afp.xml 
 +-rw-r--r--. 1 root root 399 Nov  6  2023 amanda-client.xml 
 +-rw-r--r--. 1 root root 427 Nov  6  2023 amanda-k5-client.xml 
 +-rw-r--r--. 1 root root 283 Nov  6  2023 amqps.xml 
 +-rw-r--r--. 1 root root 273 Nov  6  2023 amqp.xml 
 +-rw-r--r--. 1 root root 285 Nov  6  2023 apcupsd.xml 
 +-rw-r--r--. 1 root root 301 Nov  6  2023 audit.xml 
 +-rw-r--r--. 1 root root 436 Nov  6  2023 ausweisapp2.xml 
 +-rw-r--r--. 1 root root 320 Nov  6  2023 bacula-client.xml 
 +-rw-r--r--. 1 root root 346 Nov  6  2023 bacula.xml 
 +-rw-r--r--. 1 root root 390 Nov  6  2023 bareos-director.xml 
 +-rw-r--r--. 1 root root 255 Nov  6  2023 bareos-filedaemon.xml 
 +-rw-r--r--. 1 root root 316 Nov  6  2023 bareos-storage.xml 
 +-rw-r--r--. 1 root root 429 Nov  6  2023 bb.xml 
 +-rw-r--r--. 1 root root 339 Nov  6  2023 bgp.xml 
 +-rw-r--r--. 1 root root 275 Nov  6  2023 bitcoin-rpc.xml 
 +-rw-r--r--. 1 root root 307 Nov  6  2023 bitcoin-testnet-rpc.xml 
 +-rw-r--r--. 1 root root 281 Nov  6  2023 bitcoin-testnet.xml 
 +-rw-r--r--. 1 root root 244 Nov  6  2023 bitcoin.xml 
 +-rw-r--r--. 1 root root 410 Nov  6  2023 bittorrent-lsd.xml 
 +-rw-r--r--. 1 root root 222 Nov  6  2023 ceph-exporter.xml 
 +-rw-r--r--. 1 root root 294 Nov  6  2023 ceph-mon.xml 
 +-rw-r--r--. 1 root root 329 Nov  6  2023 ceph.xml 
 +-rw-r--r--. 1 root root 168 Nov  6  2023 cfengine.xml 
 +-rw-r--r--. 1 root root 234 Nov  6  2023 checkmk-agent.xml 
 +-rw-r--r--. 1 root root 211 Nov  6  2023 cockpit.xml 
 +-rw-r--r--. 1 root root 296 Nov  6  2023 collectd.xml 
 +-rw-r--r--. 1 root root 260 Nov  6  2023 condor-collector.xml 
 +-rw-r--r--. 1 root root 343 Nov  6  2023 cratedb.xml 
 +-rw-r--r--. 1 root root 296 Nov  6  2023 ctdb.xml 
 +-rw-r--r--. 1 root root 981 Nov  6  2023 dds-multicast.xml 
 +-rw-r--r--. 1 root root 947 Nov  6  2023 dds-unicast.xml 
 +-rw-r--r--. 1 root root 574 Nov  6  2023 dds.xml 
 +-rw-r--r--. 1 root root 305 Nov  6  2023 dhcpv6-client.xml 
 +-rw-r--r--. 1 root root 234 Nov  6  2023 dhcpv6.xml 
 +-rw-r--r--. 1 root root 227 Nov  6  2023 dhcp.xml 
 +-rw-r--r--. 1 root root 205 Nov  6  2023 distcc.xml 
 +-rw-r--r--. 1 root root 318 Nov  6  2023 dns-over-tls.xml 
 +-rw-r--r--. 1 root root 346 Nov  6  2023 dns.xml 
 +-rw-r--r--. 1 root root 374 Nov  6  2023 docker-registry.xml 
 +-rw-r--r--. 1 root root 391 Nov  6  2023 docker-swarm.xml 
 +-rw-r--r--. 1 root root 228 Nov  6  2023 dropbox-lansync.xml 
 +-rw-r--r--. 1 root root 338 Nov  6  2023 elasticsearch.xml 
 +-rw-r--r--. 1 root root 304 Nov  6  2023 etcd-client.xml 
 +-rw-r--r--. 1 root root 304 Nov  6  2023 etcd-server.xml 
 +-rw-r--r--. 1 root root 224 Nov  6  2023 finger.xml 
 +-rw-r--r--. 1 root root 270 Nov  6  2023 foreman-proxy.xml 
 +-rw-r--r--. 1 root root 408 Nov  6  2023 foreman.xml 
 +-rw-r--r--. 1 root root 709 Nov  6  2023 freeipa-4.xml 
 +-rw-r--r--. 1 root root 489 Nov  6  2023 freeipa-ldaps.xml 
 +-rw-r--r--. 1 root root 488 Nov  6  2023 freeipa-ldap.xml 
 +-rw-r--r--. 1 root root 242 Nov  6  2023 freeipa-replication.xml 
 +-rw-r--r--. 1 root root 657 Nov  6  2023 freeipa-trust.xml 
 +-rw-r--r--. 1 root root 361 Nov  6  2023 ftp.xml 
 +-rw-r--r--. 1 root root 292 Nov  6  2023 galera.xml 
 +-rw-r--r--. 1 root root 184 Nov  6  2023 ganglia-client.xml 
 +-rw-r--r--. 1 root root 176 Nov  6  2023 ganglia-master.xml 
 +-rw-r--r--. 1 root root 212 Nov  6  2023 git.xml 
 +-rw-r--r--. 1 root root 406 Nov  6  2023 gpsd.xml 
 +-rw-r--r--. 1 root root 218 Nov  6  2023 grafana.xml 
 +-rw-r--r--. 1 root root 119 Nov  6  2023 gre.xml 
 +-rw-r--r--. 1 root root 608 Nov  6  2023 high-availability.xml 
 +-rw-r--r--. 1 root root 336 Nov  6  2023 http3.xml 
 +-rw-r--r--. 1 root root 448 Nov  6  2023 https.xml 
 +-rw-r--r--. 1 root root 353 Nov  6  2023 http.xml 
 +-rw-r--r--. 1 root root 293 Nov  6  2023 ident.xml 
 +-rw-r--r--. 1 root root 372 Nov  6  2023 imaps.xml 
 +-rw-r--r--. 1 root root 327 Nov  6  2023 imap.xml 
 +-rw-r--r--. 1 root root 315 Nov  6  2023 ipfs.xml 
 +-rw-r--r--. 1 root root 454 Nov  6  2023 ipp-client.xml 
 +-rw-r--r--. 1 root root 427 Nov  6  2023 ipp.xml 
 +-rw-r--r--. 1 root root 895 Nov  6  2023 ipsec.xml 
 +-rw-r--r--. 1 root root 255 Nov  6  2023 ircs.xml 
 +-rw-r--r--. 1 root root 247 Nov  6  2023 irc.xml 
 +-rw-r--r--. 1 root root 264 Nov  6  2023 iscsi-target.xml 
 +-rw-r--r--. 1 root root 358 Nov  6  2023 isns.xml 
 +-rw-r--r--. 1 root root 213 Nov  6  2023 jenkins.xml 
 +-rw-r--r--. 1 root root 182 Nov  6  2023 kadmin.xml 
 +-rw-r--r--. 1 root root 272 Nov  6  2023 kdeconnect.xml 
 +-rw-r--r--. 1 root root 233 Nov  6  2023 kerberos.xml 
 +-rw-r--r--. 1 root root 384 Nov  6  2023 kibana.xml 
 +-rw-r--r--. 1 root root 249 Nov  6  2023 klogin.xml 
 +-rw-r--r--. 1 root root 221 Nov  6  2023 kpasswd.xml 
 +-rw-r--r--. 1 root root 182 Nov  6  2023 kprop.xml 
 +-rw-r--r--. 1 root root 242 Nov  6  2023 kshell.xml 
 +-rw-r--r--. 1 root root 308 Nov  6  2023 kube-apiserver.xml 
 +-rw-r--r--. 1 root root 204 Nov  6  2023 kube-api.xml 
 +-rw-r--r--. 1 root root 289 Nov  6  2023 kube-controller-manager-secure.xml 
 +-rw-r--r--. 1 root root 280 Nov  6  2023 kube-controller-manager.xml 
 +-rw-r--r--. 1 root root 560 Nov  6  2023 kube-control-plane-secure.xml 
 +-rw-r--r--. 1 root root 537 Nov  6  2023 kube-control-plane.xml 
 +-rw-r--r--. 1 root root 244 Nov  6  2023 kubelet-readonly.xml 
 +-rw-r--r--. 1 root root 212 Nov  6  2023 kubelet-worker.xml 
 +-rw-r--r--. 1 root root 239 Nov  6  2023 kubelet.xml 
 +-rw-r--r--. 1 root root 224 Nov  6  2023 kube-nodeport-services.xml 
 +-rw-r--r--. 1 root root 328 Nov  6  2023 kube-scheduler-secure.xml 
 +-rw-r--r--. 1 root root 319 Nov  6  2023 kube-scheduler.xml 
 +-rw-r--r--. 1 root root 374 Nov  6  2023 kube-worker.xml 
 +-rw-r--r--. 1 root root 232 Nov  6  2023 ldaps.xml 
 +-rw-r--r--. 1 root root 199 Nov  6  2023 ldap.xml 
 +-rw-r--r--. 1 root root 385 Nov  6  2023 libvirt-tls.xml 
 +-rw-r--r--. 1 root root 389 Nov  6  2023 libvirt.xml 
 +-rw-r--r--. 1 root root 269 Nov  6  2023 lightning-network.xml 
 +-rw-r--r--. 1 root root 468 Nov  6  2023 llmnr-client.xml 
 +-rw-r--r--. 1 root root 410 Nov  6  2023 llmnr-tcp.xml 
 +-rw-r--r--. 1 root root 463 Nov  6  2023 llmnr-udp.xml 
 +-rw-r--r--. 1 root root 519 Nov  6  2023 llmnr.xml 
 +-rw-r--r--. 1 root root 349 Nov  6  2023 managesieve.xml 
 +-rw-r--r--. 1 root root 432 Nov  6  2023 matrix.xml 
 +-rw-r--r--. 1 root root 424 Nov  6  2023 mdns.xml 
 +-rw-r--r--. 1 root root 245 Nov  6  2023 memcache.xml 
 +-rw-r--r--. 1 root root 334 Nov  6  2023 minidlna.xml 
 +-rw-r--r--. 1 root root 237 Nov  6  2023 mongodb.xml 
 +-rw-r--r--. 1 root root 473 Nov  6  2023 mosh.xml 
 +-rw-r--r--. 1 root root 211 Nov  6  2023 mountd.xml 
 +-rw-r--r--. 1 root root 296 Nov  6  2023 mqtt-tls.xml 
 +-rw-r--r--. 1 root root 287 Nov  6  2023 mqtt.xml 
 +-rw-r--r--. 1 root root 170 Nov  6  2023 mssql.xml 
 +-rw-r--r--. 1 root root 180 Nov  6  2023 ms-wbt.xml 
 +-rw-r--r--. 1 root root 242 Nov  6  2023 murmur.xml 
 +-rw-r--r--. 1 root root 171 Nov  6  2023 mysql.xml 
 +-rw-r--r--. 1 root root 250 Nov  6  2023 nbd.xml 
 +-rw-r--r--. 1 root root 309 Nov  6  2023 nebula.xml 
 +-rw-r--r--. 1 root root 262 Nov  6  2023 netbios-ns.xml 
 +-rw-r--r--. 1 root root 243 Nov  6  2023 netdata-dashboard.xml 
 +-rw-r--r--. 1 root root 342 Nov  6  2023 nfs3.xml 
 +-rw-r--r--. 1 root root 324 Nov  6  2023 nfs.xml 
 +-rw-r--r--. 1 root root 293 Nov  6  2023 nmea-0183.xml 
 +-rw-r--r--. 1 root root 247 Nov  6  2023 nrpe.xml 
 +-rw-r--r--. 1 root root 389 Nov  6  2023 ntp.xml 
 +-rw-r--r--. 1 root root 368 Nov  6  2023 nut.xml 
 +-rw-r--r--. 1 root root 335 Nov  6  2023 openvpn.xml 
 +-rw-r--r--. 1 root root 260 Nov  6  2023 ovirt-imageio.xml 
 +-rw-r--r--. 1 root root 343 Nov  6  2023 ovirt-storageconsole.xml 
 +-rw-r--r--. 1 root root 235 Nov  6  2023 ovirt-vmconsole.xml 
 +-rw-r--r--. 1 root root 869 Nov  6  2023 plex.xml 
 +-rw-r--r--. 1 root root 433 Nov  6  2023 pmcd.xml 
 +-rw-r--r--. 1 root root 474 Nov  6  2023 pmproxy.xml 
 +-rw-r--r--. 1 root root 544 Nov  6  2023 pmwebapis.xml 
 +-rw-r--r--. 1 root root 460 Nov  6  2023 pmwebapi.xml 
 +-rw-r--r--. 1 root root 357 Nov  6  2023 pop3s.xml 
 +-rw-r--r--. 1 root root 348 Nov  6  2023 pop3.xml 
 +-rw-r--r--. 1 root root 181 Nov  6  2023 postgresql.xml 
 +-rw-r--r--. 1 root root 509 Nov  6  2023 privoxy.xml 
 +-rw-r--r--. 1 root root 226 Nov  6  2023 prometheus-node-exporter.xml 
 +-rw-r--r--. 1 root root 213 Nov  6  2023 prometheus.xml 
 +-rw-r--r--. 1 root root 261 Nov  6  2023 proxy-dhcp.xml 
 +-rw-r--r--. 1 root root 262 Nov  6  2023 ps2link.xml 
 +-rw-r--r--. 1 root root 173 Nov  6  2023 ps3netsrv.xml 
 +-rw-r--r--. 1 root root 424 Nov  6  2023 ptp.xml 
 +-rw-r--r--. 1 root root 414 Nov  6  2023 pulseaudio.xml 
 +-rw-r--r--. 1 root root 297 Nov  6  2023 puppetmaster.xml 
 +-rw-r--r--. 1 root root 273 Nov  6  2023 quassel.xml 
 +-rw-r--r--. 1 root root 520 Nov  6  2023 radius.xml 
 +-rw-r--r--. 1 root root 183 Nov  6  2023 rdp.xml 
 +-rw-r--r--. 1 root root 212 Nov  6  2023 redis-sentinel.xml 
 +-rw-r--r--. 1 root root 268 Nov  6  2023 redis.xml 
 +-rw-r--r--. 1 root root 381 Nov  6  2023 RH-Satellite-6-capsule.xml 
 +-rw-r--r--. 1 root root 556 Nov  6  2023 RH-Satellite-6.xml 
 +-rw-r--r--. 1 root root 214 Nov  6  2023 rpc-bind.xml 
 +-rw-r--r--. 1 root root 213 Nov  6  2023 rquotad.xml 
 +-rw-r--r--. 1 root root 310 Nov  6  2023 rsh.xml 
 +-rw-r--r--. 1 root root 311 Nov  6  2023 rsyncd.xml 
 +-rw-r--r--. 1 root root 350 Nov  6  2023 rtsp.xml 
 +-rw-r--r--. 1 root root 329 Nov  6  2023 salt-master.xml 
 +-rw-r--r--. 1 root root 339 Nov  6  2023 samba-client.xml 
 +-rw-r--r--. 1 root root 782 Nov  6  2023 samba-dc.xml 
 +-rw-r--r--. 1 root root 382 Nov  6  2023 samba.xml 
 +-rw-r--r--. 1 root root 324 Nov  6  2023 sane.xml 
 +-rw-r--r--. 1 root root 283 Nov  6  2023 sips.xml 
 +-rw-r--r--. 1 root root 496 Nov  6  2023 sip.xml 
 +-rw-r--r--. 1 root root 299 Nov  6  2023 slp.xml 
 +-rw-r--r--. 1 root root 231 Nov  6  2023 smtp-submission.xml 
 +-rw-r--r--. 1 root root 577 Nov  6  2023 smtps.xml 
 +-rw-r--r--. 1 root root 550 Nov  6  2023 smtp.xml 
 +-rw-r--r--. 1 root root 359 Nov  6  2023 snmptls-trap.xml 
 +-rw-r--r--. 1 root root 390 Nov  6  2023 snmptls.xml 
 +-rw-r--r--. 1 root root 308 Nov  6  2023 snmptrap.xml 
 +-rw-r--r--. 1 root root 342 Nov  6  2023 snmp.xml 
 +-rw-r--r--. 1 root root 405 Nov  6  2023 spideroak-lansync.xml 
 +-rw-r--r--. 1 root root 275 Nov  6  2023 spotify-sync.xml 
 +-rw-r--r--. 1 root root 173 Nov  6  2023 squid.xml 
 +-rw-r--r--. 1 root root 421 Nov  6  2023 ssdp.xml 
 +-rw-r--r--. 1 root root 463 Nov  6  2023 ssh.xml 
 +-rw-r--r--. 1 root root 631 Nov  6  2023 steam-streaming.xml 
 +-rw-r--r--. 1 root root 287 Nov  6  2023 svdrp.xml 
 +-rw-r--r--. 1 root root 231 Nov  6  2023 svn.xml 
 +-rw-r--r--. 1 root root 297 Nov  6  2023 syncthing-gui.xml 
 +-rw-r--r--. 1 root root 414 Nov  6  2023 syncthing-relay.xml 
 +-rw-r--r--. 1 root root 350 Nov  6  2023 syncthing.xml 
 +-rw-r--r--. 1 root root 496 Nov  6  2023 synergy.xml 
 +-rw-r--r--. 1 root root 444 Nov  6  2023 syslog-tls.xml 
 +-rw-r--r--. 1 root root 329 Nov  6  2023 syslog.xml 
 +-rw-r--r--. 1 root root 393 Nov  6  2023 telnet.xml 
 +-rw-r--r--. 1 root root 252 Nov  6  2023 tentacle.xml 
 +-rw-r--r--. 1 root root 424 Nov  6  2023 tftp.xml 
 +-rw-r--r--. 1 root root 221 Nov  6  2023 tile38.xml 
 +-rw-r--r--. 1 root root 336 Nov  6  2023 tinc.xml 
 +-rw-r--r--. 1 root root 771 Nov  6  2023 tor-socks.xml 
 +-rw-r--r--. 1 root root 244 Nov  6  2023 transmission-client.xml 
 +-rw-r--r--. 1 root root 264 Nov  6  2023 upnp-client.xml 
 +-rw-r--r--. 1 root root 593 Nov  6  2023 vdsm.xml 
 +-rw-r--r--. 1 root root 475 Nov  6  2023 vnc-server.xml 
 +-rw-r--r--. 1 root root 443 Nov  6  2023 warpinator.xml 
 +-rw-r--r--. 1 root root 310 Nov  6  2023 wbem-https.xml 
 +-rw-r--r--. 1 root root 352 Nov  6  2023 wbem-http.xml 
 +-rw-r--r--. 1 root root 285 Nov  6  2023 wireguard.xml 
 +-rw-r--r--. 1 root root 355 Nov  6  2023 ws-discovery-client.xml 
 +-rw-r--r--. 1 root root 320 Nov  6  2023 ws-discovery-tcp.xml 
 +-rw-r--r--. 1 root root 375 Nov  6  2023 ws-discovery-udp.xml 
 +-rw-r--r--. 1 root root 357 Nov  6  2023 ws-discovery.xml 
 +-rw-r--r--. 1 root root 323 Nov  6  2023 wsmans.xml 
 +-rw-r--r--. 1 root root 316 Nov  6  2023 wsman.xml 
 +-rw-r--r--. 1 root root 329 Nov  6  2023 xdmcp.xml 
 +-rw-r--r--. 1 root root 509 Nov  6  2023 xmpp-bosh.xml 
 +-rw-r--r--. 1 root root 488 Nov  6  2023 xmpp-client.xml 
 +-rw-r--r--. 1 root root 264 Nov  6  2023 xmpp-local.xml 
 +-rw-r--r--. 1 root root 545 Nov  6  2023 xmpp-server.xml 
 +-rw-r--r--. 1 root root 314 Nov  6  2023 zabbix-agent.xml 
 +-rw-r--r--. 1 root root 315 Nov  6  2023 zabbix-server.xml 
 +-rw-r--r--. 1 root root 242 Nov  6  2023 zerotier.xml 
 + 
 +[root@redhat9 ~]# ls -l /usr/lib/firewalld/icmptypes/ 
 +total 180 
 +-rw-r--r--. 1 root root 385 Nov  6  2023 address-unreachable.xml 
 +-rw-r--r--. 1 root root 258 Nov  6  2023 bad-header.xml 
 +-rw-r--r--. 1 root root 293 Nov  6  2023 beyond-scope.xml 
 +-rw-r--r--. 1 root root 279 Nov  6  2023 communication-prohibited.xml 
 +-rw-r--r--. 1 root root 222 Nov  6  2023 destination-unreachable.xml 
 +-rw-r--r--. 1 root root 173 Nov  6  2023 echo-reply.xml 
 +-rw-r--r--. 1 root root 210 Nov  6  2023 echo-request.xml 
 +-rw-r--r--. 1 root root 261 Nov  6  2023 failed-policy.xml 
 +-rw-r--r--. 1 root root 280 Nov  6  2023 fragmentation-needed.xml 
 +-rw-r--r--. 1 root root 266 Nov  6  2023 host-precedence-violation.xml 
 +-rw-r--r--. 1 root root 257 Nov  6  2023 host-prohibited.xml 
 +-rw-r--r--. 1 root root 242 Nov  6  2023 host-redirect.xml 
 +-rw-r--r--. 1 root root 239 Nov  6  2023 host-unknown.xml 
 +-rw-r--r--. 1 root root 247 Nov  6  2023 host-unreachable.xml 
 +-rw-r--r--. 1 root root 229 Nov  6  2023 ip-header-bad.xml 
 +-rw-r--r--. 1 root root 355 Nov  6  2023 neighbour-advertisement.xml 
 +-rw-r--r--. 1 root root 457 Nov  6  2023 neighbour-solicitation.xml 
 +-rw-r--r--. 1 root root 250 Nov  6  2023 network-prohibited.xml 
 +-rw-r--r--. 1 root root 248 Nov  6  2023 network-redirect.xml 
 +-rw-r--r--. 1 root root 239 Nov  6  2023 network-unknown.xml 
 +-rw-r--r--. 1 root root 247 Nov  6  2023 network-unreachable.xml 
 +-rw-r--r--. 1 root root 239 Nov  6  2023 no-route.xml 
 +-rw-r--r--. 1 root root 328 Nov  6  2023 packet-too-big.xml 
 +-rw-r--r--. 1 root root 225 Nov  6  2023 parameter-problem.xml 
 +-rw-r--r--. 1 root root 233 Nov  6  2023 port-unreachable.xml 
 +-rw-r--r--. 1 root root 256 Nov  6  2023 precedence-cutoff.xml 
 +-rw-r--r--. 1 root root 249 Nov  6  2023 protocol-unreachable.xml 
 +-rw-r--r--. 1 root root 185 Nov  6  2023 redirect.xml 
 +-rw-r--r--. 1 root root 244 Nov  6  2023 reject-route.xml 
 +-rw-r--r--. 1 root root 241 Nov  6  2023 required-option-missing.xml 
 +-rw-r--r--. 1 root root 227 Nov  6  2023 router-advertisement.xml 
 +-rw-r--r--. 1 root root 223 Nov  6  2023 router-solicitation.xml 
 +-rw-r--r--. 1 root root 248 Nov  6  2023 source-quench.xml 
 +-rw-r--r--. 1 root root 236 Nov  6  2023 source-route-failed.xml 
 +-rw-r--r--. 1 root root 253 Nov  6  2023 time-exceeded.xml 
 +-rw-r--r--. 1 root root 233 Nov  6  2023 timestamp-reply.xml 
 +-rw-r--r--. 1 root root 228 Nov  6  2023 timestamp-request.xml 
 +-rw-r--r--. 1 root root 258 Nov  6  2023 tos-host-redirect.xml 
 +-rw-r--r--. 1 root root 257 Nov  6  2023 tos-host-unreachable.xml 
 +-rw-r--r--. 1 root root 272 Nov  6  2023 tos-network-redirect.xml 
 +-rw-r--r--. 1 root root 269 Nov  6  2023 tos-network-unreachable.xml 
 +-rw-r--r--. 1 root root 293 Nov  6  2023 ttl-zero-during-reassembly.xml 
 +-rw-r--r--. 1 root root 256 Nov  6  2023 ttl-zero-during-transit.xml 
 +-rw-r--r--. 1 root root 259 Nov  6  2023 unknown-header-type.xml 
 +-rw-r--r--. 1 root root 249 Nov  6  2023 unknown-option.xml 
 +</code> 
 + 
 +Ces fichiers sont au format **xml**, par exemple : 
 + 
 +<code> 
 +[root@redhat9 ~]# cat /usr/lib/firewalld/zones/home.xml 
 +<?xml version="1.0" encoding="utf-8"?> 
 +<zone> 
 +  <short>Home</short> 
 +  <description>For use in home areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> 
 +  <service name="ssh"/> 
 +  <service name="mdns"/> 
 +  <service name="samba-client"/> 
 +  <service name="dhcpv6-client"/> 
 +  <service name="cockpit"/> 
 +  <forward/> 
 +</zone> 
 +</code> 
 + 
 +La configuration de firewalld ainsi que les définitions et règles personnalisées se trouvent dans **/etc/firewalld** : 
 + 
 +<code> 
 +[root@redhat9 ~]# ls -l /etc/firewalld/ 
 +total 8 
 +-rw-r--r--. 1 root root 2483 Nov  6  2023 firewalld.conf 
 +drwxr-x---. 2 root root    6 Nov  6  2023 helpers 
 +drwxr-x---. 2 root root    6 Nov  6  2023 icmptypes 
 +drwxr-x---. 2 root root    6 Nov  6  2023 ipsets 
 +-rw-r--r--. 1 root root  271 Nov  6  2023 lockdown-whitelist.xml 
 +drwxr-x---. 2 root root    6 Nov  6  2023 policies 
 +drwxr-x---. 2 root root    6 Nov  6  2023 services 
 +drwxr-x---. 2 root root   46 Nov  6  2023 zones 
 + 
 +[root@redhat9 ~]# ls -l /etc/firewalld/zones/ 
 +total 8 
 +-rw-r--r--. 1 root root 356 Oct 19  2023 public.xml 
 +-rw-r--r--. 1 root root 356 Oct 19  2023 public.xml.old 
 + 
 +[root@redhat9 ~]# ls -l /etc/firewalld/services/ 
 +total 0 
 + 
 +[root@redhat9 ~]# ls -l /etc/firewalld/icmptypes/ 
 +total 0 
 +</code> 
 + 
 +Le fichier de configuration de firewalld est **/etc/firewalld/firewalld.conf** : 
 + 
 +<code> 
 +[root@redhat9 ~]# cat /etc/firewalld/firewalld.conf 
 +# firewalld config file 
 + 
 +# default zone 
 +# The default zone used if an empty zone string is used. 
 +# Default: public 
 +DefaultZone=public 
 + 
 +# Clean up on exit 
 +# If set to no or false the firewall configuration will not get cleaned up 
 +# on exit or stop of firewalld. 
 +# Default: yes 
 +CleanupOnExit=yes 
 + 
 +# Clean up kernel modules on exit 
 +# If set to yes or true the firewall related kernel modules will be 
 +# unloaded on exit or stop of firewalld. This might attempt to unload 
 +# modules not originally loaded by firewalld. 
 +# Default: no 
 +CleanupModulesOnExit=no 
 + 
 +# Lockdown 
 +# If set to enabled, firewall changes with the D-Bus interface will be limited 
 +# to applications that are listed in the lockdown whitelist. 
 +# The lockdown whitelist file is lockdown-whitelist.xml 
 +# Default: no 
 +Lockdown=no 
 + 
 +# IPv6_rpfilter 
 +# Performs a reverse path filter test on a packet for IPv6. If a reply to the 
 +# packet would be sent via the same interface that the packet arrived on, the 
 +# packet will match and be accepted, otherwise dropped. 
 +# The rp_filter for IPv4 is controlled using sysctl. 
 +# Note: This feature has a performance impact. See man page FIREWALLD.CONF(5) 
 +# for details. 
 +# Default: yes 
 +IPv6_rpfilter=yes 
 + 
 +# IndividualCalls 
 +# Do not use combined -restore calls, but individual calls. This increases the 
 +# time that is needed to apply changes and to start the daemon, but is good for 
 +# debugging. 
 +# Default: no 
 +IndividualCalls=no 
 + 
 +# LogDenied 
 +# Add logging rules right before reject and drop rules in the INPUT, FORWARD 
 +# and OUTPUT chains for the default rules and also final reject and drop rules 
 +# in zones. Possible values are: all, unicast, broadcast, multicast and off. 
 +# Default: off 
 +LogDenied=off 
 + 
 +# FirewallBackend 
 +# Selects the firewall backend implementation. 
 +# Choices are: 
 +#       - nftables (default) 
 +#       - iptables (iptables, ip6tables, ebtables and ipset) 
 +# Note: The iptables backend is deprecated. It will be removed in a future 
 +# release. 
 +FirewallBackend=nftables 
 + 
 +# FlushAllOnReload 
 +# Flush all runtime rules on a reload. In previous releases some runtime 
 +# configuration was retained during a reload, namely; interface to zone 
 +# assignment, and direct rules. This was confusing to users. To get the old 
 +# behavior set this to "no"
 +# Default: yes 
 +FlushAllOnReload=yes 
 + 
 +# RFC3964_IPv4 
 +# As per RFC 3964, filter IPv6 traffic with 6to4 destination addresses that 
 +# correspond to IPv4 addresses that should not be routed over the public 
 +# internet. 
 +# Defaults to "yes"
 +RFC3964_IPv4=yes 
 +</code> 
 + 
 +====4.3 - La Commande firewall-cmd==== 
 + 
 +firewalld s'appuie sur netfilter. Pour cette raison, l'utilisation de firewall-cmd est incompatible avec l'utilisation des commandes iptables et system-config-firewall. 
 + 
 +<WRAP center round important 50%> 
 +**Important** - firewall-cmd est le front-end de firewalld en ligne de commande. Il existe aussi la commande **firewall-config** qui lance un outi de configuration graphique. 
 +</WRAP> 
 + 
 +Pour obtenir la liste de toutes les zones prédéfinies, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --get-zones 
 +block dmz drop external home internal nm-shared public trusted work 
 +</code> 
 + 
 +Pour obtenir la liste de toutes les services prédéfinis, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --get-services 
 +RH-Satellite-6 RH-Satellite-6-capsule afp amanda-client amanda-k5-client amqp amqps apcupsd audit ausweisapp2 bacula bacula-client bareos-director bareos-filedaemon bareos-storage bb bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc bittorrent-lsd ceph ceph-exporter ceph-mon cfengine checkmk-agent cockpit collectd condor-collector cratedb ctdb dds dds-multicast dds-unicast dhcp dhcpv6 dhcpv6-client distcc dns dns-over-tls docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client etcd-server finger foreman foreman-proxy freeipa-4 freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp galera ganglia-client ganglia-master git gpsd grafana gre high-availability http http3 https ident imap imaps ipfs ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kdeconnect kerberos kibana klogin kpasswd kprop kshell kube-api kube-apiserver kube-control-plane kube-control-plane-secure kube-controller-manager kube-controller-manager-secure kube-nodeport-services kube-scheduler kube-scheduler-secure kube-worker kubelet kubelet-readonly kubelet-worker ldap ldaps libvirt libvirt-tls lightning-network llmnr llmnr-client llmnr-tcp llmnr-udp managesieve matrix mdns memcache minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nbd nebula netbios-ns netdata-dashboard nfs nfs3 nmea-0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy prometheus prometheus-node-exporter proxy-dhcp ps2link ps3netsrv ptp pulseaudio puppetmaster quassel radius rdp redis redis-sentinel rpc-bind rquotad rsh rsyncd rtsp salt-master samba samba-client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptls snmptls-trap snmptrap spideroak-lansync spotify-sync squid ssdp ssh steam-streaming svdrp svn syncthing syncthing-gui syncthing-relay synergy syslog syslog-tls telnet tentacle tftp tile38 tinc tor-socks transmission-client upnp-client vdsm vnc-server warpinator wbem-http wbem-https wireguard ws-discovery ws-discovery-client ws-discovery-tcp ws-discovery-udp wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server zerotier 
 +</code> 
 + 
 +Pour obtenir la liste de toutes les types ICMP prédéfinis, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --get-icmptypes 
 +address-unreachable bad-header beyond-scope communication-prohibited destination-unreachable echo-reply echo-request failed-policy fragmentation-needed host-precedence-violation host-prohibited host-redirect host-unknown host-unreachable ip-header-bad neighbour-advertisement neighbour-solicitation network-prohibited network-redirect network-unknown network-unreachable no-route packet-too-big parameter-problem port-unreachable precedence-cutoff protocol-unreachable redirect reject-route required-option-missing router-advertisement router-solicitation source-quench source-route-failed time-exceeded timestamp-reply timestamp-request tos-host-redirect tos-host-unreachable tos-network-redirect tos-network-unreachable ttl-zero-during-reassembly ttl-zero-during-transit unknown-header-type unknown-option 
 +</code> 
 + 
 +Pour obtenir la liste des zones de la configuration courante, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --get-active-zones 
 +public 
 +  interfaces: ens18 
 +</code> 
 + 
 +Pour obtenir la liste des zones de la configuration courante pour une interface spécifique, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --get-zone-of-interface=ens18 
 +public 
 +</code> 
 + 
 +Pour obtenir la liste des services autorisés pour la zone public, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=public --list-services 
 +cockpit dhcpv6-client ssh 
 +</code> 
 + 
 +Pour obtenir toute la configuration pour la zone public, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=public --list-all 
 +public (active) 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces: ens18 
 +  sources:  
 +  services: cockpit dhcpv6-client ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 +</code> 
 + 
 +Pour obtenir la liste complète de toutes les zones et leurs configurations, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --list-all-zones 
 +block 
 +  target: %%REJECT%% 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services:  
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 + 
 +dmz 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services: ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 + 
 +drop 
 +  target: DROP 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services:  
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 + 
 +external 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services: ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: yes 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 + 
 +home 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services: cockpit dhcpv6-client mdns samba-client ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 + 
 +internal 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services: cockpit dhcpv6-client mdns samba-client ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 + 
 +nm-shared 
 +  target: ACCEPT 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services: dhcp dns ssh 
 +  ports:  
 +  protocols: icmp ipv6-icmp 
 +  forward: no 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 +        rule priority="32767" reject 
 + 
 +public (active) 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces: ens18 
 +  sources:  
 +  services: cockpit dhcpv6-client ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 + 
 +trusted 
 +  target: ACCEPT 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services:  
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 + 
 +work 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services: cockpit dhcpv6-client ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules: 
 +</code> 
 + 
 +Pour changer la zone par défaut de public à work, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --set-default-zone=work 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --get-active-zones 
 +work 
 +  interfaces: ens18 
 +</code> 
 + 
 +Pour ajouter l'interface ip_fixe à la zone work, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --add-interface=ip_fixe 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --get-active-zones 
 +work 
 +  interfaces: ens18 ip_fixe 
 +</code> 
 + 
 +Pour supprimer l'interface ip_fixe à la zone work, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --remove-interface=ip_fixe 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --get-active-zones 
 +work 
 +  interfaces: ens18 
 +</code> 
 + 
 +Pour ajouter le service **http** à la zone **work**, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --add-service=http 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --zone=work --list-services 
 +cockpit dhcpv6-client http ssh 
 +</code> 
 + 
 +Pour supprimer le service **http** de la zone **work**, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --remove-service=http 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --zone=work --list-services 
 +cockpit dhcpv6-client ssh 
 +</code> 
 + 
 +Pour ajouter un nouveau bloc ICMP, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --add-icmp-block=echo-reply 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --zone=work --list-icmp-blocks 
 +echo-reply 
 +</code> 
 + 
 +Pour supprimer un bloc ICMP, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --remove-icmp-block=echo-reply 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --zone=work --list-icmp-blocks 
 + 
 +[root@redhat9 ~]# 
 +</code> 
 + 
 +Pour ajouter le port 591/tcp à la zone work, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --add-port=591/tcp 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --zone=work --list-ports 
 +591/tcp 
 +</code> 
 + 
 +Pour supprimer le port 591/tcp à la zone work, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --remove-port=591/tcp 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --zone=work --list-ports 
 + 
 +[root@redhat9 ~]# 
 +</code> 
 + 
 +Pour créer un nouveau service, il convient de : 
 + 
 +  * copier un fichier existant se trouvant dans le répertoire **/usr/lib/firewalld/services** vers **/etc/firewalld/services**, 
 +  * modifier le fichier, 
 +  * recharger la configuration de firewalld, 
 +  * vérifier que firewalld voit le nouveau service. 
 + 
 +Par exemple : 
 + 
 +<code> 
 +[root@redhat9 ~]# cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services/filemaker.xml 
 + 
 +[root@redhat9 ~]# vi /etc/firewalld/services/filemaker.xml 
 + 
 +[root@redhat9 ~]# cat /etc/firewalld/services/filemaker.xml 
 +<?xml version="1.0" encoding="utf-8"?> 
 +<service> 
 +  <short>FileMakerPro</short> 
 +  <description>fichier de service firewalld pour FileMaker Pro</description> 
 +  <port protocol="tcp" port="591"/> 
 +</service> 
 + 
 +[root@redhat9 ~]# firewall-cmd --reload 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --get-services | grep filemaker 
 +RH-Satellite-6 RH-Satellite-6-capsule afp amanda-client amanda-k5-client amqp amqps apcupsd audit ausweisapp2 bacula bacula-client bareos-director bareos-filedaemon bareos-storage bb bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc bittorrent-lsd ceph ceph-exporter ceph-mon cfengine checkmk-agent cockpit collectd condor-collector cratedb ctdb dds dds-multicast dds-unicast dhcp dhcpv6 dhcpv6-client distcc dns dns-over-tls docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client etcd-server filemaker finger foreman foreman-proxy freeipa-4 freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp galera ganglia-client ganglia-master git gpsd grafana gre high-availability http http3 https ident imap imaps ipfs ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kdeconnect kerberos kibana klogin kpasswd kprop kshell kube-api kube-apiserver kube-control-plane kube-control-plane-secure kube-controller-manager kube-controller-manager-secure kube-nodeport-services kube-scheduler kube-scheduler-secure kube-worker kubelet kubelet-readonly kubelet-worker ldap ldaps libvirt libvirt-tls lightning-network llmnr llmnr-client llmnr-tcp llmnr-udp managesieve matrix mdns memcache minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nbd nebula netbios-ns netdata-dashboard nfs nfs3 nmea-0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy prometheus prometheus-node-exporter proxy-dhcp ps2link ps3netsrv ptp pulseaudio puppetmaster quassel radius rdp redis redis-sentinel rpc-bind rquotad rsh rsyncd rtsp salt-master samba samba-client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptls snmptls-trap snmptrap spideroak-lansync spotify-sync squid ssdp ssh steam-streaming svdrp svn syncthing syncthing-gui syncthing-relay synergy syslog syslog-tls telnet tentacle tftp tile38 tinc tor-socks transmission-client upnp-client vdsm vnc-server warpinator wbem-http wbem-https wireguard ws-discovery ws-discovery-client ws-discovery-tcp ws-discovery-udp wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server zerotier 
 +</code> 
 + 
 +====4.4 - La Configuration Avancée de firewalld==== 
 + 
 +La configuration de base de firewalld ne permet que la configuration des zones, services, blocs ICMP et les ports non-standard. Cependant firewalld peut également être configuré avec des **Rich Rules** ou **//Règles Riches//**. Rich Rules ou Règles Riches évaluent des **critères** pour ensuite entreprendre une **action**.  
 + 
 +Les **Critères** sont : 
 + 
 +  * **source address="<adresse_IP>"** 
 +  * **destination address="<adresse_IP>"**, 
 +  * **rule port port="<numéro_du_port>"**, 
 +  * **service name=<nom_d'un_sevice_prédéfini>**. 
 + 
 +Les **Actions** sont : 
 + 
 +  * **accept**, 
 +  * **reject**, 
 +    * une Action reject peut être associée avec un message d'erreur spécifique par la clause **type="<type_d'erreur>**, 
 +  * **drop**. 
 + 
 +Saisissez la commande suivante pour ouvrir le port 80 : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --add-rich-rule='rule port port="80" protocol="tcp" accept' 
 +success 
 +</code> 
 + 
 +<WRAP center round important 50%> 
 +**Important** - Notez que la Rich Rule doit être entourée de caractères **'**.  
 +</WRAP> 
 + 
 +<WRAP center round important 50%> 
 +**Important** - Notez que la Rich Rule a créé deux règles, une pour IPv4 et une deuxième pour IPv6. Une règle peut être créée pour IPv4 seul en incluant le Critère **family=ipv4**. De la même façon, une règle peut être créée pour IPv6 seul en incluant le Critère **family=ipv6**. 
 +</WRAP> 
 + 
 +Cette nouvelle règle est écrite en mémoire mais non pas sur disque. Pour l'écrire sur disque dans le fichier zone se trouvant dans **/etc/firewalld**, il faut ajouter l'option **--permanent** : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --add-rich-rule='rule port port="80" protocol="tcp" accept' --permanent 
 +success 
 + 
 +[root@redhat9 ~]# cat /etc/firewalld/zones/work.xml 
 +<?xml version="1.0" encoding="utf-8"?> 
 +<zone> 
 +  <short>Work</short> 
 +  <description>For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> 
 +  <service name="ssh"/> 
 +  <service name="dhcpv6-client"/> 
 +  <service name="cockpit"/> 
 +  <rule> 
 +    <port port="80" protocol="tcp"/> 
 +    <accept/> 
 +  </rule> 
 +  <forward/> 
 +</zone> 
 +</code> 
 + 
 +<WRAP center round important 50%> 
 +**Important** - Attention ! La règle ajoutée avec l'option --permanent n'est pas prise en compte imédiatement mais uniquement au prochain redémmarge. Pour qu'une règle soit appliquée immédiatement **et** être écrite sur disque, il faut saisir la commande deux fois dont une avec l'option --permanent et l'autre sans l'option --permanent. 
 +</WRAP> 
 + 
 +Redémarrez le service **firewalld** : 
 + 
 +<code> 
 +[root@redhat9 ~]# systemctl restart firewalld.service 
 +</code> 
 + 
 +Pour visualiser cette règle dans la configuration de firewalld, il convient de saisir la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=work --list-all 
 +work (active) 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces: ens18 
 +  sources:  
 +  services: cockpit dhcpv6-client ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 +        rule port port="80" protocol="tcp" accept 
 +</code> 
 + 
 +Notez que la Rich Rule est créée dans la Zone par Défaut. Il est possible de créer une Rich Rule dans une autre zone en utilisant l'option **--zone=<zone>** de la commande firewall-cmd : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=public --add-rich-rule='rule port port="80" protocol="tcp" accept' 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --zone=public --list-all 
 +public 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services: cockpit dhcpv6-client ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 +        rule port port="80" protocol="tcp" accept 
 +</code> 
 + 
 + 
 +Pour supprimer une Rich Rule, il faut copier la ligne entière la concernant qui se trouve dans la sortie de la commande **firewall-cmd --list-all-zones** : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --zone=public --remove-rich-rule='rule port port="80" protocol="tcp" accept' 
 +success 
 + 
 +[root@redhat9 ~]# firewall-cmd --zone=public --list-all 
 +public 
 +  target: default 
 +  icmp-block-inversion: no 
 +  interfaces:  
 +  sources:  
 +  services: cockpit dhcpv6-client ssh 
 +  ports:  
 +  protocols:  
 +  forward: yes 
 +  masquerade: no 
 +  forward-ports:  
 +  source-ports:  
 +  icmp-blocks:  
 +  rich rules:  
 +</code> 
 + 
 +====4.5 - Le mode Panic de firewalld==== 
 + 
 +Le mode Panic de firewalld permet de bloquer tout le trafic avec une seule commande. Pour connaître l'état du mode Panic, utilisez la commande suivante : 
 + 
 +<code> 
 +[root@redhat9 ~]# firewall-cmd --query-panic 
 +no 
 +</code> 
 + 
 +Pour activer le mode Panic, il convient de saisir la commande suivante : 
 + 
 +<code> 
 +# firewall-cmd --panic-on 
 +</code> 
 + 
 +Pour désactiver le mode Panic, il convient de saisir la commande suivante : 
 + 
 +<code> 
 +# firewall-cmd --panic-off
 </code> </code>
  
 ----- -----
-<html> +Copyright © 2024 Hugh Norris.<br><br>
-<div align="center"> +
-Copyright © 2021 Hugh Norris.<br><br+
-</div> +
-</html>+
Menu