diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/ansible/shared.yml b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/ansible/shared.yml index c971daf1afb2..db8156b2f75b 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/ansible/shared.yml +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/ansible/shared.yml @@ -22,8 +22,59 @@ loop: "{{ result_privileged_commands_search.results }}" when: item is not skipped +{{% if product in ["fedora", "rhel10"] %}} +- name: {{{ rule_title }}} - Set architecture for audit {{{ PATH }}} + ansible.builtin.set_fact: + audit_arch: "b64" + when: + - ansible_architecture == "aarch64" or + ansible_architecture == "ppc64" or + ansible_architecture == "ppc64le" or + ansible_architecture == "s390x" or + ansible_architecture == "x86_64" +{{% endif %}} + - name: {{{ rule_title }}} - Privileged Commands are Present in the System block: +{{% if product in ["fedora", "rhel10"] %}} + - name: {{{ rule_title }}} - Ensure Rules for All Privileged Commands in augenrules Format 32-bit + ansible.builtin.lineinfile: + path: /etc/audit/rules.d/privileged.rules + line: '-a always,exit -F arch=b32 -F path={{ item }} -F perm=x -F auid>={{{ auid }}} -F auid!=unset -F key=privileged' + regexp: "^.* -F arch=b32 -F path={{ item | regex_escape() }} .*$" + create: yes + with_items: + - "{{ privileged_commands }}" + + - name: {{{ rule_title }}} - Ensure Rules for All Privileged Commands in auditctl Format 32-bit + ansible.builtin.lineinfile: + path: /etc/audit/audit.rules + line: '-a always,exit -F arch=b32 -F path={{ item }} -F perm=x -F auid>={{{ auid }}} -F auid!=unset -F key=privileged' + regexp: "^.* -F arch=b32 -F path={{ item | regex_escape() }} .*$" + create: yes + with_items: + - "{{ privileged_commands }}" + + - name: {{{ rule_title }}} - Ensure Rules for All Privileged Commands in augenrules Format 64-bit + ansible.builtin.lineinfile: + path: /etc/audit/rules.d/privileged.rules + line: '-a always,exit -F arch=b64 -F path={{ item }} -F perm=x -F auid>={{{ auid }}} -F auid!=unset -F key=privileged' + regexp: "^.* -F arch=b64 -F path={{ item | regex_escape() }} .*$" + create: yes + with_items: + - "{{ privileged_commands }}" + when: audit_arch == "b64" + + - name: {{{ rule_title }}} - Ensure Rules for All Privileged Commands in auditctl Format 64-bit + ansible.builtin.lineinfile: + path: /etc/audit/audit.rules + line: '-a always,exit -F arch=b64 -F path={{ item }} -F perm=x -F auid>={{{ auid }}} -F auid!=unset -F key=privileged' + regexp: "^.* -F arch=b64 -F path={{ item | regex_escape() }} .*$" + create: yes + with_items: + - "{{ privileged_commands }}" + when: audit_arch == "b64" +{{% else %}} - name: {{{ rule_title }}} - Ensure Rules for All Privileged Commands in augenrules Format ansible.builtin.lineinfile: path: /etc/audit/rules.d/privileged.rules @@ -41,12 +92,13 @@ create: yes with_items: - "{{ privileged_commands }}" +{{% endif %}} - name: {{{ rule_title }}} - Search for Duplicated Rules in Other Files ansible.builtin.find: paths: "/etc/audit/rules.d" recurse: no - contains: "^-a always,exit -F path={{ item }} .*$" + contains: "^-a always,exit (-F arch=b32 |-F arch=b64 )?-F path={{ item | regex_escape() }} .*$" patterns: "*.rules" with_items: - "{{ privileged_commands }}" @@ -55,7 +107,7 @@ - name: {{{ rule_title }}} - Ensure Rules for Privileged Commands are Defined Only in One File ansible.builtin.lineinfile: path: "{{ item.1.path }}" - regexp: "^-a always,exit -F path={{ item.0.item }} .*$" + regexp: "^-a always,exit (-F arch=b32 |-F arch=b64 )?-F path={{ item.0.item | regex_escape() }} .*$" state: absent with_subelements: - "{{ result_augenrules_files.results }}" diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/bash/shared.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/bash/shared.sh index d0371afcb3d4..3e3132fa5740 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/bash/shared.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/bash/shared.sh @@ -15,8 +15,19 @@ function add_audit_rule() local PRIV_CMD="$1" local OTHER_FILTERS="-F path=$PRIV_CMD -F perm=x" # Perform the remediation for both possible tools: 'auditctl' and 'augenrules' +{{% if product in ["fedora", "rhel10"] %}} + [ "$(getconf LONG_BIT)" = "32" ] && RULE_ARCHS=("b32") || RULE_ARCHS=("b32" "b64") + for ARCH in "${RULE_ARCHS[@]}" ; do + ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH" + {{{ bash_fix_audit_syscall_rule("augenrules", "$ACTION_ARCH_FILTERS", "$OTHER_FILTERS", "$AUID_FILTERS", "$SYSCALL", "$SYSCALL_GROUPING", "$KEY") | indent(4) }}} + {{{ bash_fix_audit_syscall_rule("auditctl", "$ACTION_ARCH_FILTERS", "$OTHER_FILTERS", "$AUID_FILTERS", "$SYSCALL", "$SYSCALL_GROUPING", "$KEY") | indent(4) }}} + done +{{% else %}} + ACTION_ARCH_FILTERS="-a always,exit" {{{ bash_fix_audit_syscall_rule("augenrules", "$ACTION_ARCH_FILTERS", "$OTHER_FILTERS", "$AUID_FILTERS", "$SYSCALL", "$SYSCALL_GROUPING", "$KEY") | indent(4) }}} {{{ bash_fix_audit_syscall_rule("auditctl", "$ACTION_ARCH_FILTERS", "$OTHER_FILTERS", "$AUID_FILTERS", "$SYSCALL", "$SYSCALL_GROUPING", "$KEY") | indent(4) }}} +{{% endif %}} + } if {{{ bash_bootc_build() }}} ; then diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/oval/shared.xml b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/oval/shared.xml index a6ff74a006c7..01d4e202ab2a 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/oval/shared.xml +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/oval/shared.xml @@ -1,47 +1,50 @@ {{% if product not in ['ubuntu2404'] %}} + +{{% macro arpc_condition(audit_tool, bootc=True) %}} + + +{{% if product in ["fedora", "rhel10"] %}} + + + + + + + + + + + +{{% else %}} + + +{{% endif %}} + +{{% endmacro %}} + {{{ oval_metadata("Audit rules about the information on the use of privileged commands are enabled.", rule_title=rule_title) }}} - + - - - - - - - - - - + {{{ arpc_condition("augenrules", bootc=True) }}} + {{{ arpc_condition("augenrules", bootc=False) }}} - + - - - - - - - - - - + {{{ arpc_condition("auditctl", bootc=True) }}} + {{{ arpc_condition("auditctl", bootc=False) }}} @@ -120,195 +123,126 @@ state_audit_rules_privileged_commands_sysroot - - + +{{% if product in ["fedora", "rhel10"] %}} + + ^[\s]*-a always,exit -F arch=b32 (?:-F path=([\S]+))+(?: -F perm=x)? -F auid>={{{ auid }}} -F auid!=(?:4294967295|unset)[\s]+(?:-k[\s]+|-F[\s]+key=)[\S]+[\s]*$ - - + + ^[\s]*-a always,exit -F arch=b64 (?:-F path=([\S]+))+(?: -F perm=x)? -F auid>={{{ auid }}} -F auid!=(?:4294967295|unset)[\s]+(?:-k[\s]+|-F[\s]+key=)[\S]+[\s]*$ +{{% else %}} + + ^[\s]*-a always,exit (?:-F path=([\S]+))+(?: -F perm=x)? -F auid>={{{ auid }}} -F auid!=(?:4294967295|unset)[\s]+(?:-k[\s]+|-F[\s]+key=)[\S]+[\s]*$ + +{{% endif %}} - - - - +{{% macro arpc_variables_and_states(bootc) %}} + + - + object_ref="object_audit_rules_privileged_commands{{{ '_bootc' if bootc else '' }}}"/> - - var_audit_rules_privileged_commands_priv_cmds_count - - - var_audit_rules_privileged_commands_priv_cmds_count_bootc + var_audit_rules_privileged_commands_priv_cmds_count{{{ '_bootc' if bootc else '' }}} - - - ^[\s]*-a always,exit (?:-F path=([\S]+))+(?: -F perm=x)? -F auid>={{{ auid }}} -F auid!=(?:4294967295|unset)[\s]+(?:-k[\s]+|-F[\s]+key=)[\S]+[\s]*$ - - - - - - + + var_ref="var_audit_rules_privileged_commands_priv_cmds{{{ '_bootc' if bootc else '' }}}"/> - - - ^/etc/audit/rules\.d/.*\.rules$ - - 1 - state_unprivileged_commands - - - ^/etc/audit/rules\.d/.*\.rules$ - - 1 - state_unprivileged_commands_bootc - - - - - - + + var_ref="var_audit_rules_privileged_commands_priv_cmds{{{ '_bootc' if bootc else '' }}}"/> +{{% endmacro %}} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /etc/audit/audit.rules - - 1 - state_unprivileged_commands - - +{{% macro arpc_object_priv_cmds(audit_tool, bits=None, bootc=False) %}} + + {{% if audit_tool == "augenrules" %}} + ^/etc/audit/rules\.d/.*\.rules$ + {{% elif audit_tool == "auditctl" %}} /etc/audit/audit.rules + {{% else %}} + {{{ raise("Unknown audit tool: " + audit_tool) }}} + {{% endif %}} + var_ref="var_audit_rules_privileged_commands_rule_regex{{{ ('_' + bits + 'bit') if bits else '' }}}"/> 1 - state_unprivileged_commands_bootc + state_unprivileged_commands{{{ '_bootc' if bootc else '' }}} +{{% endmacro %}} - - - - - - - + comment="There is one {{{ audit_tool }}} rule for each privileged command on the system."> + + +{{% endmacro %}} - - - - - - +{{% macro arpc_var_priv_cmds_count(audit_tool, bits=None, bootc=False) %}} + - + +{{% endmacro %}} - +{{% macro arpc_state_priv_cmds_count(audit_tool, bits=None, bootc=False) %}} + - - - + var_ref="var_priv_cmds_from_{{{ audit_tool }}}_count{{{ '_bootc' if bootc else '' }}}{{{ ('_' + bits + 'bit') if bits else '' }}}"/> +{{% endmacro %}} - - - - - - - + comment="Count of {{{ audit_tool }}} for priv cmds matches the count of priv cmds in the system"> + + +{{% endmacro %}} + +{{% for bootc in [False, True] %}} + {{{ arpc_variables_and_states(bootc) }}} + {{% if product in ["fedora", "rhel10"] %}} + {{% set bits_options = ["32", "64"] %}} + {{% else %}} + {{% set bits_options = [None] %}} + {{% endif %}} + {{% for bits in bits_options %}} + {{% for audit_tool in ["augenrules", "auditctl"] %}} + {{{ arpc_object_priv_cmds(audit_tool, bits=bits, bootc=bootc) }}} + {{{ arpc_test_all_priv_cmds_covered(audit_tool, bits=bits, bootc=bootc) }}} + {{{ arpc_var_priv_cmds_count(audit_tool, bits=bits, bootc=bootc) }}} + {{{ arpc_state_priv_cmds_count(audit_tool, bits=bits, bootc=bootc) }}} + {{{ arpc_test_count_matches_system_priv_cmds(audit_tool, bits=bits, bootc=bootc) }}} + {{% endfor %}} + {{% endfor %}} +{{% endfor %}} + {{% endif %}} diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/rule.yml b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/rule.yml index ad5a1f91a639..7baee897f2ee 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/rule.yml +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/rule.yml @@ -13,10 +13,16 @@ description: |- setuid / setgid programs using the following command:
$ sudo find PARTITION -xdev -perm /6000 -type f 2>/dev/null
+{{% if product in ["fedora", "rhel10"] %}} For each setuid / setgid program identified by the previous command, an audit rule must be present in the appropriate place using the following line structure, setting ARCH to either b32 for 32-bit system, or having two lines for both b32 and b64 in case your system is 64-bit:
-a always,exit -F arch=ARCH -F path=PROG_PATH -F perm=x -F auid>={{{ auid }}} -F auid!=unset -F key=privileged
+{{% else %}} + For each setuid / setgid program identified by the previous command, an audit rule must be + present in the appropriate place using the following line structure: +
-a always,exit -F path=PROG_PATH -F perm=x -F auid>={{{ auid }}} -F auid!=unset -F key=privileged
+{{% endif %}} If the auditd daemon is configured to use the augenrules program to read audit rules during daemon startup, add the line to a file with suffix .rules in the diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_extra_rules_configured.pass.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_extra_rules_configured.pass.sh index adbf71ccf508..4f991c60a85d 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_extra_rules_configured.pass.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_extra_rules_configured.pass.sh @@ -3,4 +3,9 @@ # platform = multi_platform_fedora,multi_platform_rhel,Oracle Linux 7,Oracle Linux 8,multi_platform_ubuntu ./generate_privileged_commands_rule.sh {{{ uid_min }}} privileged /etc/audit/rules.d/privileged.rules -echo "-a always,exit -F path=/usr/bin/notrelevant -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +{{% if product in ["fedora", "rhel10"] %}} + echo "-a always,exit -F arch=b32 -F path=/usr/bin/notrelevant -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules + echo "-a always,exit -F arch=b64 -F path=/usr/bin/notrelevant -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +{{% else %}} + echo "-a always,exit -F path=/usr/bin/notrelevant -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +{{% endif %}} diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_one_rule.fail.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_one_rule.fail.sh index 2c3c6124c6ba..6e197e75a561 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_one_rule.fail.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_one_rule.fail.sh @@ -1,5 +1,9 @@ #!/bin/bash # packages = audit # platform = multi_platform_fedora,multi_platform_rhel,Oracle Linux 7,Oracle Linux 8,multi_platform_ubuntu - -echo "-a always,exit -F path=/usr/bin/sudo -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +{{% if product in ["fedora", "rhel10"] %}} + echo "-a always,exit -F arch=b32 -F path=/usr/bin/sudo -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules + echo "-a always,exit -F arch=b64 -F path=/usr/bin/sudo -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +{{% else %}} + echo "-a always,exit -F path=/usr/bin/sudo -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +{{% endif %}} diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_two_rules_sep_files.fail.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_two_rules_sep_files.fail.sh index 8f3c02693f5a..6bba4a1c089c 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_two_rules_sep_files.fail.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/augenrules_two_rules_sep_files.fail.sh @@ -2,6 +2,15 @@ # packages = audit # platform = multi_platform_fedora,multi_platform_rhel,Oracle Linux 7,Oracle Linux 8,multi_platform_ubuntu +{{% if product in ["fedora", "rhel10"] %}} +echo "-a always,exit -F arch=b32 -F path=/usr/bin/newgrp -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/priv.rules +echo "-a always,exit -F arch=b64 -F path=/usr/bin/newgrp -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/priv.rules +echo "-a always,exit -F arch=b32 -F path=/usr/bin/notrelevant -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/priv.rules +echo "-a always,exit -F arch=b64 -F path=/usr/bin/notrelevant -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/priv.rules +echo "-a always,exit -F arch=b32 -F path=/usr/bin/passwd -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +echo "-a always,exit -F arch=b64 -F path=/usr/bin/passwd -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +{{% else %}} echo "-a always,exit -F path=/usr/bin/newgrp -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/priv.rules echo "-a always,exit -F path=/usr/bin/notrelevant -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/priv.rules echo "-a always,exit -F path=/usr/bin/passwd -F perm=x -F auid>={{{ uid_min }}} -F auid!=unset -F key=privileged" >> /etc/audit/rules.d/privileged.rules +{{% endif %}} diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/generate_privileged_commands_rule.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/generate_privileged_commands_rule.sh index 7120537185ea..51fe6dc630d4 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/generate_privileged_commands_rule.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/tests/generate_privileged_commands_rule.sh @@ -4,5 +4,12 @@ AUID=$1 KEY=$2 RULEPATH=$3 for file in $(find / -not \( -fstype afs -o -fstype autofs -o -fstype ceph -o -fstype cifs -o -fstype smb3 -o -fstype smbfs -o -fstype sshfs -o -fstype ncpfs -o -fstype ncp -o -fstype nfs -o -fstype nfs4 -o -fstype gfs -o -fstype gfs2 -o -fstype glusterfs -o -fstype gpfs -o -fstype pvfs2 -o -fstype ocfs2 -o -fstype lustre -o -fstype davfs -o -fstype fuse.sshfs \) -type f \( -perm -4000 -o -perm -2000 \) 2> /dev/null); do - echo "-a always,exit -F path=$file -F perm=x -F auid>=$AUID -F auid!=unset -k $KEY" >> $RULEPATH +{{% if product in ["fedora", "rhel10"] %}} + [ "$(getconf LONG_BIT)" = "32" ] && RULE_ARCHS=("b32") || RULE_ARCHS=("b32" "b64") + for ARCH in "${RULE_ARCHS[@]}" ; do + echo "-a always,exit -F arch=$ARCH -F path=$file -F perm=x -F auid>=$AUID -F auid!=unset -k $KEY" >> $RULEPATH + done +{{% else %}} + echo "-a always,exit -F path=$file -F perm=x -F auid>=$AUID -F auid!=unset -k $KEY" >> $RULEPATH +{{% endif %}} done