2017-12-20 15:14:30 +01:00
|
|
|
#!/bin/bash
|
2020-11-23 17:10:37 +01:00
|
|
|
|
2017-12-20 15:14:30 +01:00
|
|
|
# run-shellcheck
|
|
|
|
#
|
|
|
|
# OVH Security audit
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
2019-10-18 17:26:31 +02:00
|
|
|
# 5.3.4 Ensure password hashing algorithm is SHA-512 (Scored)
|
2017-12-20 15:14:30 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
set -e # One error, it's over
|
|
|
|
set -u # One variable unset, it's over
|
|
|
|
|
|
|
|
# shellcheck disable=2034
|
|
|
|
DESCRIPTION="Check that any password that may exist in /etc/shadow is SHA512 hashed and salted"
|
|
|
|
|
|
|
|
CONF_FILE="/etc/pam.d/common-password"
|
|
|
|
CONF_LINE="^\s*password\s.+\s+pam_unix\.so\s+.*sha512"
|
|
|
|
|
|
|
|
# This function will be called if the script status is on enabled / audit mode
|
2020-12-04 14:08:01 +01:00
|
|
|
audit() {
|
|
|
|
# Check conf file for default SHA512 hash
|
2017-12-20 15:14:30 +01:00
|
|
|
if $SUDO_CMD [ ! -r $CONF_FILE ]; then
|
|
|
|
crit "$CONF_FILE is not readable"
|
|
|
|
else
|
2020-12-10 08:34:57 +01:00
|
|
|
# shellcheck disable=SC2001
|
2020-12-04 14:08:01 +01:00
|
|
|
does_pattern_exist_in_file $CONF_FILE "$(sed 's/ /[[:space:]]+/g' <<<"$CONF_LINE")"
|
2017-12-20 15:14:30 +01:00
|
|
|
if [ "$FNRET" = 0 ]; then
|
|
|
|
ok "$CONF_LINE is present in $CONF_FILE"
|
|
|
|
else
|
|
|
|
crit "$CONF_LINE is not present in $CONF_FILE"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# This function will be called if the script status is on enabled mode
|
2020-12-04 14:08:01 +01:00
|
|
|
apply() {
|
2020-10-29 16:47:34 +01:00
|
|
|
if $SUDO_CMD [ ! -r $CONF_FILE ]; then
|
|
|
|
crit "$CONF_FILE is not readable"
|
|
|
|
else
|
2020-12-10 08:34:57 +01:00
|
|
|
# shellcheck disable=SC2001
|
2020-12-04 14:08:01 +01:00
|
|
|
does_pattern_exist_in_file $CONF_FILE "$(sed 's/ /[[:space:]]+/g' <<<"$CONF_LINE")"
|
2020-10-29 16:47:34 +01:00
|
|
|
if [ "$FNRET" = 0 ]; then
|
|
|
|
ok "$CONF_LINE is present in $CONF_FILE"
|
|
|
|
else
|
|
|
|
warn "$CONF_LINE is not present in $CONF_FILE"
|
|
|
|
add_line_file_before_pattern $CONF_FILE "password [success=1 default=ignore] pam_unix.so sha512" "# pam-auth-update(8) for details."
|
|
|
|
fi
|
|
|
|
fi
|
2017-12-20 15:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# This function will check config parameters required
|
|
|
|
check_config() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
# Source Root Dir Parameter
|
|
|
|
if [ -r /etc/default/cis-hardening ]; then
|
2020-12-04 14:08:01 +01:00
|
|
|
# shellcheck source=../../debian/default
|
2017-12-20 15:14:30 +01:00
|
|
|
. /etc/default/cis-hardening
|
|
|
|
fi
|
|
|
|
if [ -z "$CIS_ROOT_DIR" ]; then
|
2020-12-04 14:08:01 +01:00
|
|
|
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
|
|
|
|
echo "Cannot source CIS_ROOT_DIR variable, aborting."
|
2017-12-20 15:14:30 +01:00
|
|
|
exit 128
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
|
2020-11-27 09:29:11 +01:00
|
|
|
if [ -r "$CIS_ROOT_DIR"/lib/main.sh ]; then
|
2020-11-27 09:18:00 +01:00
|
|
|
# shellcheck source=../../lib/main.sh
|
2020-11-27 09:29:11 +01:00
|
|
|
. "$CIS_ROOT_DIR"/lib/main.sh
|
2017-12-20 15:14:30 +01:00
|
|
|
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
|