How to check if an audit rule is set in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if audit rules are set in Linux. You will begin by listing the currently loaded audit rules using the auditctl -l command, which interacts with the Linux Audit Daemon (auditd) to display the rules that define what system events are being tracked.

Following that, you will examine the audit rules configuration file located at /etc/audit/audit.rules to understand how these rules are persistently stored. Finally, you will verify the audit logs in the /var/log/audit directory to see the recorded events based on the configured rules, providing practical insight into the system's auditing activity.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicSystemCommandsGroup(["Basic System Commands"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux/BasicSystemCommandsGroup -.-> linux/help("Command Assistance") linux/BasicSystemCommandsGroup -.-> linux/man("Manual Access") linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/BasicFileOperationsGroup -.-> linux/tail("File End Display") subgraph Lab Skills linux/help -.-> lab-558780{{"How to check if an audit rule is set in Linux"}} linux/man -.-> lab-558780{{"How to check if an audit rule is set in Linux"}} linux/ls -.-> lab-558780{{"How to check if an audit rule is set in Linux"}} linux/cat -.-> lab-558780{{"How to check if an audit rule is set in Linux"}} linux/tail -.-> lab-558780{{"How to check if an audit rule is set in Linux"}} end

List audit rules with auditctl -l

In this step, you will learn how to list the current audit rules configured on the system using the auditctl command. The Linux Audit Daemon (auditd) is a powerful tool for tracking security-relevant information on your system. Audit rules define what events the system should log.

The auditctl command is used to control the audit daemon. To list the currently loaded audit rules, you use the -l option.

Open the terminal if you haven't already. You can do this by clicking the Xfce Terminal icon on the left side of the desktop.

Now, type the following command in the terminal and press Enter:

sudo auditctl -l

You might see output similar to this:

