Ensure There Are No Accounts With Blank or Null Passwords

Classification:

compliance

Framework:

Control:

Description

Check the “/etc/shadow” file for blank passwords with the following command:

$ sudo awk -F: '!$2 {print $1}' /etc/shadow

If the command returns any results, this is a finding. Configure all accounts on the system to have a password or lock the account with the following commands: Perform a password reset:

$ sudo passwd [username]

Lock an account:

$ sudo passwd -l [username]

Rationale

If an account has an empty password, anyone could log in and run commands with the privileges of that account. Accounts with empty passwords should never be used in operational environments.

Remediation

Shell script

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

# Remediation is applicable only in certain platforms
if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then

readarray -t users\_with\_empty\_pass < <(sudo awk -F: '!$2 {print $1}' /etc/shadow)

for user\_with\_empty\_pass in "${users\_with\_empty\_pass[@]}"
do
 passwd -l $user\_with\_empty\_pass
done

else
 >&2 echo 'Remediation is not applicable, nothing was done'
fi

Ansible playbook

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

- name: Collect users with no password
 command: |
 awk -F: '!$2 {print $1}' /etc/shadow
 register: users\_nopasswd
 when: ansible\_virtualization\_type not in ["docker", "lxc", "openvz", "podman", "container"]
 tags:
 - NIST-800-53-CM-6(b)
 - NIST-800-53-CM-6.1(iv)
 - high\_severity
 - low\_complexity
 - low\_disruption
 - no\_empty\_passwords\_etc\_shadow
 - no\_reboot\_needed
 - restrict\_strategy

- name: Lock users with no password
 command: |
 passwd -l {{ item }}
 with\_items: '{{ users\_nopasswd.stdout\_lines }}'
 when:
 - ansible\_virtualization\_type not in ["docker", "lxc", "openvz", "podman", "container"]
 - users\_nopasswd.stdout\_lines | length > 0
 tags:
 - NIST-800-53-CM-6(b)
 - NIST-800-53-CM-6.1(iv)
 - high\_severity
 - low\_complexity
 - low\_disruption
 - no\_empty\_passwords\_etc\_shadow
 - no\_reboot\_needed
 - restrict\_strategy

Warning

Note that this rule is not applicable for systems running within a container. Having user with empty password within a container is not considered a risk, because it should not be possible to directly login into a container anyway.