User Initialization Files Must Not Run World-Writable Programs

Classification:

compliance

Framework:

Control:

Description

Set the mode on files being executed by the user initialization files with the following command:

$ sudo chmod o-w *FILE*

Rationale

If user start-up files execute world-writable programs, especially in unprotected directories, they could be maliciously modified to destroy user files or otherwise compromise the system at the user level. If the system is compromised at the user level, it is easier to elevate privileges to eventually compromise the system at the root and network level.

Remediation

Shell script

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

readarray -t world\_writable\_files < <(find / -xdev -type f -perm -0002 2> /dev/null)
readarray -t interactive\_home\_dirs < <(awk -F':' '{ if ($3 >= 1000 && $3 != 65534) print $6 }' /etc/passwd)

for world\_writable in "${world\_writable\_files[@]}"; do
 for homedir in "${interactive\_home\_dirs[@]}"; do
 if grep -q -d skip "$world\_writable" "$homedir"/.\*; then
 chmod o-w $world\_writable
 break
 fi
 done
done