-w /etc/passwd -p wa -k passwd_changes
-w /etc/shadow -p wa -k shadow_changes
-w /etc/gshadow -p wa -k gshadow_changes
-w /etc/group -p wa -k group_changes
-w /etc/sudoers -p wa -k sudoers_changes
-w /etc/sudoers.d/ -p wa -k sudoers_changes
-w /var/log/faillog -p wa -k logins
-w /var/log/lastlog -p wa -k logins
-w /var/log/tallylog -p wa -k logins
-w /var/run/utmp -p wa -k session
-w /var/log/wtmp -p wa -k session
-w /var/log/btmp -p wa -k session
-a always,exit -F arch=b32 -S open,creat,truncate,ftruncate,chmod,fchmod,chown,fchown,setxattr,lsetxattr,fsetxattr,removexattr,lremovexattr,fremovexattr -F auid>=1000 -F auid!=unset -k access
-a always,exit -F arch=b64 -S open,creat,truncate,ftruncate,chmod,fchmod,chown,fchown,setxattr,lsetxattr,fsetxattr,removexattr,lremovexattr,fremovexattr -F auid>=1000 -F auid!=unset -k access
-a always,exit -F arch=b32 -S execve -F auid>=1000 -F auid!=unset -k exec
-a always,exit -F arch=b64 -S execve -F auid>=1000 -F auid!=unset -k exec
-a always,exit -F arch=b32 -S unlink,unlinkat,rename,renameat -F auid>=1000 -F auid!=unset -k delete
-a always,exit -F arch=b64 -S unlink,unlinkat,rename,renameat -F auid>=1000 -F auid!=unset -k delete
-a always,exit -F arch=b32 -S rmdir -F auid>=1000 -F auid!=unset -k delete
-a always,exit -F arch=b64 -S rmdir -F auid>=1000 -F auid!=unset -k delete
-a always,exit -F arch=b32 -S mount -F auid>=1000 -F auid!=unset -k mount
-a always,exit -F arch=b64 -S mount -F auid>=1000 -F auid!=unset -k mount
-a always,exit -F arch=b32 -S swapon -F auid>=1000 -F auid!=unset -k swapon
-a always,exit -F arch=b64 -S swapon -F auid>=1000 -F auid!=unset -k swapon
-a always,exit -F arch=b32 -S swapoff -F auid>=1000 -F auid!=unset -k swapoff
-a always,exit -F arch=b64 -S swapoff -F auid>=1000 -F auid!=unset -k swapoff
-a always,exit -F arch=b32 -S acct -F auid>=1000 -F auid!=unset -k acct
-a always,exit -F arch=b64 -S acct -F auid>=1000 -F auid!=unset -k acct
-a always,exit -F arch=b32 -S settimeofday,adjtimex,stime -F auid>=1000 -F auid!=unset -k time-change
-a always,exit -F arch=b64 -S settimeofday,adjtimex,stime -F auid>=1000 -F auid!=unset -k time-change
-a always,exit -F arch=b32 -S clock_settime -F auid>=1000 -F auid!=unset -k time-change
-a always,exit -F arch=b64 -S clock_settime -F auid>=1000 -F auid!=unset -k time-change
-a always,exit -F arch=b32 -S sethostname,setdomainname -F auid>=1000 -F auid!=unset -k system-locale
-a always,exit -F arch=b64 -S sethostname,setdomainname -F auid>=1000 -F auid!=unset -k system-locale
-a always,exit -F arch=b32 -S init_module,finit_module,delete_module -F auid>=1000 -F auid!=unset -k modules
-a always,exit -F arch=b64 -S init_module,finit_module,delete_module -F auid>=1000 -F auid!=unset -k modules
-a always,exit -F arch=b32 -S creat_module,delete_module -F auid>=1000 -F auid!=unset -k modules
-a always,exit -F arch=b64 -S creat_module,delete_module -F auid>=1000 -F auid!=unset -k modules
-a always,exit -F arch=b32 -S syslog -F auid>=1000 -F auid!=unset -k syslog
-a always,exit -F arch=b64 -S syslog -F auid>=1000 -F auid!=unset -k syslog
-a always,exit -F arch=b32 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec
-a always,exit -F arch=b64 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec
-a always,exit -F arch=b32 -S bpf -F auid>=1000 -F auid!=unset -k bpf
-a always,exit -F arch=b64 -S bpf -F auid>=1000 -F auid!=unset -k bpf
-a always,exit -F arch=b32 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify
-a always,exit -F arch=b64 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify
-a always,exit -F arch=b32 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event
-a always,exit -F arch=b64 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event
-a always,exit -F arch=b32 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring
-a always,exit -F arch=b64 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring
-a always,exit -F arch=b32 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle
-a always,exit -F arch=b64 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle
-a always,exit -F arch=b32 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle
-a always,exit -F arch=b64 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle
-a always,exit -F arch=b32 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice
-a always,exit -F arch=b64 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice
-a always,exit -F arch=b32 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv
-a always,exit -F arch=b64 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv
-a always,exit -F arch=b32 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev
-a always,exit -F arch=b64 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev
-a always,exit -F arch=b32 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace
-a always,exit -F arch=b64 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace
-a always,exit -F arch=b32 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp
-a always,exit -F arch=b64 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp
-a always,exit -F arch=b32 -S finit_module -F auid>=1000 -F auid!=unset -k finit_module
-a always,exit -F arch=b64 -S finit_module -F auid>=1000 -F auid!=unset -k finit_module
-a always,exit -F arch=b32 -S delete_module -F auid>=1000 -F auid!=unset -k delete_module
-a always,exit -F arch=b64 -S delete_module -F auid>=1000 -F auid!=unset -k delete_module
-a always,exit -F arch=b32 -S init_module -F auid>=1000 -F auid!=unset -k init_module
-a always,exit -F arch=b64 -S init_module -F auid>=1000 -F auid!=unset -k init_module
-a always,exit -F arch=b32 -S creat_module -F auid>=1000 -F auid!=unset -k creat_module
-a always,exit -F arch=b64 -S creat_module -F auid>=1000 -F auid!=unset -k creat_module
-a always,exit -F arch=b32 -S syslog -F auid>=1000 -F auid!=unset -k syslog
-a always,exit -F arch=b64 -S syslog -F auid>=1000 -F auid!=unset -k syslog
-a always,exit -F arch=b32 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec_load
-a always,exit -F arch=b64 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec_load
-a always,exit -F arch=b32 -S bpf -F auid>=1000 -F auid!=unset -k bpf
-a always,exit -F arch=b64 -S bpf -F auid>=1000 -F auid!=unset -k bpf
-a always,exit -F arch=b32 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify_init
-a always,exit -F arch=b64 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify_init
-a always,exit -F arch=b32 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event_open
-a always,exit -F arch=b64 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event_open
-a always,exit -F arch=b32 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring_setup
-a always,exit -F arch=b64 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring_setup
-a always,exit -F arch=b32 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle_at
-a always,exit -F arch=b64 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle_at
-a always,exit -F arch=b32 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle_at
-a always,exit -F arch=b64 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle_at
-a always,exit -F arch=b32 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice
-a always,exit -F arch=b64 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice
-a always,exit -F arch=b32 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv
-a always,exit -F arch=b64 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv
-a always,exit -F arch=b32 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev
-a always,exit -F arch=b64 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev
-a always,exit -F arch=b32 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace
-a always,exit -F arch=b64 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace
-a always,exit -F arch=b32 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp
-a always,exit -F arch=b64 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp

