### Install python-libnmap via Git and setup.py Source: https://github.com/savon-noir/python-libnmap/blob/master/README.rst Installs the python-libnmap library by cloning the repository and then using the setup.py script. This is a more traditional, though deprecated, method of installation. ```bash ronald@brouette:~$ git clone https://github.com/savon-noir/python-libnmap.git ronald@brouette:~$ cd python-libnmap ronald@brouette:~$ python setup.py install ``` -------------------------------- ### Install python-libnmap via Git and Pip Source: https://github.com/savon-noir/python-libnmap/blob/master/README.rst Installs the python-libnmap library by cloning the repository from GitHub and then using pip to install it. This method is useful for development or when needing the latest code. ```bash ronald@brouette:~$ git clone https://github.com/savon-noir/python-libnmap.git ronald@brouette:~$ cd python-libnmap ronald@brouette:~$ pip install . ``` -------------------------------- ### Install python-libnmap via Pip Source: https://github.com/savon-noir/python-libnmap/blob/master/README.rst Installs the python-libnmap library using pip, the standard Python package installer. This is the recommended method for installing the library. ```bash ronald@brouette:~$ pip install python-libnmap ``` -------------------------------- ### Install defusedxml for Security Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/parser.rst Installs the defusedxml library, which is recommended for parsing untrusted XML scan outputs with libnmap to mitigate XML External Entities (XXE) attacks. ```bash ronald@brouette:~/dev$ pip install defusedxml ``` -------------------------------- ### Install defusedxml for Security Source: https://github.com/savon-noir/python-libnmap/blob/master/README.rst Installs the defusedxml library to prevent XML External Entities (XXE) attacks when parsing untrusted XML scan data. This is crucial for security and addresses a CVE vulnerability. ```bash ronald@brouette:~/dev$ pip install defusedxml ``` -------------------------------- ### Using libnmap.objects.cpe Module Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/objects/cpe.rst Illustrates how to import and utilize the libnmap.objects.cpe module for handling CPE data in Python. This section is a placeholder for usage examples. ```python # TODO: Add example usage for libnmap.objects.cpe module here. # Example: # from libnmap.objects.cpe import CPE # cpe_obj = CPE("cpe:2.3:a:apache:log4j:2.14.1:*:*:*:*:*:*:*") # print(cpe_obj.get_product()) ``` -------------------------------- ### Asynchronous Nmap Scan with Progress Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/process.rst Illustrates running an Nmap scan in the background using threading and accessing scan progress and estimated time to completion (ETC) while the scan is active. This example shows how to monitor the scan's progress through the NmapProcess attributes. ```python # Example from ../examples/proc_async.py (content not fully provided in input) # This snippet represents the concept of asynchronous scanning and progress monitoring. ``` -------------------------------- ### Recursive Diff Example for Nmap Objects Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/diff.rst Provides a more concise and automated way to identify and display differences between Nmap objects by recursively traversing nested structures. It uses prefixes like '~', '+', and '-' to indicate changed, added, and removed elements, respectively. ```python .. literalinclude:: ../examples/diff_sample2.py ``` -------------------------------- ### Nmap Process and Parsing Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/parser.rst Shows how to run an nmap scan using NmapProcess, capture its output, and then parse the results using NmapParser. ```python from libnmap.process import NmapProcess from libnmap.parser import NmapParser nm = NmapProcess("127.0.0.1, scanme.nmap.org") nm.run() nmap_report = NmapParser.parse(nm.stdout) for scanned_hosts in nmap_report.hosts: print scanned_hosts ``` -------------------------------- ### Basic Nmap Scan Execution Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/process.rst Demonstrates how to instantiate NmapProcess, run a scan against a target with specific options, and check the return code to print either the standard output or standard error. ```python from libnmap.process import NmapProcess nm = NmapProcess("scanme.nmap.org", options="-sV") rc = nm.run() if nm.rc == 0: print(nm.stdout) else: print(nm.stderr) ``` -------------------------------- ### libnmap Modules Overview Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/index.rst Provides an overview of the different modules available in the libnmap Python toolkit, including their functionalities and the objects they contain. ```python Modules: - process: Launch nmap scans. - parse: Parse nmap XML reports from files or strings. - report: Manipulate parsed scan results and serialize/deserialize to JSON. - diff: Compare two scan results. - objects: Contains nmap object definitions (NmapHost, NmapService, etc.). - plugins: Support datastores for scan results within NmapReport objects. ``` -------------------------------- ### libnmap Plugin Datastores Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/index.rst Describes the plugin system in libnmap for supporting datastores with scan results, including implemented and planned plugins. ```python Plugins: - mongodb: Basic plugin for MongoDB (POC). - sqlalchemy: Supports storing/retrieving NmapReport using SQLAlchemy engines (sqlite, mysql, etc.). - rabbitMQ: Planned plugin. - couchdb: Planned plugin. - elastic search: Planned plugin. - csv: Planned plugin. ``` -------------------------------- ### NmapHost Class Documentation Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/objects/nmaphost.rst Provides detailed documentation for the NmapHost class, including its members (methods and attributes) for representing a host discovered by nmap. This is auto-generated documentation. ```APIDOC .. autoclass:: libnmap.objects.NmapHost :members: ``` -------------------------------- ### NmapParser Class Methods Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/parser.rst Documentation for the NmapParser class, detailing its methods for parsing nmap scan data from various sources like files, strings, or raw output. ```APIDOC class NmapParser: """Factory for NmapReport, NmapHost, NmapService objects.""" @staticmethod def parse(string: str) -> Union[NmapReport, NmapHost, NmapService, dict]: """Parses nmap XML output from a string. Can return NmapReport, NmapHost, NmapService, or a dict based on input. """ pass @staticmethod def parse_fromfile(file_path: str) -> Union[NmapReport, NmapHost, NmapService, dict]: """Parses nmap XML output from a file. Can return NmapReport, NmapHost, NmapService, or a dict based on input. """ pass @staticmethod def parse_fromstring(string: str) -> Union[NmapReport, NmapHost, NmapService, dict]: """Parses nmap XML output from a string. Can return NmapReport, NmapHost, NmapService, or a dict based on input. """ pass ``` -------------------------------- ### Basic Nmap Report Parsing Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/parser.rst Demonstrates how to parse a full nmap XML scan report from a file using NmapParser and access its summary. ```python from libnmap.parser import NmapParser nmap_report = NmapParser.parse_fromfile('libnmap/test/files/1_os_banner_scripts.xml') print "Nmap scan summary: {0}".format(nmap_report.summary) ``` -------------------------------- ### CPE Class Documentation Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/objects/cpe.rst Provides detailed documentation for the CPE class within the libnmap.objects.cpe module. This includes all public methods and their functionalities for working with CPE data. ```APIDOC CPE Represents a Common Platform Enumeration (CPE) object. Attributes: vendor (str): The vendor of the product. product (str): The product name. version (str): The version of the product. update (str): The update information for the product. edition (str): The edition of the product. language (str): The language of the product. sw_edition (str): The software edition. target_sw (str): The target software. target_hw (str): The target hardware. other (str): Other CPE attributes. Methods: __init__(self, cpe_str=None, **kwargs) Initializes a CPE object. Args: cpe_str (str, optional): A CPE string to parse. Defaults to None. **kwargs: Keyword arguments to set CPE attributes. __str__(self) -> str Returns the string representation of the CPE object. __repr__(self) -> str Returns the developer-friendly representation of the CPE object. to_dict(self) -> dict Converts the CPE object to a dictionary. to_json(self) -> str Converts the CPE object to a JSON string. is_exact(self) -> bool Checks if the CPE is an exact match. is_partially_exact(self) -> bool Checks if the CPE is partially exact. is_generic(self) -> bool Checks if the CPE is generic. is_any(self) -> bool Checks if the CPE is 'any'. is_empty(self) -> bool Checks if the CPE object is empty. update(self, cpe) Updates the CPE object with another CPE object or string. Args: cpe (CPE or str): The CPE object or string to update with. match(self, other_cpe) -> bool Checks if this CPE matches another CPE. Args: other_cpe (CPE): The other CPE object to compare against. Returns: bool: True if the CPEs match, False otherwise. get_vendor(self) -> str Gets the vendor attribute. get_product(self) -> str Gets the product attribute. get_version(self) -> str Gets the version attribute. get_update(self) -> str Gets the update attribute. get_edition(self) -> str Gets the edition attribute. get_language(self) -> str Gets the language attribute. get_sw_edition(self) -> str Gets the software edition attribute. get_target_sw(self) -> str Gets the target software attribute. get_target_hw(self) -> str Gets the target hardware attribute. get_other(self) -> str Gets the other attributes. set_vendor(self, vendor: str) Sets the vendor attribute. set_product(self, product: str) Sets the product attribute. set_version(self, version: str) Sets the version attribute. set_update(self, update: str) Sets the update attribute. set_edition(self, edition: str) Sets the edition attribute. set_language(self, language: str) Sets the language attribute. set_sw_edition(self, sw_edition: str) Sets the software edition attribute. set_target_sw(self, target_sw: str) Sets the target software attribute. set_target_hw(self, target_hw: str) Sets the target hardware attribute. set_other(self, other: str) Sets the other attributes. parse(self, cpe_str: str) Parses a CPE string and updates the object's attributes. Args: cpe_str (str): The CPE string to parse. from_string(cls, cpe_str: str) -> 'CPE' Creates a CPE object from a CPE string. Args: cpe_str (str): The CPE string. Returns: CPE: A new CPE object. from_dict(cls, cpe_dict: dict) -> 'CPE' Creates a CPE object from a dictionary. Args: cpe_dict (dict): The dictionary containing CPE attributes. Returns: CPE: A new CPE object. from_json(cls, cpe_json: str) -> 'CPE' Creates a CPE object from a JSON string. Args: cpe_json (str): The JSON string. Returns: CPE: A new CPE object. ``` -------------------------------- ### Nmap Scan Results (Nmap-like Output) Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/process.rst Shows how to execute an Nmap scan and display the results in a format similar to the standard nmap command-line output. This is useful for users familiar with nmap's default reporting. ```python # Example from ../examples/proc_nmap_like.py (content not fully provided in input) # This snippet represents the concept of displaying nmap-like output. ``` -------------------------------- ### NmapS3Plugin Class Documentation Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/plugins_s3.rst Provides documentation for the NmapS3Plugin class, detailing its methods for S3 integration. This includes functionalities for storing and retrieving Nmap reports from S3 buckets. ```APIDOC libnmap.plugins.s3.NmapS3Plugin This module enables the user to directly use S3 buckets to store and retrieve NmapReports. Methods: (Details for each method of NmapS3Plugin would be listed here, including parameters, return values, and usage examples, as extracted from the source or documentation.) ``` -------------------------------- ### NmapProcess Class Methods Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/process.rst Details the methods available within the NmapProcess class for processing Nmap scan results. This includes initialization and other member functions. ```APIDOC NmapProcess: __init__(self, targets='localhost', ports=None, options='-sV') Initializes the NmapProcess with target hosts, ports, and Nmap options. Parameters: targets: A string or list of targets to scan. ports: A string specifying the ports to scan (e.g., '1-1000', '22,80,443'). options: A string of Nmap command-line options. (Other methods documented by :members: directive) ``` -------------------------------- ### NmapReport Class Documentation Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/objects/nmapreport.rst Provides comprehensive documentation for the NmapReport class, including its methods, parameters, and return values for parsing nmap scan results. ```APIDOC libnmap.objects.report ====================== Using libnmap.objects.report module ----------------------------------- TODO NmapReport methods ------------------ .. automodule:: libnmap.objects .. autoclass:: NmapReport :members: ``` -------------------------------- ### NmapService Methods Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/objects/nmapservice.rst This section documents the methods available for the NmapService class. It covers various aspects of network service information obtained from Nmap scans. ```APIDOC NmapService: __init__(**kwargs) Initializes an NmapService object with provided keyword arguments. all_ports(): Returns a list of all ports associated with the service. Returns: list[int] ports(): Returns a list of ports on which the service is running. Returns: list[int] service(): Returns the name of the service. Returns: str banner(): Returns the banner information for the service. Returns: str or None reason(): Returns the reason for the port being open. Returns: str state(): Returns the state of the port (e.g., 'open', 'closed'). Returns: str product(): Returns the product name of the service. Returns: str or None version(): Returns the version of the service. Returns: str or None extrainfo(): Returns additional information about the service. Returns: str or None hostname(): Returns the hostname associated with the service. Returns: str or None cpe(): Returns the CPE (Common Platform Enumeration) string for the service. Returns: str or None get_dict(): Returns a dictionary representation of the NmapService object. Returns: dict ``` -------------------------------- ### Nmap OS Fingerprint Classes Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/objects/os.rst Details the classes used for representing Nmap OS detection results, including fingerprint, match, class, and port usage information. ```APIDOC NmapOSFingerprint: Represents an Nmap OS fingerprint. :members: (Provides access to all methods and attributes of the class) NmapOSMatch: Represents a match for an OS fingerprint. :members: (Provides access to all methods and attributes of the class) NmapOSClass: Represents an OS class within a fingerprint. :members: (Provides access to all methods and attributes of the class) OSFPPortUsed: Represents a port used in an OS fingerprint. :members: (Provides access to all methods and attributes of the class) ``` -------------------------------- ### NmapTask Class Methods Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/process.rst Details the methods available within the NmapTask class. This class likely handles individual Nmap tasks or operations. ```APIDOC NmapTask: (Methods documented by :members: directive) ``` -------------------------------- ### NmapDiff Class API Documentation Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/diff.rst API reference for the NmapDiff class within the libnmap.diff module. This class is instantiated with two NmapObjects and provides methods to query the differences between them. ```APIDOC libnmap.diff.NmapDiff Initializes a diff object between two NmapObjects. Methods: added() -> set Returns a python set() of keys that were added in the second object compared to the first. removed() -> set Returns a python set() of keys that were removed in the second object compared to the first. changed() -> set Returns a python set() of keys whose values have changed between the two objects. unchanged() -> set Returns a python set() of keys whose values remain the same between the two objects. Note: The keys returned by these methods correspond to the keys found in the dictionary representation of the NmapObjects (obtained via get_dict()). ``` -------------------------------- ### Comparing Nmap Objects with libnmap.diff Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/diff.rst Demonstrates how to use the NmapDiff object to compare two Nmap reports and find changed items. It shows a detailed, albeit verbose, method of iterating through nested objects to pinpoint attribute differences in services. ```python from libnmap.parser import NmapParser rep1 = NmapParser.parse_fromfile('libnmap/test/files/1_hosts.xml') rep2 = NmapParser.parse_fromfile('libnmap/test/files/1_hosts_diff.xml') rep1_items_changed = rep1.diff(rep2).changed() changed_host_id = rep1_items_changed.pop().split('::')[1] changed_host1 = rep1.get_host_byid(changed_host_id) changed_host2 = rep2.get_host_byid(changed_host_id) host1_items_changed = changed_host1.diff(changed_host2).changed() changed_service_id = host1_items_changed.pop().split('::')[1] changed_service1 = changed_host1.get_service_byid(changed_service_id) changed_service2 = changed_host2.get_service_byid(changed_service_id) service1_items_changed = changed_service1.diff(changed_service2).changed() for diff_attr in service1_items_changed: print("diff({0}, {1}) [{2}:{3}] [{4}:{5}]".format(changed_service1.id, changed_service2.id, diff_attr, getattr(changed_service1, diff_attr), diff_attr, getattr(changed_service2, diff_attr))) ``` -------------------------------- ### libnmap Object Definitions Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/index.rst Details the object definitions within the 'objects' module of libnmap, which represent various nmap scan entities. ```python Objects: - report: NmapReport class. - host: NmapHost class. - service: NmapService class. - os: NmapOSFingerprint, NmapOSMatch, NmapOSClass classes. - cpe: CPE class. ``` -------------------------------- ### Nmap Object Structure and Relationships Source: https://github.com/savon-noir/python-libnmap/blob/master/docs/objects.rst This documentation describes the hierarchical structure of Nmap objects within the libnmap library. It details how NmapReport contains NmapHost objects, and how NmapHost objects contain NmapService objects, along with their respective attributes. ```APIDOC NmapReport: - Scan header data (start time, nmap command, nmap version, ...) - List of NmapHosts (0 to X scanned hosts) - Scan footer data (end time, summary, ...) NmapHost: - Host header data (state, hostnames, ip, ...) - List of NmapService (0 to X scanned services) - Host footer data (os version, fingerprint, uptime, ...) NmapService: - Scan results for this service: - Service state, service name - Optional: service banner - Optional: NSE scripts data Common Methods: - diff(): Compares two objects of the same type. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.