Verify permissions of log files

Classification:

compliance

Framework:

Control:

Description

Any operating system providing too much information in error messages risks compromising the data and security of the structure, and content of error messages needs to be carefully considered by the organization.

Organizations carefully consider the structure/content of error messages. The extent to which information systems are able to identify and handle error conditions is guided by organizational policy and operational requirements. Information that could be exploited by adversaries includes, for example, erroneous logon attempts with passwords entered by mistake as the username, mission/business information that can be derived from (if not stated explicitly by) information recorded, and personal information, such as account numbers, social security numbers, and credit card numbers.

Rationale

The Ubuntu 20.04 must generate error messages that provide information necessary for corrective actions without revealing information that could be exploited by adversaries.

Remediation

Shell script

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

readarray -t files < <(find /var/log/)
for file in "${files[@]}"; do
 if basename $file | grep -qE '^.\*$'; then
 chmod 0640 $file
 fi
done

if grep -qE "^f \/var\/log\/(btmp|wtmp|lastlog)? " /usr/lib/tmpfiles.d/var.conf; then
 sed -i --follow-symlinks "s/\(^f[[:space:]]\+\/var\/log\/btmp[[:space:]]\+\)\(\([[:digit:]]\+\)[^ $]\*\)/\10640/" /usr/lib/tmpfiles.d/var.conf
 sed -i --follow-symlinks "s/\(^f[[:space:]]\+\/var\/log\/wtmp[[:space:]]\+\)\(\([[:digit:]]\+\)[^ $]\*\)/\10640/" /usr/lib/tmpfiles.d/var.conf
 sed -i --follow-symlinks "s/\(^f[[:space:]]\+\/var\/log\/lastlog[[:space:]]\+\)\(\([[:digit:]]\+\)[^ $]\*\)/\10640/" /usr/lib/tmpfiles.d/var.conf
fi

Ansible playbook

The following playbook can be run with Ansible to remediate the issue.

- name: Find /var/log/ file(s)
 command: find -H /var/log/ -maxdepth 1 -perm /u+xs,g+xws,o+xwrt -type f -regex
 ".\*"
 register: files\_found
 changed\_when: false
 failed\_when: false
 check\_mode: false
 tags:
 - DISA-STIG-UBTU-20-010416
 - NIST-800-53-SI-11(a)
 - NIST-800-53-SI-11(b)
 - NIST-800-53-SI-11.1(iii)
 - configure\_strategy
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed
 - permissions\_local\_var\_log

- name: Set permissions for /var/log/ file(s)
 file:
 path: '{{ item }}'
 mode: u-xs,g-xws,o-xwrt
 state: file
 with\_items:
 - '{{ files\_found.stdout\_lines }}'
 tags:
 - DISA-STIG-UBTU-20-010416
 - NIST-800-53-SI-11(a)
 - NIST-800-53-SI-11(b)
 - NIST-800-53-SI-11.1(iii)
 - configure\_strategy
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed
 - permissions\_local\_var\_log