dumb fuzzer: randpkt vs nDPId-test

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2021-09-20 00:28:44 +02:00
parent 7829bfe4e6
commit 992d3a207d
2 changed files with 64 additions and 6 deletions

54
test/dumb_fuzzer.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -e
MYDIR="$(realpath "$(dirname ${0})")"
nDPId_test_EXEC="$(realpath "${1:-"${MYDIR}/../nDPId-test"}")"
PROTOCOL="${2:-tcp}"
MAX_RUNS="${3:-100}"
MAX_COUNT="${4:-10000}"
function usage()
{
cat <<EOF
usage: ${0} [path-to-nDPId-test-exec] [protocol] [max-runs] [max-count]
path-to-nDPId-test-exec defaults to ${nDPId_test_EXEC}
protocol defaults to ${PROTOCOL}
max-runs defaults to ${MAX_RUNS}
max-count defaults to ${MAX_COUNT}
EOF
return 0
}
if [ $# -eq 0 ]; then
usage
exit 1
elif [ ! -x "${nDPId_test_EXEC}" ]; then
printf '%s\n' "Required nDPId-test executable does not exist; ${nDPId_test_EXEC}"
exit 1
fi
function sighandler()
{
printf '%s\n' ' Received shutdown SIGNAL, bye' >&2
rm -f "/tmp/randpkt_$$.pcap"
$(which pkill) -P $$
wait
exit 2
}
trap sighandler SIGINT SIGTERM
test -z "$(which pkill)" && { printf '%s\n' 'pkill not found'; exit 1; }
test -z "$(which randpkt)" && { printf '%s\n' 'randpkt not found'; exit 1; }
while (( ${MAX_RUNS} > 0 )); do
printf '.'
test $((${MAX_RUNS} % 10)) -ne 0 || printf '%s' "${MAX_RUNS}"
$(which randpkt) -c "${MAX_COUNT}" -t "${PROTOCOL}" "/tmp/randpkt_$$.pcap"
${nDPId_test_EXEC} "/tmp/randpkt_$$.pcap" >/dev/null
MAX_RUNS=$((${MAX_RUNS} - 1))
done
rm -f "/tmp/randpkt_$$.pcap"
printf '\n'

View File

@@ -5,7 +5,7 @@ set -e
LINE_SPACES=${LINE_SPACES:-48}
MYDIR="$(realpath "$(dirname ${0})")"
nDPId_test_EXEC="$(realpath "${2:-"${MYDIR}/../nDPId-test"}")"
NETCAT_EXEC="nc -q 0 -l 127.0.0.1 9000"
NETCAT_EXEC="$(which nc) -q 0 -l 127.0.0.1 9000"
JSON_VALIDATOR="$(realpath "${3:-"${MYDIR}/../examples/py-schema-validation/py-schema-validation.py"}")"
SEMN_VALIDATOR="$(realpath "${4:-"${MYDIR}/../examples/py-semantic-validation/py-semantic-validation.py"}")"
@@ -22,6 +22,10 @@ EOF
return 0
}
test -z "$(which flock)" && { printf '%s\n' 'flock not found'; exit 1; }
test -z "$(which pkill)" && { printf '%s\n' 'pkill not found'; exit 1; }
test -z "$(which nc)" && { printf '%s\n' 'nc not found'; exit 1; }
if [ $# -eq 0 -a -x "${MYDIR}/../libnDPI/tests/pcap" ]; then
nDPI_SOURCE_ROOT="${MYDIR}/../libnDPI"
elif [ $# -ne 1 -a $# -ne 2 -a $# -ne 3 -a $# -ne 4 ]; then
@@ -40,14 +44,14 @@ LOCKFILE="$(realpath "${0}").lock"
touch "${LOCKFILE}"
exec 42< "${LOCKFILE}"
flock -x -n 42 || {
$(which flock) -x -n 42 || {
printf '%s\n' "Could not aquire file lock for ${0}. Already running instance?" >&2;
exit 3;
}
function sighandler()
{
printf '%s\n' ' Received shutdown SIGNAL, bye' >&2
pkill -P $$
$(which pkill) -P $$
wait
rm -f "${LOCKFILE}"
exit 4
@@ -60,9 +64,9 @@ if [ ! -x "${nDPId_test_EXEC}" ]; then
exit 5
fi
nc -h |& head -n1 | grep -qoE '^OpenBSD netcat' || {
printf '%s\n' "OpenBSD netcat (nc) version required!" >&2;
printf '%s\n' "Your version: $(nc -h |& head -n1)" >&2;
$(which nc) -h |& head -n1 | grep -qoE '^OpenBSD netcat' || {
printf '%s\n' "$(which nc): OpenBSD netcat (nc) version required!" >&2;
printf '%s\n' "$(which nc): Your version: $(nc -h |& head -n1)" >&2;
exit 6;
}