From 43fc23ee4063e801b7fb7bf38bed8d74cb83e5e1 Mon Sep 17 00:00:00 2001 From: Isma399 Date: Thu, 22 Feb 2024 17:55:03 +0100 Subject: [PATCH] fix: catch cidr network in ssh keys (#236) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ismaƫl Tanguy --- bin/hardening/99.5.2.4_ssh_keys_from.sh | 2 +- tests/hardening/99.5.2.4_ssh_keys_from.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/hardening/99.5.2.4_ssh_keys_from.sh b/bin/hardening/99.5.2.4_ssh_keys_from.sh index 5699122..75ebe0b 100755 --- a/bin/hardening/99.5.2.4_ssh_keys_from.sh +++ b/bin/hardening/99.5.2.4_ssh_keys_from.sh @@ -19,7 +19,7 @@ DESCRIPTION="Check field in ssh authorized keys files for users with logi # Regex looking for empty, hash starting lines, or 'from="127.127.127,127.127.127" ssh' # shellcheck disable=2089 -REGEX_FROM_IP="from=(?:'|\")(,?(\d{1,3}(\.\d{1,3}){3}))+(?:'|\")" +REGEX_FROM_IP="from=(?:'|\")(,?(\d{1,3}(\.\d{1,3}){3})(\/\d{1,2})?)+(?:'|\")" REGEX_OK_LINES="(^(#|$)|($REGEX_FROM_IP))" AUTHKEYFILE_PATTERN="" AUTHKEYFILE_PATTERN_DEFAULT=".ssh/authorized_keys .ssh/authorized_keys2" diff --git a/tests/hardening/99.5.2.4_ssh_keys_from.sh b/tests/hardening/99.5.2.4_ssh_keys_from.sh index a675d64..8f0d6a2 100644 --- a/tests/hardening/99.5.2.4_ssh_keys_from.sh +++ b/tests/hardening/99.5.2.4_ssh_keys_from.sh @@ -72,11 +72,11 @@ test_audit() { run allwdfromip "${CIS_CHECKS_DIR}/${script}.sh" --audit-all # shellcheck disable=2016 - echo 'ALLOWED_IPS="$ALLOWED_IPS 127.0.0.1,10.2.3.1"' >>"${CIS_CONF_DIR}/conf.d/${script}.cfg" + echo 'ALLOWED_IPS="$ALLOWED_IPS 127.0.0.1,10.2.3.1/8"' >>"${CIS_CONF_DIR}/conf.d/${script}.cfg" { echo -n 'from="10.0.1.2",command="echo bla" ' cat /tmp/key1.pub - echo -n 'command="echo bla,from="10.0.1.2,10.2.3.1"" ' + echo -n 'command="echo bla,from="10.0.1.2,10.2.3.1/8"" ' cat /tmp/key1.pub } >>/home/secaudit/.ssh/authorized_keys2 describe Key with from and command options