11#! /usr/bin/env bash
2+ # @AI-Generated
3+ # Modified with AI assistance using Cursor with Composer
4+ # Description:
5+ # 2026-04-07: Audit rules: drop stime, use always,exit for system-locale, heredoc append (no leading blank line), tidy privileged header line.
26
37set -e
48
59base_dir=$( readlink -nf $( dirname $0 ) /../..)
610source $base_dir /lib/prelude_apply.bash
711
812function write_shared_audit_rules {
9- echo '
13+ cat << ' AUDIT_RULES ' >> "$chroot/etc/audit/rules.d/audit.rules"
1014-w /sbin/insmod -p x -k modules
1115-w /sbin/rmmod -p x -k modules
1216-w /sbin/modprobe -p x -k modules
@@ -20,7 +24,7 @@ function write_shared_audit_rules {
2024
2125# Record events that modify system date and time
2226-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change
23- -a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime - k time-change
27+ -a always,exit -F arch=b32 -S adjtimex -S settimeofday -k time-change
2428-a always,exit -F arch=b64 -S clock_settime -k time-change
2529-a always,exit -F arch=b32 -S clock_settime -k time-change
2630-w /etc/localtime -p wa -k time-change
@@ -52,8 +56,8 @@ function write_shared_audit_rules {
5256-w /etc/security/opasswd -p wa -k identity
5357
5458# Record events that modify system network environment
55- -a exit, always -F arch=b64 -S sethostname -S setdomainname -k system-locale
56- -a exit, always -F arch=b32 -S sethostname -S setdomainname -k system-locale
59+ -a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale
60+ -a always,exit -F arch=b32 -S sethostname -S setdomainname -k system-locale
5761-w /etc/issue -p wa -k system-locale
5862-w /etc/issue.net -p wa -k system-locale
5963-w /etc/hosts -p wa -k system-locale
@@ -135,7 +139,7 @@ function write_shared_audit_rules {
135139
136140# Recorde execution of unix_update
137141-a always,exit -F path=/sbin/unix_update -F perm=x -F auid>=500 -F auid!=4294967295 -k privileged-unix-update
138- ' >> $chroot /etc/audit/rules.d/audit.rules
142+ AUDIT_RULES
139143}
140144
141145function override_default_audit_variables {
@@ -154,7 +158,6 @@ function override_default_audit_variables {
154158}
155159
156160function record_use_of_privileged_binaries {
157- echo '
158- # Record use of privileged commands' >> $chroot /etc/audit/rules.d/audit.rules
161+ echo ' # Record use of privileged commands' >> $chroot /etc/audit/rules.d/audit.rules
159162 find $chroot /bin $chroot /sbin $chroot /usr/bin $chroot /usr/sbin $chroot /boot -xdev \( -perm -4000 -o -perm -2000 \) -type f | sed -e s:^${chroot} :: | awk ' {print "-a always,exit -F path=" $1 " -F perm=x -F auid>=500 -F auid!=4294967295 -k privileged" }' >> $chroot /etc/audit/rules.d/audit.rules
160163}
0 commit comments