From fa9082ab77c198fdcd6c98ea43a33b35c47e9bcf Mon Sep 17 00:00:00 2001 From: nser77 <104022475+nser77@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:31:05 +0200 Subject: [PATCH] Update tests_firewalls --- include/tests_firewalls | 224 +++++++++++++++++++++------------------- 1 file changed, 118 insertions(+), 106 deletions(-) diff --git a/include/tests_firewalls b/include/tests_firewalls index 1d41e0e6..d8d9ce0b 100644 --- a/include/tests_firewalls +++ b/include/tests_firewalls @@ -112,127 +112,139 @@ tables="filter nat mangle raw security" for t in ${tables} do - ${IPTABLESBINARY} -t "${t}" -S -v -w 1 2>/dev/zero | while read -r line - do - set -- ${line} - while [ $# -gt 0 ] + ${IPTABLESBINARY} -t "${t}" -S -v -w 1 2>/dev/zero | + { + while read -r line do - if [ "${1}" = "!" ] - then - not="${1}" - if [ "${2}" = "-d" ] + set -- ${line} + while [ $# -gt 0 ] + do + if [ "${1}" = "!" ] then - d="${not} ${3}" - shift 3 - elif [ "${2}" = "-s" ] + not="${1}" + if [ "${2}" = "-d" ] + then + d="${not} ${3}" + shift 3 + elif [ "${2}" = "-s" ] + then + s="${not} ${3}" + shift 3 + elif [ "${2}" = "-i" ] + then + p="${not} ${3}" + shift 3 + elif [ "${2}" = "-o" ] + then + o="${not} ${3}" + shift 3 + elif [ "${2}" = "-f" ] + then + p="${not} ${3}" + shift 3 + fi + shift + elif [ "${1}" = "-P" ] then - s="${not} ${3}" + c="${2}" + j="${3}" shift 3 - elif [ "${2}" = "-i" ] + elif [ "${1}" = "-A" ] || [ "${1}" = "-N" ] then - p="${not} ${3}" - shift 3 - elif [ "${2}" = "-o" ] + c="${2}" + shift 2 + elif [ "${1}" = "-j" ] then - o="${not} ${3}" - shift 3 - elif [ "${2}" = "-f" ] + j="${2}" + shift + elif [ "${1}" = "-p" ] then - p="${not} ${3}" + p="${2}" + shift + elif [ "${1}" = "-d" ] + then + d="${2}" + shift + elif [ "${1}" = "-s" ] + then + s="${2}" + shift + elif [ "${1}" = "-m" ] + then + m="${2}" + shift + elif [ "${1}" = "-g" ] + then + g="${2}" + shift + elif [ "${1}" = "-i" ] + then + i="${2}" + shift + elif [ "${1}" = "-o" ] + then + o="${2}" + shift + elif [ "${1}" = "-f" ] + then + f="${2}" + shift + elif [ "${1}" = "-c" ] + then + pc="${2}" + bc="${3}" shift 3 + else + shift fi - shift - elif [ "${1}" = "-P" ] + done + # logics + if [ "${t}" = "filter" ] || [ "${t}" = "security" ] then - c="${2}" - j="${3}" - shift 3 - elif [ "${1}" = "-A" ] || [ "${1}" = "-N" ] - then - c="${2}" - shift 2 - elif [ "${1}" = "-j" ] - then - j="${2}" - shift - elif [ "${1}" = "-p" ] - then - p="${2}" - shift - elif [ "${1}" = "-d" ] - then - d="${2}" - shift - elif [ "${1}" = "-s" ] - then - s="${2}" - shift - elif [ "${1}" = "-m" ] - then - m="${2}" - shift - elif [ "${1}" = "-g" ] - then - g="${2}" - shift - elif [ "${1}" = "-i" ] - then - i="${2}" - shift - elif [ "${1}" = "-o" ] - then - o="${2}" - shift - elif [ "${1}" = "-f" ] - then - f="${2}" - shift - elif [ "${1}" = "-c" ] - then - pc="${2}" - bc="${3}" - shift 3 - else - shift + if [ "${c}" = "INPUT" ] + then + if [ "${j}" = "ACCEPT" ] + then + errqueue="${errqueue}\n${t} ${c} ${j} YELLOW" + AddHP 1 3 + elif [ "${j}" = "DROP" ] + then + errqueue="${errqueue}\n${t} ${c} ${j} GREEN" + AddHP 3 3 + fi + elif [ "${c}" = "FORWARD" ] + then + : + elif [ "${c}" = "OUTPUT" ] + then + : + fi + if [ "${c}" = "INPUT" ] || [ "${c}" = "FORWARD" ] || [ "${c}" = "OUTPUT" ] + then + if [ "${j}" = "NFQUEUE" ] + then + errqueue="${errqueue}\n${t} ${c} ${j} RED" + AddHP 0 3 + fi + fi fi done - # logics - if [ "${t}" = "filter" ] || [ "${t}" = "security" ] - then - if [ "${c}" = "INPUT" ] - then - if [ "${j}" = "ACCEPT" ] + # resume + echo ${errqueue} | ${SORTBINARY} -u | while read -r eq + do + set -- ${eq} + while [ $# -gt 0 ] + do + Display --indent 6 --text "Checking chain ${2} (table: ${1}, target: ${3})" --result "${3}" --color "${4}" + if [ "${3}" = "NFQUEUE" ] then - LogText "Result: Found ${j} for ${c} (table: ${t})" - Display --indent 6 --text "- Checking chain ${c} (table: ${t}, chain ${c})" --result "${j}" --color YELLOW - AddHP 1 3 - elif [ "${j}" = "DROP" ] - then - LogText "Result: Found ${j} for ${c} (table: ${t})" - Display --indent 6 --text "- Checking chain ${c} (table: ${t}, chain ${c})" --result "${j}" --color GREEN - AddHP 3 3 + ReportSuggestion "${TEST_NO}" "Consider avoid ${3} target if possible (iptables chain ${2}, table: ${1})" fi - elif [ "${c}" = "FORWARD" ] - then - : - elif [ "${c}" = "OUTPUT" ] - then - : - fi - if [ "${c}" = "INPUT" ] || [ "${c}" = "FORWARD" ] || [ "${c}" = "OUTPUT" ] - then - if [ "${j}" = "NFQUEUE" ] - then - LogText "Result: Found ${j} for ${c} (table: ${t})" - Display --indent 6 --text "- Checking chain ${c} (table: ${t}, chain ${c})" --result "${j}" --color RED - ReportSuggestion "${TEST_NO}" "Consider avoid ${j} target if possible (iptables chain ${c}, table: ${t})" - AddHP 0 3 - fi - fi - fi - done + shift 4 + done + done + } done - # resume fi # #################################################################################