This output shows the rules that are currently active in the audit system. Each line represents a rule. Don't worry about understanding every detail of the rules right now. The important part is that you can see the list of rules.

The -w option is used to watch a specific file or directory for changes. The -a option is used to add a rule. The -S option specifies system calls to audit.

Click Continue to proceed to the next step.

Check audit rules file with cat /etc/audit/audit.rules

In the previous step, you listed the currently active audit rules using auditctl -l. These rules are typically loaded from a configuration file when the audit daemon starts. The main configuration file for audit rules is /etc/audit/audit.rules.

Let's examine the contents of this file using the cat command. The cat command is used to display the content of files.

Type the following command in your terminal and press Enter:

cat /etc/audit/audit.rules

You will see the content of the /etc/audit/audit.rules file printed to your terminal. This file contains the rules that are loaded by the audit daemon at startup.

### This file is automatically generated from /etc/audit/rules.d
##
### The rules are simply the concatenation of all rules files in /etc/audit/rules.d
### and will be loaded after the kernel rules are loaded.
##
##
### First rule - delete all
-D

### Increase the buffers to survive stress events.
### Make this bigger for busy systems
-b 8192

### Set failure mode to syslog
-f 1

### Log all attempts to alter system time
-a always,exit -F arch=b32 -S settimeofday,adjtimex,stime -F auid>=1000 -F auid!=unset -k time-change
-a always,exit -F arch=b64 -S settimeofday,adjtimex,stime -F auid>=1000 -F auid!=unset -k time-change
-a always,exit -F arch=b32 -S clock_settime -F auid>=1000 -F auid!=unset -k time-change
-a always,exit -F arch=b64 -S clock_settime -F auid>=1000 -F auid!=unset -k time-change

### Log all attempts to alter system locale
-a always,exit -F arch=b32 -S sethostname,setdomainname -F auid>=1000 -F auid!=unset -k system-locale
-a always,exit -F arch=b64 -S sethostname,setdomainname -F auid>=1000 -F auid!=unset -k system-locale

### Log all attempts to alter system modules
-a always,exit -F arch=b32 -S init_module,finit_module,delete_module -F auid>=1000 -F auid!=unset -k modules
-a always,exit -F arch=b64 -S init_module,finit_module,delete_module -F auid>=1000 -F auid!=unset -k modules
-a always,exit -F arch=b32 -S creat_module,delete_module -F auid>=1000 -F auid!=unset -k modules
-a always,exit -F arch=b64 -S creat_module,delete_module -F auid>=1000 -F auid!=unset -k modules

