mirror of
https://github.com/hardenedlinux/harbian-audit.git
synced 2025-04-08 17:06:34 +02:00
Eliminate duplicate audit items 9.3.26
This commit is contained in:
parent
0e20dd251a
commit
3fbb8a8452
@ -1,11 +1,12 @@
|
||||
#!/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
|
||||
@ -15,28 +16,59 @@ 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 () {
|
||||
OPTIONS="AllowUsers='$ALLOWED_USERS' AllowGroups='$ALLOWED_GROUPS' DenyUsers='$DENIED_USERS' DenyGroups='$DENIED_GROUPS'"
|
||||
is_pkg_installed $PACKAGE
|
||||
if [ $FNRET != 0 ]; then
|
||||
crit "$PACKAGE is not installed!"
|
||||
else
|
||||
ok "$PACKAGE is installed"
|
||||
for SSH_OPTION in $OPTIONS; do
|
||||
SSH_PARAM=$(echo $SSH_OPTION | cut -d= -f 1)
|
||||
SSH_VALUE=$(echo $SSH_OPTION | cut -d= -f 2)
|
||||
SSH_VALUE=$(sed "s/'//g" <<< $SSH_VALUE)
|
||||
PATTERN="^$SSH_PARAM[[:space:]]*$SSH_VALUE"
|
||||
does_pattern_exist_in_file $FILE "$PATTERN"
|
||||
if [ $FNRET = 0 ]; then
|
||||
ok "$PATTERN is present in $FILE"
|
||||
else
|
||||
crit "$PATTERN is not present in $FILE"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
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
|
||||
@ -48,59 +80,31 @@ apply () {
|
||||
crit "$PACKAGE is absent, installing it"
|
||||
install_package $PACKAGE
|
||||
fi
|
||||
for SSH_OPTION in $OPTIONS; do
|
||||
SSH_PARAM=$(echo $SSH_OPTION | cut -d= -f 1)
|
||||
SSH_VALUE=$(echo $SSH_OPTION | cut -d= -f 2)
|
||||
SSH_VALUE=$(sed "s/'//g" <<< $SSH_VALUE)
|
||||
PATTERN="^$SSH_PARAM[[:space:]]*$SSH_VALUE"
|
||||
does_pattern_exist_in_file $FILE "$PATTERN"
|
||||
if [ $FNRET = 0 ]; then
|
||||
ok "$PATTERN is present in $FILE"
|
||||
else
|
||||
warn "$PATTERN is not present in $FILE, adding it"
|
||||
does_pattern_exist_in_file $FILE "^$SSH_PARAM"
|
||||
if [ $FNRET != 0 ]; then
|
||||
add_end_of_file $FILE "$SSH_PARAM $SSH_VALUE"
|
||||
else
|
||||
info "Parameter $SSH_PARAM is present but with the wrong value -- Fixing"
|
||||
replace_in_file $FILE "^$SSH_PARAM[[:space:]]*.*" "$SSH_PARAM $SSH_VALUE"
|
||||
fi
|
||||
systemctl reload sshd
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 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
|
||||
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() {
|
||||
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
|
||||
|
@ -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