Record Attempts to Alter Time Through clock_settime

Classification:

compliance

Framework:

Control:

Description

If the auditd daemon is configured to use the augenrules program to read audit rules during daemon startup (the default), add the following line to a file with suffix .rules in the directory /etc/audit/rules.d:

-a always,exit -F arch=b32 -S clock_settime -F a0=0x0 -F key=time-change

If the system is 64 bit then also add the following line:

-a always,exit -F arch=b64 -S clock_settime -F a0=0x0 -F key=time-change

If the auditd daemon is configured to use the auditctl utility to read audit rules during daemon startup, add the following line to /etc/audit/audit.rules file:

-a always,exit -F arch=b32 -S clock_settime -F a0=0x0 -F key=time-change

If the system is 64 bit then also add the following line:

-a always,exit -F arch=b64 -S clock_settime -F a0=0x0 -F key=time-change

The -k option allows for the specification of a key in string form that can be used for better reporting capability through ausearch and aureport. Multiple system calls can be defined on the same line to save space if desired, but is not required. See an example of multiple combined syscalls:

-a always,exit -F arch=b64 -S adjtimex,settimeofday -F key=audit_time_rules

Rationale

Arbitrary changes to the system time can be used to obfuscate nefarious activities in log files, as well as to confuse network services that are highly dependent upon an accurate system time (such as sshd). All changes to the system time should be audited.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

# First perform the remediation of the syscall rule
# Retrieve hardware architecture of the underlying system
[ "$(getconf LONG\_BIT)" = "32" ] && RULE\_ARCHS=("b32") || RULE\_ARCHS=("b32" "b64")

for ARCH in "${RULE\_ARCHS[@]}"
do
 PATTERN="-a always,exit -F arch=$ARCH -S clock\_settime -F a0=.\* \(-F key=\|-k \).\*"
 GROUP="clock\_settime"
 FULL\_RULE="-a always,exit -F arch=$ARCH -S clock\_settime -F a0=0x0 -k time-change"
 # Perform the remediation for both possible tools: 'auditctl' and 'augenrules'

 fix\_audit\_syscall\_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL\_RULE"
 fix\_audit\_syscall\_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL\_RULE"
done