lynis/include/tests_firewalls

533 lines
27 KiB
Plaintext
Raw Normal View History

2014-08-26 17:33:55 +02:00
#!/bin/sh
#################################################################################
#
# Lynis
# ------------------
#
2016-03-13 16:00:39 +01:00
# Copyright 2007-2013, Michael Boelen
2017-02-09 13:35:40 +01:00
# Copyright 2007-2017, CISOfy
2016-03-13 16:00:39 +01:00
#
# Website : https://cisofy.com
# Blog : http://linux-audit.com
# GitHub : https://github.com/CISOfy/lynis
2014-08-26 17:33:55 +02:00
#
# Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
# welcome to redistribute it under the terms of the GNU General Public License.
# See LICENSE file for usage of this software.
#
#################################################################################
#
# Firewalls
#
#################################################################################
#
InsertSection "Software: firewalls"
#
#################################################################################
#
IPTABLES_ACTIVE=0
2017-03-08 21:19:20 +01:00
IP6TABLES_ACTIVE=0
2014-08-26 17:33:55 +02:00
IPTABLES_INKERNEL_ACTIVE=0
IPTABLES_MODULE_ACTIVE=0
FIREWALL_ACTIVE=0
2015-12-30 14:33:50 +01:00
FIREWALL_EMPTY_RULESET=0
2014-08-26 17:33:55 +02:00
FIREWALL_SOFTWARE=""
2015-12-30 14:33:50 +01:00
NFTABLES_ACTIVE=0
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2015-12-30 14:33:50 +01:00
# Test : FIRE-4502
2014-08-26 17:33:55 +02:00
# Description : Check iptables kernel module
Register --test-no FIRE-4502 --os Linux --weight L --network NO --category security --description "Check iptables kernel module"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
FIND=$(${LSMODBINARY} | ${AWKBINARY} '{ print $1 }' | ${GREPBINARY} "^ip*_tables")
if [ ! -z "${FIND}" ]; then
2014-08-26 17:33:55 +02:00
FIREWALL_ACTIVE=1
FIREWALL_SOFTWARE="iptables"
IPTABLES_ACTIVE=1
IPTABLES_MODULE_ACTIVE=1
Display --indent 2 --text "- Checking iptables kernel module" --result "${STATUS_FOUND}" --color GREEN
2017-03-08 21:19:20 +01:00
Report "firewall_software[]=iptables"
LogText "Result: Found iptables in loaded kernel modules"
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2017-03-08 21:19:20 +01:00
if [ "${I}" = "ip6_tables" ]; then IP6TABLES_ACTIVE=1; Report "firewall_software[]=ip6tables"; fi
LogText "Found module: ${I}"
2014-08-26 17:33:55 +02:00
done
2017-03-08 21:19:20 +01:00
elif [ -f ${ROOTDIR}proc/net/ip_tables_names ]; then
FIREWALL_ACTIVE=1
FIREWALL_SOFTWARE="iptables"
Report "firewall_software[]=iptables"
IPTABLES_ACTIVE=1
Display --indent 2 --text "- Checking iptables support" --result "${STATUS_FOUND}" --color GREEN
elif [ -f ${ROOTDIR}proc/net/ip6_tables_names ]; then
FIREWALL_ACTIVE=1
IP6TABLES_ACTIVE=1
Report "firewall_software[]=ip6tables"
Display --indent 2 --text "- Checking ip6tables support" --result "${STATUS_FOUND}" --color GREEN
else
Display --indent 2 --text "- Checking iptables kernel module" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-08-26 17:33:55 +02:00
# If we can't find an active module, try to find the Linux configuration file and check that
2017-03-08 21:19:20 +01:00
if [ -f /proc/config.gz ]; then LINUXCONFIGFILE="/proc/config.gz"; tCATCMD="zcat"; fi
2016-09-10 16:12:44 +02:00
sLINUXCONFIGFILE="/boot/config-$(uname -r)"
2017-03-08 21:19:20 +01:00
if [ -f ${sLINUXCONFIGFILE} ]; then LINUXCONFIGFILE=${sLINUXCONFIGFILE}; tCATCMD="cat"; fi
2014-08-26 17:33:55 +02:00
# If we have a kernel configuration file, use it for testing
# Do not perform test if we already found it in kernel module list, to avoid triggered it in the upcoming
# tests, when using iptables --list
2017-03-08 21:19:20 +01:00
if [ ! -z "${LINUXCONFIGFILE}" ]; then
if [ -f ${LINUXCONFIGFILE} -a ${IPTABLES_MODULE_ACTIVE} -eq 0 ]; then
LogText "Result: found kernel configuration file (${LINUXCONFIGFILE})"
2016-09-10 16:12:44 +02:00
FIND=$(${tCATCMD} ${LINUXCONFIGFILE} | ${GREPBINARY} -v '^#' | ${GREPBINARY} "CONFIG_IP_NF_IPTABLES" | head -n 1)
if [ ! -z "${FIND}" ]; then
HAVEMOD=$(echo ${FIND} | ${CUTBINARY} -d '=' -f2)
# Do not use iptables if it's compiled as a module (=m), since we already tested for it in the
# active list.
if [ "${HAVEMOD}" = "y" ]; then
Lots of cleanups (#366) * Description fix: SafePerms works on files not dirs. All uses of SafePerms are on files (and indeed, it would reject directories which would have +x set). * Lots of whitespace cleanups. Enforce everywhere(?) the same indentations for if/fi blocks. The standard for the Lynis codebase is 4 spaces. But sometimes it's 1, sometimes 3, sometimes 8. These patches standardize all(?) if blocks but _not_ else's (which are usually indented 2, but sometimes zero); I was too lazy to identify those (see below). This diff is giant, but should not change code behavior at all; diff -w shows no changes apart from whitespace. FWIW I identified instances to check by using: perl -ne 'if ($oldfile ne $ARGV) { $.=1; $oldfile=$ARGV; }; chomp; if ($spaces) { next unless /^( *)([^ ]+)/; $newspaces=length($1); $firsttok = $2; next unless defined($firsttok); $offset = ($firsttok eq "elif" ? 0 : 4); if ($newspaces != $spaces + $offset) { print "$ARGV:$ifline\n$ARGV:$.:$_\n\n" }; $ifline=""; $spaces=""; } if (/^( *)if (?!.*[; ]fi)/) { $ifline = "$.:$_"; $spaces = length($1); }' $(find . -type f -print0 | xargs -0 file | egrep shell | cut -d: -f1) Which produced output like: ./extras/build-lynis.sh:217: if [ ${VERSION_IN_SPECFILE} = "" -o ! "${VERSION_IN_SPECFILE}" = "${LYNIS_VERSION}" ]; then ./extras/build-lynis.sh:218: echo "[X] Version in specfile is outdated" ./plugins/plugin_pam_phase1:69: if [ -d ${PAM_DIRECTORY} ]; then ./plugins/plugin_pam_phase1:70: LogText "Result: /etc/pam.d exists" ...There's probably formal shellscript-beautification tools that I'm oblivious about. * More whitespace standardization. * Fix a syntax error. This looks like an if [ foo -o bar ]; was converted to if .. elif, but incompletely. * Add whitespace before closing ]. Without it, the shell thinks the ] is part of the last string, and emits warnings like: .../lynis/include/tests_authentication: line 1028: [: missing `]'
2017-03-07 20:23:08 +01:00
LogText "Result: iptables available as a module in the configuration"
IPTABLES_ACTIVE=1
IPTABLES_INKERNEL_ACTIVE=1
FIREWALL_ACTIVE=1
FIREWALL_SOFTWARE="iptables"
Display --indent 2 --text "- Checking iptables in config file" --result "${STATUS_FOUND}" --color GREEN
2017-03-08 21:19:20 +01:00
else
LogText "Result: no iptables found in Linux kernel config file"
fi
2017-03-08 21:19:20 +01:00
else
LogText "Result: no Linux configuration file found"
Display --indent 2 --text "- Checking iptables in config file" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-08-26 17:33:55 +02:00
fi
fi
fi
fi
fi
#
#################################################################################
2015-12-30 14:33:50 +01:00
#
# Test : FIRE-4508
# Description : Check iptables chain policies
# Notes : Suggestions are currently disabled, until related page and documentation is available
if [ ! "${IPTABLESBINARY}" = "" -a ${IPTABLES_ACTIVE} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4508 --preqs-met ${PREQS_MET} --os Linux --weight L --network NO --root-only YES --category security --description "Check used policies of iptables chains"
2015-12-30 14:33:50 +01:00
if [ ${SKIPTEST} -eq 0 ]; then
Display --indent 4 --text "- Checking iptables policies of chains" --result "${STATUS_FOUND}" --color GREEN
2015-12-30 14:33:50 +01:00
TABLES="filter"
for TABLE in ${TABLES}; do
LogText "Test: gathering information from table ${TABLE}"
FIND="$FIND""\n"$(${IPTABLESBINARY} -t ${TABLE} --numeric --list | ${EGREPBINARY} -z -o -w '[A-Z]+' | ${AWKBINARY} -v t=${TABLE} 'NR%2 {printf "%s %s ",t, $0 ; next;}1')
2015-12-30 14:33:50 +01:00
done
echo "${FIND}" | while read line; do
2016-09-10 16:12:44 +02:00
table=$(echo ${line} | ${AWKBINARY} '{ print $1 }')
chainname=$(echo ${line} | ${AWKBINARY} '{ print $2 }')
policy=$(echo ${line} | ${AWKBINARY} '{ print $3 }')
2015-12-30 14:33:50 +01:00
LogText "Result: iptables ${table} -- ${chainname} policy is ${policy}."
LogText "Result: ${policy}"
if [ "${TABLE}" = "filter" ]; then
if [ "${chainname}" = "INPUT" ]; then
case ${policy} in
"ACCEPT")
LogText "Result: Found ACCEPT for ${chainname} (table: ${table})"
Display --indent 6 --text "- Checking chain ${chainname} (table: ${table}) policy" --result ${policy} --color YELLOW
#ReportSuggestion ${TEST_NO} "Consider settings default chain policy to DROP (iptables chain ${chainname}, table: ${table})"
AddHP 1 3
;;
"DROP")
LogText "Result: Found DROP for ${chainname} (table: ${table})"
Display --indent 6 --text "- Checking chain ${chainname} (table: ${table}) policy" --result ${policy} --color GREEN
AddHP 3 3
;;
*)
Display --indent 6 --text "- Checking chain ${chainname} (table: ${table}) policy" --result ${policy} --color YELLOW
LogText "Result: Unknown policy: ${policy}"
#ReportSuggestion ${TEST_NO} "Check iptables ${chainname} (table: ${table}) chain policy"
;;
esac
fi
fi
done
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : FIRE-4512
# Description : Check iptables for empty ruleset (should have at least 10 or more rules)
if [ ! -z "${IPTABLESBINARY}" -a ${IPTABLES_ACTIVE} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4512 --preqs-met ${PREQS_MET} --os Linux --weight L --network NO --root-only YES --category security --description "Check iptables for empty ruleset"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
FIND=$(${IPTABLESBINARY} --list --numeric 2> /dev/null | ${EGREPBINARY} -v "^(Chain|target|$)" | ${WCBINARY} -l | ${TRBINARY} -d ' ')
if [ ! -z "${FIND}" ]; then
2014-08-26 17:33:55 +02:00
FIREWALL_ACTIVE=1
if [ ${FIND} -le 5 ]; then
# Firewall is active, but needs configuration
2015-12-30 14:33:50 +01:00
FIREWALL_EMPTY_RULESET=1
LogText "Result: iptables ruleset seems to be empty (found ${FIND} rules)"
Display --indent 4 --text "- Checking for empty ruleset" --result "${STATUS_WARNING}" --color RED
2016-08-10 07:24:10 +02:00
ReportWarning ${TEST_NO} "iptables module(s) loaded, but no rules active"
else
LogText "Result: one or more rules are available (${FIND} rules)"
Display --indent 4 --text "- Checking for empty ruleset" --result "${STATUS_OK}" --color GREEN
fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FIRE-4513
# Description : Check iptables for unused rules
2016-09-10 16:12:44 +02:00
if [ ! -z "${IPTABLESBINARY}" -a ${IPTABLES_ACTIVE} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4513 --preqs-met ${PREQS_MET} --os Linux --weight L --network NO --root-only YES --category security --description "Check iptables for unused rules"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
FIND=$(${IPTABLESBINARY} --list --numeric --line-numbers --verbose | ${AWKBINARY} '{ if ($2=="0") print $1 }' | ${XARGSBINARY})
if IsEmpty "${FIND}"; then
Display --indent 4 --text "- Checking for unused rules" --result "${STATUS_OK}" --color GREEN
LogText "Result: There are no unused rules present"
else
Display --indent 4 --text "- Checking for unused rules" --result "${STATUS_FOUND}" --color YELLOW
LogText "Result: Found one or more possible unused rules"
LogText "Description: Unused rules can be a sign that the firewall rules aren't optimized or up-to-date"
LogText "Note: Sometimes rules aren't triggered but still in use. Keep this in mind before cleaning up rules."
LogText "Output: iptables rule numbers: ${FIND}"
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Check iptables rules to see which rules are currently not used"
LogText "Tip: iptables --list --numeric --line-numbers --verbose"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
2017-03-08 21:19:20 +01:00
# Test : FIRE-4514
# Notes :
# Check if ipv6 is active on any network interface
# If ip_tables is active, and ip6_tables is not, show warning about missing filtering
#
#################################################################################
#
2014-08-26 17:33:55 +02:00
# Test : FIRE-4518
# Description : Checking status of pf firewall components
2016-10-15 15:26:15 +02:00
# Notes : Use /dev/pf as first detection method if pf is available
2016-10-15 15:28:22 +02:00
if [ -e /dev/pf ]; then PREQS_MET="YES"; SKIPREASON=""; else PREQS_MET="NO"; SKIPREASON="No /dev/pf device"; fi
Register --test-no FIRE-4518 --preqs-met ${PREQS_MET} --skip-reason "${SKIPREASON}" --weight L --network NO --root-only YES --category security --description "Check pf firewall components"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
PFFOUND=0; PFLOGDFOUND=0
# Check status with pfctl
LogText "Test: checking pf status via pfctl"
2016-09-10 16:12:44 +02:00
if [ ! -z "${PFCTLBINARY}" ]; then
FIND=$(${PFCTLBINARY} -sa 2>&1 | ${GREPBINARY} "^Status" | ${HEADBINARY} -1 | ${AWKBINARY} '{ print $2 }')
2016-10-15 15:26:15 +02:00
if [ "${FIND}" = "Disabled" ]; then
if IsVerbose; then Display --indent 2 --text "- Checking pf status (pfctl)" --result "${STATUS_DISABLED}" --color RED; fi
LogText "Result: pf is disabled"
AddHP 0 3
elif [ "${FIND}" = "Enabled" ]; then
Display --indent 2 --text "- Checking pf status (pfctl)" --result "${STATUS_ENABLED}" --color GREEN
LogText "Result: pf is enabled"
2014-08-26 17:33:55 +02:00
PFFOUND=1
AddHP 3 3
else
2016-10-15 15:26:15 +02:00
Display --indent 2 --text "- Checking pf status (pfctl)" --result "${STATUS_UNKNOWN}" --color YELLOW
ReportException ${TEST_NO} "Unknown status of pf firewall"
2014-08-26 17:33:55 +02:00
fi
fi
# If we didn't find the status to be enabled, stop searching
2015-04-07 17:19:49 +02:00
if [ ${PFFOUND} -eq 0 ]; then
2014-08-26 17:33:55 +02:00
# Check for pf kernel module (FreeBSD and similar)
LogText "Test: searching for pf kernel module"
2016-09-10 16:12:44 +02:00
if [ ! -z "${KLDSTATBINARY}" ]; then
FIND=$(${KLDSTATBINARY} | ${GREPBINARY} 'pf.ko')
if [ -z "${FIND}" ]; then
LogText "Result: Can not find pf KLD"
else
LogText "Result: pf KLD loaded"
2014-08-26 17:33:55 +02:00
PFFOUND=1
fi
else
LogText "Result: no kldstat binary, skipping this part"
2014-08-26 17:33:55 +02:00
fi
IsRunning pflogd
if [ ${RUNNING} -eq 1 ]; then
LogText "Result: found pflog daemon in process list"
Display --indent 4 --text "- Checking pflogd status" --result "ACTIVE" --color GREEN
2014-08-26 17:33:55 +02:00
PFFOUND=1
PFLOGDFOUND=1
else
LogText "Result: pflog daemon not found in process list"
2014-08-26 17:33:55 +02:00
fi
fi
if [ ${PFFOUND} -eq 1 ]; then
FIREWALL_ACTIVE=1
FIREWALL_SOFTWARE="pf"
2016-04-27 10:52:45 +02:00
Report "firewall_software[]=pf"
else
LogText "Result: pf not running on this system"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FIRE-4520
# Description : Check pf configuration consistency
if [ ${PFFOUND} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4520 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check pf configuration consistency"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: check /etc/pf.conf"
2014-08-26 17:33:55 +02:00
# Test for warnings (-n don't load the rules)
if [ -f /etc/pf.conf ]; then
LogText "Result: /etc/pf.conf exists"
2014-08-26 17:33:55 +02:00
# Check results from pfctl
PFWARNINGS=$(${PFCTLBINARY} -n -f /etc/pf.conf -vvv 2>&1 | ${GREPBINARY} -i 'warning')
2016-09-10 16:12:44 +02:00
if [ -z "${PFWARNINGS}" ]; then
Display --indent 4 --text "- Checking pf configuration consistency" --result "${STATUS_OK}" --color GREEN
LogText "Result: no pf filter warnings found"
else
Display --indent 4 --text "- Checking pf configuration consistency" --result "${STATUS_WARNING}" --color RED
LogText "Result: found one or more warnings in the pf filter rules"
2016-09-05 11:21:27 +02:00
ReportWarning ${TEST_NO} "Found one or more warnings in pf configuration file" "/etc/pf.conf" "text:Run 'pfctl -n -f /etc/pf.conf -vvv' to see available pf warnings"
2014-08-26 17:33:55 +02:00
fi
else
LogText "Result: /etc/pf.conf does NOT exist"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FIRE-4522
# Description : Check ipchains
#
#################################################################################
2015-03-17 18:06:00 +01:00
#
# Test : FIRE-4524
# Description : Check for CSF (ConfigServer Security & Firewall)
Register --test-no FIRE-4524 --weight L --network NO --category security --description "Check for CSF presence"
2015-03-17 18:06:00 +01:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-03-18 10:40:59 +01:00
FILE="/etc/csf/csf.conf"
LogText "Test: check ${FILE}"
2015-03-18 10:40:59 +01:00
if [ -f ${FILE} ]; then
LogText "Result: ${FILE} exists"
2015-03-17 18:06:00 +01:00
FIREWALL_ACTIVE=1
FIREWALL_SOFTWARE="csf"
2016-04-27 10:52:45 +02:00
Report "firewall_software[]=csf"
Display --indent 2 --text "- Checking CSF status (configuration file)" --result "${STATUS_FOUND}" --color GREEN
LogText "Test: check if CSF testing mode is disabled"
FIND=$(${GREPBINARY} -P "^TESTING(\s|=)" ${FILE} | ${CUTBINARY} -d= -f2 | ${XARGSBINARY})
if [ "${FIND}" = "0" ]; then
Display --indent 4 --text "- Check if CSF testing mode is disabled" --result "${STATUS_OK}" --color GREEN
else
Display --indent 4 --text "- Check if CSF testing mode is disabled" --result "${STATUS_WARNING}" --color RED
fi
else
LogText "Result: ${FILE} does NOT exist"
2015-03-17 18:06:00 +01:00
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : FIRE-4526
# Description : Check ipf (Solaris)
if [ ! "${IPFBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4526 --os Solaris --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check ipf status"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
FIND=$(${IPFBINARY} -n -V | ${GREPBINARY} "^Running" | ${AWKBINARY} '{ print $2 }')
2014-08-26 17:33:55 +02:00
if [ "${FIND}" = "yes" ]; then
Display --indent 4 --text "- Checking ipf status" --result "${STATUS_RUNNING}" --color GREEN
LogText "Result: ipf is enabled and running"
2014-08-26 17:33:55 +02:00
FIREWALL_ACTIVE=1
FIREWALL_SOFTWARE="ipf"
2016-04-27 10:52:45 +02:00
Report "firewall_software[]=ipf"
else
Display --indent 4 --text "- Checking ipf status" --result "${STATUS_NOT_RUNNING}" --color YELLOW
LogText "Result: ipf is not running"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FIRE-4530
# Description : Check IPFW (FreeBSD)
Register --test-no FIRE-4530 --os FreeBSD --weight L --network NO --category security --description "Check IPFW status"
2015-04-27 18:26:39 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
if [ ! -z "${SYSCTLBINARY}" ]; then
2015-04-27 18:26:39 +02:00
# For now, only check for IPv4.
FIND=$(${SYSCTLBINARY} net.inet.ip.fw.enable 2> /dev/null | ${AWKBINARY} '{ print $2 }')
2015-04-27 18:26:39 +02:00
if [ "${FIND}" = "1" ]; then
Display --indent 2 --text "- Checking IPFW status" --result "${STATUS_RUNNING}" --color GREEN
LogText "Result: IPFW is running for IPv4"
2015-04-27 18:26:39 +02:00
FIREWALL_ACTIVE=1
FIREWALL_SOFTWARE="ipfw"
2016-04-27 10:52:45 +02:00
Report "firewall_software[]=ipfw"
IPFW_ENABLED=$(service -e | ${GREPBINARY} -o ipfw)
2015-04-27 18:26:39 +02:00
if [ "${IPFW_ENABLED}" = "ipfw" ]; then
Display --indent 4 --text "- IPFW enabled in /etc/rc.conf" --result "${STATUS_YES}" --color GREEN
LogText "Result: IPFW is enabled at start-up for IPv4"
else
Display --indent 4 --text "- ipfw enabled in /etc/rc.conf" --result "${STATUS_NO}" --color YELLOW
LogText "Result: IPFW is disabled at start-up for IPv4"
2015-04-27 18:26:39 +02:00
fi
else
if IsVerbose; then Display --indent 2 --text "- Checking IPFW status" --result "${STATUS_NOT_RUNNING}" --color YELLOW; fi
LogText "Result: IPFW is not running for IPv4"
2015-04-27 12:00:58 +02:00
fi
else
ReportException "${TEST_NO}:1" "No IPFW test available (sysctl missing)"
fi
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : FIRE-4532
# Description : Check Application Firewall in macOS
if [ -x /usr/libexec/ApplicationFirewall/socketfilterfw ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4532 --weight L --os "macOS" --preqs-met ${PREQS_MET} --network NO --category security --description "Check macOS application firewall"
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
FIND=$(/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate 2> /dev/null | ${GREPBINARY} "Firewall is enabled")
if [ ! -z "${FIND}" ]; then
2016-10-15 11:26:51 +02:00
Display --indent 2 --text "- Checking macOS: Application Firewall" --result "${STATUS_ENABLED}" --color GREEN
AddHP 3 3
2016-10-15 11:26:51 +02:00
LogText "Result: application firewall of macOS is enabled"
FIREWALL_ACTIVE=1
APPLICATION_FIREWALL_ACTIVE=1
2016-10-15 11:26:51 +02:00
Report "firewall_software[]=macosx-app-fw"
Report "app_fw[]=macosx-app-fw"
else
2016-10-15 11:35:07 +02:00
if IsVerbose; then Display --indent 2 --text "- Checking macOS: Application Firewall" --result "${STATUS_DISABLED}" --color YELLOW; fi
2016-10-15 11:26:51 +02:00
AddHP 1 3
LogText "Result: application firewall of macOS is disabled"
fi
fi
#
#################################################################################
#
# Test : FIRE-4534
# Description : Check Little Snitch Daemon on macOS
Register --test-no FIRE-4534 --weight L --os "macOS" --network NO --category security --description "Check for presence of Little Snitch on macOS"
2016-10-15 11:26:51 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
if IsRunning "Little Snitch Daemon"; then
2016-10-15 11:26:51 +02:00
Display --indent 2 --text "- Checking Little Snitch Daemon" --result "${STATUS_ENABLED}" --color GREEN
AddHP 3 3
LogText "Result: little Snitch found"
FIREWALL_ACTIVE=1
APPLICATION_FIREWALL_ACTIVE=1
Report "app_fw[]=little-snitch"
Report "firewall_software[]=little-snitch"
else
2016-10-15 11:26:51 +02:00
if IsVerbose; then Display --indent 2 --text "- Checking Little Snitch Daemon" --result "${STATUS_DISABLED}" --color YELLOW; fi
AddHP 1 3
2016-10-15 11:26:51 +02:00
LogText "Result: could not find Little Snitch"
fi
fi
#
#################################################################################
2015-12-30 14:33:50 +01:00
#
# Test : FIRE-4536
# Description : Check nftables kernel module
if HasData "${NFTBINARY}"; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4536 --os Linux --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check nftables status"
2015-12-30 14:33:50 +01:00
if [ ${SKIPTEST} -eq 0 ]; then
FIND=$(${LSMODBINARY} | ${AWKBINARY} '{ print $1 }' | ${GREPBINARY} "^nf*_tables")
if [ ! -z "${FIND}" ]; then
LogText "Result: found nftables kernel module"
2015-12-30 14:33:50 +01:00
FIREWALL_SOFTWARE="nftables"
FIREWALL_ACTIVE=1
2015-12-30 14:33:50 +01:00
NFTABLES_ACTIVE=1
2016-04-27 10:52:45 +02:00
Report "firewall_software[]=nftables"
else
LogText "Result: no nftables kernel module found"
2015-12-30 14:33:50 +01:00
fi
fi
#
#################################################################################
#
# Test : FIRE-4538
# Description : Check nftables configuration
if HasData "${NFTBINARY}"; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4538 --os Linux --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check nftables basic configuration"
2015-12-30 14:33:50 +01:00
if [ ${SKIPTEST} -eq 0 ]; then
# Retrieve nft version
NFT_VERSION=$(${NFTBINARY} --version 2> /dev/null | ${AWKBINARY} '{ if ($1=="nftables") { print $2 }}' | ${TRBINARY} -d 'v')
2016-04-27 10:52:45 +02:00
Report "nft_version=${NFT_VERSION}"
LogText "Result: found version ${NFT_VERSION} of nft"
fi
#
#################################################################################
#
# Test : FIRE-4540
# Description : Check nftables configuration
if HasData "${NFTBINARY}"; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4540 --os Linux --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check for empty nftables configuration"
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-30 14:33:50 +01:00
# Check for empty ruleset
NFT_RULES_LENGTH=$(${NFTBINARY} export json 2> /dev/null | wc -c)
2015-12-30 14:33:50 +01:00
if [ ${NFT_RULES_LENGTH} -le 16 ]; then
FIREWALL_EMPTY_RULESET=1
LogText "Result: this firewall set has 16 rules or less and is considered to be empty"
else
LogText "Result: found ${NFT_RULES_LENGTH} rules in nftables configuration"
2015-12-30 14:33:50 +01:00
fi
fi
#
#################################################################################
2017-01-28 15:46:42 +01:00
#
# Test : FIRE-4586
# Description : Check firewall logging
if [ ${FIREWALL_ACTIVE} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FIRE-4586 --preqs-met ${PREQS_MET} --weight L --network NO --root-only YES --category security --description "Check firewall logging"
if [ ${SKIPTEST} -eq 0 ]; then
if [ ${IPTABLES_ACTIVE} -eq 1 ]; then
if [ ! -z "${IPTABLESSAVEBINARY}" ]; then
2017-02-10 11:14:01 +01:00
HAS_LOGGING=$(${IPTABLESSAVEBINARY} | ${GREPBINARY} "\-j LOG")
2017-01-28 15:46:42 +01:00
if [ -z "${HAS_LOGGING}" ]; then
Report "firewall_no_logging[]=iptables"
fi
fi
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : FIRE-4590
# Description : Check if at least one firewall if active
Register --test-no FIRE-4590 --weight L --network NO --category security --description "Check firewall status"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
if [ ${FIREWALL_ACTIVE} -eq 1 ]; then
Display --indent 2 --text "- Checking host based firewall" --result "ACTIVE" --color GREEN
LogText "Result: host based firewall or packet filter is active"
Report "manual[]=Verify if there is a formal process for testing and applying firewall rules"
Report "manual[]=Verify all traffic is filtered the right way between the different security zones"
Report "manual[]=Verify if a list is available with all required services"
2014-08-26 17:33:55 +02:00
# YYY Solaris ipf (determine default policy)
Report "manual[]=Make sure an explicit deny all is the default policy for all unmatched traffic"
2014-08-26 17:33:55 +02:00
AddHP 5 5
else
2014-08-26 17:33:55 +02:00
Display --indent 2 --text "- Checking host based firewall" --result "NOT ACTIVE" --color YELLOW
LogText "Result: no host based firewall/packet filter found or configured"
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Configure a firewall/packet filter to filter incoming and outgoing traffic"
AddHP 0 5
fi
fi
#
#################################################################################
#
# Report firewall installed for now, if we found one active. Next step would be determining binaries first and apply additional checks.
Report "firewall_active=${FIREWALL_ACTIVE}"
2015-12-30 14:33:50 +01:00
Report "firewall_empty_ruleset=${FIREWALL_EMPTY_RULESET}"
Report "firewall_installed=${FIREWALL_ACTIVE}"
Report "firewall_software=${FIREWALL_SOFTWARE}"
2014-08-26 17:33:55 +02:00
WaitForKeyPress
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# TODO
# Suggestion to disable iptables if nftables is enabled
# Check for specific features in nftables releases
2014-08-26 17:33:55 +02:00
#
#================================================================================
# Lynis - Security Auditing and System Hardening for Linux and UNIX - https://cisofy.com