123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import argparse
- import sys
- from ID2TLib.Controller import Controller
- class LoadFromFile(argparse.Action):
- """
- Parses the parameter file given by application param -c/--config.
- """
- def __call__(self, parser, namespace, values, option_string=None):
- with values as f:
- parser.parse_args(f.read().split(), namespace)
- class CLI(object):
- def __init__(self):
- """
- Creates a new CLI object used to handle
- """
-
- self.args = None
- self.attack_config = None
- def process_arguments(self):
- """
- Loads the application controller, the PCAP file statistics and if present, processes the given attacks. Evaluates
- given queries.
- """
-
- controller = Controller(self.args.input)
-
- controller.load_pcap_statistics(self.args.export, self.args.recalculate, self.args.statistics)
-
- if self.args.attack is not None:
-
- controller.process_attacks(self.args.attack)
-
- if self.args.query == [None]:
- controller.enter_query_mode()
-
- elif self.args.query is not None:
- controller.process_db_queries(self.args.query, True)
- def parse_arguments(self, args):
- """
- Defines the allowed application arguments and invokes the evaluation of the arguments.
- :param args: The application arguments
- """
-
- parser = argparse.ArgumentParser(description="Intrusion Detection Dataset Toolkit (ID2T) - A toolkit for "
- "injection of synthetically created attacks into PCAP datasets.")
-
-
-
-
-
- parser.add_argument('-i', '--input', metavar="FILEPATH", help='path to the input pcap file', required=False)
- parser.add_argument('-c', '--config', metavar='FILEPATH', help='file containing parameters used as input.',
- action=LoadFromFile, type=open)
- parser.add_argument('-e', '--export',
- help='stores the statistics as a textfile with ending .stat into the dataset directory',
- action='store_true', default=False)
- parser.add_argument('-a', '--attack', metavar="ATTACKNAME", action='append',
- help='injects a new attack into the given dataset.', nargs='+')
- parser.add_argument('-g', '--gui', help='enables the Graphical User Interface (GUI) mode.', action='store_true',
- default=False)
- parser.add_argument('-r', '--recalculate',
- help='forces to recalculate the statistics in case of an already existing statistics database.',
- action='store_true', default=False)
- parser.add_argument('-s', '--statistics', help='print general file statistics to stdout.', action='store_true',
- default=False)
- parser.add_argument('-q', '--query', metavar="QUERY",
- action='append', nargs='?',
- help='queries the statistics database. If no query is provided, the application enters into query mode.')
-
- self.args = parser.parse_args(args)
-
- if not self.args.input and not self.args.gui:
- parser.error("Parameter -i/--input or -g/--gui required.")
-
- if self.args.gui:
- raise NotImplementedError("Feature not implemented yet.")
-
- pass
-
- else:
- self.process_arguments()
- def main(args):
- """
- Creates a new CLI object and invokes the arguments parsing.
- :param args: The provided arguments
- """
- cli = CLI()
-
- cli.parse_arguments(args)
- if __name__ == '__main__':
- main(sys.argv[1:])
-
|