mirror of
https://github.com/ovh/debian-cis.git
synced 2025-08-04 14:21:15 +02:00
feat: add debian12 scripts
- nftables_is_enabled.sh -> 4.2.9 - nftables_has_table.sh -> 4.2.4 - nftables_has_base_chains.sh -> 4.2.5
This commit is contained in:
94
bin/hardening/nftables_has_base_chains.sh
Executable file
94
bin/hardening/nftables_has_base_chains.sh
Executable file
@@ -0,0 +1,94 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# run-shellcheck
|
||||||
|
#
|
||||||
|
# CIS Debian Hardening
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ensure nftables base chains exist (Automated)
|
||||||
|
#
|
||||||
|
|
||||||
|
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 nftables base chains exist"
|
||||||
|
|
||||||
|
# This function will be called if the script status is on enabled / audit mode
|
||||||
|
audit() {
|
||||||
|
INPUT_CHAIN=1
|
||||||
|
OUTPUT_CHAIN=1
|
||||||
|
FORWARD_CHAIN=1
|
||||||
|
|
||||||
|
if nft list ruleset | grep 'hook input'; then
|
||||||
|
INPUT_CHAIN=0
|
||||||
|
ok "nft base input chain exist"
|
||||||
|
else
|
||||||
|
crit "nft base input chain does not exist"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if nft list ruleset | grep 'hook output'; then
|
||||||
|
OUTPUT_CHAIN=0
|
||||||
|
ok "nft base output chain exist"
|
||||||
|
else
|
||||||
|
crit "nft base output chain does not exist"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if nft list ruleset | grep 'hook forward'; then
|
||||||
|
FORWARD_CHAIN=0
|
||||||
|
ok "nft base forward chain exist"
|
||||||
|
else
|
||||||
|
crit "nft base forward chain does not exist"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# This function will be called if the script status is on enabled mode
|
||||||
|
apply() {
|
||||||
|
audit
|
||||||
|
if [ "$INPUT_CHAIN" -eq 1 ]; then
|
||||||
|
info "adding nft base input chain"
|
||||||
|
# shellcheck disable=1083
|
||||||
|
nft create chain inet filter input { type filter hook input priority 0 \; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$OUTPUT_CHAIN" -eq 1 ]; then
|
||||||
|
info "adding nft base output chain"
|
||||||
|
# shellcheck disable=1083
|
||||||
|
nft create chain inet filter output { type filter hook output priority 0 \; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$FORWARD_CHAIN" -eq 1 ]; then
|
||||||
|
info "adding nft base forward chain"
|
||||||
|
# shellcheck disable=1083
|
||||||
|
nft create chain inet filter forward { type filter hook forward priority 0 \; }
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# This function will check config parameters required
|
||||||
|
check_config() {
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
# Source Root Dir Parameter
|
||||||
|
if [ -r /etc/default/cis-hardening ]; then
|
||||||
|
# shellcheck source=../../debian/default
|
||||||
|
. /etc/default/cis-hardening
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$CIS_LIB_DIR" ]; then
|
||||||
|
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
|
||||||
|
echo "Cannot source CIS_LIB_DIR variable, aborting."
|
||||||
|
exit 128
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
|
||||||
|
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
|
||||||
|
# shellcheck source=../../lib/main.sh
|
||||||
|
. "${CIS_LIB_DIR}"/main.sh
|
||||||
|
else
|
||||||
|
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
|
||||||
|
exit 128
|
||||||
|
fi
|
67
bin/hardening/nftables_has_table.sh
Executable file
67
bin/hardening/nftables_has_table.sh
Executable file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# run-shellcheck
|
||||||
|
#
|
||||||
|
# CIS Debian Hardening
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ensure a nftables table exists (Automated)
|
||||||
|
#
|
||||||
|
|
||||||
|
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 a nftables table exists"
|
||||||
|
|
||||||
|
# This function will be called if the script status is on enabled / audit mode
|
||||||
|
audit() {
|
||||||
|
NFTABLES_HAS_TABLES=0
|
||||||
|
local tables
|
||||||
|
tables=$(nft list tables | wc -l)
|
||||||
|
if [ "$tables" -eq 0 ]; then
|
||||||
|
crit "There are no nft tables"
|
||||||
|
NFTABLES_HAS_TABLES=1
|
||||||
|
else
|
||||||
|
ok "There are $tables nft tables"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# This function will be called if the script status is on enabled mode
|
||||||
|
apply() {
|
||||||
|
audit
|
||||||
|
if [ "$NFTABLES_HAS_TABLES" -eq 1 ]; then
|
||||||
|
info "Adding 'filter' nft table"
|
||||||
|
nft create table inet filter
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# This function will check config parameters required
|
||||||
|
check_config() {
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
# Source Root Dir Parameter
|
||||||
|
if [ -r /etc/default/cis-hardening ]; then
|
||||||
|
# shellcheck source=../../debian/default
|
||||||
|
. /etc/default/cis-hardening
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$CIS_LIB_DIR" ]; then
|
||||||
|
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
|
||||||
|
echo "Cannot source CIS_LIB_DIR variable, aborting."
|
||||||
|
exit 128
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
|
||||||
|
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
|
||||||
|
# shellcheck source=../../lib/main.sh
|
||||||
|
. "${CIS_LIB_DIR}"/main.sh
|
||||||
|
else
|
||||||
|
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
|
||||||
|
exit 128
|
||||||
|
fi
|
68
bin/hardening/nftables_is_enabled.sh
Executable file
68
bin/hardening/nftables_is_enabled.sh
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# run-shellcheck
|
||||||
|
#
|
||||||
|
# CIS Debian Hardening
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ensure nftables service is enabled (Automated)
|
||||||
|
#
|
||||||
|
|
||||||
|
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 nftables service is enabled"
|
||||||
|
SERVICE="nftables.service"
|
||||||
|
|
||||||
|
# This function will be called if the script status is on enabled / audit mode
|
||||||
|
audit() {
|
||||||
|
SERVICE_ENABLED=1
|
||||||
|
|
||||||
|
is_service_enabled "$SERVICE"
|
||||||
|
if [ "$FNRET" -eq 0 ]; then
|
||||||
|
ok "$SERVICE is enabled"
|
||||||
|
SERVICE_ENABLED=0
|
||||||
|
else
|
||||||
|
crit "$SERVICE is not enabled"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# This function will be called if the script status is on enabled mode
|
||||||
|
apply() {
|
||||||
|
audit
|
||||||
|
if [ "$SERVICE_ENABLED" -ne 0 ]; then
|
||||||
|
manage_service unmask "$SERVICE"
|
||||||
|
manage_service enable "$SERVICE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# This function will check config parameters required
|
||||||
|
check_config() {
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
# Source Root Dir Parameter
|
||||||
|
if [ -r /etc/default/cis-hardening ]; then
|
||||||
|
# shellcheck source=../../debian/default
|
||||||
|
. /etc/default/cis-hardening
|
||||||
|
fi
|
||||||
|
if [ -z "$CIS_LIB_DIR" ]; then
|
||||||
|
echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment."
|
||||||
|
echo "Cannot source CIS_LIB_DIR variable, aborting."
|
||||||
|
exit 128
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Main function, will call the proper functions given the configuration (audit, enabled, disabled)
|
||||||
|
if [ -r "${CIS_LIB_DIR}"/main.sh ]; then
|
||||||
|
# shellcheck source=../../lib/main.sh
|
||||||
|
. "${CIS_LIB_DIR}"/main.sh
|
||||||
|
else
|
||||||
|
echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_LIB_DIR in /etc/default/cis-hardening"
|
||||||
|
exit 128
|
||||||
|
fi
|
11
tests/hardening/nftables_has_base_chains.sh
Normal file
11
tests/hardening/nftables_has_base_chains.sh
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# shellcheck shell=bash
|
||||||
|
# run-shellcheck
|
||||||
|
test_audit() {
|
||||||
|
# running on a non privilieged container, wont test much...
|
||||||
|
describe Running on blank host
|
||||||
|
register_test retvalshouldbe 1
|
||||||
|
dismiss_count_for_test
|
||||||
|
# shellcheck disable=2154
|
||||||
|
run blank "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
|
||||||
|
|
||||||
|
}
|
11
tests/hardening/nftables_has_table.sh
Normal file
11
tests/hardening/nftables_has_table.sh
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# shellcheck shell=bash
|
||||||
|
# run-shellcheck
|
||||||
|
test_audit() {
|
||||||
|
# running on a non privilieged container, wont test much...
|
||||||
|
describe Running on blank host
|
||||||
|
register_test retvalshouldbe 1
|
||||||
|
dismiss_count_for_test
|
||||||
|
# shellcheck disable=2154
|
||||||
|
run blank "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
|
||||||
|
|
||||||
|
}
|
10
tests/hardening/nftables_is_enabled.sh
Normal file
10
tests/hardening/nftables_is_enabled.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# shellcheck shell=bash
|
||||||
|
# run-shellcheck
|
||||||
|
test_audit() {
|
||||||
|
describe Running on blank host
|
||||||
|
register_test retvalshouldbe 0
|
||||||
|
dismiss_count_for_test
|
||||||
|
# shellcheck disable=2154
|
||||||
|
run blank "${CIS_CHECKS_DIR}/${script}.sh" --audit-all
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user