2019-04-08 22:03:38 +02:00
#!/bin/bash
#
2020-02-27 17:56:28 +01:00
# harbian-audit for Debian GNU/Linux 9 Hardening
2019-04-08 22:03:38 +02:00
#
#
2019-04-16 12:09:05 +02:00
# 7.7.4.2 Ensure loopback traffic is configured (Scored)
2019-04-08 22:03:38 +02:00
# Include ipv4 and ipv6
2019-04-12 10:07:44 +02:00
# Add this feature:Author : Samson wen, Samson <sccxboy@gmail.com>
2019-04-08 22:03:38 +02:00
#
set -e # One error, it's over
set -u # One variable unset, it's over
HARDENING_LEVEL = 2
2019-04-09 10:59:31 +02:00
INPUT_ACCEPT = 1
OUTPUT_ACCEPT = 1
INPUT_DENY = 1
2019-04-16 12:09:05 +02:00
IP4VERSION = "IPS4"
2019-04-09 10:59:31 +02:00
2019-04-08 22:03:38 +02:00
# This function will be called if the script status is on enabled / audit mode
audit ( ) {
2019-04-09 06:28:45 +02:00
# Check the loopback interface to accept INPUT traffic.
2019-04-16 12:09:05 +02:00
ensure_lo_traffic_input_is_accept " $IP4VERSION "
2019-04-09 10:31:57 +02:00
if [ $FNRET = 0 ] ; then
INPUT_ACCEPT = 0
2019-04-16 12:09:05 +02:00
info "Iptables loopback traffic INPUT has configured!"
2019-04-09 06:28:45 +02:00
else
2019-04-09 10:31:57 +02:00
INPUT_ACCEPT = 1
2019-04-16 12:09:05 +02:00
info "Iptables: loopback traffic INPUT is not configured!"
2019-04-09 10:31:57 +02:00
fi
2019-04-09 06:28:45 +02:00
# Check the loopback interface to accept OUTPUT traffic.
2019-04-16 12:09:05 +02:00
ensure_lo_traffic_output_is_accept " $IP4VERSION "
2019-04-09 10:31:57 +02:00
if [ $FNRET = 0 ] ; then
OUTPUT_ACCEPT = 0
2019-04-16 12:09:05 +02:00
info "Iptables loopback traffic OUTPUT has configured!"
2019-04-09 06:28:45 +02:00
else
2019-04-09 10:31:57 +02:00
OUTPUT_ACCEPT = 1
2019-04-16 12:09:05 +02:00
info "Iptables: loopback traffic OUTPUT is not configured!"
2019-04-09 10:31:57 +02:00
fi
2019-04-09 06:28:45 +02:00
# all other interfaces to deny traffic to the loopback network.
2019-04-16 12:09:05 +02:00
ensure_lo_traffic_other_if_input_is_deny " $IP4VERSION "
2019-04-09 10:31:57 +02:00
if [ $FNRET = 0 ] ; then
INPUT_DENY = 0
2019-04-16 12:09:05 +02:00
info "Iptables loopback traffic INPUT deny from other interfaces has configured!"
2019-04-08 22:03:38 +02:00
else
2019-04-09 10:31:57 +02:00
INPUT_DENY = 1
2019-04-16 12:09:05 +02:00
info "Iptables: loopback traffic INPUT deny from other interfaces is not configured!"
2019-04-09 10:31:57 +02:00
fi
2019-04-16 12:09:05 +02:00
if [ $INPUT_ACCEPT -eq 0 -a $OUTPUT_ACCEPT -eq 0 -a $INPUT_DENY -eq 0 ] ; then
ok "Loopback traffic rules are configured!"
else
crit "Loopback traffic rules are not configured!"
fi
2019-04-08 22:03:38 +02:00
}
# This function will be called if the script status is on enabled mode
apply ( ) {
2019-04-09 10:31:57 +02:00
if [ $INPUT_ACCEPT = 0 ] ; then
ok "Iptables loopback traffic INPUT has configured!"
else
2019-04-16 12:09:05 +02:00
warn "Iptables loopback traffic INPUT is not configured! need the administrator to manually add it. Howto set: iptables -A INPUT -i lo -j ACCEPT"
2019-04-09 10:31:57 +02:00
fi
if [ $OUTPUT_ACCEPT = 0 ] ; then
ok "Iptables loopback traffic OUTPUT has configured!"
else
2019-04-16 12:09:05 +02:00
warn "Iptables loopback traffic OUTPUT is not configured! need the administrator to manually add it. Howto set: iptables -A OUTPUT -o lo -j ACCEPT"
2019-04-09 10:31:57 +02:00
fi
if [ $INPUT_DENY = 0 ] ; then
ok "Iptables loopback traffic INPUT deny from other interfaces has configured!"
else
2019-04-16 12:09:05 +02:00
warn "Iptables loopback traffic INPUT deny from 127.0.0.0/8 is not configured! need the administrator to manually add it. Howto set: iptables -A INPUT -s 127.0.0.0/8 -j DROP"
2019-04-09 10:31:57 +02:00
fi
2019-04-08 22:03:38 +02:00
}
# 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