#!/bin/bash # # harbian-audit for Debian GNU/Linux 7/8/9/10 or CentOS Hardening # # # 7.1.1 Disable IP Forwarding (Scored) # set -e # One error, it's over set -u # One variable unset, it's over HARDENING_LEVEL=3 HARDENING_EXCEPTION=gw SYSCTL_PARAM='net.ipv4.ip_forward' SYSCTL_EXP_RESULT=0 # This function will be called if the script status is on enabled / audit mode audit () { has_sysctl_param_expected_result $SYSCTL_PARAM $SYSCTL_EXP_RESULT if [ $FNRET != 0 ]; then if [ $ISEXCEPTION -eq 1 ]; then warn "$PACKAGE is installed! But Exception is set to 1, so it's pass!" else crit "$SYSCTL_PARAM was not set to $SYSCTL_EXP_RESULT" fi elif [ $FNRET = 255 ]; then warn "$SYSCTL_PARAM does not exist -- Typo?" else ok "$SYSCTL_PARAM correctly set to $SYSCTL_EXP_RESULT" fi } # This function will be called if the script status is on enabled mode apply () { has_sysctl_param_expected_result $SYSCTL_PARAM $SYSCTL_EXP_RESULT if [ $FNRET != 0 ]; then if [ $ISEXCEPTION -eq 1 ]; then warn "$PACKAGE is installed! But the exception is set to true, so don't need any operate." else warn "$SYSCTL_PARAM was not set to $SYSCTL_EXP_RESULT -- Fixing" set_sysctl_param $SYSCTL_PARAM $SYSCTL_EXP_RESULT sysctl -w net.ipv4.route.flush=1 > /dev/null fi elif [ $FNRET = 255 ]; then warn "$SYSCTL_PARAM does not exist -- Typo?" else ok "$SYSCTL_PARAM correctly set to $SYSCTL_EXP_RESULT" fi } # This function will create the config file for this check with default values create_config() { cat <