Skip to content

Commit

Permalink
fix: catch cidr network in ssh keys (#236)
Browse files Browse the repository at this point in the history
Co-authored-by: Ismaël Tanguy <[email protected]>
  • Loading branch information
Isma399 and Ismaël Tanguy authored Feb 22, 2024
1 parent 3bd4078 commit 43fc23e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/hardening/99.5.2.4_ssh_keys_from.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DESCRIPTION="Check <from> 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"
Expand Down
4 changes: 2 additions & 2 deletions tests/hardening/99.5.2.4_ssh_keys_from.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 43fc23e

Please sign in to comment.