From 362019b833d715617488fdc3d5436d42babeb2b9 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 10 Dec 2018 14:13:34 +0100 Subject: contrib: move auxiliary scripts to own directory Signed-off-by: Tobias Klauser --- contrib/dissector_fuzz.sh | 79 +++++++++++++++++++++++++++++++++++++++++++ contrib/oui-update.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100755 contrib/dissector_fuzz.sh create mode 100755 contrib/oui-update.py (limited to 'contrib') diff --git a/contrib/dissector_fuzz.sh b/contrib/dissector_fuzz.sh new file mode 100755 index 0000000..40b6170 --- /dev/null +++ b/contrib/dissector_fuzz.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- +# +# dissector_fuzz.sh -- fuzz test netsniff-ng's dissector and pcap io methods +# with shitty pcap example files from the Wireshark archive +# +# Copyright (C) 2012 Daniel Borkmann +# Copyright (C) 2012 Stefan Seering +# +# Note: build and *install* the toolkit first before running this script! +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. + +set -u + +if [ ${BASH_VERSINFO} -lt 3 ] ; then + echo 'Error: Your bash need to be version 3 or newer. Exiting.' + exit 1 # operators like =~ produce errors silently in old bash versions, so exit here +fi + +archive='ftp://wireshark.org/automated/captures/' +show_output='' # empty string evaluates to false +run_through='' # empty string evaluates to false +count_cores=0 +count_files=0 +netsniff_ng_opts='' + +if [ $# -gt 0 ] ; then + if [ "$1" = '-h' -o "$1" = '--help' -o "$1" = '--usage' ] ; then + echo 'Usage: dissector_fuzz [-s (show netsniff-ng output, default: no)] [-r (keep running on errors, default: no)] [netsniff-ng long-args]' + exit 0 + fi + + for opt in $@ ; do + if [ "${opt}" = '-s' ] ; then + show_output='true' + elif [ "${opt}" = '-r' ] ; then + run_through='true' + else + netsniff_ng_opts="${netsniff_ng_opts} ${opt}"; + fi + done +fi + +mkdir -p fuzzing +cd fuzzing +wget -r -Nc -np -nd -A.pcap "$archive" |& grep -E "%|^--" +ulimit -c unlimited +rm -f core +for file in *.pcap +do + echo "Testing file $file ..." + if [ $show_output ]; then + netsniff-ng --in "$file" "${netsniff_ng_opts}" + else + netsniff-ng --in "$file" "${netsniff_ng_opts}" > /dev/null + fi + if [ -e core ]; then + echo "Fuck, core dumped on $file!" + let count_cores=count_cores+1 + if [ $run_through ]; then + rm core + else + exit + fi + fi +done + +if which cowsay > /dev/null ; then + echo_cmd='cowsay' +else + echo_cmd='echo' +fi + +${echo_cmd} 'Your fuckup Score' +echo " * tested pcaps: $count_files" +echo " * core dumps: $count_cores" diff --git a/contrib/oui-update.py b/contrib/oui-update.py new file mode 100755 index 0000000..07add9f --- /dev/null +++ b/contrib/oui-update.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# update-oui.py -- update netsniff-ng oui.conf from official IEEE OUI list +# +# Copyright (C) 2013 Tobias Klauser +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. + +import os +import sys +import re +import getopt +try: + from urllib2 import urlopen # Python 2.x +except ImportError: + from urllib.request import urlopen # Python 3.x + +DEFAULT_OUPUT_FILE = "oui.conf" +DEFAULT_OUI_URL = "http://standards.ieee.org/develop/regauth/oui/oui.txt" + +OUI_PATTERN = re.compile(b"^\s*([a-fA-F0-9]{2})-([a-fA-F0-9]{2})-([a-fA-F0-9]{2})\s+\(hex\)\s+(.*)$") + +def usage(): + print("""usage: {0} [OPTION...] +available options: + -f force overwrite of existing file + -o set output file (default: {1}) + -u set URL to fetch OUI list from (default: {2}) + -h show this help and exit""".format(os.path.basename(sys.argv[0]), + DEFAULT_OUPUT_FILE, DEFAULT_OUI_URL)) + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], "fo:u:h") + except getopt.GetoptError as err: + print(str(err)) + usage() + sys.exit(-1) + + overwrite = False + output_file = DEFAULT_OUPUT_FILE + oui_url = DEFAULT_OUI_URL + for o, a in opts: + if o == '-f': + overwrite = True + elif o == '-o': + output_file = a + elif o == '-u': + oui_url = a + elif o == '-h': + usage() + sys.exit(0) + else: + assert False, "unhandled option" + + if not overwrite and os.path.exists(output_file): + print("Error: output file {} already exists".format(output_file)) + sys.exit(-1) + + print("Updating OUI information in {} from {}... ".format(output_file, oui_url)) + + fh_url = urlopen(oui_url) + + ouis = [] + for line in fh_url: + m = OUI_PATTERN.match(line) + if m: + oui = "0x{}{}{}".format(m.group(1), m.group(2), m.group(3)) + vendor = m.group(4).rstrip() + ouis.append((oui, vendor)) + + fh_file = open(output_file, 'w') + for oui, vendor in sorted(ouis): + fh_file.write("{}, {}\n".format(oui, vendor)) + + fh_url.close() + fh_file.close() + + print("{} OUIs written to {}".format(len(ouis), output_file)) + +if __name__ == '__main__': + main() -- cgit v1.2.3-54-g00ecf