geneva.actions.utils

exception utils.SkipStrategyException(msg, fitness)

Bases: Exception

Raised to signal that this strategy evaluation should be cut off.

__init__(msg, fitness)

Creates the exception with the fitness to pass back

class utils.CustomAdapter(logger, extras)

Bases: logging.LoggerAdapter

Used for demo mode, to change sensitive IP addresses where necessary. Can be used (mostly) like a regular logger.

__init__(logger, extras)

Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.

You can effectively pass keyword arguments as shown in the following example:

adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=”v2”))

critical(msg, *args, **kwargs)

Print a critical message, uses logger.critical.

debug(msg, *args, **kwargs)

Print a debug message, uses logger.debug.

error(msg, *args, **kwargs)

Print an error message, uses logger.error.

get_ip(ip)

Lookup the assigned random IP for a given real IP. If no random IP exists, a new one is created and a message is logged indicating it.

info(msg, *args, **kwargs)

Print an info message, uses logger.info.

process(msg, args, kwargs)

Modify the log message to replace any instance of an IP in msg or args with its assigned random IP.

warning(msg, *args, **kwargs)

Print a warning message, uses logger.warning.

regex = re.compile('\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}')
class utils.Logger(log_dir, logger_name, log_name, environment_id, log_level='DEBUG')

Bases: object

Logging class context manager, as a thin wrapper around the logging class to help handle closing open file descriptors.

__init__(log_dir, logger_name, log_name, environment_id, log_level='DEBUG')

Initialize self. See help(type(self)) for accurate signature.

utils.build_command(args)

Given a dictionary of arguments, build it back into a command line string.

utils.close_logger(logger)

Closes open file handles for a given logger.

utils.get_console_log_level()

returns log level of console handler

utils.get_from_fuzzed_or_real_packet(environment_id, real_packet_probability, enable_options=True, enable_load=True)

Retrieves a protocol, field, and value from a fuzzed or real packet, depending on the given probability and if given packets is not None.

utils.get_id()

Returns a random ID

utils.get_interface()

Chooses an interface on the machine to use for socket testing.

utils.get_logger(basepath, log_dir, logger_name, log_name, environment_id, log_level='DEBUG', file_log_level='DEBUG', demo_mode=False)

Configures and returns a logger.

utils.get_plugins()

Iterates over this current directory to retrieve plugins.

utils.get_worker(name, logger)

Returns information dictionary about a worker given its name.

utils.import_plugin(plugin, side)

Imports given plugin. :param - plugin: plugin to import (e.g. “http”) :param - side: which side of the connection should be imported (“client” or “server”)

utils.parse(requested_trees, logger)

Parses a string representation of a solution into its object form.

utils.punish_complexity(fitness, logger, ind)

Reduces fitness based on number of actions - optimizes for simplicity.

utils.punish_fitness(fitness, logger, eng)

Adjusts fitness based on additional optimizer functions.

utils.punish_unused(fitness, logger, ind)

Punishes strategy for each action that was not run.

utils.read_packets(environment_id)

Reads the pcap file associated with the last evaluation of this strategy. Returns a list of Geneva Packet objects.

utils.setup_dirs(output_dir)

Sets up Geneva folder structure.

utils.string_to_protocol(protocol)

Converts string representations of scapy protocol objects to their actual objects. For example, “TCP” to the scapy TCP object.

utils.write_fitness(fitness, output_path, eid)

Writes fitness to disk.