Outils pour utilisateurs

Outils du site


tech:audit_modification_droits_systeme_de_fichier_avec_auditd

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
tech:audit_modification_droits_systeme_de_fichier_avec_auditd [2025/10/23 10:15] Jean-Baptistetech: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:
 +<!DOCTYPE markdown>
 +{{tag>Brouillon Audit Sécurité Syscall}}
 +
 +# Audit modification droits systeme de fichier avec auditd
 +
 +Voir :
 +* [[Notes auditd]]
 +* https://access.redhat.com/solutions/10107
 +* https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security_guide/sec-searching_the_audit_log_files
 +* https://connect.ed-diamond.com/GNU-Linux-Magazine/GLMFHS-093/Journalisez-les-actions-de-vos-utilisateurs-avec-Auditd
 +* https://gist.github.com/Neo23x0/9fe88c0c5979e017a389b90fd19ddfee
 +* https://www.tecmint.com/query-audit-logs-using-ausearch-tool-on-centos-rhel/
 +* https://www.linux.com/learn/customized-file-monitoring-auditd%20
 +* https://www.digitalocean.com/community/tutorials/how-to-use-the-linux-auditing-system-on-centos-7
 +* https://www.server-world.info/en/note?os=CentOS_7&p=audit&f=3
 +
 +~~~bash
 +systemctl status auditd
 +~~~
 +
 +https://www.dsfc.net/logiciel-libre/linux/centos-linux-logiciel-libre/configurer-auditd-sur-centos-7/
 +
 +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 `/lib/systemd/system/auditd.service` et de modifier la directive RefuseManualStop en la passant à no :
 +
 +`/lib/systemd/system/auditd.service`
 +~~~ini
 +RefuseManualStop=no
 +~~~
 +
 +Une fois le fichier modifié, pour le redémarrer, faites :
 +~~~bash
 +systemctl daemon-reload
 +systemctl restart auditd
 +~~~
 +
 +Ajout de règles
 +
 +Sur CentOS 7, les règles doivent être ajoutées au fichier `/etc/audit/rules.d/audit.rules`.
 +
 +`/etc/audit/rules.d/audit.rules`
 +~~~
 +#Surveillance du fichier /etc/ssh/sshd_config
 +-w /etc/ssh/sshd_config -p w -k ssh_configuration_change
 +#Audit de l'exécution des Commandes 32 et 64 bits
 +-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'exécution de la commande passwd
 +-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 `/var/log/audit/audit.log` qui se réfèrent à la ligne concernant la modification de la configuration du fichier `/etc/ssh/sshd_config`, tapez à partir de l’invite de commandes :
 +~~~bash
 +ausearch -f /etc/ssh/sshd_config -i
 +~~~
 +
 +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  -x --summary
 +~~~
 +
 +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
 +
 +`/etc/audit/audit.rules`
 +~~~
 +# 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://www.ssi.gouv.fr/uploads/2016/01/linux_configuration-fr-v1.2.pdf)
 +
 +`/etc/audit/audit.rules`
 +~~~
 +# Exécution de insmod , rmmod et modprobe
 +-w /sbin/insmod -p x
 +-w /sbin/modprobe -p x
 +-w /sbin/rmmod -p x
 +# Journaliser les modifications dans /etc/
 +-w /etc/ -p wa
 +# Surveillance de montage/dé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 /dev/ftpd17909 /usr/sbin/proftpd no 13931
 +2. 22/11/20 23:27:41 user1 10.1.5.33 ssh /usr/sbin/sshd yes 27355
 +3. 23/11/20 09:00:31 ftpng 127.0.0.1 /dev/ftpd10919 /usr/sbin/proftpd no 1425
 +4. 23/11/20 09:03:48 user1 10.1.5.25 ssh /usr/sbin/sshd yes 1723
 +5. 23/11/20 09:03:52 user1 10.1.5.24 ssh /usr/sbin/sshd yes 1734
 +
 +# aureport -ts 01/12/20 10:58:00 -te 01/12/20 10:59:00 -e -i
 +~~~
 +
 +### Failed to restart auditd.service: Operation refused, unit auditd.service may be requested by dependency only.
 +
 +Voir : https://bugzilla.redhat.com/show_bug.cgi?id=1026648
 +
 +RedHat 7 & 8
 +
 +~~~bash
 +# systemctl restart auditd
 +Failed to restart auditd.service: Operation refused, unit auditd.service may be requested by dependency only.
 +~~~
 +
 +#### Solution
 +
 +~~~bash
 +service auditd stop 
 +systemctl start auditd
 +~~~
 +
 +
 +## Autres
 +
 +Status
 +~~~bash
 +auditctl -s
 +~~~
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki