6.3.3.3 Ensure events that modify the sudo log file are collected

Information

Monitor the sudo log file. If the system has been properly configured to disable the use of the su command and force all administrators to have to log in first and then use sudo to execute privileged commands, then all administrator commands will be logged to /var/log/sudo.log Any time a command is executed, an audit event will be triggered as the /var/log/sudo.log file will be opened for write and the executed administration command will be written to the log.

Changes in /var/log/sudo.log indicate that an administrator has executed a command or the log file itself has been tampered with. Administrators will want to correlate the events written to the audit trail with the records written to /var/log/sudo.log to verify if unauthorized commands have been executed.

Solution

Note:

- This recommendation requires that the sudo logfile is configured. For additional information see guidance provided in the recommendation "Ensure sudo log file exists".
- The -w option is deprecated and the rule should be updated in accordance with the Remediation Procedure.
- For best performance, the arch field should be supplied in the rule. The individual permissions will cause the selection of specific system calls that use that kind of access. Not supplying the arch will cause the selection of all system calls which will affect performance as all system calls will be evaluated.

- Edit the file /etc/sudoers or a file in /etc/sudoers.d/ with visudo -f <PATH TO FILE> and add the following line:

Defaults logfile="<PATH TO CUSTOM LOG FILE>"

Example:

Defaults logfile="/var/log/sudo.log" <xhtml:ol start="2"> - Edit or create a file in the /etc/audit/rules.d/ directory, ending inrules extension, with the relevant rules to monitor events that modify the sudo log file.

Example:

# printf "
-a always,exit -F arch=b64 -S all -F path=/var/log/sudo.log -F perm=wa -F key=sudo_log_file
" >> /etc/audit/rules.d/50-sudo.rules

Note : path= should be set to the same sudo log file location as configured above in step 1.

<xhtml:ol start="3"> - Merge and load the rules into active configuration:

# augenrules --load <xhtml:ol start="4"> - Check if reboot is required:

# if [[ $(auditctl -s | grep "enabled") =~ "2" ]]; then printf "Reboot required to load rules\n"; fi

See Also

https://workbench.cisecurity.org/benchmarks/24010