Lab 09: auditd — System Call Auditing

Time: 40 minutes | Level: Advanced | Docker: docker run -it --rm --privileged ubuntu:22.04 bash

The Linux Audit Framework (auditd) provides a comprehensive event logging system for tracking security-relevant system activity. It can log file access, system calls, user logins, privilege escalations, and more. This lab covers installing auditd, writing audit rules, searching audit logs, and generating compliance reports.

⚠️ Docker Note: auditd requires the kernel audit subsystem (CAP_AUDIT_CONTROL). In most Docker environments, auditctl commands fail with "Operation not permitted" even with --privileged. This lab covers all concepts, rule syntax, log format, and query tools with real verified output from the package installation and config files.


Step 1: Install auditd

apt-get update -qq && apt-get install -y auditd 2>/dev/null

📸 Verified Output:

$ docker run --rm ubuntu:22.04 bash -c "apt-get update -qq 2>/dev/null && apt-get install -y -qq auditd 2>/dev/null && dpkg -l auditd"
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halted-Config/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version              Architecture Description
+++-==============-====================-============-========================
ii  auditd         1:3.0.7-1build1      amd64        User space tools for security auditing

Check what's installed:

# Check auditd components
dpkg -L auditd | grep bin
# Key binaries:
# /sbin/auditd       - the daemon
# /sbin/auditctl     - rule management
# /sbin/ausearch     - log search
# /sbin/aureport     - report generator
# /sbin/autrace      - trace a process

📸 Verified Output:

💡 augenrules merges rule files from /etc/audit/rules.d/*.rules into /etc/audit/audit.rules. This is the modern way to manage audit rules — edit files in rules.d/, then run augenrules --load.


Step 2: Default Configuration Files

📸 Verified Output:

View the main audit configuration:

📸 Verified Output:

💡 max_log_file = 8 (MB) and num_logs = 5 means auditd keeps 5 rotated log files, each up to 8MB. On busy systems, increase these to avoid log rotation erasing evidence.


Step 3: Writing File Watch Rules — auditctl -w

File watch rules monitor access to specific files or directories.

📸 Verified Output (real Linux host with audit subsystem):

💡 The -k flag sets a key (tag) for the rule. This lets you ausearch -k passwd_watch to find all events related to that specific rule — essential when you have dozens of audit rules.


Step 4: System Call Auditing — auditctl -a

System call rules are more powerful than file watches — they can audit by user, group, and any syscall.

📸 Verified Output (real host):

💡 arch=b64 is essential on 64-bit systems. Without it, 32-bit syscall variants can bypass your rules. Always specify both architectures for critical rules: one rule with b64, another with b32.


Step 5: Persistent Rules — /etc/audit/rules.d/

Rules added with auditctl disappear on reboot. Make them persistent:

📸 Verified Output:


Step 6: Searching Audit Logs — ausearch

ausearch queries the audit log with powerful filters:

📸 Verified Output (real host sample):

💡 The auid (audit UID) field is crucial — it shows the original login user even after sudo. If user alice runs sudo cat /etc/passwd, auid shows alice's UID, not root's.


Step 7: Generating Reports — aureport

aureport generates summary and detailed reports from audit logs:

📸 Verified Output (real host sample):


Step 8: Capstone — Deploy a Compliance Audit Framework

Scenario: Your company needs to pass a PCI-DSS audit. Implement a complete audit framework that monitors all required events and generates daily compliance reports.

📸 Verified Output:


Summary

Task
Command
Notes

Install

apt-get install auditd

Installs daemon + tools

Start daemon

systemctl start auditd

Required on real host

List rules

auditctl -l

Shows active rules

Watch a file

auditctl -w /etc/passwd -p rwxa -k key

File watch rule

Syscall rule

auditctl -a always,exit -F arch=b64 -S execve -k key

System call audit

Delete rule

auditctl -d -w /etc/passwd

Remove specific rule

Delete all rules

auditctl -D

Clear all rules

Persistent rules

/etc/audit/rules.d/*.rules

Survives reboot

Reload rules

augenrules --load

Merge and load rules.d/

Search by file

ausearch -f /etc/passwd

Find events for a file

Search by key

ausearch -k keyname

Find events by rule key

Search by time

ausearch -ts today

Today's events

Summary report

aureport --summary

Event count overview

Failed events

aureport --failed

All failed events

Login report

aureport -l

Login events

Config file

/etc/audit/auditd.conf

Daemon configuration

Last updated