|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# run-shellcheck |
| 4 | +# |
| 5 | +# CIS Debian Hardening |
| 6 | +# |
| 7 | + |
| 8 | +# |
| 9 | +# Ensure /etc/shadow password fields are not empty (Automated) |
| 10 | +# |
| 11 | + |
| 12 | +set -e # One error, it's over |
| 13 | +set -u # One variable unset, it's over |
| 14 | + |
| 15 | +# shellcheck disable=2034 |
| 16 | +HARDENING_LEVEL=1 |
| 17 | +# shellcheck disable=2034 |
| 18 | +DESCRIPTION="Ensure /etc/shadow password fields are not empty" |
| 19 | +EXCEPTIONS="" |
| 20 | + |
| 21 | +# This function will be called if the script status is on enabled / audit mode |
| 22 | +audit() { |
| 23 | + INVALID_USERS="" |
| 24 | + |
| 25 | + local tmp_invalid_users="" |
| 26 | + tmp_invalid_users=$($SUDO_CMD cat /etc/shadow | awk -F: '($2 == "" ) { print $1 }') |
| 27 | + |
| 28 | + if [ -n "$tmp_invalid_users" ]; then |
| 29 | + for user in $tmp_invalid_users; do |
| 30 | + if [ -n "$EXCEPTIONS" ]; then |
| 31 | + if ! grep -w "$user" <<<"$EXCEPTIONS" >/dev/null; then |
| 32 | + crit "$user does not have a password" |
| 33 | + INVALID_USERS="$INVALID_USERS $user" |
| 34 | + fi |
| 35 | + else |
| 36 | + crit "$user does not have a password" |
| 37 | + INVALID_USERS="$INVALID_USERS $user" |
| 38 | + fi |
| 39 | + done |
| 40 | + fi |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +# This function will be called if the script status is on enabled mode |
| 45 | +apply() { |
| 46 | + |
| 47 | + if [ -n "$INVALID_USERS" ]; then |
| 48 | + for user in $INVALID_USERS; do |
| 49 | + info "locking $user" |
| 50 | + passwd -l "$user" |
| 51 | + done |
| 52 | + fi |
| 53 | +} |
| 54 | + |
| 55 | +# This function will check config parameters required |
| 56 | +check_config() { |
| 57 | + : |
| 58 | +} |
| 59 | + |
| 60 | +# maybe someone is gonna have a legit use case.... |
| 61 | +create_config() { |
| 62 | + cat <<EOF |
| 63 | +# shellcheck disable=2034 |
| 64 | +status=audit |
| 65 | +# Put here the accounts that should keep their non shadowed password |
| 66 | +EXCEPTIONS='' |
| 67 | +EOF |
| 68 | +} |
| 69 | + |
| 70 | +# Source Root Dir Parameter |
| 71 | +if [ -r /etc/default/cis-hardening ]; then |
| 72 | + # shellcheck source=../../debian/default |
| 73 | + . /etc/default/cis-hardening |
| 74 | +fi |
| 75 | +if [ -z "$CIS_LIB_DIR" ]; then |
| 76 | + echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment." |
| 77 | + echo "Cannot source CIS_LIB_DIR variable, aborting." |
| 78 | + exit 128 |
| 79 | +fi |
| 80 | + |
| 81 | +# Main function, will call the proper functions given the configuration (audit, enabled, disabled) |
| 82 | +if [ -r "${CIS_LIB_DIR}"/main.sh ]; then |
| 83 | + # shellcheck source=../../lib/main.sh |
| 84 | + . "${CIS_LIB_DIR}"/main.sh |
| 85 | +else |
| 86 | + echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening" |
| 87 | + exit 128 |
| 88 | +fi |
0 commit comments