From eaebe73b610e31e2cfa8565dfbd2d9c4460f9037 Mon Sep 17 00:00:00 2001 From: Alan Moore Date: Tue, 7 Jan 2025 11:03:17 +0000 Subject: [PATCH 1/2] Set the cis recommend value --- controls/cis_ubuntu2404.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/controls/cis_ubuntu2404.yml b/controls/cis_ubuntu2404.yml index a50874b1fdf..9a7a72c4b1e 100644 --- a/controls/cis_ubuntu2404.yml +++ b/controls/cis_ubuntu2404.yml @@ -2008,11 +2008,10 @@ controls: levels: - l1_server - l1_workstation - related_rules: - - var_password_pam_remember=5 - - accounts_password_pam_unix_remember - status: planned - notes: TODO. Partial/incorrect implementation exists.See related rules. Analogous to ubuntu2204/5.4.3. + rules: + - var_password_pam_remember=24 + - accounts_password_pam_pwhistory_remember + status: automated - id: 5.3.3.3.2 title: Ensure password history is enforced for the root user (Automated) From 1c20e93ca360173fc1c2813eff28dd04b32a307f Mon Sep 17 00:00:00 2001 From: Alan Moore Date: Tue, 7 Jan 2025 21:31:38 +0000 Subject: [PATCH 2/2] Rewrite the remediation and tests of accounts_password_pam_pwhistory_remember to use pam-auth-update --- .../bash/ubuntu.sh | 21 +++++++ .../oval/shared.xml | 58 +++++++++++++++++++ .../rule.yml | 2 + .../tests/ubuntu_argument_missing.fail.sh | 17 ++++++ .../tests/ubuntu_correct_value.pass.sh | 17 ++++++ .../tests/ubuntu_wrong_value.fail.sh | 17 ++++++ 6 files changed, 132 insertions(+) create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/bash/ubuntu.sh create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/oval/shared.xml create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_argument_missing.fail.sh create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_correct_value.pass.sh create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_wrong_value.fail.sh diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/bash/ubuntu.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/bash/ubuntu.sh new file mode 100644 index 00000000000..dcde536514b --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/bash/ubuntu.sh @@ -0,0 +1,21 @@ +# platform = multi_platform_ubuntu + +{{{ bash_pam_pwhistory_enable('cac_pwhistory','requisite') }}} + +{{{ bash_instantiate_variables("var_password_pam_remember") }}} + +sed -i -E '/^Password:/,/^[^[:space:]]/ { + /pam_pwhistory\.so/ { + s/\s*remember=[^[:space:]]*//g + s/$/ remember='"$var_password_pam_remember"'/g + } +}' /usr/share/pam-configs/cac_pwhistory + +sed -i -E '/^Password-Initial:/,/^[^[:space:]]/ { + /pam_pwhistory\.so/ { + s/\s*remember=[^[:space:]]*//g + s/$/ remember='"$var_password_pam_remember"'/g + } +}' /usr/share/pam-configs/cac_pwhistory + +DEBIAN_FRONTEND=noninteractive pam-auth-update --enable cac_pwhistory diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/oval/shared.xml b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/oval/shared.xml new file mode 100644 index 00000000000..584a670f605 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/oval/shared.xml @@ -0,0 +1,58 @@ +{{% if "sle12" in product or "debian" in product or "ubuntu" in product %}} +{{%- set accounts_password_pam_file = '/etc/pam.d/common-password' -%}} +{{% endif %}} + + + + {{{ oval_metadata("The passwords to remember of pam_pwhistory should be set correctly.") }}} + + + + + + + + + + + + + + + {{{ accounts_password_pam_file }}} + + 1 + + + + + ^[ \t]*password[ \t]+(?:(?:sufficient)|(?:required)|(?:requisite)|(?:\[.*\]))[ \t]+pam_pwhistory\.so.*$ + + + + + + + + + + + + + + {{{ accounts_password_pam_file }}} + ^[ \t]*password[ \t]+(?:(?:sufficient)|(?:required)|(?:requisite)|(?:\[.*\]))[ \t]+pam_pwhistory\.so[ \t]+[^#\n\r]*\bremember=([0-9]*)\b.*$ + 1 + + + diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/rule.yml b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/rule.yml index 8758454ece6..eb6a270e031 100644 --- a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/rule.yml +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/rule.yml @@ -49,6 +49,7 @@ ocil: |- platform: package[pam] +{{% if 'ubuntu' not in product or product == 'ubuntu2004' %}} template: name: pam_options vars: @@ -61,3 +62,4 @@ template: operation: greater than or equal - argument: use_authtok new_argument: use_authtok +{{% endif %}} diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_argument_missing.fail.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_argument_missing.fail.sh new file mode 100644 index 00000000000..490a64c26e2 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_argument_missing.fail.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# packages = pam +# variables = var_password_pam_remember=5 + +config_file=/usr/share/pam-configs/tmp_pwhistory + +cat << EOF > "$config_file" +Name: pwhistory password history checking +Default: yes +Priority: 1024 +Password-Type: Primary +Password: requisite pam_pwhistory.so enforce_for_root try_first_pass use_authtok +EOF + +DEBIAN_FRONTEND=noninteractive pam-auth-update --enable tmp_pwhistory +rm "$config_file" diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_correct_value.pass.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_correct_value.pass.sh new file mode 100644 index 00000000000..d685766fff8 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_correct_value.pass.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# packages = pam +# variables = var_password_pam_remember=5 + +config_file=/usr/share/pam-configs/tmp_pwhistory + +cat << EOF > "$config_file" +Name: pwhistory password history checking +Default: yes +Priority: 1024 +Password-Type: Primary +Password: requisite pam_pwhistory.so remember=5 enforce_for_root try_first_pass use_authtok +EOF + +DEBIAN_FRONTEND=noninteractive pam-auth-update --enable tmp_pwhistory +rm "$config_file" diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_wrong_value.fail.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_wrong_value.fail.sh new file mode 100644 index 00000000000..8600b5e059c --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_password_pam_pwhistory_remember/tests/ubuntu_wrong_value.fail.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# packages = pam +# variables = var_password_pam_remember=5 + +config_file=/usr/share/pam-configs/tmp_pwhistory + +cat << EOF > "$config_file" +Name: pwhistory password history checking +Default: yes +Priority: 1024 +Password-Type: Primary +Password: requisite pam_pwhistory.so remember=4 enforce_for_root try_first_pass use_authtok +EOF + +DEBIAN_FRONTEND=noninteractive pam-auth-update --enable tmp_pwhistory +rm "$config_file"