diff --git a/CHANGELOG/current/fix_xml_nmap.md b/CHANGELOG/current/fix_xml_nmap.md new file mode 100644 index 00000000..bba79048 --- /dev/null +++ b/CHANGELOG/current/fix_xml_nmap.md @@ -0,0 +1 @@ +* Fix broken xml on nmap plugin diff --git a/faraday_plugins/plugins/repo/nmap/plugin.py b/faraday_plugins/plugins/repo/nmap/plugin.py index cfc0cd41..0c493b56 100644 --- a/faraday_plugins/plugins/repo/nmap/plugin.py +++ b/faraday_plugins/plugins/repo/nmap/plugin.py @@ -5,10 +5,9 @@ """ -from faraday_plugins.plugins.plugin import PluginXMLFormat import re import os - +from io import BytesIO try: import xml.etree.cElementTree as ET @@ -17,12 +16,15 @@ except ImportError: import xml.etree.ElementTree as ET ETREE_VERSION = ET.VERSION +from lxml import etree +from lxml.etree import XMLParser +from faraday_plugins.plugins.plugin import PluginXMLFormat ETREE_VERSION = [int(i) for i in ETREE_VERSION.split(".")] - current_path = os.path.abspath(os.getcwd()) + class NmapXmlParser: """ The objective of this class is to parse an xml file generated by @@ -55,7 +57,8 @@ def parse_xml(self, xml_output): """ try: - return ET.fromstring(xml_output) + magical_parser = XMLParser(recover=True) + return etree.parse(BytesIO(xml_output), magical_parser) except SyntaxError as err: #logger.error("SyntaxError: %s." % (err)) return None