Sub topic 15
Auditing Security-Relevant Events with auditd
Prerequisites and the audit model
Assume you can use sudo, edit configuration files, and use systemctl and journalctl. You should also understand Linux users, groups, and file permissions.
auditd is the Linux auditing daemon. It receives audit events from the kernel and records actions such as changes to account files, use of privileged commands, and changes to security configuration. Unlike general system logs, audit records include security details such as the user ID, process ID, executable, and result of an operation.
The audit workflow has three parts:
- Rules define which activity to record.
- auditd writes events, usually to
/var/log/audit/audit.log. - Search tools such as
ausearchandaureporthelp investigate events.
flowchart TD
A[Kernel or process event] --> B[audit rules]
B --> C[auditd]
C --> D[/var/log/audit/audit.log]
D --> E[ausearch and aureport]
E --> F[Investigation and alerting]Create rules for identity and privilege changes
A rule can watch a file and record writes and attribute changes. The -w option selects a path, -p wa records writes and attribute changes, and -k adds a searchable key.
Create /etc/audit/rules.d/50-cis.rules:
-w /etc/sudoers -p wa -k scope
-w /etc/sudoers.d -p wa -k scope
-w /etc/passwd -p wa -k identity
-w /etc/group -p wa -k identity
-w /etc/shadow -p wa -k identityThese rules record changes to sudo policy and local account databases. They do not prevent a change. They provide evidence that you can review later.
Load the rules and confirm that the kernel accepted them:
sudo augenrules --load
sudo auditctl -l
sudo systemctl enable --now auditdOn some distributions, auditd must be restarted through its service-specific command rather than systemctl restart. Check the distribution documentation before changing a running audit service.
Search and interpret events
Use the key to find matching records:
sudo ausearch -k identity --interpret
sudo ausearch -k identity --start today --interpret
sudo aureport --auth --summary--interpret converts numeric IDs and timestamps into readable values. One user action may produce several records, such as a syscall record and a path record. Group related records by their event ID and timestamp instead of counting every line as a separate action.
Check audit storage and retention settings. If the audit filesystem fills, the configured failure mode determines whether events are discarded, logged, or the system stops. Forward important records to a protected log collector so an attacker cannot easily erase local evidence.
Exercise
Exercise
Which command searches for changes recorded with the identity key, and why is the key useful?
Show answer
sudo ausearch -k identity --interpret searches those events. The key groups related records so investigators can find them without searching the entire audit log.