From 98b429265adadb74fd5acc3846d5d3e643f43d7b Mon Sep 17 00:00:00 2001 From: Alan Moore Date: Wed, 22 Jan 2025 17:34:24 +0000 Subject: [PATCH 1/2] Add rule no_invalid_shell_accounts_unlocked --- components/pam.yml | 1 + controls/cis_ubuntu2404.yml | 7 +++++-- .../rule.yml | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/rule.yml diff --git a/components/pam.yml b/components/pam.yml index ee251b74a56..8be5a136d48 100644 --- a/components/pam.yml +++ b/components/pam.yml @@ -185,6 +185,7 @@ rules: - no_empty_passwords - no_empty_passwords_etc_shadow - no_forward_files +- no_invalid_shell_accounts_unlocked - no_legacy_plus_entries_etc_group - no_legacy_plus_entries_etc_passwd - no_legacy_plus_entries_etc_shadow diff --git a/controls/cis_ubuntu2404.yml b/controls/cis_ubuntu2404.yml index c0b809c6ca8..3ab08351a34 100644 --- a/controls/cis_ubuntu2404.yml +++ b/controls/cis_ubuntu2404.yml @@ -2208,8 +2208,11 @@ 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: + - no_invalid_shell_accounts_unlocked + status: automated + notes: | + Remediation is not automated. - id: 5.4.3.1 title: Ensure nologin is not listed in /etc/shells (Automated) diff --git a/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/rule.yml b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/rule.yml new file mode 100644 index 00000000000..69a285e7f35 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/rule.yml @@ -0,0 +1,20 @@ +documentation_complete: true + +title: 'Verify Non-Interactive Accounts Are Locked' + +description: |- + Accounts meant for non-interactive purposes should be locked to prevent + unauthorized access. Accounts with non-standard shells (those not defined in + /etc/shells) should be locked using usermod -L. + +rationale: |- + Locking non-interactive accounts improves security by preventing potential + misuse. While many systems configure these accounts with invalid strings, + setting the shell field to nologin is also suggested + +severity: medium + +warnings: + - general: |- + Automatic remediation of this control is not recommended. Locking system accounts + could be highly disruptive. From 65140d2dd03c59860cf912ee23628c3e8bdfed65 Mon Sep 17 00:00:00 2001 From: Alan Moore Date: Wed, 22 Jan 2025 17:35:16 +0000 Subject: [PATCH 2/2] Add oval and tests --- .../oval/shared.xml | 80 +++++++++++++++++++ .../tests/asterisks.pass.sh | 4 + .../tests/correct.pass.sh | 6 ++ .../tests/invalid_shell.fail.sh | 5 ++ 4 files changed, 95 insertions(+) create mode 100644 linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/oval/shared.xml create mode 100644 linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/asterisks.pass.sh create mode 100644 linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/correct.pass.sh create mode 100644 linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/invalid_shell.fail.sh diff --git a/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/oval/shared.xml b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/oval/shared.xml new file mode 100644 index 00000000000..654a4c6ffbc --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/oval/shared.xml @@ -0,0 +1,80 @@ + + + {{{ oval_metadata("Ensure Accounts Without Valid Login Shell Are Locked") }}} + + + + + + + + + + + + + + + + + + + + /etc/shells + ^\/[^\n\r]*$ + 1 + filter_{{{ rule_id }}}_not_valid_shell + + + + ^.*\bnologin\b.*$ + + + + + /etc/passwd + + + 1 + + + + + ^(?: + + ):(?:[^:]*:){5}([^:]+)$ + + + + + + /etc/passwd + ^([^:]*):[^:]*:\d+:(?:[^:]*:){3}(?!(\/usr)?(\/sbin\/nologin|\/bin\/false))[^:]*$ + 1 + state_{{{ rule_id }}}_users_ignored + state_{{{ rule_id }}}_locked_accounts + + + {{%- set ignored_users_list="(nobody|nfsnobody|root)" %}} + + ^{{{ ignored_users_list }}}$ + + + + + + + + + + + + + /etc/shadow + ^([^:]*):(?:[ \t\n\r\:\;\*\!\\]*):(?:[^:]*:){6}$ + 1 + + + diff --git a/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/asterisks.pass.sh b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/asterisks.pass.sh new file mode 100644 index 00000000000..b8d546a67f4 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/asterisks.pass.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# remediation = none + +sed -i 's/^\([^:]*\):x:/\1:\*:/' /etc/passwd diff --git a/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/correct.pass.sh b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/correct.pass.sh new file mode 100644 index 00000000000..6e2a92192eb --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/correct.pass.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# remediation = none + +echo "testuser:*:1001:1001::/home/testuser:/bin/bash" > /etc/passwd +echo "testuser:!:20111:0:99999:7:::" > /etc/shadow +echo "/bin/bash" >> /etc/shells diff --git a/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/invalid_shell.fail.sh b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/invalid_shell.fail.sh new file mode 100644 index 00000000000..d2dddcd1d39 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-restrictions/root_logins/no_invalid_shell_accounts_unlocked/tests/invalid_shell.fail.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# remediation = none + +echo "testuser:x:8000:8000:testuser:/home/testuser:/bin/dash" > /etc/passwd +echo "/bin/bash" > /etc/shells