From ceb7ea6459b7fe05e04b17e1d5192537a22fc8ea Mon Sep 17 00:00:00 2001 From: Mackemania <8738793+Mackemania@users.noreply.github.com> Date: Tue, 22 Aug 2023 10:12:42 +0200 Subject: [PATCH] Change rule to use variable when auditing faillock Some benchmarks specify different paths when monitoring the faillock file, depending on if a permanent faillock path has been configured. This updates the audit_rules_login_event_faillock to use the variable var_accounts_passwords_pam_faillock_dir instead of the profile faillock_path --- controls/cis_rhel8.yml | 1 + controls/cis_rhel9.yml | 1 + ...ar_accounts_passwords_pam_faillock_dir.var | 1 + .../rule.yml | 16 +++++++++------- .../audit_login_events/group.yml | 4 ++-- .../audit_rules_login_events/ansible.template | 6 ++++++ .../audit_rules_login_events/bash.template | 6 ++++++ .../audit_rules_login_events/oval.template | 19 ++++++++++++++++--- .../tests/auditctl_correct.pass.sh | 6 +++++- .../auditctl_correct_extra_permission.pass.sh | 6 +++++- .../auditctl_correct_without_key.pass.sh | 6 +++++- .../tests/auditctl_wrong_rule.fail.sh | 7 ++++++- .../auditctl_wrong_rule_without_key.fail.sh | 6 +++++- .../tests/augenrules_correct.pass.sh | 6 +++++- ...ugenrules_correct_extra_permission.pass.sh | 6 +++++- .../augenrules_correct_without_key.pass.sh | 6 +++++- .../tests/augenrules_wrong_rule.fail.sh | 6 +++++- .../augenrules_wrong_rule_without_key.fail.sh | 6 +++++- 18 files changed, 93 insertions(+), 22 deletions(-) diff --git a/controls/cis_rhel8.yml b/controls/cis_rhel8.yml index 09d049c9dee8..12b71cadd2d2 100644 --- a/controls/cis_rhel8.yml +++ b/controls/cis_rhel8.yml @@ -1622,6 +1622,7 @@ controls: rules: - audit_rules_login_events_faillock - audit_rules_login_events_lastlog + - var_accounts_passwords_pam_faillock_dir=run - id: 4.1.3.13 title: Ensure file deletion events by users are collected (Automated) diff --git a/controls/cis_rhel9.yml b/controls/cis_rhel9.yml index 81cb3e31e8ef..954bd8b7f534 100644 --- a/controls/cis_rhel9.yml +++ b/controls/cis_rhel9.yml @@ -1375,6 +1375,7 @@ controls: rules: - audit_rules_login_events_faillock - audit_rules_login_events_lastlog + - var_accounts_passwords_pam_faillock_dir=run - id: 4.1.3.13 title: Ensure file deletion events by users are collected (Automated) diff --git a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/var_accounts_passwords_pam_faillock_dir.var b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/var_accounts_passwords_pam_faillock_dir.var index 6dfa79aa3088..1cd7df8c8906 100644 --- a/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/var_accounts_passwords_pam_faillock_dir.var +++ b/linux_os/guide/system/accounts/accounts-pam/locking_out_password_attempts/var_accounts_passwords_pam_faillock_dir.var @@ -13,3 +13,4 @@ interactive: false options: ol8: "/var/log/faillock" default: "/var/log/faillock" + run: "/var/run/faillock" diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_login_events/audit_rules_login_events_faillock/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_login_events/audit_rules_login_events_faillock/rule.yml index 6a073f18309c..93a43951456b 100644 --- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_login_events/audit_rules_login_events_faillock/rule.yml +++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_login_events/audit_rules_login_events_faillock/rule.yml @@ -11,12 +11,12 @@ description: |- default), add the following lines to a file with suffix .rules in the directory /etc/audit/rules.d in order to watch for attempted manual edits of files involved in storing logon events: -
-w {{{ faillock_path }}} -p wa -k logins+
-w {{{ xccdf_value("var_accounts_passwords_pam_faillock_dir") }}} -p wa -k loginsIf the auditd daemon is configured to use the auditctl utility to read audit rules during daemon startup, add the following lines to /etc/audit/audit.rules file in order to watch for unattempted manual edits of files involved in storing logon events: -
-w {{{ faillock_path }}} -p wa -k logins+
-w {{{ xccdf_value("var_accounts_passwords_pam_faillock_dir") }}} -p wa -k loginsrationale: |- Manual editing of these files may indicate nefarious activity, such @@ -66,16 +66,18 @@ ocil_clause: 'the command does not return a line, or the line is commented out' ocil: |- Verify {{{ full_name }}} generates audit records for all account creations, modifications, disabling, and termination events that affect "/etc/security/opasswd" with the following command: - $ sudo auditctl -l | grep {{{ faillock_path }}} + $ sudo auditctl -l | grep {{{ xccdf_value("var_accounts_passwords_pam_faillock_dir") }}} - -w {{{ faillock_path }}} -p wa -k logins + -w {{{ xccdf_value("var_accounts_passwords_pam_faillock_dir") }}} -p wa -k logins template: name: audit_rules_login_events vars: - path: {{{ faillock_path }}} + path: var_accounts_passwords_pam_faillock_dir + path_is_variable: "true" + fixtext: |- - {{{ fixtext_audit_file_watch_rule(faillock_path, "logins", "/etc/audit/rules.d/audit.rules") | indent(4) }}} + {{{ fixtext_audit_file_watch_rule(xccdf_value("var_accounts_passwords_pam_faillock_dir"), "logins", "/etc/audit/rules.d/audit.rules") | indent(4) }}} -srg_requirement: '{{{ srg_requirement_audit_file_watch_rule(faillock_path) }}}' +srg_requirement: '{{{ srg_requirement_audit_file_watch_rule(xccdf_value("var_accounts_passwords_pam_faillock_dir")) }}}' diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_login_events/group.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_login_events/group.yml index d54032a4d218..184bbc332919 100644 --- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_login_events/group.yml +++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_login_events/group.yml @@ -10,12 +10,12 @@ description: |- directory /etc/audit/rules.d in order to watch for attempted manual edits of files involved in storing logon events:
-w /var/log/tallylog -p wa -k logins - -w {{{ faillock_path }}} -p wa -k logins + -w {{{ xccdf_value("var_accounts_passwords_pam_faillock_dir") }}} -p wa -k logins -w /var/log/lastlog -p wa -k loginsIf the auditd daemon is configured to use the auditctl utility to read audit rules during daemon startup, add the following lines to /etc/audit/audit.rules file in order to watch for unattempted manual edits of files involved in storing logon events:
-w /var/log/tallylog -p wa -k logins - -w {{{ faillock_path }}} -p wa -k logins + -w {{{ xccdf_value("var_accounts_passwords_pam_faillock_dir") }}} -p wa -k logins -w /var/log/lastlog -p wa -k loginsdiff --git a/shared/templates/audit_rules_login_events/ansible.template b/shared/templates/audit_rules_login_events/ansible.template index 2ccdb54835fb..6972e4450e76 100644 --- a/shared/templates/audit_rules_login_events/ansible.template +++ b/shared/templates/audit_rules_login_events/ansible.template @@ -4,5 +4,11 @@ # complexity = low # disruption = low +{{% if PATH_IS_VARIABLE %}} +{{{ ansible_instantiate_variables("var_accounts_passwords_pam_faillock_dir") }}} +{{{ ansible_audit_augenrules_add_watch_rule(path="{{ var_accounts_passwords_pam_faillock_dir }}", permissions='wa', key='logins') }}} +{{{ ansible_audit_auditctl_add_watch_rule(path="{{ var_accounts_passwords_pam_faillock_dir }}", permissions='wa', key='logins') }}} +{{% else %}} {{{ ansible_audit_augenrules_add_watch_rule(path=PATH, permissions='wa', key='logins') }}} {{{ ansible_audit_auditctl_add_watch_rule(path=PATH, permissions='wa', key='logins') }}} +{{% endif %}} \ No newline at end of file diff --git a/shared/templates/audit_rules_login_events/bash.template b/shared/templates/audit_rules_login_events/bash.template index c94b10739806..3c924ee40755 100644 --- a/shared/templates/audit_rules_login_events/bash.template +++ b/shared/templates/audit_rules_login_events/bash.template @@ -2,5 +2,11 @@ # Perform the remediation for both possible tools: 'auditctl' and 'augenrules' +{{% if PATH_IS_VARIABLE %}} +{{{ bash_instantiate_variables("var_accounts_passwords_pam_faillock_dir") }}} +{{{ bash_fix_audit_watch_rule("auditctl", "$var_accounts_passwords_pam_faillock_dir", "wa", "logins") }}} +{{{ bash_fix_audit_watch_rule("augenrules", "$var_accounts_passwords_pam_faillock_dir", "wa", "logins") }}} +{{% else %}} {{{ bash_fix_audit_watch_rule("auditctl", PATH, "wa", "logins") }}} {{{ bash_fix_audit_watch_rule("augenrules", PATH, "wa", "logins") }}} +{{% endif %}} \ No newline at end of file diff --git a/shared/templates/audit_rules_login_events/oval.template b/shared/templates/audit_rules_login_events/oval.template index f173fc8fa369..669211b24afa 100644 --- a/shared/templates/audit_rules_login_events/oval.template +++ b/shared/templates/audit_rules_login_events/oval.template @@ -24,7 +24,7 @@