diff --git a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/ansible/shared.yml b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/ansible/shared.yml index 178a7711a54..9e5172cc5aa 100644 --- a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/ansible/shared.yml +++ b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/ansible/shared.yml @@ -4,22 +4,16 @@ # strategy = restrict # complexity = high # disruption = medium -- name: "Set fact: Package manager reinstall command (dnf)" +- name: "Set fact: Package manager reinstall command" set_fact: - package_manager_reinstall_cmd: dnf reinstall -y - when: ansible_distribution == "Fedora" - -- name: "Set fact: Package manager reinstall command (yum)" - set_fact: - package_manager_reinstall_cmd: yum reinstall -y - when: (ansible_distribution == "RedHat" or ansible_distribution == "CentOS" or ansible_distribution == "OracleLinux") + package_manager_reinstall_cmd: {{{ pkg_manager }}} reinstall -y + when: ansible_distribution in [ "Fedora", "RedHat", "CentOS", "OracleLinux" ] - name: "Set fact: Package manager reinstall command (zypper)" set_fact: package_manager_reinstall_cmd: zypper in -f -y when: ansible_distribution == "SLES" - - name: "Read files with incorrect hash" command: rpm -Va --nodeps --nosize --nomtime --nordev --nocaps --nolinkto --nouser --nogroup --nomode --noghost --noconfig register: files_with_incorrect_hash diff --git a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/bash/shared.sh b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/bash/shared.sh index fe8f7abc14e..a40f350d453 100644 --- a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/bash/shared.sh +++ b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/bash/shared.sh @@ -3,11 +3,13 @@ # Find which files have incorrect hash (not in /etc, because of the system related config files) and then get files names files_with_incorrect_hash="$(rpm -Va --noconfig | grep -E '^..5' | awk '{print $NF}' )" -# From files names get package names and change newline to space, because rpm writes each package to new line -packages_to_reinstall="$(rpm -qf $files_with_incorrect_hash | tr '\n' ' ')" +if [ -n "$files_with_incorrect_hash" ]; then + # From files names get package names and change newline to space, because rpm writes each package to new line + packages_to_reinstall="$(rpm -qf $files_with_incorrect_hash | tr '\n' ' ')" -{{% if product in ["sle12", "sle15"] %}} -{{{ pkg_manager }}} install -f -y $packages_to_reinstall -{{% else %}} -{{{ pkg_manager }}} reinstall -y $packages_to_reinstall -{{% endif %}} + {{% if product in ["sle12", "sle15"] %}} + {{{ pkg_manager }}} install -f -y $packages_to_reinstall + {{% else %}} + {{{ pkg_manager }}} reinstall -y $packages_to_reinstall + {{% endif %}} +fi diff --git a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/oval/shared.xml b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/oval/shared.xml index 58baf253db8..1efa91bcb30 100644 --- a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/oval/shared.xml +++ b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/oval/shared.xml @@ -1,21 +1,29 @@ - + {{{ oval_metadata("Verify the RPM digests of system binaries using the RPM database.") }}} - + - - - - - - - - - - - + + + + fail + false + false + + + + + + + .* .* @@ -23,14 +31,11 @@ .* .* ^/(bin|sbin|lib|lib64|usr)/.+$ - state_files_fail_md5_hash + state_rpm_verify_hashes_fail_md5_hash - - fail - false - - false - - - + + + + diff --git a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/rule.yml b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/rule.yml index 3472f117b5e..91b9b4c9e90 100644 --- a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/rule.yml +++ b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/rule.yml @@ -5,24 +5,23 @@ prodtype: alinux2,alinux3,anolis23,anolis8,fedora,ol7,ol8,ol9,rhel7,rhel8,rhel9, title: 'Verify File Hashes with RPM' description: |- - Without cryptographic integrity protections, system - executables and files can be altered by unauthorized users without - detection. - The RPM package management system can check the hashes of - installed software packages, including many that are important to system - security. - To verify that the cryptographic hash of system files and commands matches vendor - values, run the following command to list which files on the system - have hashes that differ from what is expected by the RPM database: + Without cryptographic integrity protections, system executables and files can be altered by + unauthorized users without detection. The RPM package management system can check the hashes + of installed software packages, including many that are important to system security. + + To verify that the cryptographic hash of system files and commands matches vendor values, run + the following command to list which files on the system have hashes that differ from what is + expected by the RPM database:
$ rpm -Va --noconfig | grep '^..5'
- A "c" in the second column indicates that a file is a configuration file, which - may appropriately be expected to change. If the file was not expected to - change, investigate the cause of the change using audit logs or other means. - The package can then be reinstalled to restore the file. - Run the following command to determine which package owns the file: + + If the file was not expected to change, investigate the cause of the change using audit logs + or other means. The package can then be reinstalled to restore the file. Run the following + command to determine which package owns the file:
$ rpm -qf FILENAME
+ The package can be reinstalled from a {{{ pkg_manager }}} repository using the command:
$ sudo {{{ pkg_manager }}} reinstall PACKAGENAME
+ Alternatively, the package can be reinstalled from trusted media using the command:
$ sudo rpm -Uvh PACKAGENAME
@@ -64,9 +63,9 @@ references: ocil_clause: 'there is output' ocil: |- - The following command will list which files on the system - have file hashes different from what is expected by the RPM database. -
$ rpm -Va --noconfig | awk '$1 ~ /..5/ && $2 != "c"'
+ The following command will list which files on the system have file hashes different from what + is expected by the RPM database. +
$ rpm -Va --noconfig | awk '$1 ~ /..5/'
fixtext: |- Run the following command to determine which package owns the file: @@ -82,3 +81,13 @@ fixtext: |- $ sudo rpm -Uvh [PATH TO RPM] srg_requirement: '{{{ full_name }}} must be configured so that the cryptographic hash of system files and commands matches vendor values.' + +warnings: + - general: |- + This rule can take a long time to perform the check and might consume a considerable + amount of resources depending on the number of packages present on the system. It is not a + problem in most cases, but especially systems with a large number of installed packages + can be affected. + {{% if "rhel" in product %}} + See https://access.redhat.com/articles/6999111. + {{% endif %}} diff --git a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/tests/bad_document.fail.sh b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/tests/bad_document.fail.sh deleted file mode 100644 index e90f77d677a..00000000000 --- a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/tests/bad_document.fail.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# - -# find all TODO files in /usr/share/doc and get first of them -todo_file=$(find /usr/share/doc -name TODO | head -n 1) - -# append space to that file, so it will change digest -echo " " >> $todo_file diff --git a/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/tests/bad_hash_ls.fail.sh b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/tests/bad_hash_ls.fail.sh new file mode 100644 index 00000000000..ab003d07bc4 --- /dev/null +++ b/linux_os/guide/system/software/integrity/software-integrity/rpm_verification/rpm_verify_hashes/tests/bad_hash_ls.fail.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "# CaC rpm_verify_hashes test" >> /bin/ls