diff --git a/components/pam.yml b/components/pam.yml index ba5cd08db3d..af9441e878a 100644 --- a/components/pam.yml +++ b/components/pam.yml @@ -65,6 +65,7 @@ rules: - accounts_password_pam_retry - accounts_password_pam_ucredit - accounts_password_pam_unix_enabled +- accounts_password_pam_unix_no_remember - accounts_password_pam_unix_remember - accounts_password_pam_unix_rounds_password_auth - accounts_password_pam_unix_rounds_system_auth diff --git a/controls/cis_ubuntu2404.yml b/controls/cis_ubuntu2404.yml index efcac5f7805..564710df1c9 100644 --- a/controls/cis_ubuntu2404.yml +++ b/controls/cis_ubuntu2404.yml @@ -2040,8 +2040,9 @@ controls: levels: - l1_server - l1_workstation - status: planned - notes: TODO. Rule does not seem to be implemented, nor does it map to any rules in ubuntu2204 profile. + rules: + - accounts_password_pam_unix_no_remember + status: automated - id: 5.3.3.4.3 title: Ensure pam_unix includes a strong password hashing algorithm (Automated) diff --git a/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/bash/shared.sh b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/bash/shared.sh new file mode 100644 index 00000000000..0793ace9668 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/bash/shared.sh @@ -0,0 +1,15 @@ +# platform = multi_platform_ubuntu +# reboot = false +# strategy = configure +# complexity = low +# disruption = medium + +{{{ bash_pam_unix_enable() }}} +config_file="/usr/share/pam-configs/cac_unix" +sed -i -E '/^Password(-Initial)?:/,/^[^[:space:]]/ { + /pam_unix\.so/ { + s/\s*\bremember=\d+\b//g + } +}' "$config_file" + +DEBIAN_FRONTEND=noninteractive pam-auth-update diff --git a/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/oval/shared.xml b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/oval/shared.xml new file mode 100644 index 00000000000..d425c1fa4fe --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/oval/shared.xml @@ -0,0 +1,19 @@ + + + {{{ oval_metadata("The pam_unix module should not include remember option") }}} + + + + + + + + + ^/etc/pam.d/common-(password|auth|account|session|session-noninteractive)$ + ^\s*password\s+(?:(?:sufficient)|(?:required)|(?:\[.*\]))\s+pam_unix\.so[^#]+\bremember=\d+\b.*$ + 1 + + diff --git a/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/rule.yml b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/rule.yml new file mode 100644 index 00000000000..5c13a69aeff --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/rule.yml @@ -0,0 +1,21 @@ +documentation_complete: true + +title: 'Avoid using remember in pam_unix module' + +description: |- + The remember option stores the last n passwords for each user in /etc/security/opasswd, + enforcing password history and preventing users from reusing the same passwords. However, this feature + relies on the MD5 password hash algorithm, which is less secure. Instead, the pam_pwhistory + module should be used. This module also stores the last n passwords in /etc/security/opasswd + and it uses the password hash algorithm configured in the pam_unix module, such as yescrypt or SHA512, + offering enhanced security. + +rationale: |- + Removing the remember argument ensures the use of a stronger password hashing algorithm. + A more robust hash algorithm increases the difficulty for attackers to crack stored + passwords in /etc/security/opasswd, thereby improving system security and + protecting user credentials. + +severity: medium + +platform: package[pam] diff --git a/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/no_remember.pass.sh b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/no_remember.pass.sh new file mode 100644 index 00000000000..865ca2f7dbe --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/no_remember.pass.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# packages = pam + +config_file=/usr/share/pam-configs/tmpunix + +cat << EOF > "$config_file" +Name: Unix authentication +Default: yes +Priority: 256 +Auth-Type: Primary +Auth: + [success=end default=ignore] pam_unix.so try_first_pass +Auth-Initial: + [success=end default=ignore] pam_unix.so +Account-Type: Primary +Account: + [success=end new_authtok_reqd=done default=ignore] pam_unix.so +Account-Initial: + [success=end new_authtok_reqd=done default=ignore] pam_unix.so +Session-Type: Additional +Session: + required pam_unix.so +Session-Initial: + required pam_unix.so +Password-Type: Primary +Password: + [success=end default=ignore] pam_unix.so obscure use_authtok try_first_pass yescrypt +Password-Initial: + [success=end default=ignore] pam_unix.so obscure yescrypt +EOF + +DEBIAN_FRONTEND=noninteractive pam-auth-update +rm $config_file diff --git a/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/remember_commented.pass.sh b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/remember_commented.pass.sh new file mode 100644 index 00000000000..1dac4919324 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/remember_commented.pass.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# packages = pam + +config_file=/usr/share/pam-configs/tmpunix + +cat << EOF > "$config_file" +Name: Unix authentication +Default: yes +Priority: 256 +Auth-Type: Primary +Auth: + [success=end default=ignore] pam_unix.so try_first_pass +Auth-Initial: + [success=end default=ignore] pam_unix.so +Account-Type: Primary +Account: + [success=end new_authtok_reqd=done default=ignore] pam_unix.so +Account-Initial: + [success=end new_authtok_reqd=done default=ignore] pam_unix.so +Session-Type: Additional +Session: + required pam_unix.so +Session-Initial: + required pam_unix.so +Password-Type: Primary +Password: + [success=end default=ignore] pam_unix.so obscure use_authtok try_first_pass yescrypt #remember=5 +Password-Initial: + [success=end default=ignore] pam_unix.so obscure yescrypt #remember=5 +EOF + +DEBIAN_FRONTEND=noninteractive pam-auth-update +rm $config_file diff --git a/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/remember_present.fail.sh b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/remember_present.fail.sh new file mode 100644 index 00000000000..61daaa5d7c0 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/password_storage/accounts_password_pam_unix_no_remember/tests/remember_present.fail.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# packages = pam + +config_file=/usr/share/pam-configs/tmpunix + +cat << EOF > "$config_file" +Name: Unix authentication +Default: yes +Priority: 256 +Auth-Type: Primary +Auth: + [success=end default=ignore] pam_unix.so try_first_pass +Auth-Initial: + [success=end default=ignore] pam_unix.so +Account-Type: Primary +Account: + [success=end new_authtok_reqd=done default=ignore] pam_unix.so +Account-Initial: + [success=end new_authtok_reqd=done default=ignore] pam_unix.so +Session-Type: Additional +Session: + required pam_unix.so +Session-Initial: + required pam_unix.so +Password-Type: Primary +Password: + [success=end default=ignore] pam_unix.so obscure use_authtok try_first_pass yescrypt remember=5 +Password-Initial: + [success=end default=ignore] pam_unix.so obscure yescrypt remember=5 +EOF + +DEBIAN_FRONTEND=noninteractive pam-auth-update + +rm $config_file