#!/bin/bash # run-shellcheck # # CIS Debian Hardening # # # Ensure ufw outbound connections are configured (Manual) # set -e # One error, it's over set -u # One variable unset, it's over # shellcheck disable=2034 HARDENING_LEVEL=2 # shellcheck disable=2034 DESCRIPTION="Ensure ufw outbound connections are configured" UFW_RULES_FILE="/etc/ufw/user.rules" # variable defined in config file ALLOW_OUTBOUND_ALL="" # This function will be called if the script status is on enabled / audit mode audit() { UFW_RULE_IS_VALID=1 # rules are saved in /etc/ufw/user.rules # easier to parse than ufw output if $SUDO_CMD grep "^[^#]*-[A,I].*output -o all -j ACCEPT" "$UFW_RULES_FILE" >/dev/null 2>&1; then if [ "$ALLOW_OUTBOUND_ALL" -eq 0 ]; then UFW_RULE_IS_VALID=0 ok "ufw output is allowed for all" else crit "ufw output is allowed for all, and ALLOW_OUTBOUND_ALL=1" fi else if [ "$ALLOW_OUTBOUND_ALL" -eq 1 ]; then UFW_RULE_IS_VALID=0 ok "ufw output is not allowed for all" else crit "ufw output is not allowed for all, and ALLOW_OUTBOUND_ALL=0" fi fi } # This function will be called if the script status is on enabled mode apply() { if [ "$UFW_RULE_IS_VALID" -ne 0 ]; then info "Please review the output rules according to your site policy, and update 'ALLOW_OUTBOUND_ALL' in configuration accordingly" fi } create_config() { cat <