Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| elearning:workbooks:debian:11:sec:l105 [2025/11/30 15:24] – admin | elearning:workbooks:debian:11:sec:l105 [2025/12/04 09:51] (Version actuelle) – admin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ~~PDF: | ~~PDF: | ||
| - | |||
| - | APPARMOR | ||
| Version : **2026.01** | Version : **2026.01** | ||
| Ligne 30: | Ligne 28: | ||
| * 1.2 - Installation | * 1.2 - Installation | ||
| * 1.3 - Utilisation | * 1.3 - Utilisation | ||
| - | * LAB #2 - Mise en place de AppArmor pour sécuriser le serveur | + | * LAB #2 - Mise en Place d'un Chroot pour isoler un utilisateur/ |
| - | * LAB #3 - Travailler avec AppArmor | + | * LAB #3 - Mise en place d'AppArmor pour sécuriser le serveur |
| - | * LAB #4 - Mise en place de SELinux pour sécuriser le serveur | + | * 3.1 - Présentation |
| - | * 4.1 - Introduction | + | * 3.2 - Définitions |
| - | * 4.2 - Définitions | + | * Les Profils d' |
| + | * Les Etats ou Modes d' | ||
| + | * 3.3 - Installation | ||
| + | * Installation des Paquets | ||
| + | * Modification de GRUB | ||
| + | * Vérification de l' | ||
| + | * LAB #4 - Travailler avec AppArmor | ||
| + | * 4.1 - Consulter la Liste des Profils Chargés | ||
| + | * La Commande aa-status | ||
| + | * 4.2 - Passer le Mode d'un Profil de Complain à Enforce | ||
| + | * La Commande aa-complain | ||
| + | * 4.3 - Passer le Mode d'un Profil d' | ||
| + | * La Commande aa-enforce | ||
| + | * 4.4 - Désactiver et Réactiver tous les Profils | ||
| + | * 4.5 - Créer un Profil | ||
| + | * La Commande aa-genprof | ||
| + | * La Commande aa-logprof | ||
| + | * 4.6 - Supprimer un Profil | ||
| + | * La Commande apparmor_parser | ||
| + | * La Commande aa-remove-unknown | ||
| + | * LAB #5 - Mise en place de SELinux pour sécuriser le serveur | ||
| + | * 5.1 - Présentation | ||
| + | * 5.2 - Définitions | ||
| * Security Context | * Security Context | ||
| * Domains et Types | * Domains et Types | ||
| Ligne 46: | Ligne 66: | ||
| * Décisions d' | * Décisions d' | ||
| * Décisions de Transition | * Décisions de Transition | ||
| - | * 4.3 - Commandes SELinux | + | * 5.3 - Commandes SELinux |
| - | * 4.4 - Les Etats de SELinux | + | * 5.4 - Les Etats de SELinux |
| - | * 4.5 - Booléens | + | * 5.5 - Booléens |
| - | * LAB #5 - Travailler avec SELinux | + | * LAB #6 - Travailler avec SELinux |
| - | * 5.1 - Copier et Déplacer des Fichiers | + | * 6.1 - Copier et Déplacer des Fichiers |
| - | * 5.2 - Vérifier les SC des Processus | + | * 6.2 - Vérifier les SC des Processus |
| - | * 5.3 - Visualiser la SC d'un Utilisateur | + | * 6.3 - Visualiser la SC d'un Utilisateur |
| - | * 5.4 - Vérifier la SC d'un fichier | + | * 6.4 - Vérifier la SC d'un fichier |
| - | * 5.5 - Troubleshooting SELinux | + | * 6.5 - Troubleshooting SELinux |
| * La commande chcon | * La commande chcon | ||
| * La commande restorecon | * La commande restorecon | ||
| - | * 5.6 - Le fichier / | + | * 6.6 - Le fichier / |
| - | * 5.7 - La commande semanage | + | * 6.7 - La commande semanage |
| - | * 5.8 - La commande audit2allow | + | * 6.8 - La commande audit2allow |
| =====System Hardening Manuel===== | =====System Hardening Manuel===== | ||
| Ligne 812: | Ligne 831: | ||
| A l' | A l' | ||
| - | |||
| <WRAP center round todo 50%> | <WRAP center round todo 50%> | ||
| Ligne 818: | Ligne 836: | ||
| </ | </ | ||
| - | =====LAB #4 - Mise en place de SELinux | + | =====LAB #2 - Mise en Place d'un Chroot |
| - | ====4.1 - Installation==== | + | Le chrootage permet de séparer un utilisateur ou un utilisateur système ( et donc un serveur ) du système. |
| + | |||
| + | Sous Debian 12 le binaire chroot est installé par défaut : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | Commencez par créer un répertoire pour l' | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | Le binaire **/ | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | -rwxr-xr-x. 1 root root 48112 Sep 20 2022 / | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | -rwsr-sr-x. 1 root root 48112 Sep 20 2022 / | ||
| + | </ | ||
| + | |||
| + | Créez maintenant un script de connexion générique pour que l' | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | # | ||
| + | exec -c / | ||
| + | </ | ||
| + | |||
| + | Rendez ce script exécutable : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | Il est maintenant nécessaire de copier toutes les commandes dont l' | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | linux-vdso.so.1 (0x00007ffd39fcf000) | ||
| + | libtinfo.so.6 | ||
| + | libc.so.6 | ||
| + | / | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | linux-vdso.so.1 (0x00007fff3db26000) | ||
| + | libselinux.so.1 | ||
| + | libc.so.6 | ||
| + | libpcre2-8.so.0 => / | ||
| + | / | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | Créez maintenant le groupe chroot : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | chroot: | ||
| + | </ | ||
| + | |||
| + | Créez maintenant l' | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | Dernièrement, | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | Essayez maintenant de vous connecter en tant que l' | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | bash-5.2$ pwd | ||
| + | / | ||
| + | |||
| + | bash-5.2$ ls | ||
| + | bin lib lib64 | ||
| + | |||
| + | bash-5.2$ ls -la | ||
| + | total 20 | ||
| + | drwxr-xr-x. 5 1001 1001 4096 Dec 1 13:59 . | ||
| + | drwxr-xr-x. 5 1001 1001 4096 Dec 1 13:59 .. | ||
| + | drwxr-xr-x. 2 1001 1001 4096 Dec 1 13:56 bin | ||
| + | drwxr-xr-x. 3 1001 1001 4096 Dec 1 13:59 lib | ||
| + | drwxr-xr-x. 2 1001 1001 4096 Dec 1 13:56 lib64 | ||
| + | |||
| + | bash-5.2$ exit | ||
| + | exit | ||
| + | |||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | Notez que l' | ||
| + | |||
| + | =====LAB #3 - Mise en place d' | ||
| + | |||
| + | ====3.1 - Présentation==== | ||
| + | |||
| + | **AppArmor**, | ||
| + | |||
| + | L' | ||
| + | |||
| + | ^ Type de Sécurité ^ Nom ^ Description ^ | ||
| + | | DAC | // | ||
| + | | TE | //Type enforcement// | ||
| + | | RBAC | //Role Based Access Control// | ||
| + | | MAC | //Mandatory Access Control// | ||
| + | | MLS | // | ||
| + | |||
| + | Les avantages clés de l' | ||
| + | |||
| + | * **Isolation** : AppArmor aide à contenir les menaces de sécurité en isolant les applications les unes des autres et du reste du système. | ||
| + | * **Contrôle précis** (Fine-grained control) : Vous pouvez spécifier exactement quels fichiers, répertoires et capacités une application peut accéder. | ||
| + | * **Conformité en matière de sécurité** : De nombreuses distributions Linux, notamment Debian et Ubuntu, utilisent AppArmor par défaut pour appliquer des politiques de sécurité. | ||
| + | |||
| + | ====3.2 - Définitions==== | ||
| + | |||
| + | ===Les Profils d' | ||
| + | |||
| + | AppArmor utilise des **profils** pour définir les règles de sécurité pour les applications. Ces profils sont stockés dans le répertoire **/ | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | total 220 | ||
| + | drwxr-xr-x 2 root root 4096 Nov 24 17:22 abi | ||
| + | drwxr-xr-x | ||
| + | drwxr-xr-x 2 root root 4096 Dec 3 12:40 apache2.d | ||
| + | -rw-r--r-- | ||
| + | drwxr-xr-x 2 root root 4096 Apr 3 2021 disable | ||
| + | drwxr-xr-x 2 root root 4096 Apr 3 2021 force-complain | ||
| + | -rw-r--r-- 1 root root 819 Feb 3 2020 lightdm-guest-session | ||
| + | drwxr-xr-x 2 root root 4096 Dec 3 12:40 local | ||
| + | -rw-r--r-- 1 root root 1379 Feb 14 2023 lsb_release | ||
| + | -rw-r--r-- 1 root root 1189 Feb 14 2023 nvidia_modprobe | ||
| + | -rw-r--r-- 1 root root 1713 Feb 14 2023 php-fpm | ||
| + | -rw-r--r-- 1 root root 623 Feb 14 2023 samba-bgqd | ||
| + | -rw-r--r-- 1 root root 1061 Feb 14 2023 samba-dcerpcd | ||
| + | -rw-r--r-- 1 root root 817 Feb 14 2023 samba-rpcd | ||
| + | -rw-r--r-- 1 root root 755 Feb 14 2023 samba-rpcd-classic | ||
| + | -rw-r--r-- 1 root root 964 Feb 14 2023 samba-rpcd-spoolss | ||
| + | -rw-r--r-- 1 root root 3461 Mar 30 2023 sbin.dhclient | ||
| + | -rw-r--r-- 1 root root 1017 Feb 14 2023 sbin.klogd | ||
| + | -rw-r--r-- 1 root root 1458 Feb 14 2023 sbin.syslogd | ||
| + | -rw-r--r-- 1 root root 2076 Feb 14 2023 sbin.syslog-ng | ||
| + | drwxr-xr-x 5 root root 4096 Nov 24 17:22 tunables | ||
| + | -rw-r--r-- 1 root root 1446 Dec 10 2022 usr.bin.irssi | ||
| + | -rw-r--r-- 1 root root 3448 Feb 19 2021 usr.bin.man | ||
| + | -rw-r--r-- 1 root root 2561 Dec 10 2022 usr.bin.pidgin | ||
| + | -rw-r--r-- 1 root root 2038 Dec 10 2022 usr.bin.totem | ||
| + | -rw-r--r-- 1 root root 1400 Dec 10 2022 usr.bin.totem-previewers | ||
| + | -rw-r--r-- 1 root root 1519 Aug 13 17:35 usr.lib.libreoffice.program.oosplash | ||
| + | -rw-r--r-- 1 root root 1227 Oct 10 2021 usr.lib.libreoffice.program.senddoc | ||
| + | -rw-r--r-- 1 root root 10694 Aug 13 17:35 usr.lib.libreoffice.program.soffice.bin | ||
| + | -rw-r--r-- 1 root root 1046 Oct 10 2021 usr.lib.libreoffice.program.xpdfimport | ||
| + | -rw-r--r-- 1 root root 28486 Jun 6 16:53 usr.lib.snapd.snap-confine.real | ||
| + | -rw-r--r-- 1 root root 1060 Dec 10 2022 usr.sbin.apt-cacher-ng | ||
| + | -rw-r--r-- 1 root root 1027 Feb 14 2023 usr.sbin.avahi-daemon | ||
| + | -rw-r--r-- 1 root root 761 May 19 2023 usr.sbin.cups-browsed | ||
| + | -rw-r--r-- 1 root root 6027 Sep 7 19:45 usr.sbin.cupsd | ||
| + | -rw-r--r-- 1 root root 4291 Feb 14 2023 usr.sbin.dnsmasq | ||
| + | -rw-r--r-- 1 root root 1071 Feb 14 2023 usr.sbin.identd | ||
| + | -rw-r--r-- 1 root root 1001 Feb 14 2023 usr.sbin.mdnsd | ||
| + | -rw-r--r-- 1 root root 987 Feb 14 2023 usr.sbin.nmbd | ||
| + | -rw-r--r-- 1 root root 1381 Feb 14 2023 usr.sbin.nscd | ||
| + | -rw-r--r-- 1 root root 2164 Feb 14 2023 usr.sbin.smbd | ||
| + | -rw-r--r-- 1 root root 981 Feb 14 2023 usr.sbin.smbldap-useradd | ||
| + | -rw-r--r-- 1 root root 1091 Feb 14 2023 usr.sbin.traceroute | ||
| + | </ | ||
| + | |||
| + | Le profil est un fichier texte qui fournit la liste complète des autorisations (et des interdictions) pour un programme particulier : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | abi < | ||
| + | |||
| + | include < | ||
| + | |||
| + | profile smbd / | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | |||
| + | capability audit_write, | ||
| + | capability dac_override, | ||
| + | capability dac_read_search, | ||
| + | capability fowner, | ||
| + | capability lease, | ||
| + | capability net_bind_service, | ||
| + | capability setgid, | ||
| + | capability setuid, | ||
| + | capability sys_admin, | ||
| + | capability sys_resource, | ||
| + | capability sys_tty_config, | ||
| + | |||
| + | signal send set=term peer=samba-bgqd, | ||
| + | |||
| + | /etc/mtab r, | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | @{PROC}/ | ||
| + | @{PROC}/ | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | @{run}/ | ||
| + | @{run}/ | ||
| + | @{run}/ | ||
| + | @{run}/ | ||
| + | @{run}/ | ||
| + | @{run}/ | ||
| + | / | ||
| + | |||
| + | @{HOMEDIRS}/ | ||
| + | / | ||
| + | |||
| + | # Permissions for all configured shares (file autogenerated by | ||
| + | # update-apparmor-samba-profile on service startup on Debian and openSUSE) | ||
| + | include if exists < | ||
| + | include if exists < | ||
| + | |||
| + | # Site-specific additions and overrides. See local/ | ||
| + | include if exists < | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Ce que le profil définit : | ||
| + | |||
| + | * **Accès aux fichiers** : Le profil spécifie quels fichiers et répertoires l' | ||
| + | * **Accès au réseau** : Il détermine si l' | ||
| + | * **Capacités du noyau** : Il restreint certaines fonctions puissantes du noyau Linux que l' | ||
| + | |||
| + | Le rôle principal du profil est de créer un bac à sable (sandbox) autour de l' | ||
| + | |||
| + | ===Les Modes d' | ||
| + | |||
| + | AppArmor connait trois états ou modes pour chaque profil : | ||
| + | |||
| + | ^ Mode ^ Description ^ | ||
| + | | **unconfined** | AppArmor est inactif. | | ||
| + | | **complain** | AppArmor autorise l' | ||
| + | | **enforce** | C'est le mode par défaut. AppArmor bloque toute tentative de l' | ||
| + | |||
| + | ====3.3 | ||
| + | |||
| + | ===Installation des Paquets=== | ||
| + | |||
| + | **AppArmor** peut être installé en utilisant **APT** : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | ===Modification de GRUB=== | ||
| + | |||
| + | Editez la ligne **GRUB_CMDLINE_LINUX_DEFAULT** dans le fichier **/ | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | # If you change this file, run ' | ||
| + | # / | ||
| + | # For full documentation of the options in this file, see: | ||
| + | # info -f grub -n ' | ||
| + | |||
| + | GRUB_DEFAULT=0 | ||
| + | GRUB_TIMEOUT=5 | ||
| + | GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` | ||
| + | GRUB_CMDLINE_LINUX_DEFAULT=" | ||
| + | GRUB_CMDLINE_LINUX="" | ||
| + | |||
| + | # If your computer has multiple operating systems installed, then you | ||
| + | # probably want to run os-prober. However, if your computer is a host | ||
| + | # for guest OSes installed via LVM or raw disk devices, running | ||
| + | # os-prober can cause damage to those guest OSes as it mounts | ||
| + | # filesystems to look for things. | ||
| + | # | ||
| + | |||
| + | # Uncomment to enable BadRAM filtering, modify to suit your needs | ||
| + | # This works with Linux (no patch required) and with any kernel that obtains | ||
| + | # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...) | ||
| + | # | ||
| + | |||
| + | # Uncomment to disable graphical terminal | ||
| + | # | ||
| + | |||
| + | # The resolution used on graphical terminal | ||
| + | # note that you can use only modes which your graphic card supports via VBE | ||
| + | # you can see them in real GRUB with the command `vbeinfo' | ||
| + | # | ||
| + | |||
| + | # Uncomment if you don't want GRUB to pass " | ||
| + | # | ||
| + | |||
| + | # Uncomment to disable generation of recovery mode menu entries | ||
| + | # | ||
| + | |||
| + | # Uncomment to get a beep at grub start | ||
| + | # | ||
| + | </ | ||
| + | |||
| + | Mettez à jour GRUB : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Generating grub configuration file ... | ||
| + | Found background image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Warning: os-prober will not be executed to detect other bootable partitions. | ||
| + | Systems on them will not be added to the GRUB boot configuration. | ||
| + | Check GRUB_DISABLE_OS_PROBER documentation entry. | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | Redémarrez la VM : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | ===Vérification de l' | ||
| + | |||
| + | Connectez-vous à la VM et vérifiez qu' | ||
| + | |||
| + | < | ||
| + | trainee@debian12: | ||
| + | Password: fenestros | ||
| + | |||
| + | root@debian12: | ||
| + | Y | ||
| + | |||
| + | root@debian12: | ||
| + | Yes | ||
| + | |||
| + | root@debian12: | ||
| + | ● apparmor.service - Load AppArmor profiles | ||
| + | | ||
| + | | ||
| + | Docs: man: | ||
| + | | ||
| + | Process: 342 ExecStart=/ | ||
| + | Main PID: 342 (code=exited, | ||
| + | CPU: 403ms | ||
| + | |||
| + | Dec 03 12:46:50 debian12 apparmor.systemd[342]: | ||
| + | Dec 03 12:46:50 debian12 apparmor.systemd[342]: | ||
| + | Dec 03 12:46:48 debian12 systemd[1]: Starting apparmor.service - Load AppArmor profil> | ||
| + | Dec 03 12:46:51 debian12 systemd[1]: Finished apparmor.service - Load AppArmor profil> | ||
| + | </ | ||
| + | |||
| + | Les paquets **apparmor-profiles** et **apparmor-profiles-extra** fournissent des profiles supplémentaires qui se trouvent dans **/ | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | bin.netstat | ||
| + | etc.cron.daily.logrotate | ||
| + | etc.cron.daily.slocate.cron | ||
| + | etc.cron.daily.tmpwatch | ||
| + | postfix-anvil | ||
| + | postfix-bounce | ||
| + | postfix-cleanup | ||
| + | postfix-discard | ||
| + | postfix-dnsblog | ||
| + | postfix-error | ||
| + | postfix-flush | ||
| + | postfix-lmtp | ||
| + | postfix-local | ||
| + | postfix-master | ||
| + | postfix-nqmgr | ||
| + | postfix-oqmgr | ||
| + | postfix-pickup | ||
| + | postfix-pipe | ||
| + | postfix-postscreen | ||
| + | postfix-proxymap | ||
| + | </ | ||
| + | |||
| + | Copiez donc les profils dans **/ | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | abi postfix-pickup | ||
| + | abstractions | ||
| + | apache2.d | ||
| + | bin.netstat | ||
| + | bin.ping | ||
| + | disable | ||
| + | etc.cron.daily.logrotate | ||
| + | etc.cron.daily.slocate.cron | ||
| + | etc.cron.daily.tmpwatch | ||
| + | force-complain | ||
| + | lightdm-guest-session | ||
| + | local postfix-tlsmgr | ||
| + | lsb_release | ||
| + | nvidia_modprobe | ||
| + | php-fpm | ||
| + | postfix-anvil | ||
| + | postfix-bounce | ||
| + | postfix-cleanup | ||
| + | postfix-discard | ||
| + | postfix-dnsblog | ||
| + | postfix-error | ||
| + | postfix-flush | ||
| + | postfix-lmtp | ||
| + | postfix-local | ||
| + | postfix-master | ||
| + | postfix-nqmgr | ||
| + | postfix-oqmgr | ||
| + | </ | ||
| + | |||
| + | Redémarrez le service AppArmor : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | ● apparmor.service - Load AppArmor profiles | ||
| + | | ||
| + | | ||
| + | Docs: man: | ||
| + | | ||
| + | Process: 1618 ExecStart=/ | ||
| + | Main PID: 1618 (code=exited, | ||
| + | CPU: 16.409s | ||
| + | |||
| + | Dec 03 13:48:22 debian12 systemd[1]: Starting apparmor.service - Load AppArmor profil> | ||
| + | Dec 03 13:48:22 debian12 apparmor.systemd[1618]: | ||
| + | Dec 03 13:48:22 debian12 apparmor.systemd[1618]: | ||
| + | Dec 03 13:48:24 debian12 systemd[1]: Finished apparmor.service - Load AppArmor profil> | ||
| + | </ | ||
| + | |||
| + | =====LAB #4 - Travailler avec AppArmor===== | ||
| + | |||
| + | ====4.1 - Consulter la Liste des Profils Chargés==== | ||
| + | |||
| + | Pour consulter la liste de tous les profils Apparmor chargés pour les applications et les processus et détaille leur statut (loaded., complain mode, enforce mode), utilisez la commande **aa-status** : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | apparmor module is loaded. | ||
| + | 193 profiles are loaded. | ||
| + | 148 profiles are in enforce mode. | ||
| + | / | ||
| + | ... | ||
| + | | ||
| + | 45 profiles are in complain mode. | ||
| + | / | ||
| + | ... | ||
| + | traceroute | ||
| + | 0 profiles are in kill mode. | ||
| + | 0 profiles are in unconfined mode. | ||
| + | 7 processes have profiles defined. | ||
| + | 2 processes are in enforce mode. | ||
| + | / | ||
| + | / | ||
| + | 2 processes are in complain mode. | ||
| + | / | ||
| + | / | ||
| + | 3 processes are unconfined but have a profile defined. | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | 0 processes are in mixed mode. | ||
| + | 0 processes are in kill mode. | ||
| + | </ | ||
| + | |||
| + | ===Options de la Commande=== | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Usage: aa-status [OPTIONS] | ||
| + | Displays various information about the currently loaded AppArmor policy. | ||
| + | OPTIONS (one only): | ||
| + | --enabled | ||
| + | --profiled | ||
| + | --enforced | ||
| + | --complaining | ||
| + | --kill | ||
| + | --special-unconfined | ||
| + | --process-mixed prints the number processes with mixed profile modes | ||
| + | --json | ||
| + | --pretty-json | ||
| + | --verbose | ||
| + | --help | ||
| + | </ | ||
| + | |||
| + | ====4.2 - Passer le Mode d'un Profil de Complain à Enforce==== | ||
| + | |||
| + | Le profil **traceroute** est actuellement en mode **complain**. Pour passer ce profil en mode **enforce**, | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Setting / | ||
| + | |||
| + | root@debian12: | ||
| + | apparmor module is loaded. | ||
| + | 193 profiles are loaded. | ||
| + | 149 profiles are in enforce mode. | ||
| + | / | ||
| + | ... | ||
| + | | ||
| + | | ||
| + | 44 profiles are in complain mode. | ||
| + | / | ||
| + | ... | ||
| + | | ||
| + | 0 profiles are in kill mode. | ||
| + | 0 profiles are in unconfined mode. | ||
| + | 7 processes have profiles defined. | ||
| + | 2 processes are in enforce mode. | ||
| + | / | ||
| + | / | ||
| + | 2 processes are in complain mode. | ||
| + | / | ||
| + | / | ||
| + | 3 processes are unconfined but have a profile defined. | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | 0 processes are in mixed mode. | ||
| + | 0 processes are in kill mode. | ||
| + | </ | ||
| + | |||
| + | ===Options de la Commande=== | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | usage: aa-enforce [-h] [-d DIR] [--no-reload] program [program ...] | ||
| + | |||
| + | Switch the given program to enforce mode | ||
| + | |||
| + | positional arguments: | ||
| + | program | ||
| + | |||
| + | options: | ||
| + | -h, --help | ||
| + | -d DIR, --dir DIR path to profiles | ||
| + | --no-reload | ||
| + | </ | ||
| + | |||
| + | ====4.3 - Passer le Mode d'un Profil d' | ||
| + | |||
| + | Pour repasser le profil en mode **enforce**, | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Setting / | ||
| + | |||
| + | root@debian12: | ||
| + | apparmor module is loaded. | ||
| + | 193 profiles are loaded. | ||
| + | 148 profiles are in enforce mode. | ||
| + | / | ||
| + | ... | ||
| + | | ||
| + | 45 profiles are in complain mode. | ||
| + | / | ||
| + | ... | ||
| + | | ||
| + | | ||
| + | 0 profiles are in kill mode. | ||
| + | 0 profiles are in unconfined mode. | ||
| + | 7 processes have profiles defined. | ||
| + | 2 processes are in enforce mode. | ||
| + | / | ||
| + | / | ||
| + | 2 processes are in complain mode. | ||
| + | / | ||
| + | / | ||
| + | 3 processes are unconfined but have a profile defined. | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | 0 processes are in mixed mode. | ||
| + | 0 processes are in kill mode. | ||
| + | </ | ||
| + | |||
| + | ===Options de la Commande=== | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | usage: aa-complain [-h] [-d DIR] [--no-reload] program [program ...] | ||
| + | |||
| + | Switch the given program to complain mode | ||
| + | |||
| + | positional arguments: | ||
| + | program | ||
| + | |||
| + | options: | ||
| + | -h, --help | ||
| + | -d DIR, --dir DIR path to profiles | ||
| + | --no-reload | ||
| + | </ | ||
| + | |||
| + | ====4.4 - Désactiver et Réactiver tous les Profils==== | ||
| + | |||
| + | Pour déactiver tous les profils, utilisez la commande **aa-teardown** : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Unloading AppArmor profiles | ||
| + | |||
| + | root@debian12: | ||
| + | apparmor module is loaded. | ||
| + | </ | ||
| + | |||
| + | Pour réactiver les profils, réinstallez AppArmor : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Reading package lists... Done | ||
| + | Building dependency tree... Done | ||
| + | Reading state information... Done | ||
| + | 0 upgraded, 0 newly installed, 1 reinstalled, | ||
| + | Need to get 616 kB of archives. | ||
| + | After this operation, 0 B of additional disk space will be used. | ||
| + | Get:1 http:// | ||
| + | Fetched 616 kB in 0s (10.6 MB/s) | ||
| + | Preconfiguring packages ... | ||
| + | (Reading database ... 186665 files and directories currently installed.) | ||
| + | Preparing to unpack .../ | ||
| + | Unpacking apparmor (3.0.8-3) over (3.0.8-3) ... | ||
| + | Setting up apparmor (3.0.8-3) ... | ||
| + | Reloading AppArmor profiles | ||
| + | Processing triggers for man-db (2.11.2-2) ... | ||
| + | </ | ||
| + | |||
| + | root@debian12: | ||
| + | Notification emitter started in the background | ||
| + | |||
| + | ====4.5 - Créer un Profil==== | ||
| + | |||
| + | Créez le script **newusercheck.sh** qui a pour but d' | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | # | ||
| + | # Send an email alert if a new account is added to the /etc/passwd file | ||
| + | # CRONJOB BELOW RUNS EVERY 5 MINUTES | ||
| + | # */5 * * * * /bin/bash / | ||
| + | |||
| + | |||
| + | HOSTNAME=$(hostname) | ||
| + | TO="< | ||
| + | FROM="< | ||
| + | USERLIST="/ | ||
| + | NEWUSERLIST="/ | ||
| + | PASSWDFILE="/ | ||
| + | COMPARE=0 | ||
| + | |||
| + | trap "/ | ||
| + | |||
| + | |||
| + | if [ -s " | ||
| + | / | ||
| + | LASTREV=" | ||
| + | COMPARE=1 | ||
| + | fi | ||
| + | |||
| + | |||
| + | / | ||
| + | /bin/cat $PASSWDFILE | / | ||
| + | |||
| + | |||
| + | CURRENT=" | ||
| + | |||
| + | |||
| + | if [ $COMPARE -eq 1 ] ; then | ||
| + | if [ " | ||
| + | / | ||
| + | / | ||
| + | |||
| + | / | ||
| + | / | ||
| + | |||
| + | / | ||
| + | /bin/mv $NEWUSERLIST $USERLIST | ||
| + | else | ||
| + | / | ||
| + | fi | ||
| + | else | ||
| + | / | ||
| + | /bin/mv $NEWUSERLIST $USERLIST | ||
| + | fi | ||
| + | |||
| + | /bin/chmod 600 $USERLIST | ||
| + | |||
| + | exit 0 | ||
| + | </ | ||
| + | |||
| + | Rendez ce script exécutable et testez-le : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | [*] Obtaining current user list | ||
| + | [*] Creating initial database of previously known users | ||
| + | </ | ||
| + | |||
| + | ===La Commande aa-genprof=== | ||
| + | |||
| + | Utilisez maintenant la commande **aa-genprof** pour créer un profil : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Updating AppArmor profiles in / | ||
| + | Writing updated profile for / | ||
| + | Setting / | ||
| + | |||
| + | Before you begin, you may wish to check if a | ||
| + | profile already exists for the application you | ||
| + | wish to confine. See the following wiki page for | ||
| + | more information: | ||
| + | https:// | ||
| + | |||
| + | Profiling: / | ||
| + | |||
| + | Please start the application to be profiled in | ||
| + | another window and exercise its functionality now. | ||
| + | |||
| + | Once completed, select the " | ||
| + | order to scan the system logs for AppArmor events. | ||
| + | |||
| + | For each AppArmor event, you will be given the | ||
| + | opportunity to choose whether the access should be | ||
| + | allowed or denied. | ||
| + | |||
| + | [(S)can system log for AppArmor events] / (F)inish | ||
| + | </ | ||
| + | |||
| + | Dans une deuxième connexion à votre VM Debian 12, exécutez le script **newusercheck.sh** : | ||
| + | |||
| + | < | ||
| + | trainee@debian12: | ||
| + | Password: fenestros | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | [*] Checking previously known list of users | ||
| + | [*] Obtaining current user list | ||
| + | [*] No new users have been created since the last check | ||
| + | </ | ||
| + | |||
| + | Dans la première connexion, appuyez sur la touche **S** : | ||
| + | |||
| + | < | ||
| + | Reading log entries from / | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | </ | ||
| + | |||
| + | <WRAP center round important 50%> | ||
| + | **Important** - Notez que le script exécute la commande **/ | ||
| + | </ | ||
| + | |||
| + | Appuyez maintenant sur la touche **I** pour **hériter** des permissions du processus parent du script, c' | ||
| + | |||
| + | < | ||
| + | Reading log entries from / | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: 1 | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | </ | ||
| + | |||
| + | <WRAP center round important 50%> | ||
| + | **Important** - Notez que le script exécute la commande **/ | ||
| + | </ | ||
| + | |||
| + | De nouveau appuyez sur la touche **I** et continuez ce processus jusqu' | ||
| + | |||
| + | < | ||
| + | Reading log entries from / | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: 1 | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (N)amed / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: 2 | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (N)amed / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (N)amed / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | Complain-mode changes: | ||
| + | |||
| + | Profile: | ||
| + | Path: / | ||
| + | New Mode: rw | ||
| + | Severity: 9 | ||
| + | |||
| + | [1 - include < | ||
| + | 2 - include < | ||
| + | 3 - include < | ||
| + | 4 - /dev/pts/1 rw, | ||
| + | (A)llow / [(D)eny] / (I)gnore / (G)lob / Glob with (E)xtension / (N)ew / Audi(t) / Abo(r)t / (F)inish | ||
| + | </ | ||
| + | |||
| + | Appuyez sur la touche **A** pour toutes les questions suivantes : | ||
| + | |||
| + | < | ||
| + | Reading log entries from / | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: 1 | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (N)amed / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: 2 | ||
| + | |||
| + | (I)nherit / (C)hild / (P)rofile / (N)amed / (U)nconfined / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (N)amed / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | |||
| + | Profile: | ||
| + | Execute: | ||
| + | Severity: unknown | ||
| + | |||
| + | (I)nherit / (C)hild / (N)amed / (X) ix On / (D)eny / Abo(r)t / (F)inish | ||
| + | Complain-mode changes: | ||
| + | |||
| + | Profile: | ||
| + | Path: / | ||
| + | New Mode: rw | ||
| + | Severity: 9 | ||
| + | |||
| + | [1 - include < | ||
| + | 2 - include < | ||
| + | 3 - include < | ||
| + | 4 - /dev/pts/1 rw, | ||
| + | (A)llow / [(D)eny] / (I)gnore / (G)lob / Glob with (E)xtension / (N)ew / Audi(t) / Abo(r)t / (F)inish | ||
| + | Adding include < | ||
| + | |||
| + | Profile: | ||
| + | Path: / | ||
| + | New Mode: owner w | ||
| + | Severity: unknown | ||
| + | |||
| + | [1 - owner / | ||
| + | (A)llow / [(D)eny] / (I)gnore / (G)lob / Glob with (E)xtension / (N)ew / Audi(t) / (O)wner permissions off / Abo(r)t / (F)inish | ||
| + | Adding owner / | ||
| + | |||
| + | Profile: | ||
| + | Path: / | ||
| + | New Mode: owner r | ||
| + | Severity: 1 | ||
| + | |||
| + | [1 - include < | ||
| + | 2 - owner / | ||
| + | (A)llow / [(D)eny] / (I)gnore / (G)lob / Glob with (E)xtension / (N)ew / Audi(t) / (O)wner permissions off / Abo(r)t / (F)inish | ||
| + | Adding include < | ||
| + | |||
| + | Profile: | ||
| + | Path: / | ||
| + | New Mode: owner r | ||
| + | Severity: unknown | ||
| + | |||
| + | [1 - owner / | ||
| + | (A)llow / [(D)eny] / (I)gnore / (G)lob / Glob with (E)xtension / (N)ew / Audi(t) / (O)wner permissions off / Abo(r)t / (F)inish | ||
| + | Adding owner / | ||
| + | |||
| + | Profile: | ||
| + | Path: / | ||
| + | Old Mode: owner w | ||
| + | New Mode: owner r | ||
| + | Severity: unknown | ||
| + | |||
| + | [1 - owner / | ||
| + | (A)llow / [(D)eny] / (I)gnore / (G)lob / Glob with (E)xtension / (N)ew / Audi(t) / (O)wner permissions off / Abo(r)t / (F)inish | ||
| + | Adding owner / | ||
| + | |||
| + | Profile: | ||
| + | Path: / | ||
| + | Old Mode: owner r | ||
| + | New Mode: owner w | ||
| + | Severity: unknown | ||
| + | |||
| + | [1 - owner / | ||
| + | (A)llow / [(D)eny] / (I)gnore / (G)lob / Glob with (E)xtension / (N)ew / Audi(t) / (O)wner permissions off / Abo(r)t / (F)inish | ||
| + | Adding owner / | ||
| + | |||
| + | = Changed Local Profiles = | ||
| + | |||
| + | The following local profiles were changed. Would you like to save them? | ||
| + | |||
| + | [1 - / | ||
| + | (S)ave Changes / Save Selec(t)ed Profile / [(V)iew Changes] / View Changes b/w (C)lean profiles / Abo(r)t | ||
| + | </ | ||
| + | |||
| + | Appuyez sur la touche **S** : | ||
| + | |||
| + | < | ||
| + | ... | ||
| + | Writing updated profile for / | ||
| + | |||
| + | Profiling: / | ||
| + | |||
| + | Please start the application to be profiled in | ||
| + | another window and exercise its functionality now. | ||
| + | |||
| + | Once completed, select the " | ||
| + | order to scan the system logs for AppArmor events. | ||
| + | |||
| + | For each AppArmor event, you will be given the | ||
| + | opportunity to choose whether the access should be | ||
| + | allowed or denied. | ||
| + | |||
| + | [(S)can system log for AppArmor events] / (F)inish | ||
| + | </ | ||
| + | |||
| + | Retournez dans la deuxième connexion à votre VM et exécutez de nouveau le script **newusercheck.sh** : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | [*] Checking previously known list of users | ||
| + | [*] Obtaining current user list | ||
| + | [*] No new users have been created since the last check | ||
| + | </ | ||
| + | |||
| + | Dans la première connexion, appuyez de nouveau sur la touche **S** : | ||
| + | |||
| + | < | ||
| + | ... | ||
| + | Writing updated profile for / | ||
| + | |||
| + | Profiling: / | ||
| + | |||
| + | Please start the application to be profiled in | ||
| + | another window and exercise its functionality now. | ||
| + | |||
| + | Once completed, select the " | ||
| + | order to scan the system logs for AppArmor events. | ||
| + | |||
| + | For each AppArmor event, you will be given the | ||
| + | opportunity to choose whether the access should be | ||
| + | allowed or denied. | ||
| + | |||
| + | [(S)can system log for AppArmor events] / (F)inish | ||
| + | Reading log entries from / | ||
| + | |||
| + | Profiling: / | ||
| + | |||
| + | Please start the application to be profiled in | ||
| + | another window and exercise its functionality now. | ||
| + | |||
| + | Once completed, select the " | ||
| + | order to scan the system logs for AppArmor events. | ||
| + | |||
| + | For each AppArmor event, you will be given the | ||
| + | opportunity to choose whether the access should be | ||
| + | allowed or denied. | ||
| + | |||
| + | [(S)can system log for AppArmor events] / (F)inish | ||
| + | </ | ||
| + | |||
| + | <WRAP center round important 50%> | ||
| + | **Important** - Notez l' | ||
| + | </ | ||
| + | |||
| + | Appuyez maintenant sur la touch **F** : | ||
| + | |||
| + | < | ||
| + | ... | ||
| + | Reloaded AppArmor profiles in enforce mode. | ||
| + | |||
| + | Please consider contributing your new profile! | ||
| + | See the following wiki page for more information: | ||
| + | https:// | ||
| + | |||
| + | Finished generating profile for / | ||
| + | </ | ||
| + | |||
| + | Le profil à été créé dans le répertoire **/ | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | root.scripts.newusercheck.sh | ||
| + | |||
| + | root@debian12: | ||
| + | # Last Modified: Wed Dec 3 16:36:43 2025 | ||
| + | abi < | ||
| + | |||
| + | include < | ||
| + | |||
| + | / | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | |||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | /usr/bin/rm mrix, | ||
| + | owner / | ||
| + | owner / | ||
| + | owner / | ||
| + | owner / | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | Ce fichier inclut le contenu du profil **/ | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | # ------------------------------------------------------------------ | ||
| + | # | ||
| + | # Copyright (C) 2006-2009 Novell/ | ||
| + | # Copyright (C) 2010-2014 Canonical Ltd. | ||
| + | # | ||
| + | # This program is free software; you can redistribute it and/or | ||
| + | # modify it under the terms of version 2 of the GNU General Public | ||
| + | # License published by the Free Software Foundation. | ||
| + | # | ||
| + | # ------------------------------------------------------------------ | ||
| + | |||
| + | # All the tunables definitions that should be available to every profile | ||
| + | # should be included here | ||
| + | |||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | include < | ||
| + | </ | ||
| + | |||
| + | ==Options de la Commande== | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | usage: aa-genprof [-h] [-d DIR] [-f FILE] [-j] program | ||
| + | |||
| + | Generate profile for the given program | ||
| + | |||
| + | positional arguments: | ||
| + | program | ||
| + | |||
| + | options: | ||
| + | -h, --help | ||
| + | -d DIR, --dir DIR path to profiles | ||
| + | -f FILE, --file FILE path to logfile | ||
| + | -j, --json | ||
| + | </ | ||
| + | |||
| + | ===La Commande aa-logprof=== | ||
| + | |||
| + | Exécutez maintenant la commande **aa-logprof** pour vérifier que toutes les permissions sont adéquatement placées : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Updating AppArmor profiles in / | ||
| + | Reading log entries from / | ||
| + | Complain-mode changes: | ||
| + | Enforce-mode changes: | ||
| + | |||
| + | Profile: | ||
| + | Capability: net_admin | ||
| + | Severity: | ||
| + | |||
| + | [1 - capability net_admin, | ||
| + | (A)llow / [(D)eny] / (I)gnore / Audi(t) / Abo(r)t / (F)inish | ||
| + | </ | ||
| + | |||
| + | Appuyez sur la touche **A** : | ||
| + | |||
| + | </ | ||
| + | Adding capability net_admin, to profile. | ||
| + | |||
| + | = Changed Local Profiles = | ||
| + | |||
| + | The following local profiles were changed. Would you like to save them? | ||
| + | |||
| + | [1 - / | ||
| + | (S)ave Changes / Save Selec(t)ed Profile / [(V)iew Changes] / View Changes b/w (C)lean profiles / Abo(r)t | ||
| + | |||
| + | Appuyez sur la touche **S** : | ||
| + | |||
| + | </ | ||
| + | Writing updated profile for / | ||
| + | </ | ||
| + | |||
| + | Exécutez de nouveau la commande **aa-logprof** : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Updating AppArmor profiles in / | ||
| + | Reading log entries from / | ||
| + | Complain-mode changes: | ||
| + | Enforce-mode changes: | ||
| + | </ | ||
| + | |||
| + | ==Options de la Commande== | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | usage: aa-logprof [-h] [-d DIR] [-f FILE] [-m MARK] [-j] | ||
| + | |||
| + | Process log entries to generate profiles | ||
| + | |||
| + | options: | ||
| + | -h, --help | ||
| + | -d DIR, --dir DIR path to profiles | ||
| + | -f FILE, --file FILE path to logfile | ||
| + | -m MARK, --mark MARK mark in the log to start processing after | ||
| + | -j, --json | ||
| + | </ | ||
| + | |||
| + | Dernièrement passez le nouveau profil en mode **enforce** : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Setting / | ||
| + | |||
| + | root@debian12: | ||
| + | Updating AppArmor profiles in / | ||
| + | Reading log entries from / | ||
| + | Complain-mode changes: | ||
| + | Enforce-mode changes: | ||
| + | </ | ||
| + | |||
| + | ====4.6 - Supprimer un Profil==== | ||
| + | |||
| + | Afin de supprimer le profil **root.scripts.newusercheck.sh**, | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | ===Options de la Commande=== | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | AppArmor parser version 3.0.8 | ||
| + | Copyright (C) 1999-2008 Novell Inc. | ||
| + | Copyright 2009-2018 Canonical Ltd. | ||
| + | |||
| + | Usage: apparmor_parser [options] [profile] | ||
| + | |||
| + | Options: | ||
| + | -------- | ||
| + | -a, --add Add apparmor definitions [default] | ||
| + | -r, --replace | ||
| + | -R, --remove | ||
| + | -C, --Complain | ||
| + | -B, --binary | ||
| + | -N, --names | ||
| + | -S, --stdout | ||
| + | -o n, --ofile n Write output to file n | ||
| + | -b n, --base n Set base dir and cwd | ||
| + | -I n, --Include n Add n to the search path | ||
| + | -f n, --subdomainfs n Set location of apparmor filesystem | ||
| + | -m n, --match-string n Use only features n | ||
| + | -M n, --features-file n Set compile & kernel features to file n | ||
| + | --policy-features n | ||
| + | --override-policy-abi n As policy-features but override ABI rules | ||
| + | --kernel-features n | ||
| + | -n n, --namespace n Set Namespace for the profile | ||
| + | -X, --readimpliesX | ||
| + | -k, --show-cache | ||
| + | -K, --skip-cache | ||
| + | -T, --skip-read-cache | ||
| + | -W, --write-cache | ||
| + | --skip-bad-cache | ||
| + | --purge-cache | ||
| + | --debug-cache | ||
| + | --print-cache-dir | ||
| + | -L, --cache-loc n Set the location of the profile caches | ||
| + | -q, --quiet | ||
| + | -v, --verbose | ||
| + | -Q, --skip-kernel-load | ||
| + | -V, --version | ||
| + | -d [n], --debug | ||
| + | -p, --preprocess | ||
| + | -D [n], --dump | ||
| + | -O [n], --Optimize | ||
| + | -h [cmd], --help[=cmd] | ||
| + | -j n, --jobs n Set the number of compile threads | ||
| + | --max-jobs n Hard cap on --jobs. Default 8*cpus | ||
| + | --abort-on-error | ||
| + | --skip-bad-cache-rebuild Do not try rebuilding the cache if it is rejected by the kernel | ||
| + | --config-file n | ||
| + | --print-config | ||
| + | --warn n Enable warnings (see --help=warn) | ||
| + | --Werror [n] Convert warnings to errors. If n is specified turn warn n into an error | ||
| + | </ | ||
| + | |||
| + | Terminez par procéder à un nettoyage d' | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | root@debian12: | ||
| + | root@debian12: | ||
| + | ● apparmor.service - Load AppArmor profiles | ||
| + | | ||
| + | | ||
| + | Docs: man: | ||
| + | | ||
| + | Process: 2992 ExecStart=/ | ||
| + | Main PID: 2992 (code=exited, | ||
| + | CPU: 1.261s | ||
| + | |||
| + | Dec 03 17:32:35 debian12 systemd[1]: Starting apparmor.service - Load AppArmor profiles... | ||
| + | Dec 03 17:32:35 debian12 apparmor.systemd[2992]: | ||
| + | Dec 03 17:32:35 debian12 apparmor.systemd[2992]: | ||
| + | Dec 03 17:32:36 debian12 systemd[1]: Finished apparmor.service - Load AppArmor profiles. | ||
| + | </ | ||
| + | |||
| + | ===Options de la Commande=== | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | usage: / | ||
| + | |||
| + | Remove profiles unknown to the system | ||
| + | |||
| + | Options: | ||
| + | -h, --help | ||
| + | | ||
| + | </ | ||
| + | |||
| + | =====LAB #5 - Mise en place de SELinux pour sécuriser le serveur===== | ||
| + | |||
| + | ====5.1 - Présentationn==== | ||
| Désactivez AppArmor : | Désactivez AppArmor : | ||
| Ligne 848: | Ligne 2225: | ||
| Nov 30 09:59:03 debian12 systemd[1]: apparmor.service: | Nov 30 09:59:03 debian12 systemd[1]: apparmor.service: | ||
| Nov 30 09:59:03 debian12 systemd[1]: Stopped apparmor.service - Load AppArmor profiles. | Nov 30 09:59:03 debian12 systemd[1]: Stopped apparmor.service - Load AppArmor profiles. | ||
| + | </ | ||
| + | |||
| + | Editez la ligne **GRUB_CMDLINE_LINUX_DEFAULT** dans le fichier **/ | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | |||
| + | root@debian12: | ||
| + | # If you change this file, run ' | ||
| + | # / | ||
| + | # For full documentation of the options in this file, see: | ||
| + | # info -f grub -n ' | ||
| + | |||
| + | GRUB_DEFAULT=0 | ||
| + | GRUB_TIMEOUT=5 | ||
| + | GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` | ||
| + | GRUB_CMDLINE_LINUX_DEFAULT=" | ||
| + | GRUB_CMDLINE_LINUX="" | ||
| + | |||
| + | # If your computer has multiple operating systems installed, then you | ||
| + | # probably want to run os-prober. However, if your computer is a host | ||
| + | # for guest OSes installed via LVM or raw disk devices, running | ||
| + | # os-prober can cause damage to those guest OSes as it mounts | ||
| + | # filesystems to look for things. | ||
| + | # | ||
| + | |||
| + | # Uncomment to enable BadRAM filtering, modify to suit your needs | ||
| + | # This works with Linux (no patch required) and with any kernel that obtains | ||
| + | # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...) | ||
| + | # | ||
| + | |||
| + | # Uncomment to disable graphical terminal | ||
| + | # | ||
| + | |||
| + | # The resolution used on graphical terminal | ||
| + | # note that you can use only modes which your graphic card supports via VBE | ||
| + | # you can see them in real GRUB with the command `vbeinfo' | ||
| + | # | ||
| + | |||
| + | # Uncomment if you don't want GRUB to pass " | ||
| + | # | ||
| + | |||
| + | # Uncomment to disable generation of recovery mode menu entries | ||
| + | # | ||
| + | |||
| + | # Uncomment to get a beep at g | ||
| + | </ | ||
| + | |||
| + | Mettez à jour GRUB : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | Generating grub configuration file ... | ||
| + | Found background image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Found linux image: / | ||
| + | Found initrd image: / | ||
| + | Warning: os-prober will not be executed to detect other bootable partitions. | ||
| + | Systems on them will not be added to the GRUB boot configuration. | ||
| + | Check GRUB_DISABLE_OS_PROBER documentation entry. | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | Redémarrez la VM : | ||
| + | |||
| + | < | ||
| + | root@debian12: | ||
| + | </ | ||
| + | |||
| + | Reconnectez-vous à la VM et passez en tant que l' | ||
| + | |||
| + | < | ||
| + | trainee@debian12: | ||
| + | Password: fenestros | ||
| + | |||
| + | root@debian12: | ||
| </ | </ | ||
| Ligne 853: | Ligne 2309: | ||
| < | < | ||
| - | root@debian12: | + | root@debian12: |
| </ | </ | ||
| Ligne 891: | Ligne 2347: | ||
| </ | </ | ||
| - | ====4.2 - Introducton==== | + | ====5.2 - Introducton==== |
| L' | L' | ||
| ^ Type de Sécurité ^ Nom ^ Description ^ | ^ Type de Sécurité ^ Nom ^ Description ^ | ||
| + | | DAC | // | ||
| | TE | //Type enforcement// | | TE | //Type enforcement// | ||
| | RBAC | //Role Based Access Control// | | RBAC | //Role Based Access Control// | ||
| Ligne 913: | Ligne 2370: | ||
| Chaque **//classe d' | Chaque **//classe d' | ||
| - | ====4.3 - Définitions==== | + | ====5.3 - Définitions==== |
| ===Security Context=== | ===Security Context=== | ||
| Ligne 1102: | Ligne 2559: | ||
| * de créer des **// | * de créer des **// | ||
| - | ====4.4 - Commandes SELinux==== | + | ====5.4 - Commandes SELinux==== |
| ^ Commande ^ Description ^ | ^ Commande ^ Description ^ | ||
| Ligne 1123: | Ligne 2580: | ||
| | togglesebool | Bascule la valeur d'un booléen | | | togglesebool | Bascule la valeur d'un booléen | | ||
| - | ====4.5 - Les Etats de SELinux==== | + | ====5.5 - Les Etats de SELinux==== |
| %%SELinux%% connait trois états : | %%SELinux%% connait trois états : | ||
| Ligne 1225: | Ligne 2682: | ||
| </ | </ | ||
| - | ====4.6 - Booléens==== | + | ====5.6 - Booléens==== |
| Les booléens permettent à des ensembles de règles d' | Les booléens permettent à des ensembles de règles d' | ||
| Ligne 1367: | Ligne 2824: | ||
| </ | </ | ||
| - | =====LAB #5 - Travailler avec SELinux===== | + | =====LAB #6 - Travailler avec SELinux===== |
| Afin reconstruire la politique actuelle **sans** les règles **dontaudit**, | Afin reconstruire la politique actuelle **sans** les règles **dontaudit**, | ||
| Ligne 1406: | Ligne 2863: | ||
| </ | </ | ||
| - | ====5.1 - Copier et Déplacer des Fichiers==== | + | ====6.1 - Copier et Déplacer des Fichiers==== |
| Créez deux fichiers **file1** et **file2** en tant que l' | Créez deux fichiers **file1** et **file2** en tant que l' | ||
| Ligne 1445: | Ligne 2902: | ||
| Notez que la commande **mv** maintient le **type** d' | Notez que la commande **mv** maintient le **type** d' | ||
| - | ====5.2 - Vérifier les SC des Processus==== | + | ====6.2 - Vérifier les SC des Processus==== |
| Il convient d' | Il convient d' | ||
| Ligne 1509: | Ligne 2966: | ||
| </ | </ | ||
| - | ====5.3 - Visualiser la SC d'un Utilisateur==== | + | ====6.3 - Visualiser la SC d'un Utilisateur==== |
| Utilisez l' | Utilisez l' | ||
| Ligne 1528: | Ligne 2985: | ||
| </ | </ | ||
| - | ====5.4 - Vérifier la SC d'un fichier==== | + | ====6.4 - Vérifier la SC d'un fichier==== |
| Il convient d' | Il convient d' | ||
| Ligne 1559: | Ligne 3016: | ||
| </ | </ | ||
| - | ====5.5 - Troubleshooting SELinux==== | + | ====6.5 - Troubleshooting SELinux==== |
| L' | L' | ||
| Ligne 1860: | Ligne 3317: | ||
| </ | </ | ||
| - | ====5.7 - La commande semanage==== | + | ====6.7 - La commande semanage==== |
| Pour illustrer l' | Pour illustrer l' | ||
| Ligne 1930: | Ligne 3387: | ||
| </ | </ | ||
| - | ====5.8 - La commande audit2allow==== | + | ====6.8 - La commande audit2allow==== |
| La création d'un module de politique personnalisé se fait en utilisant la commande **audit2allow**. L' | La création d'un module de politique personnalisé se fait en utilisant la commande **audit2allow**. L' | ||