From 77e6e5624f1be0c017d65090606237222abf2eba Mon Sep 17 00:00:00 2001 From: Alan Moore Date: Thu, 12 Dec 2024 11:25:26 +0000 Subject: [PATCH 1/3] Ubuntu 24.04 5.3.2.2 Ensure pam_faillock module is enabled --- components/pam.yml | 1 + controls/cis_ubuntu2404.yml | 5 +++-- .../rule.yml | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/rule.yml diff --git a/components/pam.yml b/components/pam.yml index b6789a9972c..ba5cd08db3d 100644 --- a/components/pam.yml +++ b/components/pam.yml @@ -82,6 +82,7 @@ rules: - accounts_passwords_pam_faillock_interval - accounts_passwords_pam_faillock_silent - accounts_passwords_pam_faillock_unlock_time +- accounts_passwords_pam_faillock_enabled - accounts_passwords_pam_tally2 - accounts_passwords_pam_tally2_deny_root - accounts_passwords_pam_tally2_unlock_time diff --git a/controls/cis_ubuntu2404.yml b/controls/cis_ubuntu2404.yml index fbc438cf883..444fe44b9c4 100644 --- a/controls/cis_ubuntu2404.yml +++ b/controls/cis_ubuntu2404.yml @@ -1863,8 +1863,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_passwords_pam_faillock_enabled + status: automated - id: 5.3.2.3 title: Ensure pam_pwquality module is enabled (Automated) diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/rule.yml b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/rule.yml new file mode 100644 index 00000000000..e3505d45f67 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/rule.yml @@ -0,0 +1,19 @@ +documentation_complete: true + + +title: 'Ensure pam_faillock module is enabled' + +description: |- + The pam_faillock.so module maintains a list of failed authentication attempts per + user during a specified interval and locks the account in case there were more than the + configured number of consecutive failed authentications (this is defined by the deny + parameter in the faillock configuration). It stores the failure records into per-user files in + the tally directory. + +rationale: |- + Locking out user IDs after n unsuccessful consecutive login attempts mitigates brute + force password attacks against your systems. + +severity: medium + +platform: package[pam] From 1ae10d0db6a6c84397a673d2ea8e096198842304 Mon Sep 17 00:00:00 2001 From: Alan Moore Date: Mon, 6 Jan 2025 19:43:21 +0000 Subject: [PATCH 2/3] Implement accounts_passwords_pam_faillock_enabled --- .../bash/shared.sh | 3 + .../oval/shared.xml | 116 ++++++++++++++++++ .../tests/ubuntu_correct.pass.sh | 4 + .../tests/ubuntu_empty_faillock_conf.pass.sh | 6 + .../tests/ubuntu_multiple_pam_unix.fail.sh | 11 ++ 5 files changed, 140 insertions(+) create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/bash/shared.sh create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/oval/shared.xml create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_correct.pass.sh create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_empty_faillock_conf.pass.sh create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_multiple_pam_unix.fail.sh diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/bash/shared.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/bash/shared.sh new file mode 100644 index 00000000000..43feff6ed1e --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/bash/shared.sh @@ -0,0 +1,3 @@ +# platform = multi_platform_ubuntu + +{{{ bash_pam_faillock_enable() }}} diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/oval/shared.xml b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/oval/shared.xml new file mode 100644 index 00000000000..6b8587cac60 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/oval/shared.xml @@ -0,0 +1,116 @@ + + + {{{ oval_metadata(description) }}} + + + + + + + + + + + ^\s*auth\N+pam_unix\.so + + + + {{% if 'debian' in product %}} + ^\s*auth\s+required\s+pam_faillock\.so.*preauth.*[\s\S]*^\s*auth.*pam_unix\.so[\s\S]*^\s*auth\s+\[default=die\]\s+pam_faillock\.so\s+authfail[\s\S]*^\s*auth\s+sufficient\s+pam_faillock\.so\s+authsucc + {{% elif 'ubuntu' in product %}} + ^\s*auth\s+(requisite|required)\s+pam_faillock\.so.*preauth.*[\s\S]*^\s*auth.*pam_unix\.so[\s\S]*^\s*auth\s+\[default=die\]\s+pam_faillock\.so\s+authfail + {{% elif 'openeuler' in product or 'kylinserver' in product %}} + ^[\s]*auth[\s]+(required|\[(?=.*?\bsuccess=ok\b)?(?=.*?\bnew_authtok_reqd=ok\b)?(?=.*?\bignore=ignore\b)?(?=.*?\bdefault=bad\b)?.*\])[\s]+pam_faillock\.so[\s\w\d=]+preauth[\s\S]*^[\s]*auth[\s]+(sufficient|\[(?=.*\bsuccess=done\b)?(?=.*?\bnew_authtok_reqd=done\b)?(?=.*?\bdefault=ignore\b)?.*\])[\s]+pam_unix\.so[\s\S]*^[\s]*auth[\s]+(required|\[(?=.*?\bsuccess=ok\b)?(?=.*?\bnew_authtok_reqd=ok\b)?(?=.*?\bignore=ignore\b)?(?=.*?\bdefault=die\b)?.*\])[\s]+pam_faillock\.so[\s\w\d=]+authfail + {{% else %}} + ^[\s]*auth[\s]+(required|\[(?=.*?\bsuccess=ok\b)(?=.*?\bnew_authtok_reqd=ok\b)(?=.*?\bignore=ignore\b)(?=.*?\bdefault=bad\b).*\])[\s]+pam_faillock\.so[\s\w\d=]+preauth[\s\S]*^[\s]*auth[\s]+(sufficient|\[(?=.*\bsuccess=done\b)(?=.*?\bnew_authtok_reqd=done\b)(?=.*?\bdefault=ignore\b).*\])[\s]+pam_unix\.so[\s\S]*^[\s]*auth[\s]+(required|\[(?=.*?\bsuccess=ok\b)(?=.*?\bnew_authtok_reqd=ok\b)(?=.*?\bignore=ignore\b)(?=.*?\bdefault=bad\b).*\])[\s]+pam_faillock\.so[\s\w\d=]+authfail + {{% endif %}} + + + + {{% if 'debian' in product or 'ubuntu' in product %}} + ^\s*account\s+required\s+pam_faillock\.so\s*(#.*)?$ + {{% elif 'openeuler' in product or 'kylinserver' in product %}} + ^[\s]*account[\s]+(required|\[(?=.*?\bsuccess=ok\b)?(?=.*?\bnew_authtok_reqd=ok\b)?(?=.*?\bignore=ignore\b)?(?=.*?\bdefault=bad\b)?.*\])[\s]+pam_unix\.so[\s\S]*^[\s]*account[\s]+(required|\[(?=.*?\bsuccess=ok\b)?(?=.*?\bnew_authtok_reqd=ok\b)?(?=.*?\bignore=ignore\b)?(?=.*?\bdefault=bad\b)?.*\])[\s]+pam_faillock\.so + {{% else %}} + ^[\s]*account[\s]+(required|\[(?=.*?\bsuccess=ok\b)(?=.*?\bnew_authtok_reqd=ok\b)(?=.*?\bignore=ignore\b)(?=.*?\bdefault=bad\b).*\])[\s]+pam_faillock\.so[\s\S]*^[\s]*account[\s]+(required|\[(?=.*?\bsuccess=ok\b)(?=.*?\bnew_authtok_reqd=ok\b)(?=.*?\bignore=ignore\b)(?=.*?\bdefault=bad\b).*\])[\s]+pam_unix\.so + {{% endif %}} + + + {{% macro generate_test_faillock_enabled(file_stem) %}} + + + + + + + /etc/pam.d/{{{file_stem}}}-auth + + 1 + + + + + + + + + /etc/pam.d/{{{ file_stem }}}-auth + + 1 + + {{% endmacro %}} + + {{{ generate_test_faillock_enabled (file_stem="common") }}} + + {{% macro generate_test_faillock_account(file_stem, file) %}} + + + + + + + /etc/pam.d/{{{ file }}} + + 1 + + {{% endmacro %}} + + {{{ generate_test_faillock_account (file_stem="common", file="common-account") }}} + + diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_correct.pass.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_correct.pass.sh new file mode 100644 index 00000000000..bc1a71c7614 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_correct.pass.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# platform = multi_platform_ubuntu + +{{{ bash_enable_pam_faillock_directly_in_pam_files() }}} diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_empty_faillock_conf.pass.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_empty_faillock_conf.pass.sh new file mode 100644 index 00000000000..87ad63f8fc9 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_empty_faillock_conf.pass.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# platform = multi_platform_ubuntu + +{{{ bash_enable_pam_faillock_directly_in_pam_files() }}} + +echo > /etc/security/faillock.conf diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_multiple_pam_unix.fail.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_multiple_pam_unix.fail.sh new file mode 100644 index 00000000000..20d85d14675 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_multiple_pam_unix.fail.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# remediation = none + +{{{ bash_enable_pam_faillock_directly_in_pam_files() }}} + +# Multiple instances of pam_unix.so in auth section may, intentionally or not, interfere +# in the expected behaviour of pam_faillock.so. Remediation does not solve this automatically +# in order to preserve intentional changes. + +sed -i '/# end of pam-auth-update config/i\auth sufficient pam_unix.so' /etc/pam.d/common-auth From d145e2ae1c534210af57b3879f8c9ed86ee59353 Mon Sep 17 00:00:00 2001 From: Alan Moore Date: Wed, 8 Jan 2025 14:18:01 +0000 Subject: [PATCH 3/3] Add # packages = pam Add commented value fail and missing pam_faillock fail --- .../tests/ubuntu_commented_values.fail.sh | 5 +++ .../tests/ubuntu_correct.pass.sh | 1 + .../tests/ubuntu_missing_pamd.fail.sh | 5 +++ .../tests/ubuntu_multiple_pam_unix.fail.sh | 33 ++++++++++++++++--- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_commented_values.fail.sh create mode 100644 linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_missing_pamd.fail.sh diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_commented_values.fail.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_commented_values.fail.sh new file mode 100644 index 00000000000..70b20de9f3e --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_commented_values.fail.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# packages = pam + +echo 'auth requisite pam_faillock.so preauth' >> /etc/pam.d/common-auth diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_correct.pass.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_correct.pass.sh index bc1a71c7614..acac3aee099 100644 --- a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_correct.pass.sh +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_correct.pass.sh @@ -1,4 +1,5 @@ #!/bin/bash # platform = multi_platform_ubuntu +# packages = pam {{{ bash_enable_pam_faillock_directly_in_pam_files() }}} diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_missing_pamd.fail.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_missing_pamd.fail.sh new file mode 100644 index 00000000000..fc6bd806613 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_missing_pamd.fail.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# platform = multi_platform_ubuntu +# packages = pam + +sed '/pam_faillock.so/d' /etc/pam.d/common-auth diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_multiple_pam_unix.fail.sh b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_multiple_pam_unix.fail.sh index 20d85d14675..4e3171a9d7e 100644 --- a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_multiple_pam_unix.fail.sh +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/accounts_passwords_pam_faillock_enabled/tests/ubuntu_multiple_pam_unix.fail.sh @@ -1,11 +1,36 @@ #!/bin/bash # platform = multi_platform_ubuntu -# remediation = none - -{{{ bash_enable_pam_faillock_directly_in_pam_files() }}} +# packages = pam # Multiple instances of pam_unix.so in auth section may, intentionally or not, interfere # in the expected behaviour of pam_faillock.so. Remediation does not solve this automatically # in order to preserve intentional changes. +cat << EOF > /usr/share/pam-configs/tmp_unix +Name: Unix authentication +Default: yes +Priority: 257 +Auth-Type: Primary +Auth: + [success=end default=ignore] pam_unix.so nullok try_first_pass +Auth-Initial: + [success=end default=ignore] pam_unix.so nullok +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 + auth sufficient pam_unix.so +EOF +DEBIAN_FRONTEND=noninteractive pam-auth-update -sed -i '/# end of pam-auth-update config/i\auth sufficient pam_unix.so' /etc/pam.d/common-auth +rm -f /usr/share/pam-configs/tmp_unix