mirror of
https://github.com/hardenedlinux/harbian-audit.git
synced 2025-07-31 01:24:58 +02:00
Eliminate duplicate audit items 9.3.26
This commit is contained in:
parent
0e20dd251a
commit
3fbb8a8452
@ -1,11 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#
|
#
|
||||||
# harbian-audit for Debian GNU/Linux 7/8/9 Hardening
|
# harbian-audit for Debian GNU/Linux 9 Hardening
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
# 9.3.13 Limit Access via SSH (Scored)
|
# 9.3.13 Ensure SSH access is limited (Scored)
|
||||||
|
# Auther: Samson-W (sccxboy@gmail.com)
|
||||||
#
|
#
|
||||||
|
|
||||||
set -e # One error, it's over
|
set -e # One error, it's over
|
||||||
@ -15,28 +16,59 @@ HARDENING_LEVEL=3
|
|||||||
|
|
||||||
PACKAGE='openssh-server'
|
PACKAGE='openssh-server'
|
||||||
FILE='/etc/ssh/sshd_config'
|
FILE='/etc/ssh/sshd_config'
|
||||||
|
ALLOWUSER='AllowUsers[[:space:]]*\*'
|
||||||
|
ALLOWGROUP='AllowGroups[[:space:]]*\*'
|
||||||
|
DENYUSER='DenyUsers[[:space:]]*nobody'
|
||||||
|
DENYGROUP='DenyGroups[[:space:]]*nobody'
|
||||||
|
|
||||||
|
ALLOWUSER_KEY='AllowUsers'
|
||||||
|
ALLOWGROUP_KEY='AllowGroups'
|
||||||
|
DENYUSER_KEY='DenyUsers'
|
||||||
|
DENYGROUP_KEY='DenyGroups'
|
||||||
|
|
||||||
|
ALLOWUSER_RET=1
|
||||||
|
ALLOWGROUP_RET=1
|
||||||
|
DENYUSER_RET=1
|
||||||
|
DENYGROUP_RET=1
|
||||||
|
|
||||||
# This function will be called if the script status is on enabled / audit mode
|
# This function will be called if the script status is on enabled / audit mode
|
||||||
audit () {
|
audit () {
|
||||||
OPTIONS="AllowUsers='$ALLOWED_USERS' AllowGroups='$ALLOWED_GROUPS' DenyUsers='$DENIED_USERS' DenyGroups='$DENIED_GROUPS'"
|
|
||||||
is_pkg_installed $PACKAGE
|
is_pkg_installed $PACKAGE
|
||||||
if [ $FNRET != 0 ]; then
|
if [ $FNRET != 0 ]; then
|
||||||
crit "$PACKAGE is not installed!"
|
crit "$PACKAGE is not installed!"
|
||||||
else
|
else
|
||||||
ok "$PACKAGE is installed"
|
ok "$PACKAGE is installed"
|
||||||
for SSH_OPTION in $OPTIONS; do
|
check_sshd_access_limit $ALLOWUSER_KEY $ALLOWUSER
|
||||||
SSH_PARAM=$(echo $SSH_OPTION | cut -d= -f 1)
|
if [ $FNRET != 0 ]; then
|
||||||
SSH_VALUE=$(echo $SSH_OPTION | cut -d= -f 2)
|
crit "AllowUsers is not set!"
|
||||||
SSH_VALUE=$(sed "s/'//g" <<< $SSH_VALUE)
|
else
|
||||||
PATTERN="^$SSH_PARAM[[:space:]]*$SSH_VALUE"
|
ok "AllowUsers has set limit."
|
||||||
does_pattern_exist_in_file $FILE "$PATTERN"
|
ALLOWUSER_RET=0
|
||||||
if [ $FNRET = 0 ]; then
|
fi
|
||||||
ok "$PATTERN is present in $FILE"
|
|
||||||
else
|
check_sshd_access_limit $ALLOWGROUP_KEY $ALLOWGROUP
|
||||||
crit "$PATTERN is not present in $FILE"
|
if [ $FNRET != 0 ]; then
|
||||||
fi
|
crit "AllowGroups is not set!"
|
||||||
done
|
else
|
||||||
fi
|
ok "AllowGroups has set limit."
|
||||||
|
ALLOWGROUP_RET=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
check_sshd_access_limit $DENYUSER_KEY $DENYUSER
|
||||||
|
if [ $FNRET != 0 ]; then
|
||||||
|
crit "DenyUsers is not set!"
|
||||||
|
else
|
||||||
|
ok "DenyUsers has set limit."
|
||||||
|
DENYUSER_RET=0
|
||||||
|
fi
|
||||||
|
check_sshd_access_limit $DENYGROUP_KEY $DENYGROUP
|
||||||
|
if [ $FNRET != 0 ]; then
|
||||||
|
crit "DenyGroups is not set!"
|
||||||
|
else
|
||||||
|
ok "DenyGroups has set limit."
|
||||||
|
DENYGROUP_RET=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# This function will be called if the script status is on enabled mode
|
# This function will be called if the script status is on enabled mode
|
||||||
@ -48,59 +80,31 @@ apply () {
|
|||||||
crit "$PACKAGE is absent, installing it"
|
crit "$PACKAGE is absent, installing it"
|
||||||
install_package $PACKAGE
|
install_package $PACKAGE
|
||||||
fi
|
fi
|
||||||
for SSH_OPTION in $OPTIONS; do
|
if [ $ALLOWUSER_RET -eq 1 ]; then
|
||||||
SSH_PARAM=$(echo $SSH_OPTION | cut -d= -f 1)
|
warn "AllowUsers is not set! Need manual operation set it."
|
||||||
SSH_VALUE=$(echo $SSH_OPTION | cut -d= -f 2)
|
else
|
||||||
SSH_VALUE=$(sed "s/'//g" <<< $SSH_VALUE)
|
ok "AllowUsers has set limit."
|
||||||
PATTERN="^$SSH_PARAM[[:space:]]*$SSH_VALUE"
|
fi
|
||||||
does_pattern_exist_in_file $FILE "$PATTERN"
|
if [ $ALLOWGROUP_RET -eq 1 ]; then
|
||||||
if [ $FNRET = 0 ]; then
|
warn "AllowGroups is not set! Need manual operation set it."
|
||||||
ok "$PATTERN is present in $FILE"
|
else
|
||||||
else
|
ok "AllowGroups has set limit."
|
||||||
warn "$PATTERN is not present in $FILE, adding it"
|
fi
|
||||||
does_pattern_exist_in_file $FILE "^$SSH_PARAM"
|
if [ $DENYUSER_RET -eq 1 ]; then
|
||||||
if [ $FNRET != 0 ]; then
|
warn "DenyUsers is not set! Need manual operation set it."
|
||||||
add_end_of_file $FILE "$SSH_PARAM $SSH_VALUE"
|
else
|
||||||
else
|
ok "DenyUsers has set limit."
|
||||||
info "Parameter $SSH_PARAM is present but with the wrong value -- Fixing"
|
fi
|
||||||
replace_in_file $FILE "^$SSH_PARAM[[:space:]]*.*" "$SSH_PARAM $SSH_VALUE"
|
if [ $DENYGROUP_RET -eq 1 ]; then
|
||||||
fi
|
warn "DenyGroups is not set! Need manual operation set it."
|
||||||
systemctl reload sshd
|
else
|
||||||
fi
|
ok "DenyGroups has set limit."
|
||||||
done
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
# This function will create the config file for this check with default values
|
|
||||||
create_config() {
|
|
||||||
cat <<EOF
|
|
||||||
status=disabled
|
|
||||||
# Put here ssh user hardening list, there is a default in script to not break your configuration
|
|
||||||
# However, it can erase current configuration
|
|
||||||
ALLOWED_USERS=''
|
|
||||||
ALLOWED_GROUPS=''
|
|
||||||
DENIED_USERS=''
|
|
||||||
DENIED_GROUPS=''
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# This function will check config parameters required
|
# This function will check config parameters required
|
||||||
check_config() {
|
check_config() {
|
||||||
if [ -z $ALLOWED_USERS ]; then
|
:
|
||||||
info "ALLOWED_USERS is not set, defaults to wildcard"
|
|
||||||
ALLOWED_USERS="*"
|
|
||||||
fi
|
|
||||||
if [ -z $ALLOWED_GROUPS ]; then
|
|
||||||
info "ALLOWED_GROUPS is not set, defaults to wildcard"
|
|
||||||
ALLOWED_GROUPS="*"
|
|
||||||
fi
|
|
||||||
if [ -z $DENIED_USERS ]; then
|
|
||||||
info "DENIED_USERS is not set, defaults to nobody"
|
|
||||||
DENIED_USERS="nobody"
|
|
||||||
fi
|
|
||||||
if [ -z $DENIED_GROUPS ]; then
|
|
||||||
info "DENIED_GROUPS is not set, defaults to nobody"
|
|
||||||
DENIED_GROUPS="nobody"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Source Root Dir Parameter
|
# Source Root Dir Parameter
|
||||||
|
@ -1,126 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#
|
|
||||||
# harbian-audit for Debian GNU/Linux 9 Hardening
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# 9.3.26 Ensure SSH access is limited (Scored)
|
|
||||||
# Auther: Samson-W (sccxboy@gmail.com)
|
|
||||||
#
|
|
||||||
|
|
||||||
set -e # One error, it's over
|
|
||||||
set -u # One variable unset, it's over
|
|
||||||
|
|
||||||
HARDENING_LEVEL=3
|
|
||||||
|
|
||||||
PACKAGE='openssh-server'
|
|
||||||
FILE='/etc/ssh/sshd_config'
|
|
||||||
ALLOWUSER='AllowUsers[[:space:]]*\*'
|
|
||||||
ALLOWGROUP='AllowGroups[[:space:]]*\*'
|
|
||||||
DENYUSER='DenyUsers[[:space:]]*nobody'
|
|
||||||
DENYGROUP='DenyGroups[[:space:]]*nobody'
|
|
||||||
|
|
||||||
ALLOWUSER_KEY='AllowUsers'
|
|
||||||
ALLOWGROUP_KEY='AllowGroups'
|
|
||||||
DENYUSER_KEY='DenyUsers'
|
|
||||||
DENYGROUP_KEY='DenyGroups'
|
|
||||||
|
|
||||||
ALLOWUSER_RET=1
|
|
||||||
ALLOWGROUP_RET=1
|
|
||||||
DENYUSER_RET=1
|
|
||||||
DENYGROUP_RET=1
|
|
||||||
|
|
||||||
# This function will be called if the script status is on enabled / audit mode
|
|
||||||
audit () {
|
|
||||||
is_pkg_installed $PACKAGE
|
|
||||||
if [ $FNRET != 0 ]; then
|
|
||||||
crit "$PACKAGE is not installed!"
|
|
||||||
else
|
|
||||||
ok "$PACKAGE is installed"
|
|
||||||
check_sshd_access_limit $ALLOWUSER_KEY $ALLOWUSER
|
|
||||||
if [ $FNRET != 0 ]; then
|
|
||||||
crit "AllowUsers is not set!"
|
|
||||||
else
|
|
||||||
ok "AllowUsers has set limit."
|
|
||||||
ALLOWUSER_RET=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
check_sshd_access_limit $ALLOWGROUP_KEY $ALLOWGROUP
|
|
||||||
if [ $FNRET != 0 ]; then
|
|
||||||
crit "AllowGroups is not set!"
|
|
||||||
else
|
|
||||||
ok "AllowGroups has set limit."
|
|
||||||
ALLOWGROUP_RET=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
check_sshd_access_limit $DENYUSER_KEY $DENYUSER
|
|
||||||
if [ $FNRET != 0 ]; then
|
|
||||||
crit "DenyUsers is not set!"
|
|
||||||
else
|
|
||||||
ok "DenyUsers has set limit."
|
|
||||||
DENYUSER_RET=0
|
|
||||||
fi
|
|
||||||
check_sshd_access_limit $DENYGROUP_KEY $DENYGROUP
|
|
||||||
if [ $FNRET != 0 ]; then
|
|
||||||
crit "DenyGroups is not set!"
|
|
||||||
else
|
|
||||||
ok "DenyGroups has set limit."
|
|
||||||
DENYGROUP_RET=0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# This function will be called if the script status is on enabled mode
|
|
||||||
apply () {
|
|
||||||
is_pkg_installed $PACKAGE
|
|
||||||
if [ $FNRET = 0 ]; then
|
|
||||||
ok "$PACKAGE is installed"
|
|
||||||
else
|
|
||||||
crit "$PACKAGE is absent, installing it"
|
|
||||||
install_package $PACKAGE
|
|
||||||
fi
|
|
||||||
if [ $ALLOWUSER_RET -eq 1 ]; then
|
|
||||||
warn "AllowUsers is not set! Need manual operation set it."
|
|
||||||
else
|
|
||||||
ok "AllowUsers has set limit."
|
|
||||||
fi
|
|
||||||
if [ $ALLOWGROUP_RET -eq 1 ]; then
|
|
||||||
warn "AllowGroups is not set! Need manual operation set it."
|
|
||||||
else
|
|
||||||
ok "AllowGroups has set limit."
|
|
||||||
fi
|
|
||||||
if [ $DENYUSER_RET -eq 1 ]; then
|
|
||||||
warn "DenyUsers is not set! Need manual operation set it."
|
|
||||||
else
|
|
||||||
ok "DenyUsers has set limit."
|
|
||||||
fi
|
|
||||||
if [ $DENYGROUP_RET -eq 1 ]; then
|
|
||||||
warn "DenyGroups is not set! Need manual operation set it."
|
|
||||||
else
|
|
||||||
ok "DenyGroups has set limit."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# This function will check config parameters required
|
|
||||||
check_config() {
|
|
||||||
:
|
|
||||||
}
|
|
||||||
|
|
||||||
# Source Root Dir Parameter
|
|
||||||
if [ -r /etc/default/cis-hardening ]; then
|
|
||||||
. /etc/default/cis-hardening
|
|
||||||
fi
|
|
||||||
if [ -z "$CIS_ROOT_DIR" ]; then
|
|
||||||
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
|
|
||||||
echo "Cannot source CIS_ROOT_DIR variable, aborting."
|
|
||||||
exit 128
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
|
|
||||||
if [ -r $CIS_ROOT_DIR/lib/main.sh ]; then
|
|
||||||
. $CIS_ROOT_DIR/lib/main.sh
|
|
||||||
else
|
|
||||||
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_ROOT_DIR in /etc/default/cis-hardening"
|
|
||||||
exit 128
|
|
||||||
fi
|
|
Loading…
x
Reference in New Issue
Block a user