Kahibaro
Discord Login Register

4.6.3 Auditd

Understanding Auditd’s Role

auditd is the userspace component of the Linux Auditing System. The kernel produces audit events; auditd receives them, writes them to disk, and applies configuration such as rules and rate limits.

Key pieces:

This chapter focuses specifically on configuring and using auditd, assuming you already understand general logging concepts.

Installing and Enabling Auditd

On common distributions:

  sudo dnf install audit
  sudo systemctl enable --now auditd
  sudo apt install auditd audispd-plugins
  sudo systemctl enable --now auditd

Verify it’s running:

sudo systemctl status auditd
sudo auditctl -s    # show audit subsystem status

Typical auditctl -s output fields:

Auditd Configuration Files

Main locations (paths may vary slightly by distro):

Key Options in `/etc/audit/auditd.conf`

Some of the most important options:

After modifying auditd.conf, reload:

sudo systemctl reload auditd
# or, if not supported:
sudo systemctl restart auditd

Managing Audit Rules

Audit rules tell the kernel what to watch and which syscalls or files to record.

There are two main ways:

Runtime Rules with `auditctl`

View current rules:

sudo auditctl -l

Remove all rules:

sudo auditctl -D

Mark rules as immutable (cannot be changed until reboot):

sudo auditctl -e 2

Mode values:

Once you set -e 2, you cannot change rules without rebooting; this is used for tamper-resistant configurations.

Persistent Rules with `augenrules`

The typical workflow:

  1. Put rule files in /etc/audit/rules.d/ with .rules extension, e.g.:
    • /etc/audit/rules.d/10-base.rules
    • /etc/audit/rules.d/30-privileged.rules
  2. Build and load them:
   sudo augenrules --load
  1. Confirm:
   sudo auditctl -l

On boot, augenrules is usually called by the auditd unit to load all rules from /etc/audit/rules.d.

Audit Rule Types and Syntax

Audit rules mainly come in two kinds:

You’ll often see:

Watch Rules (`-w`)

These are easy to start with. General form:

-w <path> -p <rwxad> -k <key>

Examples:

Watch /etc/passwd for writes and attribute changes:

-w /etc/passwd -p wa -k passwd_changes

Watch /etc/sudoers for any modification:

-w /etc/sudoers -p wa -k sudoers_change

Note: -w rules are internally translated to -a syscall rules; they are path-based convenience syntax.

Syscall Rules (`-a`)

Syscall rules inspect particular syscalls based on architecture, filters, and fields.

Basic form:

-a <list>,<action> -S <syscall>[,<syscall>...] [conditions] -F key=<key>

Example: log all attempts by non-root users to run chmod:

-a always,exit -F arch=b64 -S chmod -F uid!=0 -F key=chmod_nonroot

Example: log file deletions by real users in /home:

-a always,exit -F arch=b64 -S unlink,unlinkat,rename,renameat -F dir=/home -F auid>=1000 -F auid!=4294967295 -F key=home_delete

Note on auid vs uid:

Example Baseline Rule File

A minimal hardening-friendly set in /etc/audit/rules.d/10-base.rules:

# Erase all existing rules
-D
# Set buffer size
-b 8192
# Enable auditing and lock rules after they are set
-e 2

Another file, /etc/audit/rules.d/30-identity.rules:

# Watch passwd and group databases
-w /etc/passwd -p wa -k identity
-w /etc/group  -p wa -k identity
-w /etc/shadow -p wa -k identity

And /etc/audit/rules.d/40-privileged.rules:

# Watch changes to sudoers
-w /etc/sudoers -p wa -k scope
# Track use of sudo
-w /var/log/sudo.log -p wa -k sudo_log   # path may differ by distro

After saving:

sudo augenrules --load

Using ausearch to Query Audit Logs

ausearch understands the audit log format and filters by fields and keys.

Common options:

Examples:

Show all events tagged with key passwd_changes:

sudo ausearch -k passwd_changes

Show all sudo-related events in the last hour:

sudo ausearch -k sudo_log -ts recent

Show all failed login attempts (message type often USER_LOGIN or USER_AUTH):

sudo ausearch -m USER_LOGIN -sv no

(-sv no filters by success=no.)

Print in a more human-readable, interpreted format:

sudo ausearch -k home_delete --interpret

Interpreting a SYSCALL Record

A SYSCALL record may look like:

type=SYSCALL msg=audit(1700000000.123:456): arch=c000003e syscall=59 success=yes exit=0 \
 a0=55c3a5b6b4d0 a1=55c3a5b6b520 a2=55c3a5b6b540 a3=8 items=2 ppid=1234 pid=5678 \
 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 \
 tty=pts0 ses=2 comm="sudo" exe="/usr/bin/sudo" key="sudo_exec"

Critical fields:

Use ausearch --interpret to decode numeric IDs and flags into names.

Summarizing with aureport

aureport builds summaries such as:

Examples:

Overall summary:

sudo aureport

Authentication report:

sudo aureport -au

Failed logins:

sudo aureport -au --failed

File access report:

sudo aureport -f

Process/executable report:

sudo aureport -x

Include time range with --start/--end if needed:

sudo aureport -x --start today --end now

Integrating Auditd with Other Tools

audispd and Plugins

Some distros split responsibilities:

Plugins live under /etc/audisp/plugins.d/ or similar. Common use cases:

Enabling a plugin involves:

Syslog and Central Logging

While audit logs are structured separately, you may want key events also present in syslog or in a central logging stack.

Methods include:

Keep in mind:

Performance and Reliability Considerations

Auditd can produce a lot of data and overhead if misconfigured.

Avoiding Excessive Logging

Monitor:

Adjust:

Preventing Disk-Full Situations

Effective use of:

Configure space_left and admin_space_left with appropriate actions (e.g. SYSLOG then SUSPEND) so you’re alerted before the partition fills.

Example Use Cases

Monitoring Critical Config Files

In /etc/audit/rules.d/50-etc.rules:

-w /etc/ssh/sshd_config -p wa -k ssh_config
-w /etc/hosts         -p wa -k network_config
-w /etc/fstab         -p wa -k mount_config

Load:

sudo augenrules --load

Query later:

sudo ausearch -k ssh_config --interpret

Tracking Use of Specific Binaries

Suppose you want to track whenever someone runs /bin/su:

-a always,exit -F arch=b64 -S execve -F exe=/bin/su -F auid>=1000 -F auid!=4294967295 -F key=su_usage

Add to /etc/audit/rules.d/60-su.rules and load via augenrules.

Then:

sudo ausearch -k su_usage --interpret

Monitoring Access to a Sensitive Directory

Track reads/writes in /secret by real users:

-a always,exit -F arch=b64 -S open,openat,creat,truncate,ftruncate \
   -F dir=/secret -F auid>=1000 -F auid!=4294967295 -F key=secret_access

Later:

sudo ausearch -k secret_access --interpret
sudo aureport -f --summary | grep secret

Hardening Auditd

For environments that require strong tamper resistance:

  -e 2

Once -e 2 is set and the system has booted with audit=1, even root cannot modify audit rules without rebooting, which gives you a more trustworthy trail for incident response.

Views: 124

Comments

Please login to add a comment.

Don't have an account? Register now!