### Log all attempts to alter system syslog
-a always,exit -F arch=b32 -S syslog -F auid>=1000 -F auid!=unset -k syslog
-a always,exit -F arch=b64 -S syslog -F auid>=1000 -F auid!=unset -k syslog

### Log all attempts to alter system kexec
-a always,exit -F arch=b32 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec
-a always,exit -F arch=b64 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec

### Log all attempts to alter system bpf
-a always,exit -F arch=b32 -S bpf -F auid>=1000 -F auid!=unset -k bpf
-a always,exit -F arch=b64 -S bpf -F auid>=1000 -F auid!=unset -k bpf

### Log all attempts to alter system fanotify
-a always,exit -F arch=b32 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify
-a always,exit -F arch=b64 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify

### Log all attempts to alter system perf_event
-a always,exit -F arch=b32 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event
-a always,exit -F arch=b64 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event

### Log all attempts to alter system io_uring
-a always,exit -F arch=b32 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring
-a always,exit -F arch=b64 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring

### Log all attempts to alter system open_by_handle
-a always,exit -F arch=b32 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle
-a always,exit -F arch=b64 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle

### Log all attempts to alter system name_to_handle
-a always,exit -F arch=b32 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle
-a always,exit -F arch=b64 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle

### Log all attempts to alter system vmsplice
-a always,exit -F arch=b32 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice
-a always,exit -F arch=b64 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice

### Log all attempts to alter system process_vm_readv
-a always,exit -F arch=b32 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv
-a always,exit -F arch=b64 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv

### Log all attempts to alter system process_vm_writev
-a always,exit -F arch=b32 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev
-a always,exit -F arch=b64 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev

### Log all attempts to alter system ptrace
-a always,exit -F arch=b32 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace
-a always,exit -F arch=b64 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace

### Log all attempts to alter system kcmp
-a always,exit -F arch=b32 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp
-a always,exit -F arch=b64 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp

### Log all attempts to alter system finit_module
-a always,exit -F arch=b32 -S finit_module -F auid>=1000 -F auid!=unset -k finit_module
-a always,exit -F arch=b64 -S finit_module -F auid>=1000 -F auid!=unset -k finit_module

### Log all attempts to alter system delete_module
-a always,exit -F arch=b32 -S delete_module -F auid>=1000 -F auid!=unset -k delete_module
-a always,exit -F arch=b64 -S delete_module -F auid>=1000 -F auid!=unset -k delete_module

### Log all attempts to alter system init_module
-a always,exit -F arch=b32 -S init_module -F auid>=1000 -F auid!=unset -k init_module
-a always,exit -F arch=b64 -S init_module -F auid>=1000 -F auid!=unset -k init_module

### Log all attempts to alter system creat_module
-a always,exit -F arch=b32 -S creat_module -F auid>=1000 -F auid!=unset -k creat_module
-a always,exit -F arch=b64 -S creat_module -F auid>=1000 -F auid!=unset -k creat_module

### Log all attempts to alter system syslog
-a always,exit -F arch=b32 -S syslog -F auid>=1000 -F auid!=unset -k syslog
-a always,exit -F arch=b64 -S syslog -F auid>=1000 -F auid!=unset -k syslog

### Log all attempts to alter system kexec_load
-a always,exit -F arch=b32 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec_load
-a always,exit -F arch=b64 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec_load

### Log all attempts to alter system bpf
-a always,exit -F arch=b32 -S bpf -F auid>=1000 -F auid!=unset -k bpf
-a always,exit -F arch=b64 -S bpf -F auid>=1000 -F auid!=unset -k bpf

