Server IP : 184.154.167.98 / Your IP : 3.129.247.57 Web Server : Apache System : Linux pink.dnsnetservice.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64 User : puertode ( 1767) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/scap-security-guide/bash/ |
Upload File : |
#!/usr/bin/env bash ############################################################################### # # Bash Remediation Script for Protection Profile for General Purpose Operating Systems # # Profile Description: # This profile reflects mandatory configuration controls identified in the # NIAP Configuration Annex to the Protection Profile for General Purpose # Operating Systems (Protection Profile Version 4.2.1). # This configuration profile is consistent with CNSSI-1253, which requires # U.S. National Security Systems to adhere to certain configuration # parameters. Accordingly, this configuration profile is suitable for # use in U.S. National Security Systems. # # Profile ID: xccdf_org.ssgproject.content_profile_ospp # Benchmark ID: xccdf_org.ssgproject.content_benchmark_ALMALINUX-8 # Benchmark Version: 0.1.75 # XCCDF Version: 1.2 # # This file can be generated by OpenSCAP using: # $ oscap xccdf generate fix --profile xccdf_org.ssgproject.content_profile_ospp --fix-type bash ssg-almalinux8-ds.xml # # This Bash Remediation Script is generated from an XCCDF profile without preliminary evaluation. # It attempts to fix every selected rule, even if the system is already compliant. # # How to apply this Bash Remediation Script: # $ sudo ./remediation-script.sh # ############################################################################### ############################################################################### # BEGIN fix (1 / 210) for 'xccdf_org.ssgproject.content_rule_package_aide_installed' ############################################################################### (>&2 echo "Remediating rule 1/210: 'xccdf_org.ssgproject.content_rule_package_aide_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "aide" ; then yum install -y "aide" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_aide_installed' ############################################################################### # BEGIN fix (2 / 210) for 'xccdf_org.ssgproject.content_rule_enable_dracut_fips_module' ############################################################################### (>&2 echo "Remediating rule 2/210: 'xccdf_org.ssgproject.content_rule_enable_dracut_fips_module'") # Remediation is applicable only in certain platforms if ( ! ( [ "${container:-}" == "bwrap-osbuild" ] ) && rpm --quiet -q kernel ); then fips-mode-setup --enable FIPS_CONF="/etc/dracut.conf.d/40-fips.conf" if ! grep "^add_dracutmodules+=\" fips \"" $FIPS_CONF; then echo "add_dracutmodules+=\" fips \"" >> $FIPS_CONF fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_enable_dracut_fips_module' ############################################################################### # BEGIN fix (3 / 210) for 'xccdf_org.ssgproject.content_rule_enable_fips_mode' ############################################################################### (>&2 echo "Remediating rule 3/210: 'xccdf_org.ssgproject.content_rule_enable_fips_mode'") # Remediation is applicable only in certain platforms if ( ! ( [ "${container:-}" == "bwrap-osbuild" ] ) && rpm --quiet -q kernel ); then var_system_crypto_policy='FIPS:OSPP' fips-mode-setup --enable stderr_of_call=$(update-crypto-policies --set ${var_system_crypto_policy} 2>&1 > /dev/null) rc=$? if test "$rc" = 127; then echo "$stderr_of_call" >&2 echo "Make sure that the script is installed on the remediated system." >&2 echo "See output of the 'dnf provides update-crypto-policies' command" >&2 echo "to see what package to (re)install" >&2 false # end with an error code elif test "$rc" != 0; then echo "Error invoking the update-crypto-policies script: $stderr_of_call" >&2 false # end with an error code fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_enable_fips_mode' ############################################################################### # BEGIN fix (4 / 210) for 'xccdf_org.ssgproject.content_rule_package_crypto-policies_installed' ############################################################################### (>&2 echo "Remediating rule 4/210: 'xccdf_org.ssgproject.content_rule_package_crypto-policies_installed'") if ! rpm -q --quiet "crypto-policies" ; then yum install -y "crypto-policies" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_crypto-policies_installed' ############################################################################### # BEGIN fix (5 / 210) for 'xccdf_org.ssgproject.content_rule_configure_bind_crypto_policy' ############################################################################### (>&2 echo "Remediating rule 5/210: 'xccdf_org.ssgproject.content_rule_configure_bind_crypto_policy'") # Remediation is applicable only in certain platforms if rpm --quiet -q bind; then function remediate_bind_crypto_policy() { CONFIG_FILE="/etc/named.conf" if test -f "$CONFIG_FILE"; then sed -i 's|options {|&\n\tinclude "/etc/crypto-policies/back-ends/bind.config";|' "$CONFIG_FILE" return 0 else echo "Aborting remediation as '$CONFIG_FILE' was not even found." >&2 return 1 fi } remediate_bind_crypto_policy else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_configure_bind_crypto_policy' ############################################################################### # BEGIN fix (6 / 210) for 'xccdf_org.ssgproject.content_rule_configure_crypto_policy' ############################################################################### (>&2 echo "Remediating rule 6/210: 'xccdf_org.ssgproject.content_rule_configure_crypto_policy'") var_system_crypto_policy='FIPS:OSPP' stderr_of_call=$(update-crypto-policies --set ${var_system_crypto_policy} 2>&1 > /dev/null) rc=$? if test "$rc" = 127; then echo "$stderr_of_call" >&2 echo "Make sure that the script is installed on the remediated system." >&2 echo "See output of the 'dnf provides update-crypto-policies' command" >&2 echo "to see what package to (re)install" >&2 false # end with an error code elif test "$rc" != 0; then echo "Error invoking the update-crypto-policies script: $stderr_of_call" >&2 false # end with an error code fi # END fix for 'xccdf_org.ssgproject.content_rule_configure_crypto_policy' ############################################################################### # BEGIN fix (7 / 210) for 'xccdf_org.ssgproject.content_rule_configure_kerberos_crypto_policy' ############################################################################### (>&2 echo "Remediating rule 7/210: 'xccdf_org.ssgproject.content_rule_configure_kerberos_crypto_policy'") rm -f /etc/krb5.conf.d/crypto-policies ln -s /etc/crypto-policies/back-ends/krb5.config /etc/krb5.conf.d/crypto-policies # END fix for 'xccdf_org.ssgproject.content_rule_configure_kerberos_crypto_policy' ############################################################################### # BEGIN fix (8 / 210) for 'xccdf_org.ssgproject.content_rule_configure_libreswan_crypto_policy' ############################################################################### (>&2 echo "Remediating rule 8/210: 'xccdf_org.ssgproject.content_rule_configure_libreswan_crypto_policy'") function remediate_libreswan_crypto_policy() { CONFIG_FILE="/etc/ipsec.conf" if ! grep -qP "^\s*include\s+/etc/crypto-policies/back-ends/libreswan.config\s*(?:#.*)?$" "$CONFIG_FILE" ; then # the file might not end with a new line echo -e '\ninclude /etc/crypto-policies/back-ends/libreswan.config' >> "$CONFIG_FILE" fi return 0 } remediate_libreswan_crypto_policy # END fix for 'xccdf_org.ssgproject.content_rule_configure_libreswan_crypto_policy' ############################################################################### # BEGIN fix (9 / 210) for 'xccdf_org.ssgproject.content_rule_configure_openssl_crypto_policy' ############################################################################### (>&2 echo "Remediating rule 9/210: 'xccdf_org.ssgproject.content_rule_configure_openssl_crypto_policy'") OPENSSL_CRYPTO_POLICY_SECTION='[ crypto_policy ]' OPENSSL_CRYPTO_POLICY_SECTION_REGEX='\[\s*crypto_policy\s*\]' OPENSSL_CRYPTO_POLICY_INCLUSION='.include /etc/crypto-policies/back-ends/opensslcnf.config' OPENSSL_CRYPTO_POLICY_INCLUSION_REGEX='^\s*\.include\s*(?:=\s*)?/etc/crypto-policies/back-ends/opensslcnf.config$' function remediate_openssl_crypto_policy() { CONFIG_FILE=/etc/pki/tls/openssl.cnf if test -f "$CONFIG_FILE"; then if ! grep -q "^\\s*$OPENSSL_CRYPTO_POLICY_SECTION_REGEX" "$CONFIG_FILE"; then printf '\n%s\n\n%s' "$OPENSSL_CRYPTO_POLICY_SECTION" "$OPENSSL_CRYPTO_POLICY_INCLUSION" >> "$CONFIG_FILE" return 0 elif ! grep -q "^\\s*$OPENSSL_CRYPTO_POLICY_INCLUSION_REGEX" "$CONFIG_FILE"; then sed -i "s|$OPENSSL_CRYPTO_POLICY_SECTION_REGEX|&\\n\\n$OPENSSL_CRYPTO_POLICY_INCLUSION\\n|" "$CONFIG_FILE" return 0 fi else echo "Aborting remediation as '$CONFIG_FILE' was not even found." >&2 return 1 fi } remediate_openssl_crypto_policy # END fix for 'xccdf_org.ssgproject.content_rule_configure_openssl_crypto_policy' ############################################################################### # BEGIN fix (10 / 210) for 'xccdf_org.ssgproject.content_rule_configure_ssh_crypto_policy' ############################################################################### (>&2 echo "Remediating rule 10/210: 'xccdf_org.ssgproject.content_rule_configure_ssh_crypto_policy'") SSH_CONF="/etc/sysconfig/sshd" sed -i "/^\s*CRYPTO_POLICY.*$/Id" $SSH_CONF # END fix for 'xccdf_org.ssgproject.content_rule_configure_ssh_crypto_policy' ############################################################################### # BEGIN fix (11 / 210) for 'xccdf_org.ssgproject.content_rule_openssl_use_strong_entropy' ############################################################################### (>&2 echo "Remediating rule 11/210: 'xccdf_org.ssgproject.content_rule_openssl_use_strong_entropy'") cat > /etc/profile.d/openssl-rand.sh <<- 'EOM' # provide a default -rand /dev/random option to openssl commands that # support it # written inefficiently for maximum shell compatibility openssl() ( openssl_bin=/usr/bin/openssl case "$*" in # if user specified -rand, honor it *\ -rand\ *|*\ -help*) exec $openssl_bin "$@" ;; esac cmds=`$openssl_bin list -digest-commands -cipher-commands | tr '\n' ' '` for i in `$openssl_bin list -commands`; do if $openssl_bin list -options "$i" | grep -q '^rand '; then cmds=" $i $cmds" fi done case "$cmds" in *\ "$1"\ *) cmd="$1"; shift exec $openssl_bin "$cmd" -rand /dev/random "$@" ;; esac exec $openssl_bin "$@" ) EOM # END fix for 'xccdf_org.ssgproject.content_rule_openssl_use_strong_entropy' ############################################################################### # BEGIN fix (12 / 210) for 'xccdf_org.ssgproject.content_rule_partition_for_home' ############################################################################### (>&2 echo "Remediating rule 12/210: 'xccdf_org.ssgproject.content_rule_partition_for_home'") (>&2 echo "FIX FOR THIS RULE 'xccdf_org.ssgproject.content_rule_partition_for_home' IS MISSING!") # END fix for 'xccdf_org.ssgproject.content_rule_partition_for_home' ############################################################################### # BEGIN fix (13 / 210) for 'xccdf_org.ssgproject.content_rule_partition_for_var' ############################################################################### (>&2 echo "Remediating rule 13/210: 'xccdf_org.ssgproject.content_rule_partition_for_var'") (>&2 echo "FIX FOR THIS RULE 'xccdf_org.ssgproject.content_rule_partition_for_var' IS MISSING!") # END fix for 'xccdf_org.ssgproject.content_rule_partition_for_var' ############################################################################### # BEGIN fix (14 / 210) for 'xccdf_org.ssgproject.content_rule_partition_for_var_log' ############################################################################### (>&2 echo "Remediating rule 14/210: 'xccdf_org.ssgproject.content_rule_partition_for_var_log'") (>&2 echo "FIX FOR THIS RULE 'xccdf_org.ssgproject.content_rule_partition_for_var_log' IS MISSING!") # END fix for 'xccdf_org.ssgproject.content_rule_partition_for_var_log' ############################################################################### # BEGIN fix (15 / 210) for 'xccdf_org.ssgproject.content_rule_partition_for_var_log_audit' ############################################################################### (>&2 echo "Remediating rule 15/210: 'xccdf_org.ssgproject.content_rule_partition_for_var_log_audit'") (>&2 echo "FIX FOR THIS RULE 'xccdf_org.ssgproject.content_rule_partition_for_var_log_audit' IS MISSING!") # END fix for 'xccdf_org.ssgproject.content_rule_partition_for_var_log_audit' ############################################################################### # BEGIN fix (16 / 210) for 'xccdf_org.ssgproject.content_rule_partition_for_var_tmp' ############################################################################### (>&2 echo "Remediating rule 16/210: 'xccdf_org.ssgproject.content_rule_partition_for_var_tmp'") (>&2 echo "FIX FOR THIS RULE 'xccdf_org.ssgproject.content_rule_partition_for_var_tmp' IS MISSING!") # END fix for 'xccdf_org.ssgproject.content_rule_partition_for_var_tmp' ############################################################################### # BEGIN fix (17 / 210) for 'xccdf_org.ssgproject.content_rule_package_sudo_installed' ############################################################################### (>&2 echo "Remediating rule 17/210: 'xccdf_org.ssgproject.content_rule_package_sudo_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "sudo" ; then yum install -y "sudo" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_sudo_installed' ############################################################################### # BEGIN fix (18 / 210) for 'xccdf_org.ssgproject.content_rule_package_dnf-plugin-subscription-manager_installed' ############################################################################### (>&2 echo "Remediating rule 18/210: 'xccdf_org.ssgproject.content_rule_package_dnf-plugin-subscription-manager_installed'") if ! rpm -q --quiet "dnf-plugin-subscription-manager" ; then yum install -y "dnf-plugin-subscription-manager" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_dnf-plugin-subscription-manager_installed' ############################################################################### # BEGIN fix (19 / 210) for 'xccdf_org.ssgproject.content_rule_package_gnutls-utils_installed' ############################################################################### (>&2 echo "Remediating rule 19/210: 'xccdf_org.ssgproject.content_rule_package_gnutls-utils_installed'") if ! rpm -q --quiet "gnutls-utils" ; then yum install -y "gnutls-utils" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_gnutls-utils_installed' ############################################################################### # BEGIN fix (20 / 210) for 'xccdf_org.ssgproject.content_rule_package_openscap-scanner_installed' ############################################################################### (>&2 echo "Remediating rule 20/210: 'xccdf_org.ssgproject.content_rule_package_openscap-scanner_installed'") if ! rpm -q --quiet "openscap-scanner" ; then yum install -y "openscap-scanner" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_openscap-scanner_installed' ############################################################################### # BEGIN fix (21 / 210) for 'xccdf_org.ssgproject.content_rule_package_scap-security-guide_installed' ############################################################################### (>&2 echo "Remediating rule 21/210: 'xccdf_org.ssgproject.content_rule_package_scap-security-guide_installed'") if ! rpm -q --quiet "scap-security-guide" ; then yum install -y "scap-security-guide" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_scap-security-guide_installed' ############################################################################### # BEGIN fix (22 / 210) for 'xccdf_org.ssgproject.content_rule_package_subscription-manager_installed' ############################################################################### (>&2 echo "Remediating rule 22/210: 'xccdf_org.ssgproject.content_rule_package_subscription-manager_installed'") if ! rpm -q --quiet "subscription-manager" ; then yum install -y "subscription-manager" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_subscription-manager_installed' ############################################################################### # BEGIN fix (23 / 210) for 'xccdf_org.ssgproject.content_rule_package_abrt-addon-ccpp_removed' ############################################################################### (>&2 echo "Remediating rule 23/210: 'xccdf_org.ssgproject.content_rule_package_abrt-addon-ccpp_removed'") # CAUTION: This remediation script will remove abrt-addon-ccpp # from the system, and may remove any packages # that depend on abrt-addon-ccpp. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "abrt-addon-ccpp" ; then yum remove -y "abrt-addon-ccpp" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_abrt-addon-ccpp_removed' ############################################################################### # BEGIN fix (24 / 210) for 'xccdf_org.ssgproject.content_rule_package_abrt-addon-kerneloops_removed' ############################################################################### (>&2 echo "Remediating rule 24/210: 'xccdf_org.ssgproject.content_rule_package_abrt-addon-kerneloops_removed'") # CAUTION: This remediation script will remove abrt-addon-kerneloops # from the system, and may remove any packages # that depend on abrt-addon-kerneloops. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "abrt-addon-kerneloops" ; then yum remove -y "abrt-addon-kerneloops" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_abrt-addon-kerneloops_removed' ############################################################################### # BEGIN fix (25 / 210) for 'xccdf_org.ssgproject.content_rule_package_abrt-cli_removed' ############################################################################### (>&2 echo "Remediating rule 25/210: 'xccdf_org.ssgproject.content_rule_package_abrt-cli_removed'") # CAUTION: This remediation script will remove abrt-cli # from the system, and may remove any packages # that depend on abrt-cli. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "abrt-cli" ; then yum remove -y "abrt-cli" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_abrt-cli_removed' ############################################################################### # BEGIN fix (26 / 210) for 'xccdf_org.ssgproject.content_rule_package_abrt-plugin-sosreport_removed' ############################################################################### (>&2 echo "Remediating rule 26/210: 'xccdf_org.ssgproject.content_rule_package_abrt-plugin-sosreport_removed'") # CAUTION: This remediation script will remove abrt-plugin-sosreport # from the system, and may remove any packages # that depend on abrt-plugin-sosreport. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "abrt-plugin-sosreport" ; then yum remove -y "abrt-plugin-sosreport" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_abrt-plugin-sosreport_removed' ############################################################################### # BEGIN fix (27 / 210) for 'xccdf_org.ssgproject.content_rule_package_gssproxy_removed' ############################################################################### (>&2 echo "Remediating rule 27/210: 'xccdf_org.ssgproject.content_rule_package_gssproxy_removed'") # CAUTION: This remediation script will remove gssproxy # from the system, and may remove any packages # that depend on gssproxy. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "gssproxy" ; then yum remove -y "gssproxy" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_gssproxy_removed' ############################################################################### # BEGIN fix (28 / 210) for 'xccdf_org.ssgproject.content_rule_package_iprutils_removed' ############################################################################### (>&2 echo "Remediating rule 28/210: 'xccdf_org.ssgproject.content_rule_package_iprutils_removed'") # CAUTION: This remediation script will remove iprutils # from the system, and may remove any packages # that depend on iprutils. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "iprutils" ; then yum remove -y "iprutils" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_iprutils_removed' ############################################################################### # BEGIN fix (29 / 210) for 'xccdf_org.ssgproject.content_rule_package_krb5-workstation_removed' ############################################################################### (>&2 echo "Remediating rule 29/210: 'xccdf_org.ssgproject.content_rule_package_krb5-workstation_removed'") # CAUTION: This remediation script will remove krb5-workstation # from the system, and may remove any packages # that depend on krb5-workstation. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "krb5-workstation" ; then yum remove -y "krb5-workstation" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_krb5-workstation_removed' ############################################################################### # BEGIN fix (30 / 210) for 'xccdf_org.ssgproject.content_rule_package_libreport-plugin-logger_removed' ############################################################################### (>&2 echo "Remediating rule 30/210: 'xccdf_org.ssgproject.content_rule_package_libreport-plugin-logger_removed'") # CAUTION: This remediation script will remove libreport-plugin-logger # from the system, and may remove any packages # that depend on libreport-plugin-logger. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "libreport-plugin-logger" ; then yum remove -y "libreport-plugin-logger" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_libreport-plugin-logger_removed' ############################################################################### # BEGIN fix (31 / 210) for 'xccdf_org.ssgproject.content_rule_package_libreport-plugin-rhtsupport_removed' ############################################################################### (>&2 echo "Remediating rule 31/210: 'xccdf_org.ssgproject.content_rule_package_libreport-plugin-rhtsupport_removed'") # CAUTION: This remediation script will remove libreport-plugin-rhtsupport # from the system, and may remove any packages # that depend on libreport-plugin-rhtsupport. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "libreport-plugin-rhtsupport" ; then yum remove -y "libreport-plugin-rhtsupport" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_libreport-plugin-rhtsupport_removed' ############################################################################### # BEGIN fix (32 / 210) for 'xccdf_org.ssgproject.content_rule_package_python3-abrt-addon_removed' ############################################################################### (>&2 echo "Remediating rule 32/210: 'xccdf_org.ssgproject.content_rule_package_python3-abrt-addon_removed'") # CAUTION: This remediation script will remove python3-abrt-addon # from the system, and may remove any packages # that depend on python3-abrt-addon. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "python3-abrt-addon" ; then yum remove -y "python3-abrt-addon" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_python3-abrt-addon_removed' ############################################################################### # BEGIN fix (33 / 210) for 'xccdf_org.ssgproject.content_rule_package_dnf-automatic_installed' ############################################################################### (>&2 echo "Remediating rule 33/210: 'xccdf_org.ssgproject.content_rule_package_dnf-automatic_installed'") if ! rpm -q --quiet "dnf-automatic" ; then yum install -y "dnf-automatic" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_dnf-automatic_installed' ############################################################################### # BEGIN fix (34 / 210) for 'xccdf_org.ssgproject.content_rule_dnf-automatic_apply_updates' ############################################################################### (>&2 echo "Remediating rule 34/210: 'xccdf_org.ssgproject.content_rule_dnf-automatic_apply_updates'") found=false # set value in all files if they contain section or key for f in $(echo -n "/etc/dnf/automatic.conf"); do if [ ! -e "$f" ]; then continue fi # find key in section and change value if grep -qzosP "[[:space:]]*\[commands\]([^\n\[]*\n+)+?[[:space:]]*apply_updates" "$f"; then sed -i "s/apply_updates[^(\n)]*/apply_updates=yes/" "$f" found=true # find section and add key = value to it elif grep -qs "[[:space:]]*\[commands\]" "$f"; then sed -i "/[[:space:]]*\[commands\]/a apply_updates=yes" "$f" found=true fi done # if section not in any file, append section with key = value to FIRST file in files parameter if ! $found ; then file=$(echo "/etc/dnf/automatic.conf" | cut -f1 -d ' ') mkdir -p "$(dirname "$file")" echo -e "[commands]\napply_updates=yes" >> "$file" fi # END fix for 'xccdf_org.ssgproject.content_rule_dnf-automatic_apply_updates' ############################################################################### # BEGIN fix (35 / 210) for 'xccdf_org.ssgproject.content_rule_dnf-automatic_security_updates_only' ############################################################################### (>&2 echo "Remediating rule 35/210: 'xccdf_org.ssgproject.content_rule_dnf-automatic_security_updates_only'") found=false # set value in all files if they contain section or key for f in $(echo -n "/etc/dnf/automatic.conf"); do if [ ! -e "$f" ]; then continue fi # find key in section and change value if grep -qzosP "[[:space:]]*\[commands\]([^\n\[]*\n+)+?[[:space:]]*upgrade_type" "$f"; then sed -i "s/upgrade_type[^(\n)]*/upgrade_type=security/" "$f" found=true # find section and add key = value to it elif grep -qs "[[:space:]]*\[commands\]" "$f"; then sed -i "/[[:space:]]*\[commands\]/a upgrade_type=security" "$f" found=true fi done # if section not in any file, append section with key = value to FIRST file in files parameter if ! $found ; then file=$(echo "/etc/dnf/automatic.conf" | cut -f1 -d ' ') mkdir -p "$(dirname "$file")" echo -e "[commands]\nupgrade_type=security" >> "$file" fi # END fix for 'xccdf_org.ssgproject.content_rule_dnf-automatic_security_updates_only' ############################################################################### # BEGIN fix (36 / 210) for 'xccdf_org.ssgproject.content_rule_ensure_almalinux_gpgkey_installed' ############################################################################### (>&2 echo "Remediating rule 36/210: 'xccdf_org.ssgproject.content_rule_ensure_almalinux_gpgkey_installed'") readonly ALMALINUX_FINGERPRINT="5E9B8F5617B5066CE92057C3488FCF7C3ABB34F8" readonly ALMALINUX_AUXILIARY_FINGERPRINT="BC5EDDCADF502C077F1582882AE81E8ACED7258B" # Location of the key we would like to import (once it's integrity verified) readonly ALMALINUX_RELEASE_KEY="/etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux" RPM_GPG_DIR_PERMS=$(stat -c %a "$(dirname "$ALMALINUX_RELEASE_KEY")") # Verify /etc/pki/rpm-gpg directory permissions are safe if [ "${RPM_GPG_DIR_PERMS}" -le "755" ] then # If they are safe, try to obtain fingerprints from the key file # (to ensure there won't be e.g. CRC error) readarray -t GPG_OUT < <(gpg --show-keys --with-fingerprint --with-colons "$REDHAT_RELEASE_KEY" | grep -A1 "^pub" | grep "^fpr" | cut -d ":" -f 10) GPG_RESULT=$? # No CRC error, safe to proceed if [ "${GPG_RESULT}" -eq "0" ] then # Filter just hexadecimal fingerprints from gpg's output from # processing of a key file echo "${GPG_OUT[*]}" | grep -vE "${ALMALINUX_FINGERPRINT}|${ALMALINUX_AUXILIARY_FINGERPRINT}" || { # If $ALMALINUX_RELEASE_KEY file doesn't contain any keys with unknown fingerprint, import it rpm --import "${ALMALINUX_RELEASE_KEY}" } fi fi # END fix for 'xccdf_org.ssgproject.content_rule_ensure_almalinux_gpgkey_installed' ############################################################################### # BEGIN fix (37 / 210) for 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_globally_activated' ############################################################################### (>&2 echo "Remediating rule 37/210: 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_globally_activated'") # Remediation is applicable only in certain platforms if rpm --quiet -q yum; then # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^gpgcheck") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "1" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^gpgcheck\\>" "/etc/yum.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^gpgcheck\\>.*/$escaped_formatted_output/gi" "/etc/yum.conf" else if [[ -s "/etc/yum.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/yum.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/yum.conf" fi printf '%s\n' "$formatted_output" >> "/etc/yum.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_globally_activated' ############################################################################### # BEGIN fix (38 / 210) for 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_local_packages' ############################################################################### (>&2 echo "Remediating rule 38/210: 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_local_packages'") # Remediation is applicable only in certain platforms if rpm --quiet -q yum; then # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^localpkg_gpgcheck") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "1" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^localpkg_gpgcheck\\>" "/etc/yum.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^localpkg_gpgcheck\\>.*/$escaped_formatted_output/gi" "/etc/yum.conf" else if [[ -s "/etc/yum.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/yum.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/yum.conf" fi printf '%s\n' "$formatted_output" >> "/etc/yum.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_local_packages' ############################################################################### # BEGIN fix (39 / 210) for 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_never_disabled' ############################################################################### (>&2 echo "Remediating rule 39/210: 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_never_disabled'") sed -i 's/gpgcheck\s*=.*/gpgcheck=1/g' /etc/yum.repos.d/* # END fix for 'xccdf_org.ssgproject.content_rule_ensure_gpgcheck_never_disabled' ############################################################################### # BEGIN fix (40 / 210) for 'xccdf_org.ssgproject.content_rule_timer_dnf-automatic_enabled' ############################################################################### (>&2 echo "Remediating rule 40/210: 'xccdf_org.ssgproject.content_rule_timer_dnf-automatic_enabled'") SYSTEMCTL_EXEC='/usr/bin/systemctl' "$SYSTEMCTL_EXEC" start 'dnf-automatic.timer' "$SYSTEMCTL_EXEC" enable 'dnf-automatic.timer' # END fix for 'xccdf_org.ssgproject.content_rule_timer_dnf-automatic_enabled' ############################################################################### # BEGIN fix (41 / 210) for 'xccdf_org.ssgproject.content_rule_enable_authselect' ############################################################################### (>&2 echo "Remediating rule 41/210: 'xccdf_org.ssgproject.content_rule_enable_authselect'") var_authselect_profile='minimal' authselect current if test "$?" -ne 0; then authselect select "$var_authselect_profile" if test "$?" -ne 0; then if rpm --quiet --verify pam; then authselect select --force "$var_authselect_profile" else echo "authselect is not used but files from the 'pam' package have been altered, so the authselect configuration won't be forced." >&2 fi fi fi # END fix for 'xccdf_org.ssgproject.content_rule_enable_authselect' ############################################################################### # BEGIN fix (42 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_unix_remember' ############################################################################### (>&2 echo "Remediating rule 42/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_unix_remember'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_unix_remember='5' if [ -f /usr/bin/authselect ]; then if authselect list-features sssd | grep -q with-pwhistory; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi authselect enable-feature with-pwhistory authselect apply-changes -b else if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi CURRENT_PROFILE=$(authselect current -r | awk '{ print $1 }') # If not already in use, a custom profile is created preserving the enabled features. if [[ ! $CURRENT_PROFILE == custom/* ]]; then ENABLED_FEATURES=$(authselect current | tail -n+3 | awk '{ print $2 }') authselect create-profile hardening -b $CURRENT_PROFILE CURRENT_PROFILE="custom/hardening" authselect apply-changes -b --backup=before-hardening-custom-profile authselect select $CURRENT_PROFILE for feature in $ENABLED_FEATURES; do authselect enable-feature $feature; done authselect apply-changes -b --backup=after-hardening-custom-profile fi PAM_FILE_NAME=$(basename "/etc/pam.d/system-auth") PAM_FILE_PATH="/etc/authselect/$CURRENT_PROFILE/$PAM_FILE_NAME" authselect apply-changes -b if ! grep -qP "^\s*password\s+requisite\s+pam_pwhistory.so\s*.*" "$PAM_FILE_PATH"; then # Line matching group + control + module was not found. Check group + module. if [ "$(grep -cP '^\s*password\s+.*\s+pam_pwhistory.so\s*' "$PAM_FILE_PATH")" -eq 1 ]; then # The control is updated only if one single line matches. sed -i -E --follow-symlinks "s/^(\s*password\s+).*(\bpam_pwhistory.so.*)/\1requisite \2/" "$PAM_FILE_PATH" else LAST_MATCH_LINE=$(grep -nP "^password.*requisite.*pam_pwquality\.so" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1) if [ ! -z $LAST_MATCH_LINE ]; then sed -i --follow-symlinks $LAST_MATCH_LINE" a password requisite pam_pwhistory.so" "$PAM_FILE_PATH" else echo "password requisite pam_pwhistory.so" >> "$PAM_FILE_PATH" fi fi fi fi else if ! grep -qP "^\s*password\s+requisite\s+pam_pwhistory.so\s*.*" "/etc/pam.d/system-auth"; then # Line matching group + control + module was not found. Check group + module. if [ "$(grep -cP '^\s*password\s+.*\s+pam_pwhistory.so\s*' "/etc/pam.d/system-auth")" -eq 1 ]; then # The control is updated only if one single line matches. sed -i -E --follow-symlinks "s/^(\s*password\s+).*(\bpam_pwhistory.so.*)/\1requisite \2/" "/etc/pam.d/system-auth" else LAST_MATCH_LINE=$(grep -nP "^password.*requisite.*pam_pwquality\.so" "/etc/pam.d/system-auth" | tail -n 1 | cut -d: -f 1) if [ ! -z $LAST_MATCH_LINE ]; then sed -i --follow-symlinks $LAST_MATCH_LINE" a password requisite pam_pwhistory.so" "/etc/pam.d/system-auth" else echo "password requisite pam_pwhistory.so" >> "/etc/pam.d/system-auth" fi fi fi fi PWHISTORY_CONF="/etc/security/pwhistory.conf" if [ -f $PWHISTORY_CONF ]; then regex="^\s*remember\s*=" line="remember = $var_password_pam_unix_remember" if ! grep -q $regex $PWHISTORY_CONF; then echo $line >> $PWHISTORY_CONF else sed -i --follow-symlinks 's|^\s*\(remember\s*=\s*\)\(\S\+\)|\1'"$var_password_pam_unix_remember"'|g' $PWHISTORY_CONF fi if [ -e "/etc/pam.d/system-auth" ] ; then PAM_FILE_PATH="/etc/pam.d/system-auth" if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi CURRENT_PROFILE=$(authselect current -r | awk '{ print $1 }') # If not already in use, a custom profile is created preserving the enabled features. if [[ ! $CURRENT_PROFILE == custom/* ]]; then ENABLED_FEATURES=$(authselect current | tail -n+3 | awk '{ print $2 }') authselect create-profile hardening -b $CURRENT_PROFILE CURRENT_PROFILE="custom/hardening" authselect apply-changes -b --backup=before-hardening-custom-profile authselect select $CURRENT_PROFILE for feature in $ENABLED_FEATURES; do authselect enable-feature $feature; done authselect apply-changes -b --backup=after-hardening-custom-profile fi PAM_FILE_NAME=$(basename "/etc/pam.d/system-auth") PAM_FILE_PATH="/etc/authselect/$CURRENT_PROFILE/$PAM_FILE_NAME" authselect apply-changes -b fi if grep -qP "^\s*password\s.*\bpam_pwhistory.so\s.*\bremember\b" "$PAM_FILE_PATH"; then sed -i -E --follow-symlinks "s/(.*password.*pam_pwhistory.so.*)\bremember\b=?[[:alnum:]]*(.*)/\1\2/g" "$PAM_FILE_PATH" fi if [ -f /usr/bin/authselect ]; then authselect apply-changes -b fi else echo "/etc/pam.d/system-auth was not found" >&2 fi else PAM_FILE_PATH="/etc/pam.d/system-auth" if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi CURRENT_PROFILE=$(authselect current -r | awk '{ print $1 }') # If not already in use, a custom profile is created preserving the enabled features. if [[ ! $CURRENT_PROFILE == custom/* ]]; then ENABLED_FEATURES=$(authselect current | tail -n+3 | awk '{ print $2 }') authselect create-profile hardening -b $CURRENT_PROFILE CURRENT_PROFILE="custom/hardening" authselect apply-changes -b --backup=before-hardening-custom-profile authselect select $CURRENT_PROFILE for feature in $ENABLED_FEATURES; do authselect enable-feature $feature; done authselect apply-changes -b --backup=after-hardening-custom-profile fi PAM_FILE_NAME=$(basename "/etc/pam.d/system-auth") PAM_FILE_PATH="/etc/authselect/$CURRENT_PROFILE/$PAM_FILE_NAME" authselect apply-changes -b fi if ! grep -qP "^\s*password\s+requisite\s+pam_pwhistory.so\s*.*" "$PAM_FILE_PATH"; then # Line matching group + control + module was not found. Check group + module. if [ "$(grep -cP '^\s*password\s+.*\s+pam_pwhistory.so\s*' "$PAM_FILE_PATH")" -eq 1 ]; then # The control is updated only if one single line matches. sed -i -E --follow-symlinks "s/^(\s*password\s+).*(\bpam_pwhistory.so.*)/\1requisite \2/" "$PAM_FILE_PATH" else echo "password requisite pam_pwhistory.so" >> "$PAM_FILE_PATH" fi fi # Check the option if ! grep -qP "^\s*password\s+requisite\s+pam_pwhistory.so\s*.*\sremember\b" "$PAM_FILE_PATH"; then sed -i -E --follow-symlinks "/\s*password\s+requisite\s+pam_pwhistory.so.*/ s/$/ remember=$var_password_pam_unix_remember/" "$PAM_FILE_PATH" else sed -i -E --follow-symlinks "s/(\s*password\s+requisite\s+pam_pwhistory.so\s+.*)(remember=)[[:alnum:]]+\s*(.*)/\1\2$var_password_pam_unix_remember \3/" "$PAM_FILE_PATH" fi if [ -f /usr/bin/authselect ]; then authselect apply-changes -b fi fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_unix_remember' ############################################################################### # BEGIN fix (43 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny' ############################################################################### (>&2 echo "Remediating rule 43/210: 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_accounts_passwords_pam_faillock_deny='3' if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi authselect enable-feature with-faillock authselect apply-changes -b else AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth") for pam_file in "${AUTH_FILES[@]}" do if ! grep -qE '^\s*auth\s+required\s+pam_faillock\.so\s+(preauth silent|authfail).*$' "$pam_file" ; then sed -i --follow-symlinks '/^auth.*sufficient.*pam_unix\.so.*/i auth required pam_faillock.so preauth silent' "$pam_file" sed -i --follow-symlinks '/^auth.*required.*pam_deny\.so.*/i auth required pam_faillock.so authfail' "$pam_file" sed -i --follow-symlinks '/^account.*required.*pam_unix\.so.*/i account required pam_faillock.so' "$pam_file" fi sed -Ei 's/(auth.*)(\[default=die\])(.*pam_faillock\.so)/\1required \3/g' "$pam_file" done fi AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth") FAILLOCK_CONF="/etc/security/faillock.conf" if [ -f $FAILLOCK_CONF ]; then regex="^\s*deny\s*=" line="deny = $var_accounts_passwords_pam_faillock_deny" if ! grep -q $regex $FAILLOCK_CONF; then echo $line >> $FAILLOCK_CONF else sed -i --follow-symlinks 's|^\s*\(deny\s*=\s*\)\(\S\+\)|\1'"$var_accounts_passwords_pam_faillock_deny"'|g' $FAILLOCK_CONF fi for pam_file in "${AUTH_FILES[@]}" do if [ -e "$pam_file" ] ; then PAM_FILE_PATH="$pam_file" if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi CURRENT_PROFILE=$(authselect current -r | awk '{ print $1 }') # If not already in use, a custom profile is created preserving the enabled features. if [[ ! $CURRENT_PROFILE == custom/* ]]; then ENABLED_FEATURES=$(authselect current | tail -n+3 | awk '{ print $2 }') authselect create-profile hardening -b $CURRENT_PROFILE CURRENT_PROFILE="custom/hardening" authselect apply-changes -b --backup=before-hardening-custom-profile authselect select $CURRENT_PROFILE for feature in $ENABLED_FEATURES; do authselect enable-feature $feature; done authselect apply-changes -b --backup=after-hardening-custom-profile fi PAM_FILE_NAME=$(basename "$pam_file") PAM_FILE_PATH="/etc/authselect/$CURRENT_PROFILE/$PAM_FILE_NAME" authselect apply-changes -b fi if grep -qP "^\s*auth\s.*\bpam_faillock.so\s.*\bdeny\b" "$PAM_FILE_PATH"; then sed -i -E --follow-symlinks "s/(.*auth.*pam_faillock.so.*)\bdeny\b=?[[:alnum:]]*(.*)/\1\2/g" "$PAM_FILE_PATH" fi if [ -f /usr/bin/authselect ]; then authselect apply-changes -b fi else echo "$pam_file was not found" >&2 fi done else for pam_file in "${AUTH_FILES[@]}" do if ! grep -qE '^\s*auth.*pam_faillock\.so (preauth|authfail).*deny' "$pam_file"; then sed -i --follow-symlinks '/^auth.*required.*pam_faillock\.so.*preauth.*silent.*/ s/$/ deny='"$var_accounts_passwords_pam_faillock_deny"'/' "$pam_file" sed -i --follow-symlinks '/^auth.*required.*pam_faillock\.so.*authfail.*/ s/$/ deny='"$var_accounts_passwords_pam_faillock_deny"'/' "$pam_file" else sed -i --follow-symlinks 's/\(^auth.*required.*pam_faillock\.so.*preauth.*silent.*\)\('"deny"'=\)[0-9]\+\(.*\)/\1\2'"$var_accounts_passwords_pam_faillock_deny"'\3/' "$pam_file" sed -i --follow-symlinks 's/\(^auth.*required.*pam_faillock\.so.*authfail.*\)\('"deny"'=\)[0-9]\+\(.*\)/\1\2'"$var_accounts_passwords_pam_faillock_deny"'\3/' "$pam_file" fi done fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny' ############################################################################### # BEGIN fix (44 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_interval' ############################################################################### (>&2 echo "Remediating rule 44/210: 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_interval'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_accounts_passwords_pam_faillock_fail_interval='900' if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi authselect enable-feature with-faillock authselect apply-changes -b else AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth") for pam_file in "${AUTH_FILES[@]}" do if ! grep -qE '^\s*auth\s+required\s+pam_faillock\.so\s+(preauth silent|authfail).*$' "$pam_file" ; then sed -i --follow-symlinks '/^auth.*sufficient.*pam_unix\.so.*/i auth required pam_faillock.so preauth silent' "$pam_file" sed -i --follow-symlinks '/^auth.*required.*pam_deny\.so.*/i auth required pam_faillock.so authfail' "$pam_file" sed -i --follow-symlinks '/^account.*required.*pam_unix\.so.*/i account required pam_faillock.so' "$pam_file" fi sed -Ei 's/(auth.*)(\[default=die\])(.*pam_faillock\.so)/\1required \3/g' "$pam_file" done fi AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth") FAILLOCK_CONF="/etc/security/faillock.conf" if [ -f $FAILLOCK_CONF ]; then regex="^\s*fail_interval\s*=" line="fail_interval = $var_accounts_passwords_pam_faillock_fail_interval" if ! grep -q $regex $FAILLOCK_CONF; then echo $line >> $FAILLOCK_CONF else sed -i --follow-symlinks 's|^\s*\(fail_interval\s*=\s*\)\(\S\+\)|\1'"$var_accounts_passwords_pam_faillock_fail_interval"'|g' $FAILLOCK_CONF fi for pam_file in "${AUTH_FILES[@]}" do if [ -e "$pam_file" ] ; then PAM_FILE_PATH="$pam_file" if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi CURRENT_PROFILE=$(authselect current -r | awk '{ print $1 }') # If not already in use, a custom profile is created preserving the enabled features. if [[ ! $CURRENT_PROFILE == custom/* ]]; then ENABLED_FEATURES=$(authselect current | tail -n+3 | awk '{ print $2 }') authselect create-profile hardening -b $CURRENT_PROFILE CURRENT_PROFILE="custom/hardening" authselect apply-changes -b --backup=before-hardening-custom-profile authselect select $CURRENT_PROFILE for feature in $ENABLED_FEATURES; do authselect enable-feature $feature; done authselect apply-changes -b --backup=after-hardening-custom-profile fi PAM_FILE_NAME=$(basename "$pam_file") PAM_FILE_PATH="/etc/authselect/$CURRENT_PROFILE/$PAM_FILE_NAME" authselect apply-changes -b fi if grep -qP "^\s*auth\s.*\bpam_faillock.so\s.*\bfail_interval\b" "$PAM_FILE_PATH"; then sed -i -E --follow-symlinks "s/(.*auth.*pam_faillock.so.*)\bfail_interval\b=?[[:alnum:]]*(.*)/\1\2/g" "$PAM_FILE_PATH" fi if [ -f /usr/bin/authselect ]; then authselect apply-changes -b fi else echo "$pam_file was not found" >&2 fi done else for pam_file in "${AUTH_FILES[@]}" do if ! grep -qE '^\s*auth.*pam_faillock\.so (preauth|authfail).*fail_interval' "$pam_file"; then sed -i --follow-symlinks '/^auth.*required.*pam_faillock\.so.*preauth.*silent.*/ s/$/ fail_interval='"$var_accounts_passwords_pam_faillock_fail_interval"'/' "$pam_file" sed -i --follow-symlinks '/^auth.*required.*pam_faillock\.so.*authfail.*/ s/$/ fail_interval='"$var_accounts_passwords_pam_faillock_fail_interval"'/' "$pam_file" else sed -i --follow-symlinks 's/\(^auth.*required.*pam_faillock\.so.*preauth.*silent.*\)\('"fail_interval"'=\)[0-9]\+\(.*\)/\1\2'"$var_accounts_passwords_pam_faillock_fail_interval"'\3/' "$pam_file" sed -i --follow-symlinks 's/\(^auth.*required.*pam_faillock\.so.*authfail.*\)\('"fail_interval"'=\)[0-9]\+\(.*\)/\1\2'"$var_accounts_passwords_pam_faillock_fail_interval"'\3/' "$pam_file" fi done fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_interval' ############################################################################### # BEGIN fix (45 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_unlock_time' ############################################################################### (>&2 echo "Remediating rule 45/210: 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_unlock_time'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_accounts_passwords_pam_faillock_unlock_time='0' if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi authselect enable-feature with-faillock authselect apply-changes -b else AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth") for pam_file in "${AUTH_FILES[@]}" do if ! grep -qE '^\s*auth\s+required\s+pam_faillock\.so\s+(preauth silent|authfail).*$' "$pam_file" ; then sed -i --follow-symlinks '/^auth.*sufficient.*pam_unix\.so.*/i auth required pam_faillock.so preauth silent' "$pam_file" sed -i --follow-symlinks '/^auth.*required.*pam_deny\.so.*/i auth required pam_faillock.so authfail' "$pam_file" sed -i --follow-symlinks '/^account.*required.*pam_unix\.so.*/i account required pam_faillock.so' "$pam_file" fi sed -Ei 's/(auth.*)(\[default=die\])(.*pam_faillock\.so)/\1required \3/g' "$pam_file" done fi AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth") FAILLOCK_CONF="/etc/security/faillock.conf" if [ -f $FAILLOCK_CONF ]; then regex="^\s*unlock_time\s*=" line="unlock_time = $var_accounts_passwords_pam_faillock_unlock_time" if ! grep -q $regex $FAILLOCK_CONF; then echo $line >> $FAILLOCK_CONF else sed -i --follow-symlinks 's|^\s*\(unlock_time\s*=\s*\)\(\S\+\)|\1'"$var_accounts_passwords_pam_faillock_unlock_time"'|g' $FAILLOCK_CONF fi for pam_file in "${AUTH_FILES[@]}" do if [ -e "$pam_file" ] ; then PAM_FILE_PATH="$pam_file" if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi CURRENT_PROFILE=$(authselect current -r | awk '{ print $1 }') # If not already in use, a custom profile is created preserving the enabled features. if [[ ! $CURRENT_PROFILE == custom/* ]]; then ENABLED_FEATURES=$(authselect current | tail -n+3 | awk '{ print $2 }') authselect create-profile hardening -b $CURRENT_PROFILE CURRENT_PROFILE="custom/hardening" authselect apply-changes -b --backup=before-hardening-custom-profile authselect select $CURRENT_PROFILE for feature in $ENABLED_FEATURES; do authselect enable-feature $feature; done authselect apply-changes -b --backup=after-hardening-custom-profile fi PAM_FILE_NAME=$(basename "$pam_file") PAM_FILE_PATH="/etc/authselect/$CURRENT_PROFILE/$PAM_FILE_NAME" authselect apply-changes -b fi if grep -qP "^\s*auth\s.*\bpam_faillock.so\s.*\bunlock_time\b" "$PAM_FILE_PATH"; then sed -i -E --follow-symlinks "s/(.*auth.*pam_faillock.so.*)\bunlock_time\b=?[[:alnum:]]*(.*)/\1\2/g" "$PAM_FILE_PATH" fi if [ -f /usr/bin/authselect ]; then authselect apply-changes -b fi else echo "$pam_file was not found" >&2 fi done else for pam_file in "${AUTH_FILES[@]}" do if ! grep -qE '^\s*auth.*pam_faillock\.so (preauth|authfail).*unlock_time' "$pam_file"; then sed -i --follow-symlinks '/^auth.*required.*pam_faillock\.so.*preauth.*silent.*/ s/$/ unlock_time='"$var_accounts_passwords_pam_faillock_unlock_time"'/' "$pam_file" sed -i --follow-symlinks '/^auth.*required.*pam_faillock\.so.*authfail.*/ s/$/ unlock_time='"$var_accounts_passwords_pam_faillock_unlock_time"'/' "$pam_file" else sed -i --follow-symlinks 's/\(^auth.*required.*pam_faillock\.so.*preauth.*silent.*\)\('"unlock_time"'=\)[0-9]\+\(.*\)/\1\2'"$var_accounts_passwords_pam_faillock_unlock_time"'\3/' "$pam_file" sed -i --follow-symlinks 's/\(^auth.*required.*pam_faillock\.so.*authfail.*\)\('"unlock_time"'=\)[0-9]\+\(.*\)/\1\2'"$var_accounts_passwords_pam_faillock_unlock_time"'\3/' "$pam_file" fi done fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_unlock_time' ############################################################################### # BEGIN fix (46 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_dcredit' ############################################################################### (>&2 echo "Remediating rule 46/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_dcredit'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_dcredit='-1' # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^dcredit") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$var_password_pam_dcredit" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^dcredit\\>" "/etc/security/pwquality.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^dcredit\\>.*/$escaped_formatted_output/gi" "/etc/security/pwquality.conf" else if [[ -s "/etc/security/pwquality.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/security/pwquality.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/security/pwquality.conf" fi printf '%s\n' "$formatted_output" >> "/etc/security/pwquality.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_dcredit' ############################################################################### # BEGIN fix (47 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_difok' ############################################################################### (>&2 echo "Remediating rule 47/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_difok'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_difok='4' # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^difok") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$var_password_pam_difok" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^difok\\>" "/etc/security/pwquality.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^difok\\>.*/$escaped_formatted_output/gi" "/etc/security/pwquality.conf" else if [[ -s "/etc/security/pwquality.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/security/pwquality.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/security/pwquality.conf" fi printf '%s\n' "$formatted_output" >> "/etc/security/pwquality.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_difok' ############################################################################### # BEGIN fix (48 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_lcredit' ############################################################################### (>&2 echo "Remediating rule 48/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_lcredit'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_lcredit='-1' # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^lcredit") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$var_password_pam_lcredit" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^lcredit\\>" "/etc/security/pwquality.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^lcredit\\>.*/$escaped_formatted_output/gi" "/etc/security/pwquality.conf" else if [[ -s "/etc/security/pwquality.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/security/pwquality.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/security/pwquality.conf" fi printf '%s\n' "$formatted_output" >> "/etc/security/pwquality.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_lcredit' ############################################################################### # BEGIN fix (49 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_maxclassrepeat' ############################################################################### (>&2 echo "Remediating rule 49/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_maxclassrepeat'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_maxclassrepeat='4' # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^maxclassrepeat") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$var_password_pam_maxclassrepeat" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^maxclassrepeat\\>" "/etc/security/pwquality.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^maxclassrepeat\\>.*/$escaped_formatted_output/gi" "/etc/security/pwquality.conf" else if [[ -s "/etc/security/pwquality.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/security/pwquality.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/security/pwquality.conf" fi printf '%s\n' "$formatted_output" >> "/etc/security/pwquality.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_maxclassrepeat' ############################################################################### # BEGIN fix (50 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_maxrepeat' ############################################################################### (>&2 echo "Remediating rule 50/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_maxrepeat'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_maxrepeat='3' # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^maxrepeat") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$var_password_pam_maxrepeat" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^maxrepeat\\>" "/etc/security/pwquality.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^maxrepeat\\>.*/$escaped_formatted_output/gi" "/etc/security/pwquality.conf" else if [[ -s "/etc/security/pwquality.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/security/pwquality.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/security/pwquality.conf" fi printf '%s\n' "$formatted_output" >> "/etc/security/pwquality.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_maxrepeat' ############################################################################### # BEGIN fix (51 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_minlen' ############################################################################### (>&2 echo "Remediating rule 51/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_minlen'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_minlen='12' # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^minlen") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$var_password_pam_minlen" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^minlen\\>" "/etc/security/pwquality.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^minlen\\>.*/$escaped_formatted_output/gi" "/etc/security/pwquality.conf" else if [[ -s "/etc/security/pwquality.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/security/pwquality.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/security/pwquality.conf" fi printf '%s\n' "$formatted_output" >> "/etc/security/pwquality.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_minlen' ############################################################################### # BEGIN fix (52 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_ocredit' ############################################################################### (>&2 echo "Remediating rule 52/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_ocredit'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_ocredit='-1' # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^ocredit") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$var_password_pam_ocredit" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^ocredit\\>" "/etc/security/pwquality.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^ocredit\\>.*/$escaped_formatted_output/gi" "/etc/security/pwquality.conf" else if [[ -s "/etc/security/pwquality.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/security/pwquality.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/security/pwquality.conf" fi printf '%s\n' "$formatted_output" >> "/etc/security/pwquality.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_ocredit' ############################################################################### # BEGIN fix (53 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_ucredit' ############################################################################### (>&2 echo "Remediating rule 53/210: 'xccdf_org.ssgproject.content_rule_accounts_password_pam_ucredit'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_password_pam_ucredit='-1' # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^ucredit") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$var_password_pam_ucredit" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^ucredit\\>" "/etc/security/pwquality.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^ucredit\\>.*/$escaped_formatted_output/gi" "/etc/security/pwquality.conf" else if [[ -s "/etc/security/pwquality.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/security/pwquality.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/security/pwquality.conf" fi printf '%s\n' "$formatted_output" >> "/etc/security/pwquality.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_password_pam_ucredit' ############################################################################### # BEGIN fix (54 / 210) for 'xccdf_org.ssgproject.content_rule_service_debug-shell_disabled' ############################################################################### (>&2 echo "Remediating rule 54/210: 'xccdf_org.ssgproject.content_rule_service_debug-shell_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then SYSTEMCTL_EXEC='/usr/bin/systemctl' "$SYSTEMCTL_EXEC" stop 'debug-shell.service' "$SYSTEMCTL_EXEC" disable 'debug-shell.service' "$SYSTEMCTL_EXEC" mask 'debug-shell.service' # Disable socket activation if we have a unit file for it if "$SYSTEMCTL_EXEC" -q list-unit-files debug-shell.socket; then "$SYSTEMCTL_EXEC" stop 'debug-shell.socket' "$SYSTEMCTL_EXEC" mask 'debug-shell.socket' fi # The service may not be running because it has been started and failed, # so let's reset the state so OVAL checks pass. # Service should be 'inactive', not 'failed' after reboot though. "$SYSTEMCTL_EXEC" reset-failed 'debug-shell.service' || true else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_service_debug-shell_disabled' ############################################################################### # BEGIN fix (55 / 210) for 'xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_burstaction' ############################################################################### (>&2 echo "Remediating rule 55/210: 'xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_burstaction'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q systemd; }; then # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^CtrlAltDelBurstAction=") # shellcheck disable=SC2059 printf -v formatted_output "%s=%s" "$stripped_key" "none" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^CtrlAltDelBurstAction=\\>" "/etc/systemd/system.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^CtrlAltDelBurstAction=\\>.*/$escaped_formatted_output/gi" "/etc/systemd/system.conf" else if [[ -s "/etc/systemd/system.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/systemd/system.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/systemd/system.conf" fi printf '%s\n' "$formatted_output" >> "/etc/systemd/system.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_burstaction' ############################################################################### # BEGIN fix (56 / 210) for 'xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_reboot' ############################################################################### (>&2 echo "Remediating rule 56/210: 'xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_reboot'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [[ "$OSCAP_BOOTC_BUILD" == "YES" ]] ; then systemctl disable ctrl-alt-del.target systemctl mask ctrl-alt-del.target else systemctl disable --now ctrl-alt-del.target systemctl mask --now ctrl-alt-del.target fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_reboot' ############################################################################### # BEGIN fix (57 / 210) for 'xccdf_org.ssgproject.content_rule_require_singleuser_auth' ############################################################################### (>&2 echo "Remediating rule 57/210: 'xccdf_org.ssgproject.content_rule_require_singleuser_auth'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then found=false # set value in all files if they contain section or key for f in $(echo -n "/etc/systemd/system/rescue.service.d/10-oscap.conf"); do if [ ! -e "$f" ]; then continue fi # find key in section and change value if grep -qzosP "[[:space:]]*\[Service\]([^\n\[]*\n+)+?[[:space:]]*ExecStart" "$f"; then sed -i "s/ExecStart[^(\n)]*/ExecStart=-/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"/" "$f" found=true # find section and add key = value to it elif grep -qs "[[:space:]]*\[Service\]" "$f"; then sed -i "/[[:space:]]*\[Service\]/a ExecStart=-/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"" "$f" found=true fi done # if section not in any file, append section with key = value to FIRST file in files parameter if ! $found ; then file=$(echo "/etc/systemd/system/rescue.service.d/10-oscap.conf" | cut -f1 -d ' ') mkdir -p "$(dirname "$file")" echo -e "[Service]\nExecStart=-/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"" >> "$file" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_require_singleuser_auth' ############################################################################### # BEGIN fix (58 / 210) for 'xccdf_org.ssgproject.content_rule_package_tmux_installed' ############################################################################### (>&2 echo "Remediating rule 58/210: 'xccdf_org.ssgproject.content_rule_package_tmux_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "tmux" ; then yum install -y "tmux" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_tmux_installed' ############################################################################### # BEGIN fix (59 / 210) for 'xccdf_org.ssgproject.content_rule_configure_bashrc_exec_tmux' ############################################################################### (>&2 echo "Remediating rule 59/210: 'xccdf_org.ssgproject.content_rule_configure_bashrc_exec_tmux'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q tmux; }; then if ! grep -x ' case "$name" in (sshd|login) exec tmux ;; esac' /etc/bashrc; then cat >> /etc/profile.d/tmux.sh <<'EOF' if [ "$PS1" ]; then parent=$(ps -o ppid= -p $$) name=$(ps -o comm= -p $parent) case "$name" in (sshd|login) exec tmux ;; esac fi EOF chmod 0644 /etc/profile.d/tmux.sh fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_configure_bashrc_exec_tmux' ############################################################################### # BEGIN fix (60 / 210) for 'xccdf_org.ssgproject.content_rule_configure_tmux_lock_after_time' ############################################################################### (>&2 echo "Remediating rule 60/210: 'xccdf_org.ssgproject.content_rule_configure_tmux_lock_after_time'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q tmux; }; then tmux_conf="/etc/tmux.conf" if grep -qP '^\s*set\s+-g\s+lock-after-time' "$tmux_conf" ; then sed -i 's/^\s*set\s\+-g\s\+lock-after-time.*$/set -g lock-after-time 900/' "$tmux_conf" else echo "set -g lock-after-time 900" >> "$tmux_conf" fi chmod 0644 "$tmux_conf" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_configure_tmux_lock_after_time' ############################################################################### # BEGIN fix (61 / 210) for 'xccdf_org.ssgproject.content_rule_configure_tmux_lock_command' ############################################################################### (>&2 echo "Remediating rule 61/210: 'xccdf_org.ssgproject.content_rule_configure_tmux_lock_command'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q tmux; }; then tmux_conf="/etc/tmux.conf" if grep -qP '^\s*set\s+-g\s+lock-command' "$tmux_conf" ; then sed -i 's/^\s*set\s\+-g\s\+lock-command.*$/set -g lock-command vlock/' "$tmux_conf" else echo "set -g lock-command vlock" >> "$tmux_conf" fi chmod 0644 "$tmux_conf" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_configure_tmux_lock_command' ############################################################################### # BEGIN fix (62 / 210) for 'xccdf_org.ssgproject.content_rule_no_tmux_in_shells' ############################################################################### (>&2 echo "Remediating rule 62/210: 'xccdf_org.ssgproject.content_rule_no_tmux_in_shells'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if grep -q 'tmux\s*$' /etc/shells ; then sed -i '/tmux\s*$/d' /etc/shells fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_no_tmux_in_shells' ############################################################################### # BEGIN fix (63 / 210) for 'xccdf_org.ssgproject.content_rule_no_empty_passwords' ############################################################################### (>&2 echo "Remediating rule 63/210: 'xccdf_org.ssgproject.content_rule_no_empty_passwords'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -f /usr/bin/authselect ]; then if ! authselect check; then echo " authselect integrity check failed. Remediation aborted! This remediation could not be applied because an authselect profile was not selected or the selected profile is not intact. It is not recommended to manually edit the PAM files when authselect tool is available. In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended." exit 1 fi authselect enable-feature without-nullok authselect apply-changes -b else if grep -qP "^\s*auth\s+sufficient\s+pam_unix.so\s.*\bnullok\b" "/etc/pam.d/system-auth"; then sed -i -E --follow-symlinks "s/(.*auth.*sufficient.*pam_unix.so.*)\snullok=?[[:alnum:]]*(.*)/\1\2/g" "/etc/pam.d/system-auth" fi if grep -qP "^\s*password\s+sufficient\s+pam_unix.so\s.*\bnullok\b" "/etc/pam.d/system-auth"; then sed -i -E --follow-symlinks "s/(.*password.*sufficient.*pam_unix.so.*)\snullok=?[[:alnum:]]*(.*)/\1\2/g" "/etc/pam.d/system-auth" fi if grep -qP "^\s*auth\s+sufficient\s+pam_unix.so\s.*\bnullok\b" "/etc/pam.d/password-auth"; then sed -i -E --follow-symlinks "s/(.*auth.*sufficient.*pam_unix.so.*)\snullok=?[[:alnum:]]*(.*)/\1\2/g" "/etc/pam.d/password-auth" fi if grep -qP "^\s*password\s+sufficient\s+pam_unix.so\s.*\bnullok\b" "/etc/pam.d/password-auth"; then sed -i -E --follow-symlinks "s/(.*password.*sufficient.*pam_unix.so.*)\snullok=?[[:alnum:]]*(.*)/\1\2/g" "/etc/pam.d/password-auth" fi fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_no_empty_passwords' ############################################################################### # BEGIN fix (64 / 210) for 'xccdf_org.ssgproject.content_rule_securetty_root_login_console_only' ############################################################################### (>&2 echo "Remediating rule 64/210: 'xccdf_org.ssgproject.content_rule_securetty_root_login_console_only'") sed -i '/^vc\/[0-9]/d' /etc/securetty # END fix for 'xccdf_org.ssgproject.content_rule_securetty_root_login_console_only' ############################################################################### # BEGIN fix (65 / 210) for 'xccdf_org.ssgproject.content_rule_use_pam_wheel_for_su' ############################################################################### (>&2 echo "Remediating rule 65/210: 'xccdf_org.ssgproject.content_rule_use_pam_wheel_for_su'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then # uncomment the option if commented sed '/^[[:space:]]*#[[:space:]]*auth[[:space:]]\+required[[:space:]]\+pam_wheel\.so[[:space:]]\+use_uid$/s/^[[:space:]]*#//' -i /etc/pam.d/su else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_use_pam_wheel_for_su' ############################################################################### # BEGIN fix (66 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_max_concurrent_login_sessions' ############################################################################### (>&2 echo "Remediating rule 66/210: 'xccdf_org.ssgproject.content_rule_accounts_max_concurrent_login_sessions'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then var_accounts_max_concurrent_login_sessions='10' if grep -q '^[^#]*\<maxlogins\>' /etc/security/limits.d/*.conf; then sed -i "/^[^#]*\<maxlogins\>/ s/maxlogins.*/maxlogins $var_accounts_max_concurrent_login_sessions/" /etc/security/limits.d/*.conf elif grep -q '^[^#]*\<maxlogins\>' /etc/security/limits.conf; then sed -i "/^[^#]*\<maxlogins\>/ s/maxlogins.*/maxlogins $var_accounts_max_concurrent_login_sessions/" /etc/security/limits.conf else echo "* hard maxlogins $var_accounts_max_concurrent_login_sessions" >> /etc/security/limits.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_max_concurrent_login_sessions' ############################################################################### # BEGIN fix (67 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc' ############################################################################### (>&2 echo "Remediating rule 67/210: 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc'") # Remediation is applicable only in certain platforms if rpm --quiet -q bash; then var_accounts_user_umask='027' grep -q "^[^#]*\bumask" /etc/bashrc && \ sed -i -E -e "s/^([^#]*\bumask)[[:space:]]+[[:digit:]]+/\1 $var_accounts_user_umask/g" /etc/bashrc if ! [ $? -eq 0 ]; then echo "umask $var_accounts_user_umask" >> /etc/bashrc fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc' ############################################################################### # BEGIN fix (68 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_csh_cshrc' ############################################################################### (>&2 echo "Remediating rule 68/210: 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_csh_cshrc'") var_accounts_user_umask='027' grep -q "^\s*umask" /etc/csh.cshrc && \ sed -i -E -e "s/^(\s*umask).*/\1 $var_accounts_user_umask/g" /etc/csh.cshrc if ! [ $? -eq 0 ]; then echo "umask $var_accounts_user_umask" >> /etc/csh.cshrc fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_csh_cshrc' ############################################################################### # BEGIN fix (69 / 210) for 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_profile' ############################################################################### (>&2 echo "Remediating rule 69/210: 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_profile'") var_accounts_user_umask='027' readarray -t profile_files < <(find /etc/profile.d/ -type f -name '*.sh' -or -name 'sh.local') for file in "${profile_files[@]}" /etc/profile; do grep -qE '^[^#]*umask' "$file" && sed -i -E "s/^(\s*umask\s*)[0-7]+/\1$var_accounts_user_umask/g" "$file" done if ! grep -qrE '^[^#]*umask' /etc/profile*; then echo "umask $var_accounts_user_umask" >> /etc/profile fi # END fix for 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_profile' ############################################################################### # BEGIN fix (70 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_disable_recovery' ############################################################################### (>&2 echo "Remediating rule 70/210: 'xccdf_org.ssgproject.content_rule_grub2_disable_recovery'") # Remediation is applicable only in certain platforms if rpm --quiet -q grub2-common; then if grep -q '^GRUB_DISABLE_RECOVERY=.*' '/etc/default/grub' ; then sed -i 's/GRUB_DISABLE_RECOVERY=.*/GRUB_DISABLE_RECOVERY=true/' "/etc/default/grub" else echo "GRUB_DISABLE_RECOVERY=true" >> '/etc/default/grub' fi grubby --update-kernel=ALL --env=/boot/grub2/grubenv else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_grub2_disable_recovery' ############################################################################### # BEGIN fix (71 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_kernel_trust_cpu_rng' ############################################################################### (>&2 echo "Remediating rule 71/210: 'xccdf_org.ssgproject.content_rule_grub2_kernel_trust_cpu_rng'") # Remediation is applicable only in certain platforms if rpm --quiet -q grub2-common && { [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; }; then grubby --update-kernel=ALL --args=random.trust_cpu=on --env=/boot/grub2/grubenv else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_grub2_kernel_trust_cpu_rng' ############################################################################### # BEGIN fix (72 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_pti_argument' ############################################################################### (>&2 echo "Remediating rule 72/210: 'xccdf_org.ssgproject.content_rule_grub2_pti_argument'") # Remediation is applicable only in certain platforms if rpm --quiet -q grub2-common && { [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; }; then grubby --update-kernel=ALL --args=pti=on --env=/boot/grub2/grubenv else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_grub2_pti_argument' ############################################################################### # BEGIN fix (73 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_vsyscall_argument' ############################################################################### (>&2 echo "Remediating rule 73/210: 'xccdf_org.ssgproject.content_rule_grub2_vsyscall_argument'") # Remediation is applicable only in certain platforms if rpm --quiet -q grub2-common && { ( [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ] && grep -q x86_64 /proc/sys/kernel/osrelease ); }; then grubby --update-kernel=ALL --args=vsyscall=none --env=/boot/grub2/grubenv else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_grub2_vsyscall_argument' ############################################################################### # BEGIN fix (74 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_uefi_password' ############################################################################### (>&2 echo "Remediating rule 74/210: 'xccdf_org.ssgproject.content_rule_grub2_uefi_password'") (>&2 echo "FIX FOR THIS RULE 'xccdf_org.ssgproject.content_rule_grub2_uefi_password' IS MISSING!") # END fix for 'xccdf_org.ssgproject.content_rule_grub2_uefi_password' ############################################################################### # BEGIN fix (75 / 210) for 'xccdf_org.ssgproject.content_rule_zipl_audit_argument' ############################################################################### (>&2 echo "Remediating rule 75/210: 'xccdf_org.ssgproject.content_rule_zipl_audit_argument'") # Remediation is applicable only in certain platforms if grep -q s390x /proc/sys/kernel/osrelease && { [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; }; then # Correct BLS option using grubby, which is a thin wrapper around BLS operations grubby --update-kernel=ALL --args="audit=1" # Ensure new kernels and boot entries retain the boot option if [ ! -f /etc/kernel/cmdline ]; then echo "audit=1" > /etc/kernel/cmdline elif ! grep -q '^(.*\s)?audit=1(\s.*)?$' /etc/kernel/cmdline; then sed -Ei 's/^(.*)$/\1 audit=1/' /etc/kernel/cmdline fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_zipl_audit_argument' ############################################################################### # BEGIN fix (76 / 210) for 'xccdf_org.ssgproject.content_rule_zipl_audit_backlog_limit_argument' ############################################################################### (>&2 echo "Remediating rule 76/210: 'xccdf_org.ssgproject.content_rule_zipl_audit_backlog_limit_argument'") # Remediation is applicable only in certain platforms if grep -q s390x /proc/sys/kernel/osrelease && { [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; }; then # Correct BLS option using grubby, which is a thin wrapper around BLS operations grubby --update-kernel=ALL --args="audit_backlog_limit=8192" # Ensure new kernels and boot entries retain the boot option if [ ! -f /etc/kernel/cmdline ]; then echo "audit_backlog_limit=8192" > /etc/kernel/cmdline elif ! grep -q '^(.*\s)?audit_backlog_limit=8192(\s.*)?$' /etc/kernel/cmdline; then sed -Ei 's/^(.*)$/\1 audit_backlog_limit=8192/' /etc/kernel/cmdline fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_zipl_audit_backlog_limit_argument' ############################################################################### # BEGIN fix (77 / 210) for 'xccdf_org.ssgproject.content_rule_zipl_page_poison_argument' ############################################################################### (>&2 echo "Remediating rule 77/210: 'xccdf_org.ssgproject.content_rule_zipl_page_poison_argument'") # Remediation is applicable only in certain platforms if grep -q s390x /proc/sys/kernel/osrelease && { [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; }; then # Correct BLS option using grubby, which is a thin wrapper around BLS operations grubby --update-kernel=ALL --args="page_poison=1" # Ensure new kernels and boot entries retain the boot option if [ ! -f /etc/kernel/cmdline ]; then echo "page_poison=1" > /etc/kernel/cmdline elif ! grep -q '^(.*\s)?page_poison=1(\s.*)?$' /etc/kernel/cmdline; then sed -Ei 's/^(.*)$/\1 page_poison=1/' /etc/kernel/cmdline fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_zipl_page_poison_argument' ############################################################################### # BEGIN fix (78 / 210) for 'xccdf_org.ssgproject.content_rule_zipl_slub_debug_argument' ############################################################################### (>&2 echo "Remediating rule 78/210: 'xccdf_org.ssgproject.content_rule_zipl_slub_debug_argument'") # Remediation is applicable only in certain platforms if grep -q s390x /proc/sys/kernel/osrelease && { [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; }; then # Correct BLS option using grubby, which is a thin wrapper around BLS operations grubby --update-kernel=ALL --args="slub_debug=P" # Ensure new kernels and boot entries retain the boot option if [ ! -f /etc/kernel/cmdline ]; then echo "slub_debug=P" > /etc/kernel/cmdline elif ! grep -q '^(.*\s)?slub_debug=P(\s.*)?$' /etc/kernel/cmdline; then sed -Ei 's/^(.*)$/\1 slub_debug=P/' /etc/kernel/cmdline fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_zipl_slub_debug_argument' ############################################################################### # BEGIN fix (79 / 210) for 'xccdf_org.ssgproject.content_rule_zipl_bls_entries_only' ############################################################################### (>&2 echo "Remediating rule 79/210: 'xccdf_org.ssgproject.content_rule_zipl_bls_entries_only'") (>&2 echo "FIX FOR THIS RULE 'xccdf_org.ssgproject.content_rule_zipl_bls_entries_only' IS MISSING!") # END fix for 'xccdf_org.ssgproject.content_rule_zipl_bls_entries_only' ############################################################################### # BEGIN fix (80 / 210) for 'xccdf_org.ssgproject.content_rule_zipl_bootmap_is_up_to_date' ############################################################################### (>&2 echo "Remediating rule 80/210: 'xccdf_org.ssgproject.content_rule_zipl_bootmap_is_up_to_date'") # Remediation is applicable only in certain platforms if grep -q s390x /proc/sys/kernel/osrelease && { [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; }; then /usr/sbin/zipl else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_zipl_bootmap_is_up_to_date' ############################################################################### # BEGIN fix (81 / 210) for 'xccdf_org.ssgproject.content_rule_package_rsyslog_installed' ############################################################################### (>&2 echo "Remediating rule 81/210: 'xccdf_org.ssgproject.content_rule_package_rsyslog_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "rsyslog" ; then yum install -y "rsyslog" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_rsyslog_installed' ############################################################################### # BEGIN fix (82 / 210) for 'xccdf_org.ssgproject.content_rule_package_firewalld_installed' ############################################################################### (>&2 echo "Remediating rule 82/210: 'xccdf_org.ssgproject.content_rule_package_firewalld_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "firewalld" ; then yum install -y "firewalld" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_firewalld_installed' ############################################################################### # BEGIN fix (83 / 210) for 'xccdf_org.ssgproject.content_rule_service_firewalld_enabled' ############################################################################### (>&2 echo "Remediating rule 83/210: 'xccdf_org.ssgproject.content_rule_service_firewalld_enabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q firewalld; }; then SYSTEMCTL_EXEC='/usr/bin/systemctl' "$SYSTEMCTL_EXEC" unmask 'firewalld.service' "$SYSTEMCTL_EXEC" start 'firewalld.service' "$SYSTEMCTL_EXEC" enable 'firewalld.service' else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_service_firewalld_enabled' ############################################################################### # BEGIN fix (84 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_ra' ############################################################################### (>&2 echo "Remediating rule 84/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_ra'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv6.conf.all.accept_ra from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv6.conf.all.accept_ra.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv6.conf.all.accept_ra" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv6_conf_all_accept_ra_value='0' # # Set runtime for net.ipv6.conf.all.accept_ra # /sbin/sysctl -q -n -w net.ipv6.conf.all.accept_ra="$sysctl_net_ipv6_conf_all_accept_ra_value" # # If net.ipv6.conf.all.accept_ra present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv6.conf.all.accept_ra = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv6.conf.all.accept_ra") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv6_conf_all_accept_ra_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv6.conf.all.accept_ra\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv6.conf.all.accept_ra\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_ra' ############################################################################### # BEGIN fix (85 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_redirects' ############################################################################### (>&2 echo "Remediating rule 85/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_redirects'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv6.conf.all.accept_redirects from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv6.conf.all.accept_redirects.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv6.conf.all.accept_redirects" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv6_conf_all_accept_redirects_value='0' # # Set runtime for net.ipv6.conf.all.accept_redirects # /sbin/sysctl -q -n -w net.ipv6.conf.all.accept_redirects="$sysctl_net_ipv6_conf_all_accept_redirects_value" # # If net.ipv6.conf.all.accept_redirects present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv6.conf.all.accept_redirects = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv6.conf.all.accept_redirects") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv6_conf_all_accept_redirects_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv6.conf.all.accept_redirects\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv6.conf.all.accept_redirects\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_redirects' ############################################################################### # BEGIN fix (86 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_source_route' ############################################################################### (>&2 echo "Remediating rule 86/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_source_route'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv6.conf.all.accept_source_route from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv6.conf.all.accept_source_route.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv6.conf.all.accept_source_route" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv6_conf_all_accept_source_route_value='0' # # Set runtime for net.ipv6.conf.all.accept_source_route # /sbin/sysctl -q -n -w net.ipv6.conf.all.accept_source_route="$sysctl_net_ipv6_conf_all_accept_source_route_value" # # If net.ipv6.conf.all.accept_source_route present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv6.conf.all.accept_source_route = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv6.conf.all.accept_source_route") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv6_conf_all_accept_source_route_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv6.conf.all.accept_source_route\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv6.conf.all.accept_source_route\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_all_accept_source_route' ############################################################################### # BEGIN fix (87 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_ra' ############################################################################### (>&2 echo "Remediating rule 87/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_ra'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv6.conf.default.accept_ra from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv6.conf.default.accept_ra.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv6.conf.default.accept_ra" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv6_conf_default_accept_ra_value='0' # # Set runtime for net.ipv6.conf.default.accept_ra # /sbin/sysctl -q -n -w net.ipv6.conf.default.accept_ra="$sysctl_net_ipv6_conf_default_accept_ra_value" # # If net.ipv6.conf.default.accept_ra present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv6.conf.default.accept_ra = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv6.conf.default.accept_ra") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv6_conf_default_accept_ra_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv6.conf.default.accept_ra\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv6.conf.default.accept_ra\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_ra' ############################################################################### # BEGIN fix (88 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_redirects' ############################################################################### (>&2 echo "Remediating rule 88/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_redirects'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv6.conf.default.accept_redirects from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv6.conf.default.accept_redirects.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv6.conf.default.accept_redirects" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv6_conf_default_accept_redirects_value='0' # # Set runtime for net.ipv6.conf.default.accept_redirects # /sbin/sysctl -q -n -w net.ipv6.conf.default.accept_redirects="$sysctl_net_ipv6_conf_default_accept_redirects_value" # # If net.ipv6.conf.default.accept_redirects present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv6.conf.default.accept_redirects = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv6.conf.default.accept_redirects") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv6_conf_default_accept_redirects_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv6.conf.default.accept_redirects\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv6.conf.default.accept_redirects\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_redirects' ############################################################################### # BEGIN fix (89 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_source_route' ############################################################################### (>&2 echo "Remediating rule 89/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_source_route'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv6.conf.default.accept_source_route from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv6.conf.default.accept_source_route.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv6.conf.default.accept_source_route" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv6_conf_default_accept_source_route_value='0' # # Set runtime for net.ipv6.conf.default.accept_source_route # /sbin/sysctl -q -n -w net.ipv6.conf.default.accept_source_route="$sysctl_net_ipv6_conf_default_accept_source_route_value" # # If net.ipv6.conf.default.accept_source_route present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv6.conf.default.accept_source_route = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv6.conf.default.accept_source_route") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv6_conf_default_accept_source_route_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv6.conf.default.accept_source_route\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv6.conf.default.accept_source_route\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv6_conf_default_accept_source_route' ############################################################################### # BEGIN fix (90 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_accept_redirects' ############################################################################### (>&2 echo "Remediating rule 90/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_accept_redirects'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.all.accept_redirects from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.all.accept_redirects.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.all.accept_redirects" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_all_accept_redirects_value='0' # # Set runtime for net.ipv4.conf.all.accept_redirects # /sbin/sysctl -q -n -w net.ipv4.conf.all.accept_redirects="$sysctl_net_ipv4_conf_all_accept_redirects_value" # # If net.ipv4.conf.all.accept_redirects present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.all.accept_redirects = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.all.accept_redirects") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_all_accept_redirects_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.all.accept_redirects\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.all.accept_redirects\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_accept_redirects' ############################################################################### # BEGIN fix (91 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_accept_source_route' ############################################################################### (>&2 echo "Remediating rule 91/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_accept_source_route'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.all.accept_source_route from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.all.accept_source_route.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.all.accept_source_route" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_all_accept_source_route_value='0' # # Set runtime for net.ipv4.conf.all.accept_source_route # /sbin/sysctl -q -n -w net.ipv4.conf.all.accept_source_route="$sysctl_net_ipv4_conf_all_accept_source_route_value" # # If net.ipv4.conf.all.accept_source_route present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.all.accept_source_route = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.all.accept_source_route") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_all_accept_source_route_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.all.accept_source_route\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.all.accept_source_route\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_accept_source_route' ############################################################################### # BEGIN fix (92 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_log_martians' ############################################################################### (>&2 echo "Remediating rule 92/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_log_martians'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.all.log_martians from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.all.log_martians.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.all.log_martians" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_all_log_martians_value='1' # # Set runtime for net.ipv4.conf.all.log_martians # /sbin/sysctl -q -n -w net.ipv4.conf.all.log_martians="$sysctl_net_ipv4_conf_all_log_martians_value" # # If net.ipv4.conf.all.log_martians present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.all.log_martians = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.all.log_martians") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_all_log_martians_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.all.log_martians\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.all.log_martians\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_log_martians' ############################################################################### # BEGIN fix (93 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_rp_filter' ############################################################################### (>&2 echo "Remediating rule 93/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_rp_filter'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.all.rp_filter from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.all.rp_filter.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.all.rp_filter" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_all_rp_filter_value='1' # # Set runtime for net.ipv4.conf.all.rp_filter # /sbin/sysctl -q -n -w net.ipv4.conf.all.rp_filter="$sysctl_net_ipv4_conf_all_rp_filter_value" # # If net.ipv4.conf.all.rp_filter present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.all.rp_filter = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.all.rp_filter") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_all_rp_filter_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.all.rp_filter\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.all.rp_filter\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_rp_filter' ############################################################################### # BEGIN fix (94 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_secure_redirects' ############################################################################### (>&2 echo "Remediating rule 94/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_secure_redirects'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.all.secure_redirects from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.all.secure_redirects.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.all.secure_redirects" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_all_secure_redirects_value='0' # # Set runtime for net.ipv4.conf.all.secure_redirects # /sbin/sysctl -q -n -w net.ipv4.conf.all.secure_redirects="$sysctl_net_ipv4_conf_all_secure_redirects_value" # # If net.ipv4.conf.all.secure_redirects present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.all.secure_redirects = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.all.secure_redirects") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_all_secure_redirects_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.all.secure_redirects\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.all.secure_redirects\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_secure_redirects' ############################################################################### # BEGIN fix (95 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_accept_redirects' ############################################################################### (>&2 echo "Remediating rule 95/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_accept_redirects'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.default.accept_redirects from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.default.accept_redirects.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.default.accept_redirects" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_default_accept_redirects_value='0' # # Set runtime for net.ipv4.conf.default.accept_redirects # /sbin/sysctl -q -n -w net.ipv4.conf.default.accept_redirects="$sysctl_net_ipv4_conf_default_accept_redirects_value" # # If net.ipv4.conf.default.accept_redirects present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.default.accept_redirects = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.default.accept_redirects") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_default_accept_redirects_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.default.accept_redirects\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.default.accept_redirects\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_accept_redirects' ############################################################################### # BEGIN fix (96 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_accept_source_route' ############################################################################### (>&2 echo "Remediating rule 96/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_accept_source_route'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.default.accept_source_route from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.default.accept_source_route.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.default.accept_source_route" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_default_accept_source_route_value='0' # # Set runtime for net.ipv4.conf.default.accept_source_route # /sbin/sysctl -q -n -w net.ipv4.conf.default.accept_source_route="$sysctl_net_ipv4_conf_default_accept_source_route_value" # # If net.ipv4.conf.default.accept_source_route present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.default.accept_source_route = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.default.accept_source_route") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_default_accept_source_route_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.default.accept_source_route\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.default.accept_source_route\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_accept_source_route' ############################################################################### # BEGIN fix (97 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_log_martians' ############################################################################### (>&2 echo "Remediating rule 97/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_log_martians'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.default.log_martians from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.default.log_martians.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.default.log_martians" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_default_log_martians_value='1' # # Set runtime for net.ipv4.conf.default.log_martians # /sbin/sysctl -q -n -w net.ipv4.conf.default.log_martians="$sysctl_net_ipv4_conf_default_log_martians_value" # # If net.ipv4.conf.default.log_martians present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.default.log_martians = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.default.log_martians") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_default_log_martians_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.default.log_martians\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.default.log_martians\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_log_martians' ############################################################################### # BEGIN fix (98 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_rp_filter' ############################################################################### (>&2 echo "Remediating rule 98/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_rp_filter'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.default.rp_filter from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.default.rp_filter.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.default.rp_filter" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_default_rp_filter_value='1' # # Set runtime for net.ipv4.conf.default.rp_filter # /sbin/sysctl -q -n -w net.ipv4.conf.default.rp_filter="$sysctl_net_ipv4_conf_default_rp_filter_value" # # If net.ipv4.conf.default.rp_filter present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.default.rp_filter = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.default.rp_filter") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_default_rp_filter_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.default.rp_filter\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.default.rp_filter\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_rp_filter' ############################################################################### # BEGIN fix (99 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_secure_redirects' ############################################################################### (>&2 echo "Remediating rule 99/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_secure_redirects'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.default.secure_redirects from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.default.secure_redirects.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.default.secure_redirects" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_conf_default_secure_redirects_value='0' # # Set runtime for net.ipv4.conf.default.secure_redirects # /sbin/sysctl -q -n -w net.ipv4.conf.default.secure_redirects="$sysctl_net_ipv4_conf_default_secure_redirects_value" # # If net.ipv4.conf.default.secure_redirects present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.conf.default.secure_redirects = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.default.secure_redirects") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_conf_default_secure_redirects_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.default.secure_redirects\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.default.secure_redirects\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_secure_redirects' ############################################################################### # BEGIN fix (100 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_icmp_echo_ignore_broadcasts' ############################################################################### (>&2 echo "Remediating rule 100/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_icmp_echo_ignore_broadcasts'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.icmp_echo_ignore_broadcasts from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.icmp_echo_ignore_broadcasts.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.icmp_echo_ignore_broadcasts" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_icmp_echo_ignore_broadcasts_value='1' # # Set runtime for net.ipv4.icmp_echo_ignore_broadcasts # /sbin/sysctl -q -n -w net.ipv4.icmp_echo_ignore_broadcasts="$sysctl_net_ipv4_icmp_echo_ignore_broadcasts_value" # # If net.ipv4.icmp_echo_ignore_broadcasts present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.icmp_echo_ignore_broadcasts = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.icmp_echo_ignore_broadcasts") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_icmp_echo_ignore_broadcasts_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.icmp_echo_ignore_broadcasts\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.icmp_echo_ignore_broadcasts\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_icmp_echo_ignore_broadcasts' ############################################################################### # BEGIN fix (101 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_icmp_ignore_bogus_error_responses' ############################################################################### (>&2 echo "Remediating rule 101/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_icmp_ignore_bogus_error_responses'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.icmp_ignore_bogus_error_responses from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.icmp_ignore_bogus_error_responses.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.icmp_ignore_bogus_error_responses" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_icmp_ignore_bogus_error_responses_value='1' # # Set runtime for net.ipv4.icmp_ignore_bogus_error_responses # /sbin/sysctl -q -n -w net.ipv4.icmp_ignore_bogus_error_responses="$sysctl_net_ipv4_icmp_ignore_bogus_error_responses_value" # # If net.ipv4.icmp_ignore_bogus_error_responses present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.icmp_ignore_bogus_error_responses = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.icmp_ignore_bogus_error_responses") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_icmp_ignore_bogus_error_responses_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.icmp_ignore_bogus_error_responses\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.icmp_ignore_bogus_error_responses\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_icmp_ignore_bogus_error_responses' ############################################################################### # BEGIN fix (102 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_tcp_syncookies' ############################################################################### (>&2 echo "Remediating rule 102/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_tcp_syncookies'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.tcp_syncookies from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.tcp_syncookies.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.tcp_syncookies" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_net_ipv4_tcp_syncookies_value='1' # # Set runtime for net.ipv4.tcp_syncookies # /sbin/sysctl -q -n -w net.ipv4.tcp_syncookies="$sysctl_net_ipv4_tcp_syncookies_value" # # If net.ipv4.tcp_syncookies present in /etc/sysctl.conf, change value to appropriate value # else, add "net.ipv4.tcp_syncookies = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.tcp_syncookies") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_net_ipv4_tcp_syncookies_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.tcp_syncookies\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.tcp_syncookies\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_tcp_syncookies' ############################################################################### # BEGIN fix (103 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_send_redirects' ############################################################################### (>&2 echo "Remediating rule 103/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_send_redirects'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.all.send_redirects from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.all.send_redirects.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.all.send_redirects" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for net.ipv4.conf.all.send_redirects # /sbin/sysctl -q -n -w net.ipv4.conf.all.send_redirects="0" # # If net.ipv4.conf.all.send_redirects present in /etc/sysctl.conf, change value to "0" # else, add "net.ipv4.conf.all.send_redirects = 0" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.all.send_redirects") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "0" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.all.send_redirects\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.all.send_redirects\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_all_send_redirects' ############################################################################### # BEGIN fix (104 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_send_redirects' ############################################################################### (>&2 echo "Remediating rule 104/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_send_redirects'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.conf.default.send_redirects from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.conf.default.send_redirects.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.conf.default.send_redirects" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for net.ipv4.conf.default.send_redirects # /sbin/sysctl -q -n -w net.ipv4.conf.default.send_redirects="0" # # If net.ipv4.conf.default.send_redirects present in /etc/sysctl.conf, change value to "0" # else, add "net.ipv4.conf.default.send_redirects = 0" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.conf.default.send_redirects") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "0" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.conf.default.send_redirects\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.conf.default.send_redirects\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_conf_default_send_redirects' ############################################################################### # BEGIN fix (105 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_ip_forward' ############################################################################### (>&2 echo "Remediating rule 105/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_ip_forward'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.ipv4.ip_forward from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.ipv4.ip_forward.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.ipv4.ip_forward" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for net.ipv4.ip_forward # /sbin/sysctl -q -n -w net.ipv4.ip_forward="0" # # If net.ipv4.ip_forward present in /etc/sysctl.conf, change value to "0" # else, add "net.ipv4.ip_forward = 0" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.ipv4.ip_forward") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "0" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.ipv4.ip_forward\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.ipv4.ip_forward\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_ipv4_ip_forward' ############################################################################### # BEGIN fix (106 / 210) for 'xccdf_org.ssgproject.content_rule_kernel_module_atm_disabled' ############################################################################### (>&2 echo "Remediating rule 106/210: 'xccdf_org.ssgproject.content_rule_kernel_module_atm_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if LC_ALL=C grep -q -m 1 "^install atm" /etc/modprobe.d/atm.conf ; then sed -i 's#^install atm.*#install atm /bin/false#g' /etc/modprobe.d/atm.conf else echo -e "\n# Disable per security requirements" >> /etc/modprobe.d/atm.conf echo "install atm /bin/false" >> /etc/modprobe.d/atm.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_kernel_module_atm_disabled' ############################################################################### # BEGIN fix (107 / 210) for 'xccdf_org.ssgproject.content_rule_kernel_module_can_disabled' ############################################################################### (>&2 echo "Remediating rule 107/210: 'xccdf_org.ssgproject.content_rule_kernel_module_can_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if LC_ALL=C grep -q -m 1 "^install can" /etc/modprobe.d/can.conf ; then sed -i 's#^install can.*#install can /bin/false#g' /etc/modprobe.d/can.conf else echo -e "\n# Disable per security requirements" >> /etc/modprobe.d/can.conf echo "install can /bin/false" >> /etc/modprobe.d/can.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_kernel_module_can_disabled' ############################################################################### # BEGIN fix (108 / 210) for 'xccdf_org.ssgproject.content_rule_kernel_module_firewire-core_disabled' ############################################################################### (>&2 echo "Remediating rule 108/210: 'xccdf_org.ssgproject.content_rule_kernel_module_firewire-core_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if LC_ALL=C grep -q -m 1 "^install firewire-core" /etc/modprobe.d/firewire-core.conf ; then sed -i 's#^install firewire-core.*#install firewire-core /bin/false#g' /etc/modprobe.d/firewire-core.conf else echo -e "\n# Disable per security requirements" >> /etc/modprobe.d/firewire-core.conf echo "install firewire-core /bin/false" >> /etc/modprobe.d/firewire-core.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_kernel_module_firewire-core_disabled' ############################################################################### # BEGIN fix (109 / 210) for 'xccdf_org.ssgproject.content_rule_kernel_module_sctp_disabled' ############################################################################### (>&2 echo "Remediating rule 109/210: 'xccdf_org.ssgproject.content_rule_kernel_module_sctp_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if LC_ALL=C grep -q -m 1 "^install sctp" /etc/modprobe.d/sctp.conf ; then sed -i 's#^install sctp.*#install sctp /bin/false#g' /etc/modprobe.d/sctp.conf else echo -e "\n# Disable per security requirements" >> /etc/modprobe.d/sctp.conf echo "install sctp /bin/false" >> /etc/modprobe.d/sctp.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_kernel_module_sctp_disabled' ############################################################################### # BEGIN fix (110 / 210) for 'xccdf_org.ssgproject.content_rule_kernel_module_tipc_disabled' ############################################################################### (>&2 echo "Remediating rule 110/210: 'xccdf_org.ssgproject.content_rule_kernel_module_tipc_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if LC_ALL=C grep -q -m 1 "^install tipc" /etc/modprobe.d/tipc.conf ; then sed -i 's#^install tipc.*#install tipc /bin/false#g' /etc/modprobe.d/tipc.conf else echo -e "\n# Disable per security requirements" >> /etc/modprobe.d/tipc.conf echo "install tipc /bin/false" >> /etc/modprobe.d/tipc.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_kernel_module_tipc_disabled' ############################################################################### # BEGIN fix (111 / 210) for 'xccdf_org.ssgproject.content_rule_kernel_module_bluetooth_disabled' ############################################################################### (>&2 echo "Remediating rule 111/210: 'xccdf_org.ssgproject.content_rule_kernel_module_bluetooth_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if LC_ALL=C grep -q -m 1 "^install bluetooth" /etc/modprobe.d/bluetooth.conf ; then sed -i 's#^install bluetooth.*#install bluetooth /bin/false#g' /etc/modprobe.d/bluetooth.conf else echo -e "\n# Disable per security requirements" >> /etc/modprobe.d/bluetooth.conf echo "install bluetooth /bin/false" >> /etc/modprobe.d/bluetooth.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_kernel_module_bluetooth_disabled' ############################################################################### # BEGIN fix (112 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_fs_protected_hardlinks' ############################################################################### (>&2 echo "Remediating rule 112/210: 'xccdf_org.ssgproject.content_rule_sysctl_fs_protected_hardlinks'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of fs.protected_hardlinks from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*fs.protected_hardlinks.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "fs.protected_hardlinks" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for fs.protected_hardlinks # /sbin/sysctl -q -n -w fs.protected_hardlinks="1" # # If fs.protected_hardlinks present in /etc/sysctl.conf, change value to "1" # else, add "fs.protected_hardlinks = 1" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^fs.protected_hardlinks") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "1" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^fs.protected_hardlinks\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^fs.protected_hardlinks\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_fs_protected_hardlinks' ############################################################################### # BEGIN fix (113 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_fs_protected_symlinks' ############################################################################### (>&2 echo "Remediating rule 113/210: 'xccdf_org.ssgproject.content_rule_sysctl_fs_protected_symlinks'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of fs.protected_symlinks from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*fs.protected_symlinks.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "fs.protected_symlinks" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for fs.protected_symlinks # /sbin/sysctl -q -n -w fs.protected_symlinks="1" # # If fs.protected_symlinks present in /etc/sysctl.conf, change value to "1" # else, add "fs.protected_symlinks = 1" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^fs.protected_symlinks") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "1" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^fs.protected_symlinks\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^fs.protected_symlinks\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_fs_protected_symlinks' ############################################################################### # BEGIN fix (114 / 210) for 'xccdf_org.ssgproject.content_rule_kernel_module_cramfs_disabled' ############################################################################### (>&2 echo "Remediating rule 114/210: 'xccdf_org.ssgproject.content_rule_kernel_module_cramfs_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if LC_ALL=C grep -q -m 1 "^install cramfs" /etc/modprobe.d/cramfs.conf ; then sed -i 's#^install cramfs.*#install cramfs /bin/false#g' /etc/modprobe.d/cramfs.conf else echo -e "\n# Disable per security requirements" >> /etc/modprobe.d/cramfs.conf echo "install cramfs /bin/false" >> /etc/modprobe.d/cramfs.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_kernel_module_cramfs_disabled' ############################################################################### # BEGIN fix (115 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_boot_nodev' ############################################################################### (>&2 echo "Remediating rule 115/210: 'xccdf_org.ssgproject.content_rule_mount_option_boot_nodev'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ); then function perform_remediation { # the mount point /boot has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/boot")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/boot' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /boot in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /boot)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nodev)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /boot defaults,${previous_mount_opts}nodev 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nodev"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nodev|" /etc/fstab fi if mkdir -p "/boot"; then if mountpoint -q "/boot"; then mount -o remount --target "/boot" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_boot_nodev' ############################################################################### # BEGIN fix (116 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_boot_nosuid' ############################################################################### (>&2 echo "Remediating rule 116/210: 'xccdf_org.ssgproject.content_rule_mount_option_boot_nosuid'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ); then function perform_remediation { # the mount point /boot has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/boot")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/boot' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /boot in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /boot)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nosuid)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /boot defaults,${previous_mount_opts}nosuid 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nosuid"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nosuid|" /etc/fstab fi if mkdir -p "/boot"; then if mountpoint -q "/boot"; then mount -o remount --target "/boot" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_boot_nosuid' ############################################################################### # BEGIN fix (117 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_nodev' ############################################################################### (>&2 echo "Remediating rule 117/210: 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_nodev'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ); then function perform_remediation { mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /dev/shm)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nodev)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="tmpfs" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo "tmpfs /dev/shm tmpfs defaults,${previous_mount_opts}nodev 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nodev"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nodev|" /etc/fstab fi if mkdir -p "/dev/shm"; then if mountpoint -q "/dev/shm"; then mount -o remount --target "/dev/shm" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_nodev' ############################################################################### # BEGIN fix (118 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_noexec' ############################################################################### (>&2 echo "Remediating rule 118/210: 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_noexec'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ); then function perform_remediation { mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /dev/shm)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|noexec)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="tmpfs" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo "tmpfs /dev/shm tmpfs defaults,${previous_mount_opts}noexec 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "noexec"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,noexec|" /etc/fstab fi if mkdir -p "/dev/shm"; then if mountpoint -q "/dev/shm"; then mount -o remount --target "/dev/shm" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_noexec' ############################################################################### # BEGIN fix (119 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_nosuid' ############################################################################### (>&2 echo "Remediating rule 119/210: 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_nosuid'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ); then function perform_remediation { mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /dev/shm)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nosuid)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="tmpfs" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo "tmpfs /dev/shm tmpfs defaults,${previous_mount_opts}nosuid 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nosuid"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nosuid|" /etc/fstab fi if mkdir -p "/dev/shm"; then if mountpoint -q "/dev/shm"; then mount -o remount --target "/dev/shm" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_nosuid' ############################################################################### # BEGIN fix (120 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_home_nodev' ############################################################################### (>&2 echo "Remediating rule 120/210: 'xccdf_org.ssgproject.content_rule_mount_option_home_nodev'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/home" > /dev/null || findmnt --fstab "/home" > /dev/null; }; then function perform_remediation { # the mount point /home has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/home")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/home' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /home in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /home)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nodev)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /home defaults,${previous_mount_opts}nodev 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nodev"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nodev|" /etc/fstab fi if mkdir -p "/home"; then if mountpoint -q "/home"; then mount -o remount --target "/home" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_home_nodev' ############################################################################### # BEGIN fix (121 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_home_nosuid' ############################################################################### (>&2 echo "Remediating rule 121/210: 'xccdf_org.ssgproject.content_rule_mount_option_home_nosuid'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/home" > /dev/null || findmnt --fstab "/home" > /dev/null; }; then function perform_remediation { # the mount point /home has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/home")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/home' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /home in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /home)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nosuid)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /home defaults,${previous_mount_opts}nosuid 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nosuid"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nosuid|" /etc/fstab fi if mkdir -p "/home"; then if mountpoint -q "/home"; then mount -o remount --target "/home" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_home_nosuid' ############################################################################### # BEGIN fix (122 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_nodev_nonroot_local_partitions' ############################################################################### (>&2 echo "Remediating rule 122/210: 'xccdf_org.ssgproject.content_rule_mount_option_nodev_nonroot_local_partitions'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ); then MOUNT_OPTION="nodev" # Create array of local non-root partitions readarray -t partitions_records < <(findmnt --mtab --raw --evaluate | grep "^/\w" | grep -v "^/proc" | grep "\s/dev/\w") # Create array of polyinstantiated directories, in case one of them is found in mtab readarray -t polyinstantiated_dirs < \ <(grep -oP "^\s*[^#\s]+\s+\S+" /etc/security/namespace.conf | grep -oP "(?<=\s)\S+?(?=/?\$)") for partition_record in "${partitions_records[@]}"; do # Get all important information for fstab mount_point="$(echo ${partition_record} | cut -d " " -f1)" device="$(echo ${partition_record} | cut -d " " -f2)" device_type="$(echo ${partition_record} | cut -d " " -f3)" if ! printf '%s\0' "${polyinstantiated_dirs[@]}" | grep -qxzF "$mount_point"; then # device and device_type will be used only in case when the device doesn't have fstab record mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" $mount_point)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|$MOUNT_OPTION)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="$device_type" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo "$device $mount_point $device_type defaults,${previous_mount_opts}$MOUNT_OPTION 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "$MOUNT_OPTION"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,$MOUNT_OPTION|" /etc/fstab fi if mkdir -p "$mount_point"; then if mountpoint -q "$mount_point"; then mount -o remount --target "$mount_point" fi fi fi done # Remediate unmounted /etc/fstab entries sed -i -E '/nodev/! s;^\s*(/dev/\S+|UUID=\S+)\s+(/\w\S*)\s+(\S+)\s+(\S+)(.*)$;\1 \2 \3 \4,nodev \5;' /etc/fstab else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_nodev_nonroot_local_partitions' ############################################################################### # BEGIN fix (123 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_tmp_nodev' ############################################################################### (>&2 echo "Remediating rule 123/210: 'xccdf_org.ssgproject.content_rule_mount_option_tmp_nodev'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/tmp" > /dev/null || findmnt --fstab "/tmp" > /dev/null; }; then function perform_remediation { # the mount point /tmp has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/tmp")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/tmp' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /tmp in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /tmp)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nodev)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /tmp defaults,${previous_mount_opts}nodev 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nodev"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nodev|" /etc/fstab fi if mkdir -p "/tmp"; then if mountpoint -q "/tmp"; then mount -o remount --target "/tmp" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_tmp_nodev' ############################################################################### # BEGIN fix (124 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_tmp_noexec' ############################################################################### (>&2 echo "Remediating rule 124/210: 'xccdf_org.ssgproject.content_rule_mount_option_tmp_noexec'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/tmp" > /dev/null || findmnt --fstab "/tmp" > /dev/null; }; then function perform_remediation { # the mount point /tmp has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/tmp")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/tmp' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /tmp in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /tmp)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|noexec)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /tmp defaults,${previous_mount_opts}noexec 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "noexec"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,noexec|" /etc/fstab fi if mkdir -p "/tmp"; then if mountpoint -q "/tmp"; then mount -o remount --target "/tmp" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_tmp_noexec' ############################################################################### # BEGIN fix (125 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_tmp_nosuid' ############################################################################### (>&2 echo "Remediating rule 125/210: 'xccdf_org.ssgproject.content_rule_mount_option_tmp_nosuid'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/tmp" > /dev/null || findmnt --fstab "/tmp" > /dev/null; }; then function perform_remediation { # the mount point /tmp has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/tmp")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/tmp' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /tmp in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /tmp)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nosuid)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /tmp defaults,${previous_mount_opts}nosuid 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nosuid"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nosuid|" /etc/fstab fi if mkdir -p "/tmp"; then if mountpoint -q "/tmp"; then mount -o remount --target "/tmp" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_tmp_nosuid' ############################################################################### # BEGIN fix (126 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_nodev' ############################################################################### (>&2 echo "Remediating rule 126/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_nodev'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/log/audit" > /dev/null || findmnt --fstab "/var/log/audit" > /dev/null; }; then function perform_remediation { # the mount point /var/log/audit has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/log/audit")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/log/audit' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/log/audit in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/log/audit)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nodev)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/log/audit defaults,${previous_mount_opts}nodev 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nodev"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nodev|" /etc/fstab fi if mkdir -p "/var/log/audit"; then if mountpoint -q "/var/log/audit"; then mount -o remount --target "/var/log/audit" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_nodev' ############################################################################### # BEGIN fix (127 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_noexec' ############################################################################### (>&2 echo "Remediating rule 127/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_noexec'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/log/audit" > /dev/null || findmnt --fstab "/var/log/audit" > /dev/null; }; then function perform_remediation { # the mount point /var/log/audit has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/log/audit")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/log/audit' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/log/audit in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/log/audit)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|noexec)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/log/audit defaults,${previous_mount_opts}noexec 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "noexec"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,noexec|" /etc/fstab fi if mkdir -p "/var/log/audit"; then if mountpoint -q "/var/log/audit"; then mount -o remount --target "/var/log/audit" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_noexec' ############################################################################### # BEGIN fix (128 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_nosuid' ############################################################################### (>&2 echo "Remediating rule 128/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_nosuid'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/log/audit" > /dev/null || findmnt --fstab "/var/log/audit" > /dev/null; }; then function perform_remediation { # the mount point /var/log/audit has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/log/audit")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/log/audit' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/log/audit in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/log/audit)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nosuid)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/log/audit defaults,${previous_mount_opts}nosuid 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nosuid"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nosuid|" /etc/fstab fi if mkdir -p "/var/log/audit"; then if mountpoint -q "/var/log/audit"; then mount -o remount --target "/var/log/audit" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_audit_nosuid' ############################################################################### # BEGIN fix (129 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_nodev' ############################################################################### (>&2 echo "Remediating rule 129/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_log_nodev'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/log" > /dev/null || findmnt --fstab "/var/log" > /dev/null; }; then function perform_remediation { # the mount point /var/log has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/log")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/log' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/log in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/log)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nodev)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/log defaults,${previous_mount_opts}nodev 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nodev"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nodev|" /etc/fstab fi if mkdir -p "/var/log"; then if mountpoint -q "/var/log"; then mount -o remount --target "/var/log" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_nodev' ############################################################################### # BEGIN fix (130 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_noexec' ############################################################################### (>&2 echo "Remediating rule 130/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_log_noexec'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/log" > /dev/null || findmnt --fstab "/var/log" > /dev/null; }; then function perform_remediation { # the mount point /var/log has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/log")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/log' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/log in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/log)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|noexec)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/log defaults,${previous_mount_opts}noexec 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "noexec"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,noexec|" /etc/fstab fi if mkdir -p "/var/log"; then if mountpoint -q "/var/log"; then mount -o remount --target "/var/log" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_noexec' ############################################################################### # BEGIN fix (131 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_nosuid' ############################################################################### (>&2 echo "Remediating rule 131/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_log_nosuid'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/log" > /dev/null || findmnt --fstab "/var/log" > /dev/null; }; then function perform_remediation { # the mount point /var/log has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/log")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/log' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/log in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/log)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nosuid)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/log defaults,${previous_mount_opts}nosuid 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nosuid"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nosuid|" /etc/fstab fi if mkdir -p "/var/log"; then if mountpoint -q "/var/log"; then mount -o remount --target "/var/log" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_log_nosuid' ############################################################################### # BEGIN fix (132 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_nodev' ############################################################################### (>&2 echo "Remediating rule 132/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_nodev'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var" > /dev/null || findmnt --fstab "/var" > /dev/null; }; then function perform_remediation { # the mount point /var has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nodev)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var defaults,${previous_mount_opts}nodev 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nodev"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nodev|" /etc/fstab fi if mkdir -p "/var"; then if mountpoint -q "/var"; then mount -o remount --target "/var" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_nodev' ############################################################################### # BEGIN fix (133 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_nodev' ############################################################################### (>&2 echo "Remediating rule 133/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_nodev'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/tmp" > /dev/null || findmnt --fstab "/var/tmp" > /dev/null; }; then function perform_remediation { # the mount point /var/tmp has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/tmp")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/tmp' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/tmp in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/tmp)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nodev)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/tmp defaults,${previous_mount_opts}nodev 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nodev"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nodev|" /etc/fstab fi if mkdir -p "/var/tmp"; then if mountpoint -q "/var/tmp"; then mount -o remount --target "/var/tmp" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_nodev' ############################################################################### # BEGIN fix (134 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_noexec' ############################################################################### (>&2 echo "Remediating rule 134/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_noexec'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/tmp" > /dev/null || findmnt --fstab "/var/tmp" > /dev/null; }; then function perform_remediation { # the mount point /var/tmp has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/tmp")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/tmp' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/tmp in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/tmp)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|noexec)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/tmp defaults,${previous_mount_opts}noexec 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "noexec"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,noexec|" /etc/fstab fi if mkdir -p "/var/tmp"; then if mountpoint -q "/var/tmp"; then mount -o remount --target "/var/tmp" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_noexec' ############################################################################### # BEGIN fix (135 / 210) for 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_nosuid' ############################################################################### (>&2 echo "Remediating rule 135/210: 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_nosuid'") # Remediation is applicable only in certain platforms if ( ! ( { rpm --quiet -q kernel ;} && { rpm --quiet -q rpm-ostree ;} && { rpm --quiet -q bootc ;} ) && ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ) && { findmnt --kernel "/var/tmp" > /dev/null || findmnt --fstab "/var/tmp" > /dev/null; }; then function perform_remediation { # the mount point /var/tmp has to be defined in /etc/fstab # before this remediation can be executed. In case it is not defined, the # remediation aborts and no changes regarding the mount point are done. mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" "/var/tmp")" grep "$mount_point_match_regexp" -q /etc/fstab \ || { echo "The mount point '/var/tmp' is not even in /etc/fstab, so we can't set up mount options" >&2; echo "Not remediating, because there is no record of /var/tmp in /etc/fstab" >&2; return 1; } mount_point_match_regexp="$(printf "^[[:space:]]*[^#].*[[:space:]]%s[[:space:]]" /var/tmp)" # If the mount point is not in /etc/fstab, get previous mount options from /etc/mtab if ! grep -q "$mount_point_match_regexp" /etc/fstab; then # runtime opts without some automatic kernel/userspace-added defaults previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/mtab | head -1 | awk '{print $4}' \ | sed -E "s/(rw|defaults|seclabel|nosuid)(,|$)//g;s/,$//") [ "$previous_mount_opts" ] && previous_mount_opts+="," # In iso9660 filesystems mtab could describe a "blocksize" value, this should be reflected in # fstab as "block". The next variable is to satisfy shellcheck SC2050. fs_type="" if [ "$fs_type" == "iso9660" ] ; then previous_mount_opts=$(sed 's/blocksize=/block=/' <<< "$previous_mount_opts") fi echo " /var/tmp defaults,${previous_mount_opts}nosuid 0 0" >> /etc/fstab # If the mount_opt option is not already in the mount point's /etc/fstab entry, add it elif ! grep "$mount_point_match_regexp" /etc/fstab | grep -q "nosuid"; then previous_mount_opts=$(grep "$mount_point_match_regexp" /etc/fstab | awk '{print $4}') sed -i "s|\(${mount_point_match_regexp}.*${previous_mount_opts}\)|\1,nosuid|" /etc/fstab fi if mkdir -p "/var/tmp"; then if mountpoint -q "/var/tmp"; then mount -o remount --target "/var/tmp" fi fi } perform_remediation else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_mount_option_var_tmp_nosuid' ############################################################################### # BEGIN fix (136 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_core_pattern' ############################################################################### (>&2 echo "Remediating rule 136/210: 'xccdf_org.ssgproject.content_rule_sysctl_kernel_core_pattern'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of kernel.core_pattern from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*kernel.core_pattern.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "kernel.core_pattern" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for kernel.core_pattern # /sbin/sysctl -q -n -w kernel.core_pattern="|/bin/false" # # If kernel.core_pattern present in /etc/sysctl.conf, change value to "|/bin/false" # else, add "kernel.core_pattern = |/bin/false" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^kernel.core_pattern") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "|/bin/false" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^kernel.core_pattern\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^kernel.core_pattern\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_core_pattern' ############################################################################### # BEGIN fix (137 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_dmesg_restrict' ############################################################################### (>&2 echo "Remediating rule 137/210: 'xccdf_org.ssgproject.content_rule_sysctl_kernel_dmesg_restrict'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of kernel.dmesg_restrict from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*kernel.dmesg_restrict.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "kernel.dmesg_restrict" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for kernel.dmesg_restrict # /sbin/sysctl -q -n -w kernel.dmesg_restrict="1" # # If kernel.dmesg_restrict present in /etc/sysctl.conf, change value to "1" # else, add "kernel.dmesg_restrict = 1" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^kernel.dmesg_restrict") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "1" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^kernel.dmesg_restrict\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^kernel.dmesg_restrict\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_dmesg_restrict' ############################################################################### # BEGIN fix (138 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_kexec_load_disabled' ############################################################################### (>&2 echo "Remediating rule 138/210: 'xccdf_org.ssgproject.content_rule_sysctl_kernel_kexec_load_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of kernel.kexec_load_disabled from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*kernel.kexec_load_disabled.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "kernel.kexec_load_disabled" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for kernel.kexec_load_disabled # /sbin/sysctl -q -n -w kernel.kexec_load_disabled="1" # # If kernel.kexec_load_disabled present in /etc/sysctl.conf, change value to "1" # else, add "kernel.kexec_load_disabled = 1" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^kernel.kexec_load_disabled") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "1" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^kernel.kexec_load_disabled\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^kernel.kexec_load_disabled\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_kexec_load_disabled' ############################################################################### # BEGIN fix (139 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_perf_event_paranoid' ############################################################################### (>&2 echo "Remediating rule 139/210: 'xccdf_org.ssgproject.content_rule_sysctl_kernel_perf_event_paranoid'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of kernel.perf_event_paranoid from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*kernel.perf_event_paranoid.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "kernel.perf_event_paranoid" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for kernel.perf_event_paranoid # /sbin/sysctl -q -n -w kernel.perf_event_paranoid="2" # # If kernel.perf_event_paranoid present in /etc/sysctl.conf, change value to "2" # else, add "kernel.perf_event_paranoid = 2" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^kernel.perf_event_paranoid") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "2" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^kernel.perf_event_paranoid\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^kernel.perf_event_paranoid\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_perf_event_paranoid' ############################################################################### # BEGIN fix (140 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_unprivileged_bpf_disabled' ############################################################################### (>&2 echo "Remediating rule 140/210: 'xccdf_org.ssgproject.content_rule_sysctl_kernel_unprivileged_bpf_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of kernel.unprivileged_bpf_disabled from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*kernel.unprivileged_bpf_disabled.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "kernel.unprivileged_bpf_disabled" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for kernel.unprivileged_bpf_disabled # /sbin/sysctl -q -n -w kernel.unprivileged_bpf_disabled="1" # # If kernel.unprivileged_bpf_disabled present in /etc/sysctl.conf, change value to "1" # else, add "kernel.unprivileged_bpf_disabled = 1" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^kernel.unprivileged_bpf_disabled") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "1" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^kernel.unprivileged_bpf_disabled\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^kernel.unprivileged_bpf_disabled\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_unprivileged_bpf_disabled' ############################################################################### # BEGIN fix (141 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_yama_ptrace_scope' ############################################################################### (>&2 echo "Remediating rule 141/210: 'xccdf_org.ssgproject.content_rule_sysctl_kernel_yama_ptrace_scope'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of kernel.yama.ptrace_scope from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*kernel.yama.ptrace_scope.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "kernel.yama.ptrace_scope" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for kernel.yama.ptrace_scope # /sbin/sysctl -q -n -w kernel.yama.ptrace_scope="1" # # If kernel.yama.ptrace_scope present in /etc/sysctl.conf, change value to "1" # else, add "kernel.yama.ptrace_scope = 1" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^kernel.yama.ptrace_scope") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "1" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^kernel.yama.ptrace_scope\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^kernel.yama.ptrace_scope\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_yama_ptrace_scope' ############################################################################### # BEGIN fix (142 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_net_core_bpf_jit_harden' ############################################################################### (>&2 echo "Remediating rule 142/210: 'xccdf_org.ssgproject.content_rule_sysctl_net_core_bpf_jit_harden'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of net.core.bpf_jit_harden from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*net.core.bpf_jit_harden.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "net.core.bpf_jit_harden" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for net.core.bpf_jit_harden # /sbin/sysctl -q -n -w net.core.bpf_jit_harden="2" # # If net.core.bpf_jit_harden present in /etc/sysctl.conf, change value to "2" # else, add "net.core.bpf_jit_harden = 2" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^net.core.bpf_jit_harden") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "2" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^net.core.bpf_jit_harden\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^net.core.bpf_jit_harden\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_net_core_bpf_jit_harden' ############################################################################### # BEGIN fix (143 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_user_max_user_namespaces' ############################################################################### (>&2 echo "Remediating rule 143/210: 'xccdf_org.ssgproject.content_rule_sysctl_user_max_user_namespaces'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of user.max_user_namespaces from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*user.max_user_namespaces.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "user.max_user_namespaces" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" # # Set runtime for user.max_user_namespaces # /sbin/sysctl -q -n -w user.max_user_namespaces="0" # # If user.max_user_namespaces present in /etc/sysctl.conf, change value to "0" # else, add "user.max_user_namespaces = 0" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^user.max_user_namespaces") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "0" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^user.max_user_namespaces\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^user.max_user_namespaces\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_user_max_user_namespaces' ############################################################################### # BEGIN fix (144 / 210) for 'xccdf_org.ssgproject.content_rule_service_systemd-coredump_disabled' ############################################################################### (>&2 echo "Remediating rule 144/210: 'xccdf_org.ssgproject.content_rule_service_systemd-coredump_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then SOCKET_NAME="systemd-coredump.socket" SYSTEMCTL_EXEC='/usr/bin/systemctl' if "$SYSTEMCTL_EXEC" -q list-unit-files --type socket | grep -q "$SOCKET_NAME"; then "$SYSTEMCTL_EXEC" stop "$SOCKET_NAME" "$SYSTEMCTL_EXEC" mask "$SOCKET_NAME" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_service_systemd-coredump_disabled' ############################################################################### # BEGIN fix (145 / 210) for 'xccdf_org.ssgproject.content_rule_coredump_disable_backtraces' ############################################################################### (>&2 echo "Remediating rule 145/210: 'xccdf_org.ssgproject.content_rule_coredump_disable_backtraces'") # Remediation is applicable only in certain platforms if rpm --quiet -q systemd; then found=false # set value in all files if they contain section or key for f in $(echo -n "/etc/systemd/coredump.conf"); do if [ ! -e "$f" ]; then continue fi # find key in section and change value if grep -qzosP "[[:space:]]*\[Coredump\]([^\n\[]*\n+)+?[[:space:]]*ProcessSizeMax" "$f"; then sed -i "s/ProcessSizeMax[^(\n)]*/ProcessSizeMax=0/" "$f" found=true # find section and add key = value to it elif grep -qs "[[:space:]]*\[Coredump\]" "$f"; then sed -i "/[[:space:]]*\[Coredump\]/a ProcessSizeMax=0" "$f" found=true fi done # if section not in any file, append section with key = value to FIRST file in files parameter if ! $found ; then file=$(echo "/etc/systemd/coredump.conf" | cut -f1 -d ' ') mkdir -p "$(dirname "$file")" echo -e "[Coredump]\nProcessSizeMax=0" >> "$file" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_coredump_disable_backtraces' ############################################################################### # BEGIN fix (146 / 210) for 'xccdf_org.ssgproject.content_rule_coredump_disable_storage' ############################################################################### (>&2 echo "Remediating rule 146/210: 'xccdf_org.ssgproject.content_rule_coredump_disable_storage'") # Remediation is applicable only in certain platforms if rpm --quiet -q systemd; then found=false # set value in all files if they contain section or key for f in $(echo -n "/etc/systemd/coredump.conf"); do if [ ! -e "$f" ]; then continue fi # find key in section and change value if grep -qzosP "[[:space:]]*\[Coredump\]([^\n\[]*\n+)+?[[:space:]]*Storage" "$f"; then sed -i "s/Storage[^(\n)]*/Storage=none/" "$f" found=true # find section and add key = value to it elif grep -qs "[[:space:]]*\[Coredump\]" "$f"; then sed -i "/[[:space:]]*\[Coredump\]/a Storage=none" "$f" found=true fi done # if section not in any file, append section with key = value to FIRST file in files parameter if ! $found ; then file=$(echo "/etc/systemd/coredump.conf" | cut -f1 -d ' ') mkdir -p "$(dirname "$file")" echo -e "[Coredump]\nStorage=none" >> "$file" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_coredump_disable_storage' ############################################################################### # BEGIN fix (147 / 210) for 'xccdf_org.ssgproject.content_rule_disable_users_coredumps' ############################################################################### (>&2 echo "Remediating rule 147/210: 'xccdf_org.ssgproject.content_rule_disable_users_coredumps'") # Remediation is applicable only in certain platforms if rpm --quiet -q pam; then SECURITY_LIMITS_FILE="/etc/security/limits.conf" if grep -qE '^\s*\*\s+hard\s+core' $SECURITY_LIMITS_FILE; then sed -ri 's/(hard\s+core\s+)[[:digit:]]+/\1 0/' $SECURITY_LIMITS_FILE else echo "* hard core 0" >> $SECURITY_LIMITS_FILE fi if ls /etc/security/limits.d/*.conf > /dev/null; then sed -ri '/^\s*\*\s+hard\s+core/d' /etc/security/limits.d/*.conf fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_disable_users_coredumps' ############################################################################### # BEGIN fix (148 / 210) for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_kptr_restrict' ############################################################################### (>&2 echo "Remediating rule 148/210: 'xccdf_org.ssgproject.content_rule_sysctl_kernel_kptr_restrict'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Comment out any occurrences of kernel.kptr_restrict from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do # skip systemd-sysctl symlink (/etc/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf) if [[ "$(readlink -f "$f")" == "/etc/sysctl.conf" ]]; then continue; fi matching_list=$(grep -P '^(?!#).*[\s]*kernel.kptr_restrict.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do escaped_entry=$(sed -e 's|/|\\/|g' <<< "$entry") # comment out "kernel.kptr_restrict" matches to preserve user data sed -i --follow-symlinks "s/^${escaped_entry}$/# &/g" $f done <<< "$matching_list" fi done # # Set sysctl config file which to save the desired value # SYSCONFIG_FILE="/etc/sysctl.conf" sysctl_kernel_kptr_restrict_value='1' # # Set runtime for kernel.kptr_restrict # /sbin/sysctl -q -n -w kernel.kptr_restrict="$sysctl_kernel_kptr_restrict_value" # # If kernel.kptr_restrict present in /etc/sysctl.conf, change value to appropriate value # else, add "kernel.kptr_restrict = value" to /etc/sysctl.conf # # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^kernel.kptr_restrict") # shellcheck disable=SC2059 printf -v formatted_output "%s = %s" "$stripped_key" "$sysctl_kernel_kptr_restrict_value" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^kernel.kptr_restrict\\>" "${SYSCONFIG_FILE}"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^kernel.kptr_restrict\\>.*/$escaped_formatted_output/gi" "${SYSCONFIG_FILE}" else if [[ -s "${SYSCONFIG_FILE}" ]] && [[ -n "$(tail -c 1 -- "${SYSCONFIG_FILE}" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "${SYSCONFIG_FILE}" fi printf '%s\n' "$formatted_output" >> "${SYSCONFIG_FILE}" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sysctl_kernel_kptr_restrict' ############################################################################### # BEGIN fix (149 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_page_poison_argument' ############################################################################### (>&2 echo "Remediating rule 149/210: 'xccdf_org.ssgproject.content_rule_grub2_page_poison_argument'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q grub2-common; }; then grubby --update-kernel=ALL --args=page_poison=1 --env=/boot/grub2/grubenv else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_grub2_page_poison_argument' ############################################################################### # BEGIN fix (150 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_slub_debug_argument' ############################################################################### (>&2 echo "Remediating rule 150/210: 'xccdf_org.ssgproject.content_rule_grub2_slub_debug_argument'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q grub2-common; }; then var_slub_debug_options='P' grubby --update-kernel=ALL --args=slub_debug=$var_slub_debug_options --env=/boot/grub2/grubenv else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_grub2_slub_debug_argument' ############################################################################### # BEGIN fix (151 / 210) for 'xccdf_org.ssgproject.content_rule_package_policycoreutils-python-utils_installed' ############################################################################### (>&2 echo "Remediating rule 151/210: 'xccdf_org.ssgproject.content_rule_package_policycoreutils-python-utils_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "policycoreutils-python-utils" ; then yum install -y "policycoreutils-python-utils" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_policycoreutils-python-utils_installed' ############################################################################### # BEGIN fix (152 / 210) for 'xccdf_org.ssgproject.content_rule_package_policycoreutils_installed' ############################################################################### (>&2 echo "Remediating rule 152/210: 'xccdf_org.ssgproject.content_rule_package_policycoreutils_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "policycoreutils" ; then yum install -y "policycoreutils" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_policycoreutils_installed' ############################################################################### # BEGIN fix (153 / 210) for 'xccdf_org.ssgproject.content_rule_selinux_policytype' ############################################################################### (>&2 echo "Remediating rule 153/210: 'xccdf_org.ssgproject.content_rule_selinux_policytype'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then var_selinux_policy_name='targeted' if [ -e "/etc/selinux/config" ] ; then LC_ALL=C sed -i "/^SELINUXTYPE=/Id" "/etc/selinux/config" else touch "/etc/selinux/config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/selinux/config" cp "/etc/selinux/config" "/etc/selinux/config.bak" # Insert at the end of the file printf '%s\n' "SELINUXTYPE=$var_selinux_policy_name" >> "/etc/selinux/config" # Clean up after ourselves. rm "/etc/selinux/config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_selinux_policytype' ############################################################################### # BEGIN fix (154 / 210) for 'xccdf_org.ssgproject.content_rule_selinux_state' ############################################################################### (>&2 echo "Remediating rule 154/210: 'xccdf_org.ssgproject.content_rule_selinux_state'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then var_selinux_state='enforcing' if [ -e "/etc/selinux/config" ] ; then LC_ALL=C sed -i "/^SELINUX=/Id" "/etc/selinux/config" else touch "/etc/selinux/config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/selinux/config" cp "/etc/selinux/config" "/etc/selinux/config.bak" # Insert at the end of the file printf '%s\n' "SELINUX=$var_selinux_state" >> "/etc/selinux/config" # Clean up after ourselves. rm "/etc/selinux/config.bak" fixfiles onboot fixfiles -f relabel else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_selinux_state' ############################################################################### # BEGIN fix (155 / 210) for 'xccdf_org.ssgproject.content_rule_package_abrt_removed' ############################################################################### (>&2 echo "Remediating rule 155/210: 'xccdf_org.ssgproject.content_rule_package_abrt_removed'") # CAUTION: This remediation script will remove abrt # from the system, and may remove any packages # that depend on abrt. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "abrt" ; then yum remove -y "abrt" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_abrt_removed' ############################################################################### # BEGIN fix (156 / 210) for 'xccdf_org.ssgproject.content_rule_service_kdump_disabled' ############################################################################### (>&2 echo "Remediating rule 156/210: 'xccdf_org.ssgproject.content_rule_service_kdump_disabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then SYSTEMCTL_EXEC='/usr/bin/systemctl' "$SYSTEMCTL_EXEC" stop 'kdump.service' "$SYSTEMCTL_EXEC" disable 'kdump.service' "$SYSTEMCTL_EXEC" mask 'kdump.service' # Disable socket activation if we have a unit file for it if "$SYSTEMCTL_EXEC" -q list-unit-files kdump.socket; then "$SYSTEMCTL_EXEC" stop 'kdump.socket' "$SYSTEMCTL_EXEC" mask 'kdump.socket' fi # The service may not be running because it has been started and failed, # so let's reset the state so OVAL checks pass. # Service should be 'inactive', not 'failed' after reboot though. "$SYSTEMCTL_EXEC" reset-failed 'kdump.service' || true else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_service_kdump_disabled' ############################################################################### # BEGIN fix (157 / 210) for 'xccdf_org.ssgproject.content_rule_package_fapolicyd_installed' ############################################################################### (>&2 echo "Remediating rule 157/210: 'xccdf_org.ssgproject.content_rule_package_fapolicyd_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "fapolicyd" ; then yum install -y "fapolicyd" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_fapolicyd_installed' ############################################################################### # BEGIN fix (158 / 210) for 'xccdf_org.ssgproject.content_rule_service_fapolicyd_enabled' ############################################################################### (>&2 echo "Remediating rule 158/210: 'xccdf_org.ssgproject.content_rule_service_fapolicyd_enabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then SYSTEMCTL_EXEC='/usr/bin/systemctl' "$SYSTEMCTL_EXEC" unmask 'fapolicyd.service' "$SYSTEMCTL_EXEC" start 'fapolicyd.service' "$SYSTEMCTL_EXEC" enable 'fapolicyd.service' else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_service_fapolicyd_enabled' ############################################################################### # BEGIN fix (159 / 210) for 'xccdf_org.ssgproject.content_rule_kerberos_disable_no_keytab' ############################################################################### (>&2 echo "Remediating rule 159/210: 'xccdf_org.ssgproject.content_rule_kerberos_disable_no_keytab'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then rm -f /etc/*.keytab else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_kerberos_disable_no_keytab' ############################################################################### # BEGIN fix (160 / 210) for 'xccdf_org.ssgproject.content_rule_package_sendmail_removed' ############################################################################### (>&2 echo "Remediating rule 160/210: 'xccdf_org.ssgproject.content_rule_package_sendmail_removed'") # Remediation is applicable only in certain platforms if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then # CAUTION: This remediation script will remove sendmail # from the system, and may remove any packages # that depend on sendmail. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "sendmail" ; then yum remove -y "sendmail" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_sendmail_removed' ############################################################################### # BEGIN fix (161 / 210) for 'xccdf_org.ssgproject.content_rule_package_nfs-utils_removed' ############################################################################### (>&2 echo "Remediating rule 161/210: 'xccdf_org.ssgproject.content_rule_package_nfs-utils_removed'") # CAUTION: This remediation script will remove nfs-utils # from the system, and may remove any packages # that depend on nfs-utils. Execute this # remediation AFTER testing on a non-production # system! if rpm -q --quiet "nfs-utils" ; then yum remove -y "nfs-utils" fi # END fix for 'xccdf_org.ssgproject.content_rule_package_nfs-utils_removed' ############################################################################### # BEGIN fix (162 / 210) for 'xccdf_org.ssgproject.content_rule_package_chrony_installed' ############################################################################### (>&2 echo "Remediating rule 162/210: 'xccdf_org.ssgproject.content_rule_package_chrony_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "chrony" ; then yum install -y "chrony" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_chrony_installed' ############################################################################### # BEGIN fix (163 / 210) for 'xccdf_org.ssgproject.content_rule_chronyd_client_only' ############################################################################### (>&2 echo "Remediating rule 163/210: 'xccdf_org.ssgproject.content_rule_chronyd_client_only'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^port") # shellcheck disable=SC2059 printf -v formatted_output "%s %s" "$stripped_key" "0" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^port\\>" "/etc/chrony.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^port\\>.*/$escaped_formatted_output/gi" "/etc/chrony.conf" else if [[ -s "/etc/chrony.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/chrony.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/chrony.conf" fi printf '%s\n' "$formatted_output" >> "/etc/chrony.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_chronyd_client_only' ############################################################################### # BEGIN fix (164 / 210) for 'xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network' ############################################################################### (>&2 echo "Remediating rule 164/210: 'xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # Strip any search characters in the key arg so that the key can be replaced without # adding any search characters to the config file. stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^cmdport") # shellcheck disable=SC2059 printf -v formatted_output "%s %s" "$stripped_key" "0" # If the key exists, change it. Otherwise, add it to the config_file. # We search for the key string followed by a word boundary (matched by \>), # so if we search for 'setting', 'setting2' won't match. if LC_ALL=C grep -q -m 1 -i -e "^cmdport\\>" "/etc/chrony.conf"; then escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output") LC_ALL=C sed -i --follow-symlinks "s/^cmdport\\>.*/$escaped_formatted_output/gi" "/etc/chrony.conf" else if [[ -s "/etc/chrony.conf" ]] && [[ -n "$(tail -c 1 -- "/etc/chrony.conf" || true)" ]]; then LC_ALL=C sed -i --follow-symlinks '$a'\\ "/etc/chrony.conf" fi printf '%s\n' "$formatted_output" >> "/etc/chrony.conf" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network' ############################################################################### # BEGIN fix (165 / 210) for 'xccdf_org.ssgproject.content_rule_package_openssh-clients_installed' ############################################################################### (>&2 echo "Remediating rule 165/210: 'xccdf_org.ssgproject.content_rule_package_openssh-clients_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "openssh-clients" ; then yum install -y "openssh-clients" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_openssh-clients_installed' ############################################################################### # BEGIN fix (166 / 210) for 'xccdf_org.ssgproject.content_rule_package_openssh-server_installed' ############################################################################### (>&2 echo "Remediating rule 166/210: 'xccdf_org.ssgproject.content_rule_package_openssh-server_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "openssh-server" ; then yum install -y "openssh-server" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_openssh-server_installed' ############################################################################### # BEGIN fix (167 / 210) for 'xccdf_org.ssgproject.content_rule_ssh_client_rekey_limit' ############################################################################### (>&2 echo "Remediating rule 167/210: 'xccdf_org.ssgproject.content_rule_ssh_client_rekey_limit'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then var_ssh_client_rekey_limit_size='1G' var_ssh_client_rekey_limit_time='1h' main_config="/etc/ssh/ssh_config" include_directory="/etc/ssh/ssh_config.d" if grep -q '^[\s]*RekeyLimit.*$' "$main_config"; then sed -i '/^[\s]*RekeyLimit.*/d' "$main_config" fi for file in "$include_directory"/*.conf; do if grep -q '^[\s]*RekeyLimit.*$' "$file"; then sed -i '/^[\s]*RekeyLimit.*/d' "$file" fi done if [ -e "/etc/ssh/ssh_config.d/02-rekey-limit.conf" ] ; then LC_ALL=C sed -i "/^\s*RekeyLimit\s\+/d" "/etc/ssh/ssh_config.d/02-rekey-limit.conf" else touch "/etc/ssh/ssh_config.d/02-rekey-limit.conf" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/ssh_config.d/02-rekey-limit.conf" cp "/etc/ssh/ssh_config.d/02-rekey-limit.conf" "/etc/ssh/ssh_config.d/02-rekey-limit.conf.bak" # Insert at the end of the file printf '%s\n' "RekeyLimit $var_ssh_client_rekey_limit_size $var_ssh_client_rekey_limit_time" >> "/etc/ssh/ssh_config.d/02-rekey-limit.conf" # Clean up after ourselves. rm "/etc/ssh/ssh_config.d/02-rekey-limit.conf.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_ssh_client_rekey_limit' ############################################################################### # BEGIN fix (168 / 210) for 'xccdf_org.ssgproject.content_rule_ssh_client_use_strong_rng_csh' ############################################################################### (>&2 echo "Remediating rule 168/210: 'xccdf_org.ssgproject.content_rule_ssh_client_use_strong_rng_csh'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # put line into the file echo "setenv SSH_USE_STRONG_RNG 32" > /etc/profile.d/cc-ssh-strong-rng.csh # remove eventual override in /etc/profile sed -i '/^[[:space:]]*setenv[[:space:]]\+SSH_USE_STRONG_RNG.*$/d' /etc/profile else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_ssh_client_use_strong_rng_csh' ############################################################################### # BEGIN fix (169 / 210) for 'xccdf_org.ssgproject.content_rule_ssh_client_use_strong_rng_sh' ############################################################################### (>&2 echo "Remediating rule 169/210: 'xccdf_org.ssgproject.content_rule_ssh_client_use_strong_rng_sh'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then # put line into the file echo "export SSH_USE_STRONG_RNG=32" > /etc/profile.d/cc-ssh-strong-rng.sh # remove eventual override in /etc/profile sed -i '/^[[:space:]]*export[[:space:]]\+SSH_USE_STRONG_RNG=.*$/d' /etc/profile else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_ssh_client_use_strong_rng_sh' ############################################################################### # BEGIN fix (170 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_set_keepalive_0' ############################################################################### (>&2 echo "Remediating rule 170/210: 'xccdf_org.ssgproject.content_rule_sshd_set_keepalive_0'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*ClientAliveCountMax\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "ClientAliveCountMax 0" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_set_keepalive_0' ############################################################################### # BEGIN fix (171 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_set_idle_timeout' ############################################################################### (>&2 echo "Remediating rule 171/210: 'xccdf_org.ssgproject.content_rule_sshd_set_idle_timeout'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then sshd_idle_timeout_value='840' if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*ClientAliveInterval\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "ClientAliveInterval $sshd_idle_timeout_value" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_set_idle_timeout' ############################################################################### # BEGIN fix (172 / 210) for 'xccdf_org.ssgproject.content_rule_disable_host_auth' ############################################################################### (>&2 echo "Remediating rule 172/210: 'xccdf_org.ssgproject.content_rule_disable_host_auth'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*HostbasedAuthentication\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "HostbasedAuthentication no" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_disable_host_auth' ############################################################################### # BEGIN fix (173 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_disable_empty_passwords' ############################################################################### (>&2 echo "Remediating rule 173/210: 'xccdf_org.ssgproject.content_rule_sshd_disable_empty_passwords'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*PermitEmptyPasswords\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "PermitEmptyPasswords no" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_disable_empty_passwords' ############################################################################### # BEGIN fix (174 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_disable_gssapi_auth' ############################################################################### (>&2 echo "Remediating rule 174/210: 'xccdf_org.ssgproject.content_rule_sshd_disable_gssapi_auth'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*GSSAPIAuthentication\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "GSSAPIAuthentication no" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_disable_gssapi_auth' ############################################################################### # BEGIN fix (175 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_disable_kerb_auth' ############################################################################### (>&2 echo "Remediating rule 175/210: 'xccdf_org.ssgproject.content_rule_sshd_disable_kerb_auth'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*KerberosAuthentication\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "KerberosAuthentication no" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_disable_kerb_auth' ############################################################################### # BEGIN fix (176 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_disable_root_login' ############################################################################### (>&2 echo "Remediating rule 176/210: 'xccdf_org.ssgproject.content_rule_sshd_disable_root_login'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*PermitRootLogin\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "PermitRootLogin no" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_disable_root_login' ############################################################################### # BEGIN fix (177 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_enable_strictmodes' ############################################################################### (>&2 echo "Remediating rule 177/210: 'xccdf_org.ssgproject.content_rule_sshd_enable_strictmodes'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*StrictModes\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "StrictModes yes" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_enable_strictmodes' ############################################################################### # BEGIN fix (178 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_enable_warning_banner' ############################################################################### (>&2 echo "Remediating rule 178/210: 'xccdf_org.ssgproject.content_rule_sshd_enable_warning_banner'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*Banner\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "Banner /etc/issue" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_enable_warning_banner' ############################################################################### # BEGIN fix (179 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_rekey_limit' ############################################################################### (>&2 echo "Remediating rule 179/210: 'xccdf_org.ssgproject.content_rule_sshd_rekey_limit'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then var_rekey_limit_size='1G' var_rekey_limit_time='1h' if [ -e "/etc/ssh/sshd_config" ] ; then LC_ALL=C sed -i "/^\s*RekeyLimit\s\+/Id" "/etc/ssh/sshd_config" else touch "/etc/ssh/sshd_config" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/ssh/sshd_config" cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.bak" # Insert at the beginning of the file printf '%s\n' "RekeyLimit $var_rekey_limit_size $var_rekey_limit_time" > "/etc/ssh/sshd_config" cat "/etc/ssh/sshd_config.bak" >> "/etc/ssh/sshd_config" # Clean up after ourselves. rm "/etc/ssh/sshd_config.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_rekey_limit' ############################################################################### # BEGIN fix (180 / 210) for 'xccdf_org.ssgproject.content_rule_sshd_use_strong_rng' ############################################################################### (>&2 echo "Remediating rule 180/210: 'xccdf_org.ssgproject.content_rule_sshd_use_strong_rng'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if [ -e "/etc/sysconfig/sshd" ] ; then LC_ALL=C sed -i "/^\s*SSH_USE_STRONG_RNG\s*=\s*/d" "/etc/sysconfig/sshd" else touch "/etc/sysconfig/sshd" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/sysconfig/sshd" cp "/etc/sysconfig/sshd" "/etc/sysconfig/sshd.bak" # Insert before the line matching the regex '^#\s*SSH_USE_STRONG_RNG'. line_number="$(LC_ALL=C grep -n "^#\s*SSH_USE_STRONG_RNG" "/etc/sysconfig/sshd.bak" | LC_ALL=C sed 's/:.*//g')" if [ -z "$line_number" ]; then # There was no match of '^#\s*SSH_USE_STRONG_RNG', insert at # the end of the file. printf '%s\n' "SSH_USE_STRONG_RNG=32" >> "/etc/sysconfig/sshd" else head -n "$(( line_number - 1 ))" "/etc/sysconfig/sshd.bak" > "/etc/sysconfig/sshd" printf '%s\n' "SSH_USE_STRONG_RNG=32" >> "/etc/sysconfig/sshd" tail -n "+$(( line_number ))" "/etc/sysconfig/sshd.bak" >> "/etc/sysconfig/sshd" fi # Clean up after ourselves. rm "/etc/sysconfig/sshd.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_sshd_use_strong_rng' ############################################################################### # BEGIN fix (181 / 210) for 'xccdf_org.ssgproject.content_rule_package_usbguard_installed' ############################################################################### (>&2 echo "Remediating rule 181/210: 'xccdf_org.ssgproject.content_rule_package_usbguard_installed'") # Remediation is applicable only in certain platforms if ( ! grep -q s390x /proc/sys/kernel/osrelease && rpm --quiet -q kernel ); then if ! rpm -q --quiet "usbguard" ; then yum install -y "usbguard" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_usbguard_installed' ############################################################################### # BEGIN fix (182 / 210) for 'xccdf_org.ssgproject.content_rule_service_usbguard_enabled' ############################################################################### (>&2 echo "Remediating rule 182/210: 'xccdf_org.ssgproject.content_rule_service_usbguard_enabled'") # Remediation is applicable only in certain platforms if ( ! grep -q s390x /proc/sys/kernel/osrelease && rpm --quiet -q kernel ); then SYSTEMCTL_EXEC='/usr/bin/systemctl' "$SYSTEMCTL_EXEC" unmask 'usbguard.service' "$SYSTEMCTL_EXEC" start 'usbguard.service' "$SYSTEMCTL_EXEC" enable 'usbguard.service' else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_service_usbguard_enabled' ############################################################################### # BEGIN fix (183 / 210) for 'xccdf_org.ssgproject.content_rule_configure_usbguard_auditbackend' ############################################################################### (>&2 echo "Remediating rule 183/210: 'xccdf_org.ssgproject.content_rule_configure_usbguard_auditbackend'") # Remediation is applicable only in certain platforms if ( ! grep -q s390x /proc/sys/kernel/osrelease && rpm --quiet -q kernel ) && { rpm --quiet -q usbguard; }; then if [ -e "/etc/usbguard/usbguard-daemon.conf" ] ; then LC_ALL=C sed -i "/^\s*AuditBackend=/d" "/etc/usbguard/usbguard-daemon.conf" else touch "/etc/usbguard/usbguard-daemon.conf" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/usbguard/usbguard-daemon.conf" cp "/etc/usbguard/usbguard-daemon.conf" "/etc/usbguard/usbguard-daemon.conf.bak" # Insert at the end of the file printf '%s\n' "AuditBackend=LinuxAudit" >> "/etc/usbguard/usbguard-daemon.conf" # Clean up after ourselves. rm "/etc/usbguard/usbguard-daemon.conf.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_configure_usbguard_auditbackend' ############################################################################### # BEGIN fix (184 / 210) for 'xccdf_org.ssgproject.content_rule_usbguard_allow_hid_and_hub' ############################################################################### (>&2 echo "Remediating rule 184/210: 'xccdf_org.ssgproject.content_rule_usbguard_allow_hid_and_hub'") # Remediation is applicable only in certain platforms if ( ! grep -q s390x /proc/sys/kernel/osrelease && rpm --quiet -q kernel ); then echo "allow with-interface match-all { 03:*:* 09:00:* }" >> /etc/usbguard/rules.conf else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_usbguard_allow_hid_and_hub' ############################################################################### # BEGIN fix (185 / 210) for 'xccdf_org.ssgproject.content_rule_package_audit_installed' ############################################################################### (>&2 echo "Remediating rule 185/210: 'xccdf_org.ssgproject.content_rule_package_audit_installed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then if ! rpm -q --quiet "audit" ; then yum install -y "audit" fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_package_audit_installed' ############################################################################### # BEGIN fix (186 / 210) for 'xccdf_org.ssgproject.content_rule_service_auditd_enabled' ############################################################################### (>&2 echo "Remediating rule 186/210: 'xccdf_org.ssgproject.content_rule_service_auditd_enabled'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q audit; }; then SYSTEMCTL_EXEC='/usr/bin/systemctl' "$SYSTEMCTL_EXEC" unmask 'auditd.service' "$SYSTEMCTL_EXEC" start 'auditd.service' "$SYSTEMCTL_EXEC" enable 'auditd.service' else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_service_auditd_enabled' ############################################################################### # BEGIN fix (187 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_audit_argument' ############################################################################### (>&2 echo "Remediating rule 187/210: 'xccdf_org.ssgproject.content_rule_grub2_audit_argument'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q grub2-common; }; then grubby --update-kernel=ALL --args=audit=1 --env=/boot/grub2/grubenv else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_grub2_audit_argument' ############################################################################### # BEGIN fix (188 / 210) for 'xccdf_org.ssgproject.content_rule_grub2_audit_backlog_limit_argument' ############################################################################### (>&2 echo "Remediating rule 188/210: 'xccdf_org.ssgproject.content_rule_grub2_audit_backlog_limit_argument'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel && { rpm --quiet -q grub2-common; }; then grubby --update-kernel=ALL --args=audit_backlog_limit=8192 --env=/boot/grub2/grubenv else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_grub2_audit_backlog_limit_argument' ############################################################################### # BEGIN fix (189 / 210) for 'xccdf_org.ssgproject.content_rule_auditd_data_retention_flush' ############################################################################### (>&2 echo "Remediating rule 189/210: 'xccdf_org.ssgproject.content_rule_auditd_data_retention_flush'") # Remediation is applicable only in certain platforms if rpm --quiet -q audit && rpm --quiet -q kernel; then var_auditd_flush='incremental_async' AUDITCONFIG=/etc/audit/auditd.conf # if flush is present, flush param edited to var_auditd_flush # else flush param is defined by var_auditd_flush # # the freq param is only used for values 'incremental' and 'incremental_async' and will be # commented out if flush != incremental or flush != incremental_async # # if flush == incremental or flush == incremental_async && freq param is not defined, it # will be defined as the package-default value of 20 grep -q ^flush $AUDITCONFIG && \ sed -i 's/^flush.*/flush = '"$var_auditd_flush"'/g' $AUDITCONFIG if ! [ $? -eq 0 ]; then echo "flush = $var_auditd_flush" >> $AUDITCONFIG fi if ! [ "$var_auditd_flush" == "incremental" ] && ! [ "$var_auditd_flush" == "incremental_async" ]; then sed -i 's/^freq/##freq/g' $AUDITCONFIG elif [ "$var_auditd_flush" == "incremental" ] || [ "$var_auditd_flush" == "incremental_async" ]; then grep -q freq $AUDITCONFIG && \ sed -i 's/^#\+freq/freq/g' $AUDITCONFIG if ! [ $? -eq 0 ]; then echo "freq = 20" >> $AUDITCONFIG fi fi else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_auditd_data_retention_flush' ############################################################################### # BEGIN fix (190 / 210) for 'xccdf_org.ssgproject.content_rule_auditd_freq' ############################################################################### (>&2 echo "Remediating rule 190/210: 'xccdf_org.ssgproject.content_rule_auditd_freq'") # Remediation is applicable only in certain platforms if rpm --quiet -q audit && rpm --quiet -q kernel; then if [ -e "/etc/audit/auditd.conf" ] ; then LC_ALL=C sed -i "/^\s*freq\s*=\s*/Id" "/etc/audit/auditd.conf" else touch "/etc/audit/auditd.conf" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/audit/auditd.conf" cp "/etc/audit/auditd.conf" "/etc/audit/auditd.conf.bak" # Insert at the end of the file printf '%s\n' "freq = 50" >> "/etc/audit/auditd.conf" # Clean up after ourselves. rm "/etc/audit/auditd.conf.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_auditd_freq' ############################################################################### # BEGIN fix (191 / 210) for 'xccdf_org.ssgproject.content_rule_auditd_local_events' ############################################################################### (>&2 echo "Remediating rule 191/210: 'xccdf_org.ssgproject.content_rule_auditd_local_events'") # Remediation is applicable only in certain platforms if rpm --quiet -q audit && rpm --quiet -q kernel; then if [ -e "/etc/audit/auditd.conf" ] ; then LC_ALL=C sed -i "/^\s*local_events\s*=\s*/Id" "/etc/audit/auditd.conf" else touch "/etc/audit/auditd.conf" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/audit/auditd.conf" cp "/etc/audit/auditd.conf" "/etc/audit/auditd.conf.bak" # Insert at the end of the file printf '%s\n' "local_events = yes" >> "/etc/audit/auditd.conf" # Clean up after ourselves. rm "/etc/audit/auditd.conf.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_auditd_local_events' ############################################################################### # BEGIN fix (192 / 210) for 'xccdf_org.ssgproject.content_rule_auditd_log_format' ############################################################################### (>&2 echo "Remediating rule 192/210: 'xccdf_org.ssgproject.content_rule_auditd_log_format'") # Remediation is applicable only in certain platforms if rpm --quiet -q audit && rpm --quiet -q kernel; then if [ -e "/etc/audit/auditd.conf" ] ; then LC_ALL=C sed -i "/^\s*log_format\s*=\s*/Id" "/etc/audit/auditd.conf" else touch "/etc/audit/auditd.conf" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/audit/auditd.conf" cp "/etc/audit/auditd.conf" "/etc/audit/auditd.conf.bak" # Insert at the end of the file printf '%s\n' "log_format = ENRICHED" >> "/etc/audit/auditd.conf" # Clean up after ourselves. rm "/etc/audit/auditd.conf.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_auditd_log_format' ############################################################################### # BEGIN fix (193 / 210) for 'xccdf_org.ssgproject.content_rule_auditd_name_format' ############################################################################### (>&2 echo "Remediating rule 193/210: 'xccdf_org.ssgproject.content_rule_auditd_name_format'") # Remediation is applicable only in certain platforms if rpm --quiet -q audit && rpm --quiet -q kernel; then var_auditd_name_format='hostname' var_auditd_name_format="$(echo $var_auditd_name_format | cut -d \| -f 1)" if [ -e "/etc/audit/auditd.conf" ] ; then LC_ALL=C sed -i "/^\s*name_format\s*=\s*/Id" "/etc/audit/auditd.conf" else touch "/etc/audit/auditd.conf" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/audit/auditd.conf" cp "/etc/audit/auditd.conf" "/etc/audit/auditd.conf.bak" # Insert at the end of the file printf '%s\n' "name_format = $var_auditd_name_format" >> "/etc/audit/auditd.conf" # Clean up after ourselves. rm "/etc/audit/auditd.conf.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_auditd_name_format' ############################################################################### # BEGIN fix (194 / 210) for 'xccdf_org.ssgproject.content_rule_auditd_write_logs' ############################################################################### (>&2 echo "Remediating rule 194/210: 'xccdf_org.ssgproject.content_rule_auditd_write_logs'") # Remediation is applicable only in certain platforms if rpm --quiet -q audit && rpm --quiet -q kernel; then if [ -e "/etc/audit/auditd.conf" ] ; then LC_ALL=C sed -i "/^\s*write_logs\s*=\s*/Id" "/etc/audit/auditd.conf" else touch "/etc/audit/auditd.conf" fi # make sure file has newline at the end sed -i -e '$a\' "/etc/audit/auditd.conf" cp "/etc/audit/auditd.conf" "/etc/audit/auditd.conf.bak" # Insert at the end of the file printf '%s\n' "write_logs = yes" >> "/etc/audit/auditd.conf" # Clean up after ourselves. rm "/etc/audit/auditd.conf.bak" else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_auditd_write_logs' ############################################################################### # BEGIN fix (195 / 210) for 'xccdf_org.ssgproject.content_rule_audit_access_failed' ############################################################################### (>&2 echo "Remediating rule 195/210: 'xccdf_org.ssgproject.content_rule_audit_access_failed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-3-access-failed.rules ## Unsuccessful file access (any other opens) This has to go last. -a always,exit -F arch=b32 -S open,openat,openat2,open_by_handle_at -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-access -a always,exit -F arch=b64 -S open,openat,openat2,open_by_handle_at -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-access -a always,exit -F arch=b32 -S open,openat,openat2,open_by_handle_at -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-access -a always,exit -F arch=b64 -S open,openat,openat2,open_by_handle_at -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-access EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-3-access-failed.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_access_failed' ############################################################################### # BEGIN fix (196 / 210) for 'xccdf_org.ssgproject.content_rule_audit_access_success' ############################################################################### (>&2 echo "Remediating rule 196/210: 'xccdf_org.ssgproject.content_rule_audit_access_success'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-3-access-success.rules ## Successful file access (any other opens) This has to go last. ## These next two are likely to result in a whole lot of events -a always,exit -F arch=b32 -S open,openat,openat2,open_by_handle_at -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-access -a always,exit -F arch=b64 -S open,openat,openat2,open_by_handle_at -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-access EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-3-access-success.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_access_success' ############################################################################### # BEGIN fix (197 / 210) for 'xccdf_org.ssgproject.content_rule_audit_basic_configuration' ############################################################################### (>&2 echo "Remediating rule 197/210: 'xccdf_org.ssgproject.content_rule_audit_basic_configuration'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/10-base-config.rules ## First rule - delete all -D ## Increase the buffers to survive stress events. ## Make this bigger for busy systems -b 8192 ## This determine how long to wait in burst of events --backlog_wait_time 60000 ## Set failure mode to syslog -f 1 EOF chmod o-rwx /etc/audit/rules.d/10-base-config.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_basic_configuration' ############################################################################### # BEGIN fix (198 / 210) for 'xccdf_org.ssgproject.content_rule_audit_create_failed' ############################################################################### (>&2 echo "Remediating rule 198/210: 'xccdf_org.ssgproject.content_rule_audit_create_failed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-1-create-failed.rules ## Unsuccessful file creation (open with O_CREAT) -a always,exit -F arch=b32 -S openat,open_by_handle_at -F a2&0100 -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&0100 -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b32 -S open -F a1&0100 -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b64 -S open -F a1&0100 -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b32 -S creat -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b64 -S creat -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b32 -S openat,open_by_handle_at -F a2&0100 -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&0100 -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b32 -S open -F a1&0100 -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b64 -S open -F a1&0100 -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b32 -S creat -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-create -a always,exit -F arch=b64 -S creat -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-create EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-1-create-failed.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_create_failed' ############################################################################### # BEGIN fix (199 / 210) for 'xccdf_org.ssgproject.content_rule_audit_create_success' ############################################################################### (>&2 echo "Remediating rule 199/210: 'xccdf_org.ssgproject.content_rule_audit_create_success'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-1-create-success.rules ## Successful file creation (open with O_CREAT) -a always,exit -F arch=b32 -S openat,open_by_handle_at -F a2&0100 -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-create -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&0100 -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-create -a always,exit -F arch=b32 -S open -F a1&0100 -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-create -a always,exit -F arch=b64 -S open -F a1&0100 -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-create -a always,exit -F arch=b32 -S creat -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-create -a always,exit -F arch=b64 -S creat -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-create EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-1-create-success.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_create_success' ############################################################################### # BEGIN fix (200 / 210) for 'xccdf_org.ssgproject.content_rule_audit_delete_failed' ############################################################################### (>&2 echo "Remediating rule 200/210: 'xccdf_org.ssgproject.content_rule_audit_delete_failed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-4-delete-failed.rules ## Unsuccessful file delete -a always,exit -F arch=b32 -S unlink,unlinkat,rename,renameat -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-delete -a always,exit -F arch=b64 -S unlink,unlinkat,rename,renameat -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-delete -a always,exit -F arch=b32 -S unlink,unlinkat,rename,renameat -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-delete -a always,exit -F arch=b64 -S unlink,unlinkat,rename,renameat -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-delete EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-4-delete-failed.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_delete_failed' ############################################################################### # BEGIN fix (201 / 210) for 'xccdf_org.ssgproject.content_rule_audit_delete_success' ############################################################################### (>&2 echo "Remediating rule 201/210: 'xccdf_org.ssgproject.content_rule_audit_delete_success'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-4-delete-success.rules ## Successful file delete -a always,exit -F arch=b32 -S unlink,unlinkat,rename,renameat -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-delete -a always,exit -F arch=b64 -S unlink,unlinkat,rename,renameat -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-delete EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-4-delete-success.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_delete_success' ############################################################################### # BEGIN fix (202 / 210) for 'xccdf_org.ssgproject.content_rule_audit_immutable_login_uids' ############################################################################### (>&2 echo "Remediating rule 202/210: 'xccdf_org.ssgproject.content_rule_audit_immutable_login_uids'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/11-loginuid.rules ## Make the loginuid immutable. This prevents tampering with the auid. --loginuid-immutable EOF chmod o-rwx /etc/audit/rules.d/11-loginuid.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_immutable_login_uids' ############################################################################### # BEGIN fix (203 / 210) for 'xccdf_org.ssgproject.content_rule_audit_modify_failed' ############################################################################### (>&2 echo "Remediating rule 203/210: 'xccdf_org.ssgproject.content_rule_audit_modify_failed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-2-modify-failed.rules ## Unsuccessful file modifications (open for write or truncate) -a always,exit -F arch=b32 -S openat,open_by_handle_at -F a2&01003 -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&01003 -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b32 -S open -F a1&01003 -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b64 -S open -F a1&01003 -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b32 -S truncate,ftruncate -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b64 -S truncate,ftruncate -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b32 -S openat,open_by_handle_at -F a2&01003 -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&01003 -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b32 -S open -F a1&01003 -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b64 -S open -F a1&01003 -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b32 -S truncate,ftruncate -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification -a always,exit -F arch=b64 -S truncate,ftruncate -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-modification EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-2-modify-failed.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_modify_failed' ############################################################################### # BEGIN fix (204 / 210) for 'xccdf_org.ssgproject.content_rule_audit_modify_success' ############################################################################### (>&2 echo "Remediating rule 204/210: 'xccdf_org.ssgproject.content_rule_audit_modify_success'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-2-modify-success.rules ## Successful file modifications (open for write or truncate) -a always,exit -F arch=b32 -S openat,open_by_handle_at -F a2&01003 -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-modification -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&01003 -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-modification -a always,exit -F arch=b32 -S open -F a1&01003 -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-modification -a always,exit -F arch=b64 -S open -F a1&01003 -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-modification -a always,exit -F arch=b32 -S truncate,ftruncate -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-modification -a always,exit -F arch=b64 -S truncate,ftruncate -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-modification EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-2-modify-success.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_modify_success' ############################################################################### # BEGIN fix (205 / 210) for 'xccdf_org.ssgproject.content_rule_audit_module_load' ############################################################################### (>&2 echo "Remediating rule 205/210: 'xccdf_org.ssgproject.content_rule_audit_module_load'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/43-module-load.rules ## These rules watch for kernel module insertion. By monitoring ## the syscall, we do not need any watches on programs. -a always,exit -F arch=b32 -S init_module,finit_module -F key=module-load -a always,exit -F arch=b64 -S init_module,finit_module -F key=module-load -a always,exit -F arch=b32 -S delete_module -F key=module-unload -a always,exit -F arch=b64 -S delete_module -F key=module-unload EOF chmod o-rwx /etc/audit/rules.d/43-module-load.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_module_load' ############################################################################### # BEGIN fix (206 / 210) for 'xccdf_org.ssgproject.content_rule_audit_ospp_general' ############################################################################### (>&2 echo "Remediating rule 206/210: 'xccdf_org.ssgproject.content_rule_audit_ospp_general'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42.rules ## The purpose of these rules is to meet the requirements for Operating ## System Protection Profile (OSPP)v4.2. These rules depends on having ## the following rule files copied to /etc/audit/rules.d: ## ## 10-base-config.rules, 11-loginuid.rules, ## 30-ospp-v42-1-create-failed.rules, 30-ospp-v42-1-create-success.rules, ## 30-ospp-v42-2-modify-failed.rules, 30-ospp-v42-2-modify-success.rules, ## 30-ospp-v42-3-access-failed.rules, 30-ospp-v42-3-access-success.rules, ## 30-ospp-v42-4-delete-failed.rules, 30-ospp-v42-4-delete-success.rules, ## 30-ospp-v42-5-perm-change-failed.rules, ## 30-ospp-v42-5-perm-change-success.rules, ## 30-ospp-v42-6-owner-change-failed.rules, ## 30-ospp-v42-6-owner-change-success.rules ## ## original copies may be found in /usr/share/audit/sample-rules/ ## User add delete modify. This is covered by pam. However, someone could ## open a file and directly create or modify a user, so we'll watch passwd and ## shadow for writes -a always,exit -F arch=b32 -S openat,open_by_handle_at -F a2&03 -F path=/etc/passwd -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&03 -F path=/etc/passwd -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b32 -S open -F a1&03 -F path=/etc/passwd -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b64 -S open -F a1&03 -F path=/etc/passwd -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b32 -S openat,open_by_handle_at -F a2&03 -F path=/etc/shadow -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b64 -S openat,open_by_handle_at -F a2&03 -F path=/etc/shadow -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b32 -S open -F a1&03 -F path=/etc/shadow -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b64 -S open -F a1&03 -F path=/etc/shadow -F auid>=1000 -F auid!=unset -F key=user-modify ## User enable and disable. This is entirely handled by pam. ## Group add delete modify. This is covered by pam. However, someone could ## open a file and directly create or modify a user, so we'll watch group and ## gshadow for writes -a always,exit -F arch=b32 -F path=/etc/passwd -F perm=wa -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b64 -F path=/etc/passwd -F perm=wa -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b32 -F path=/etc/shadow -F perm=wa -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b64 -F path=/etc/shadow -F perm=wa -F auid>=1000 -F auid!=unset -F key=user-modify -a always,exit -F arch=b32 -F path=/etc/group -F perm=wa -F auid>=1000 -F auid!=unset -F key=group-modify -a always,exit -F arch=b64 -F path=/etc/group -F perm=wa -F auid>=1000 -F auid!=unset -F key=group-modify -a always,exit -F arch=b32 -F path=/etc/gshadow -F perm=wa -F auid>=1000 -F auid!=unset -F key=group-modify -a always,exit -F arch=b64 -F path=/etc/gshadow -F perm=wa -F auid>=1000 -F auid!=unset -F key=group-modify ## Use of special rights for config changes. This would be use of setuid ## programs that relate to user accts. This is not all setuid apps because ## requirements are only for ones that affect system configuration. -a always,exit -F arch=b32 -F path=/usr/sbin/unix_chkpwd -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/sbin/unix_chkpwd -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/sbin/usernetctl -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/sbin/usernetctl -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/sbin/userhelper -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/sbin/userhelper -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/sbin/seunshare -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/sbin/seunshare -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/mount -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/mount -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/newgrp -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/newgrp -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/newuidmap -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/newuidmap -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/gpasswd -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/gpasswd -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/newgidmap -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/newgidmap -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/umount -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/umount -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/passwd -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/passwd -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/crontab -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/crontab -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/bin/at -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/bin/at -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b32 -F path=/usr/sbin/grub2-set-bootflag -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes -a always,exit -F arch=b64 -F path=/usr/sbin/grub2-set-bootflag -F perm=x -F auid>=1000 -F auid!=unset -F key=special-config-changes ## Privilege escalation via su or sudo. This is entirely handled by pam. ## Special case for systemd-run. It is not audit aware, specifically watch it -a always,exit -F arch=b32 -F path=/usr/bin/systemd-run -F perm=x -F auid!=unset -F key=maybe-escalation -a always,exit -F arch=b64 -F path=/usr/bin/systemd-run -F perm=x -F auid!=unset -F key=maybe-escalation ## Special case for pkexec. It is not audit aware, specifically watch it -a always,exit -F arch=b32 -F path=/usr/bin/pkexec -F perm=x -F key=maybe-escalation -a always,exit -F arch=b64 -F path=/usr/bin/pkexec -F perm=x -F key=maybe-escalation ## Watch for configuration changes to privilege escalation. -a always,exit -F arch=b32 -F path=/etc/sudoers -F perm=wa -F key=special-config-changes -a always,exit -F arch=b64 -F path=/etc/sudoers -F perm=wa -F key=special-config-changes -a always,exit -F arch=b32 -F dir=/etc/sudoers.d/ -F perm=wa -F key=special-config-changes -a always,exit -F arch=b64 -F dir=/etc/sudoers.d/ -F perm=wa -F key=special-config-changes ## Audit log access -a always,exit -F arch=b32 -F dir=/var/log/audit/ -F perm=r -F auid>=1000 -F auid!=unset -F key=access-audit-trail -a always,exit -F arch=b64 -F dir=/var/log/audit/ -F perm=r -F auid>=1000 -F auid!=unset -F key=access-audit-trail ## Attempts to Alter Process and Session Initiation Information -a always,exit -F arch=b32 -F path=/var/run/utmp -F perm=wa -F auid>=1000 -F auid!=unset -F key=session -a always,exit -F arch=b64 -F path=/var/run/utmp -F perm=wa -F auid>=1000 -F auid!=unset -F key=session -a always,exit -F arch=b32 -F path=/var/log/btmp -F perm=wa -F auid>=1000 -F auid!=unset -F key=session -a always,exit -F arch=b64 -F path=/var/log/btmp -F perm=wa -F auid>=1000 -F auid!=unset -F key=session -a always,exit -F arch=b32 -F path=/var/log/wtmp -F perm=wa -F auid>=1000 -F auid!=unset -F key=session -a always,exit -F arch=b64 -F path=/var/log/wtmp -F perm=wa -F auid>=1000 -F auid!=unset -F key=session ## Attempts to modify MAC controls -a always,exit -F arch=b32 -F dir=/etc/selinux/ -F perm=wa -F auid>=1000 -F auid!=unset -F key=MAC-policy -a always,exit -F arch=b64 -F dir=/etc/selinux/ -F perm=wa -F auid>=1000 -F auid!=unset -F key=MAC-policy ## Software updates. This is entirely handled by rpm. ## System start and shutdown. This is entirely handled by systemd ## Kernel Module loading. This is handled in 43-module-load.rules ## Application invocation. The requirements list an optional requirement ## FPT_SRP_EXT.1 Software Restriction Policies. This event is intended to ## state results from that policy. This would be handled entirely by ## that daemon. EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_ospp_general' ############################################################################### # BEGIN fix (207 / 210) for 'xccdf_org.ssgproject.content_rule_audit_owner_change_failed' ############################################################################### (>&2 echo "Remediating rule 207/210: 'xccdf_org.ssgproject.content_rule_audit_owner_change_failed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-6-owner-change-failed.rules ## Unsuccessful ownership change -a always,exit -F arch=b32 -S lchown,fchown,chown,fchownat -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-owner-change -a always,exit -F arch=b64 -S lchown,fchown,chown,fchownat -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-owner-change -a always,exit -F arch=b32 -S lchown,fchown,chown,fchownat -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-owner-change -a always,exit -F arch=b64 -S lchown,fchown,chown,fchownat -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-owner-change EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-6-owner-change-failed.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_owner_change_failed' ############################################################################### # BEGIN fix (208 / 210) for 'xccdf_org.ssgproject.content_rule_audit_owner_change_success' ############################################################################### (>&2 echo "Remediating rule 208/210: 'xccdf_org.ssgproject.content_rule_audit_owner_change_success'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-6-owner-change-success.rules ## Successful ownership change -a always,exit -F arch=b32 -S lchown,fchown,chown,fchownat -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-owner-change -a always,exit -F arch=b64 -S lchown,fchown,chown,fchownat -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-owner-change EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-6-owner-change-success.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_owner_change_success' ############################################################################### # BEGIN fix (209 / 210) for 'xccdf_org.ssgproject.content_rule_audit_perm_change_failed' ############################################################################### (>&2 echo "Remediating rule 209/210: 'xccdf_org.ssgproject.content_rule_audit_perm_change_failed'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-5-perm-change-failed.rules ## Unsuccessful permission change -a always,exit -F arch=b32 -S chmod,fchmod,fchmodat,setxattr,lsetxattr,fsetxattr,removexattr,lremovexattr,fremovexattr -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-perm-change -a always,exit -F arch=b64 -S chmod,fchmod,fchmodat,setxattr,lsetxattr,fsetxattr,removexattr,lremovexattr,fremovexattr -F exit=-EACCES -F auid>=1000 -F auid!=unset -F key=unsuccessful-perm-change -a always,exit -F arch=b32 -S chmod,fchmod,fchmodat,setxattr,lsetxattr,fsetxattr,removexattr,lremovexattr,fremovexattr -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-perm-change -a always,exit -F arch=b64 -S chmod,fchmod,fchmodat,setxattr,lsetxattr,fsetxattr,removexattr,lremovexattr,fremovexattr -F exit=-EPERM -F auid>=1000 -F auid!=unset -F key=unsuccessful-perm-change EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-5-perm-change-failed.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_perm_change_failed' ############################################################################### # BEGIN fix (210 / 210) for 'xccdf_org.ssgproject.content_rule_audit_perm_change_success' ############################################################################### (>&2 echo "Remediating rule 210/210: 'xccdf_org.ssgproject.content_rule_audit_perm_change_success'") # Remediation is applicable only in certain platforms if rpm --quiet -q kernel; then cat << 'EOF' > /etc/audit/rules.d/30-ospp-v42-5-perm-change-success.rules ## Successful permission change -a always,exit -F arch=b32 -S chmod,fchmod,fchmodat,setxattr,lsetxattr,fsetxattr,removexattr,lremovexattr,fremovexattr -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-perm-change -a always,exit -F arch=b64 -S chmod,fchmod,fchmodat,setxattr,lsetxattr,fsetxattr,removexattr,lremovexattr,fremovexattr -F success=1 -F auid>=1000 -F auid!=unset -F key=successful-perm-change EOF chmod o-rwx /etc/audit/rules.d/30-ospp-v42-5-perm-change-success.rules augenrules --load else >&2 echo 'Remediation is not applicable, nothing was done' fi # END fix for 'xccdf_org.ssgproject.content_rule_audit_perm_change_success'