tech:audit_modification_droits_systeme_de_fichier_avec_auditd
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 | ||
| tech:audit_modification_droits_systeme_de_fichier_avec_auditd [2025/10/23 10:15] – Jean-Baptiste | tech:audit_modification_droits_systeme_de_fichier_avec_auditd [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Audit modification droits systeme de fichier avec auditd | ||
| + | |||
| + | Voir : | ||
| + | * [[Notes auditd]] | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | ~~~bash | ||
| + | systemctl status auditd | ||
| + | ~~~ | ||
| + | |||
| + | https:// | ||
| + | |||
| + | Par défaut, vous ne pourrez pas arrêter ce service lorsqu’il s’exécute. Il y a donc lieu d’éditer le fichier de lancement du service `/ | ||
| + | |||
| + | `/ | ||
| + | ~~~ini | ||
| + | RefuseManualStop=no | ||
| + | ~~~ | ||
| + | |||
| + | Une fois le fichier modifié, pour le redémarrer, | ||
| + | ~~~bash | ||
| + | systemctl daemon-reload | ||
| + | systemctl restart auditd | ||
| + | ~~~ | ||
| + | |||
| + | Ajout de règles | ||
| + | |||
| + | Sur CentOS 7, les règles doivent être ajoutées au fichier `/ | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | # | ||
| + | -w / | ||
| + | #Audit de l' | ||
| + | -a exit,always -F arch=b64 -S execve -k root_command_executing | ||
| + | -a exit,always -F arch=b32 -S execve -k root_command_executing | ||
| + | #Audit sur l' | ||
| + | -w /bin/passwd -p x -k passwd_command_execution | ||
| + | ~~~ | ||
| + | |||
| + | Après redémarrage du service, vous pouvez lister les règles actives en tapant : | ||
| + | ~~~bash | ||
| + | auditctl -l | ||
| + | ~~~ | ||
| + | Recherche des événements | ||
| + | |||
| + | Pour trouver les lignes du fichier `/ | ||
| + | ~~~bash | ||
| + | ausearch -f / | ||
| + | ~~~ | ||
| + | |||
| + | Vous pouvez aussi disposer du nombre d’occurrences pour chacun des audits effectués sur les fichiers par le démon : | ||
| + | ~~~bash | ||
| + | aureport -f -i --summary | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | ausearch --start 01/12/20 -m user_end --raw | aureport | ||
| + | ~~~ | ||
| + | |||
| + | Autres | ||
| + | ~~~bash | ||
| + | aureport --start today --event --summary -i | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Règle non persistante | ||
| + | |||
| + | Règle non persistante reboot, redémarrage service | ||
| + | ~~~bash | ||
| + | auditctl -w /etc/hosts -p warx -k monitor-hosts | ||
| + | ~~~ | ||
| + | |||
| + | Afficher les règles | ||
| + | ~~~bash | ||
| + | auditctl -l | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | ausearch -ts today -k monitor-hosts | ||
| + | ~~~ | ||
| + | |||
| + | Rapport clair | ||
| + | ~~~bash | ||
| + | aureport -k | ||
| + | ~~~ | ||
| + | |||
| + | Effacer les règles sauvegardées | ||
| + | ~~~bash | ||
| + | systemctl restart auditd | ||
| + | ~~~ | ||
| + | |||
| + | Règle persistante | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | # First rule - delete all | ||
| + | -D | ||
| + | |||
| + | # Increase the buffers to survive stress events. | ||
| + | # Make this bigger for busy systems | ||
| + | #-b 320 | ||
| + | -b 8192 | ||
| + | |||
| + | ## Set failure mode to panic | ||
| + | -f 2 | ||
| + | |||
| + | # Feel free to add below this line. See auditctl man page | ||
| + | -w /tmp/plop1 -p wrxa -k monitor-plop1 | ||
| + | ~~~ | ||
| + | |||
| + | Voici un exemple de configuration auditd qui cherche à enregistrer des actions pouvant | ||
| + | être dignes d’intérêt (source : https:// | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | # Exécution de insmod , rmmod et modprobe | ||
| + | -w / | ||
| + | -w / | ||
| + | -w /sbin/rmmod -p x | ||
| + | # Journaliser les modifications dans /etc/ | ||
| + | -w /etc/ -p wa | ||
| + | # Surveillance de montage/ | ||
| + | -a exit ,always -S mount -S umount2 | ||
| + | # Appels de syscalls x86 suspects | ||
| + | -a exit ,always -S ioperm -S modify_ldt | ||
| + | # Appels de syscalls qui doivent être rares et surveillés de près | ||
| + | -a exit ,always -S get_kernel_syms -S ptrace | ||
| + | -a exit ,always -S prctl | ||
| + | # Rajout du monitoring pour la création ou suppression de fichiers | ||
| + | # Ces règles peuvent avoir des conséquences importantes sur les | ||
| + | # performances du système | ||
| + | -a exit ,always -F arch=b64 -S unlink -S rmdir -S rename | ||
| + | -a exit ,always -F arch=b64 -S creat -S open -S openat -F exit=-EACCESS | ||
| + | -a exit ,always -F arch=b64 -S truncate -S ftruncate -F exit=-EACCESS | ||
| + | # Verrouillage de la configuration de auditd | ||
| + | -e 2 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | systemctl restart auditd | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Pb | ||
| + | |||
| + | ### Invalid start date | ||
| + | |||
| + | ~~~ | ||
| + | # LANG=C aureport -ts 12-01-2020 10:58:00 -te 12-01-2020 10:59:00 -e -i | ||
| + | Invalid start date (12-01-2020). Month, Day, and Year are required. | ||
| + | |||
| + | |||
| + | # aureport -au | head | ||
| + | |||
| + | Authentication Report | ||
| + | ============================================ | ||
| + | # date time acct host term exe success event | ||
| + | ============================================ | ||
| + | 1. 22/11/20 09:00:09 ftpng 127.0.0.1 / | ||
| + | 2. 22/11/20 23:27:41 user1 10.1.5.33 ssh / | ||
| + | 3. 23/11/20 09:00:31 ftpng 127.0.0.1 / | ||
| + | 4. 23/11/20 09:03:48 user1 10.1.5.25 ssh / | ||
| + | 5. 23/11/20 09:03:52 user1 10.1.5.24 ssh / | ||
| + | |||
| + | # aureport -ts 01/12/20 10:58:00 -te 01/12/20 10:59:00 -e -i | ||
| + | ~~~ | ||
| + | |||
| + | ### Failed to restart auditd.service: | ||
| + | |||
| + | Voir : https:// | ||
| + | |||
| + | RedHat 7 & 8 | ||
| + | |||
| + | ~~~bash | ||
| + | # systemctl restart auditd | ||
| + | Failed to restart auditd.service: | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution | ||
| + | |||
| + | ~~~bash | ||
| + | service auditd stop | ||
| + | systemctl start auditd | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | Status | ||
| + | ~~~bash | ||
| + | auditctl -s | ||
| + | ~~~ | ||
| + | |||