### Log all attempts to alter system fanotify_init
-a always,exit -F arch=b32 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify_init
-a always,exit -F arch=b64 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify_init

### Log all attempts to alter system perf_event_open
-a always,exit -F arch=b32 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event_open
-a always,exit -F arch=b64 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event_open

### Log all attempts to alter system io_uring_setup
-a always,exit -F arch=b32 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring_setup
-a always,exit -F arch=b64 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring_setup

### Log all attempts to alter system open_by_handle_at
-a always,exit -F arch=b32 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle_at
-a always,exit -F arch=b64 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle_at

### Log all attempts to alter system name_to_handle_at
-a always,exit -F arch=b32 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle_at
-a always,exit -F arch=b64 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle_at

### Log all attempts to alter system vmsplice
-a always,exit -F arch=b32 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice
-a always,exit -F arch=b64 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice

### Log all attempts to alter system process_vm_readv
-a always,exit -F arch=b32 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv
-a always,exit -F arch=b64 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv

### Log all attempts to alter system process_vm_writev
-a always,exit -F arch=b32 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev
-a always,exit -F arch=b64 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev

### Log all attempts to alter system ptrace
-a always,exit -F arch=b32 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace
-a always,exit -F arch=b64 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace

### Log all attempts to alter system kcmp
-a always,exit -F arch=b32 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp
-a always,exit -F arch=b64 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp

### Log all attempts to alter system finit_module
-a always,exit -F arch=b32 -S finit_module -F auid>=1000 -F auid!=unset -k finit_module
-a always,exit -F arch=b64 -S finit_module -F auid>=1000 -F auid!=unset -k finit_module

### Log all attempts to alter system delete_module
-a always,exit -F arch=b32 -S delete_module -F auid>=1000 -F auid!=unset -k delete_module
-a always,exit -F arch=b64 -S delete_module -F auid>=1000 -F auid!=unset -k delete_module

### Log all attempts to alter system init_module
-a always,exit -F arch=b32 -S init_module -F auid>=1000 -F auid!=unset -k init_module
-a always,exit -F arch=b64 -S init_module -F auid>=1000 -F auid!=unset -k init_module

### Log all attempts to alter system creat_module
-a always,exit -F arch=b32 -S creat_module -F auid>=1000 -F auid!=unset -k creat_module
-a always,exit -F arch=b64 -S creat_module -F auid>=1000 -F auid!=unset -k creat_module

### Log all attempts to alter system syslog
-a always,exit -F arch=b32 -S syslog -F auid>=1000 -F auid!=unset -k syslog
-a always,exit -F arch=b64 -S syslog -F auid>=1000 -F auid!=unset -k syslog

### Log all attempts to alter system kexec_load
-a always,exit -F arch=b32 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec_load
-a always,exit -F arch=b64 -S kexec_load -F auid>=1000 -F auid!=unset -k kexec_load

### Log all attempts to alter system bpf
-a always,exit -F arch=b32 -S bpf -F auid>=1000 -F auid!=unset -k bpf
-a always,exit -F arch=b64 -S bpf -F auid>=1000 -F auid!=unset -k bpf

### Log all attempts to alter system fanotify_init
-a always,exit -F arch=b32 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify_init
-a always,exit -F arch=b64 -S fanotify_init -F auid>=1000 -F auid!=unset -k fanotify_init

### Log all attempts to alter system perf_event_open
-a always,exit -F arch=b32 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event_open
-a always,exit -F arch=b64 -S perf_event_open -F auid>=1000 -F auid!=unset -k perf_event_open

### Log all attempts to alter system io_uring_setup
-a always,exit -F arch=b32 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring_setup
-a always,exit -F arch=b64 -S io_uring_setup -F auid>=1000 -F auid!=unset -k io_uring_setup

### Log all attempts to alter system open_by_handle_at
-a always,exit -F arch=b32 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle_at
-a always,exit -F arch=b64 -S open_by_handle_at -F auid>=1000 -F auid!=unset -k open_by_handle_at

