:py:mod:`expliot.core.tests.test` ================================= .. py:module:: expliot.core.tests.test .. autoapi-nested-parse:: Plugin/test details. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: expliot.core.tests.test.TCategory expliot.core.tests.test.TTarget expliot.core.tests.test.TResult expliot.core.tests.test.TLog expliot.core.tests.test.Test Attributes ~~~~~~~~~~ .. autoapisummary:: expliot.core.tests.test.LOGNO expliot.core.tests.test.LOGPRETTY expliot.core.tests.test.LOGNORMAL .. py:data:: LOGNO :annotation: = 0 .. py:data:: LOGPRETTY :annotation: = 1 .. py:data:: LOGNORMAL :annotation: = 2 .. py:class:: TCategory(tech, iface, action) Bases: :py:obj:`namedtuple`\ (\ :py:obj:`'TCategory'`\ , :py:obj:`'tech`\ , :py:obj:`iface`\ , :py:obj:`action'`\ ) Representation of Test Category. The class that defines the category of the test case. It is part of the Test class member _category. It can be used to identify the type of test or search for a specific category. It is a namedtuple that defines three attributes (for categorizing test cases). 1. tech: What technology does the test use 2. iface: Interface of the test i.e. whether it is for software or hardware 3. action: What action does the test perform i.e. is it an exploit or a recon test for example. .. py:attribute:: COAP :annotation: = coap .. py:attribute:: DICOM :annotation: = dicom .. py:attribute:: HTTP :annotation: = http .. py:attribute:: MDNS :annotation: = mdns .. py:attribute:: MODBUS :annotation: = modbus .. py:attribute:: MQTT :annotation: = mqtt .. py:attribute:: TCP :annotation: = tcp .. py:attribute:: UDP :annotation: = udp .. py:attribute:: UPNP :annotation: = upnp .. py:attribute:: BLE :annotation: = ble .. py:attribute:: IEEE802154 :annotation: = 802154 .. py:attribute:: ZIGBEE :annotation: = zigbee .. py:attribute:: CAN :annotation: = can .. py:attribute:: I2C :annotation: = i2c .. py:attribute:: JTAG :annotation: = jtag .. py:attribute:: SPI :annotation: = spi .. py:attribute:: UART :annotation: = uart .. py:attribute:: CRYPTO :annotation: = crypto .. py:attribute:: FW :annotation: = firmware .. py:attribute:: ZB_AUDITOR :annotation: = zbauditor .. py:attribute:: BUS_AUDITOR :annotation: = busauditor .. py:attribute:: FW_AUDITOR :annotation: = fwauditor .. py:attribute:: NMAP :annotation: = nmap .. py:attribute:: _tech .. py:attribute:: HW :annotation: = hardware .. py:attribute:: RD :annotation: = radio .. py:attribute:: SW :annotation: = software .. py:attribute:: _interfaces .. py:attribute:: ANALYSIS :annotation: = analysis .. py:attribute:: COMPLIANCE :annotation: = compliance .. py:attribute:: DISCOVERY :annotation: = discovery .. py:attribute:: EXPLOIT :annotation: = exploit .. py:attribute:: FUZZ :annotation: = fuzz .. py:attribute:: RECON :annotation: = recon .. py:attribute:: _actions .. py:class:: TTarget(name, version, vendor) Bases: :py:obj:`namedtuple`\ (\ :py:obj:`'TTarget'`\ , :py:obj:`'name`\ , :py:obj:`version`\ , :py:obj:`vendor'`\ ) Representation of Test Target class. Class that hold details about the target of the test. It is a namedtuple and holds the below details: 1. name - Target/product name 2. version - Version of the product 3. vendor - Vendor that owns the product Please note, in case it is a generic test case that can be used for multiple products use Target.GENERIC for all attributes. .. py:attribute:: GENERIC :annotation: = generic .. py:attribute:: LINUX :annotation: = linux .. py:attribute:: AWS :annotation: = aws .. py:attribute:: TP_LINK_IOT :annotation: = tpliot .. py:attribute:: _name .. py:attribute:: AMAZON :annotation: = amazon .. py:attribute:: TP_LINK :annotation: = tplink .. py:attribute:: _vendor .. py:class:: TResult Representation of a test result. self.output is a list of dict. This is populated by the plugin when it needs to push results during the execution. To make it standardized, the plugin pushes a block of info in a dict object as and when it has certain info. For ex. when enumerating on something, each item identified will be push as a dict considering there is more than one data point to be stored for that item and once the plugin execution finishes we get a list of dicts containing same/similar data for each of the items. .. py:attribute:: defaultrsn :annotation: = No reason specified .. py:method:: setstatus(passed=True, reason=None) Set the Test result status. :param passed: True or False :param reason: Reason for failure if any :return: .. py:method:: exception() Set passed to False and reason to the exception message. Returns: Nothing .. py:method:: getresult() Returns a dict with result data. Caller needs to make sure plugin execution (run()) is done before calling this. Returns: dict: the result data including status and output NOTE: This is the standard dict format that will be used by EXPLIoT for returning the plugin execution results. The dict keys and their meaning: status(int) - The execution status of the plugin. 0 if the test passed 1 otherwise. reason(str) - The reason the test failed. If it was successful, this will be None. output(list) - The actual plugin execution output. This is a list of dicts and the plugins MUST adhere to this format and document their output format clearly in the plugin class. .. py:class:: TLog Representation of a Test Log. Logger class for logging test case output. By default log to sys.stdout Must not instantiate. Use class methods. The logger needs to be initialized with the output file using init() class method .. py:attribute:: SUCCESS :annotation: = 0 .. py:attribute:: FAIL :annotation: = 1 .. py:attribute:: TRYDO :annotation: = 2 .. py:attribute:: GENERIC :annotation: = 3 .. py:attribute:: _prefix :annotation: = ['[+]', '[-]', '[?]', '[*]'] .. py:attribute:: _errprefix :annotation: = [.] .. py:attribute:: _file .. py:method:: init(file=None) :classmethod: Initialize the file object. This method should be called in the beginning of the application to open the log output file. :param file: The file where to log the test output :return: .. py:method:: close() :classmethod: Close the file object if it is not sys.stdout. :return: .. py:method:: print(prefixtype, message) :classmethod: The actual print methods that write the formatted message to the _file file. Args: prefixtype(int): the prefix type to be used for the message (defined above) message(str): The actual message from the Test object Returns: Nothing .. py:method:: success(message) :classmethod: Write a message with success prefix to the file. :param message: The message to be written :return: .. py:method:: fail(message) :classmethod: Write a message with fail prefix to the file. :param message: The message to be written :return: .. py:method:: trydo(message) :classmethod: Write a message with try prefix to the file. :param message: The message to be written :return: void .. py:method:: generic(message) :classmethod: Write a message with success prefix to the file. :param message: The message to be written :return: void .. py:class:: Test(**kwargs) Representation of Test. The Base class for test cases (plugins). It defines the basic interface and basic implementation for the test cases. All test case plugins need to inherit from a test class derived from this class or this class itself depending on the purpose of the test case. .. py:method:: pre() Action to take before the test. .. py:method:: post() Action to take after the test. .. py:method:: execute() Execute the test. .. py:method:: intro() Show the intro for test. .. py:method:: output_dict_iter(cblog, robj, rlevel, key=None, value=None) Callback method for recurse_list_dict(). It iterates over the dict output passed from a plugin to output_handler(). It performs two operations on the dict 1. If the output data is to be TLog(ged) (LOGPRETTY) on the console, then log the data recursively from the dict. 2. Convert any bytes or bytearray objects in the dict to binary string and update the original dict object itself. Args: cblog (dict): Contains logging information i.e. to log the data or not? and the Log prefix type. robj (list or dict): The list or dict object at the specified recursion level. This is updated by this callback i.e. bytes and bytearray objects found are converted to binary strings. rlevel (int): The current recursion level at which this callback instance is called. key (str): The key if the robj is a dict. value (can be any type): 1. The value of the key if robj is a dict or 2. A value from the robj if it is a list Returns: Nothing .. py:method:: output_handler(tlogtype=TLog.SUCCESS, msg=None, logkwargs=LOGPRETTY, **kwargs) Handle the Test execution output Data - Add(append) data (dict) as an item in the TResult output (list). - And/or Log (print) the output Args: tlogtype (int): TLog prefix type to use i.e. Success, fail etc. Check TLog class for prefix details. msg (str): Specify a message to be logged, if any, apart from output data. logkwargs=LOGPRETTY(int): There are three options for kwargs logging LOGPRETTY(0) - formatted logging for dict or list. LOGNORMAL(1) - Direct print of dict or list as is. LOGNO(2) - Do not log kwargs. **kwargs: plugin output keyword arguments (or a **dictObject) Returns: Nothing. .. py:method:: run(arglist) Run the test. Args: arglist (list): The argument list of the plugin. Returns: dict: The plugin result (status and output) on success, or an empty dict in case of any error. .. py:method:: _assertpriv() Raise an exception if the plugin needs root privileges but program is not executing as root. Args: None Returns: Nothing .. py:method:: _setid() Set the Unique Test ID. The ID is the plugin class name in lowercase. Args: None Returns: Nothing .. py:method:: _logstatus() Handle the log status. Args: None Returns: Nothing