### Log all attempts to alter system name_to_handle_at
-a always,exit -F arch=b32 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle_at
-a always,exit -F arch=b64 -S name_to_handle_at -F auid>=1000 -F auid!=unset -k name_to_handle_at

### Log all attempts to alter system vmsplice
-a always,exit -F arch=b32 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice
-a always,exit -F arch=b64 -S vmsplice -F auid>=1000 -F auid!=unset -k vmsplice

### Log all attempts to alter system process_vm_readv
-a always,exit -F arch=b32 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv
-a always,exit -F arch=b64 -S process_vm_readv -F auid>=1000 -F auid!=unset -k process_vm_readv

### Log all attempts to alter system process_vm_writev
-a always,exit -F arch=b32 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev
-a always,exit -F arch=b64 -S process_vm_writev -F auid>=1000 -F auid!=unset -k process_vm_writev

### Log all attempts to alter system ptrace
-a always,exit -F arch=b32 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace
-a always,exit -F arch=b64 -S ptrace -F auid>=1000 -F auid!=unset -k ptrace

### Log all attempts to alter system kcmp
-a always,exit -F arch=b32 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp
-a always,exit -F arch=b64 -S kcmp -F auid>=1000 -F auid!=unset -k kcmp

As you can see, the content of /etc/audit/audit.rules is similar to the output of sudo auditctl -l. This file is the source of the rules that are loaded into the kernel's audit subsystem.

Understanding the contents of this file is crucial for configuring system auditing. You can add, remove, or modify rules in this file to customize what events are audited. However, changes to this file require root privileges and typically require restarting the audit daemon to take effect.

Click Continue to move on to the next step.

Verify audit logs in /var/log/audit

Now that you know how to list audit rules and view the configuration file, let's look at where the audit logs are stored. The audit daemon writes log entries to files, typically located in the /var/log/audit/ directory.

The main audit log file is usually named audit.log. You can use the ls command to list the files in the /var/log/audit/ directory and see if the log file exists.

Type the following command in your terminal and press Enter:

ls /var/log/audit/

You should see output similar to this, showing the audit.log file:

audit.log

Now, let's view the contents of the audit.log file using the tail command. The tail command is useful for viewing the end of a file, which is where the most recent log entries will be. Since the audit log can be quite large, viewing the end is often more practical than viewing the entire file with cat.

Type the following command in your terminal and press Enter:

sudo tail /var/log/audit/audit.log

You will see the last few lines of the audit.log file. These lines represent recent events that have been audited according to the configured rules. The output will look something like this, with each line being a detailed audit record:

type=SYSCALL msg=audit(1678886400.123:456): arch=c000003e syscall=1 success=yes exit=1 a0=1 a1=7ffc... a2=1 a3=0 items=0 ppid=1234 pid=5678 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pts/0 ses=1 comm="bash" exe="/usr/bin/bash" subj=unconfined key="access"
type=PROCTITLE msg=audit(1678886400.123:456): proctitle=bash
type=CWD msg=audit(1678886400.123:456): cwd="/home/labex/project"
... (more log entries)

Each log entry contains a lot of information about the audited event, such as the type of event, timestamp, user ID, process ID, command executed, and more. Analyzing these logs is essential for security monitoring and incident response.

You have now successfully located and viewed the audit logs. In a real-world scenario, you would use tools like ausearch and aureport to search and summarize these logs effectively, but for this introductory lab, simply knowing where they are is a great start.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check if audit rules are set in Linux. You started by using the auditctl -l command to list the currently loaded audit rules, which are controlled by the Linux Audit Daemon (auditd) and define what system events are logged.

Following that, you would typically examine the audit rules file located at /etc/audit/audit.rules using the cat command to see the persistent configuration of audit rules. Finally, you would verify the audit logs in the /var/log/audit directory to confirm that events are being recorded according to the configured rules.