|
34 | 34 | from nmap3.exceptions import NmapNotInstalledError, NmapXMLParserError, NmapExecutionError |
35 | 35 |
|
36 | 36 | import xml |
| 37 | +import re |
37 | 38 |
|
38 | 39 | __author__ = 'Wangolo Joel (inquiry@nmapper.com)' |
39 | 40 | __version__ = '1.5.5' |
@@ -122,10 +123,14 @@ def scan_command(self, target, arg, args=None, timeout=None): |
122 | 123 | if (args): |
123 | 124 | scancommand += " {0}".format(args) |
124 | 125 |
|
| 126 | + |
125 | 127 | scan_shlex = shlex.split(scancommand) |
126 | 128 | output = self.run_command(scan_shlex, timeout=timeout) |
| 129 | + file_name=re.search(r'(\-oX|-oN-|oG)\s+[a-zA-Z-_0-9]{1,100}\.[a-zA-Z]+',scancommand) |
| 130 | + if file_name: |
| 131 | + file_name=scancommand[file_name.start():file_name.end()].split(" ")[0] |
| 132 | + return self.get_success_xml_et(file_name) |
127 | 133 | xml_root = self.get_xml_et(output) |
128 | | - |
129 | 134 | return xml_root |
130 | 135 |
|
131 | 136 | def scan_top_ports(self, target, default=10, args=None, timeout=None): |
@@ -279,6 +284,16 @@ def get_xml_et(self, command_output): |
279 | 284 | except ParseError: |
280 | 285 | raise NmapXMLParserError() |
281 | 286 |
|
| 287 | + |
| 288 | + def get_success_xml_et(self,file_name): |
| 289 | + root = ET.Element("root") |
| 290 | + success = ET.SubElement(root, "success") |
| 291 | + success.text = "Nmap scan completed successfully." |
| 292 | + file_path = ET.SubElement(root, "file_path") |
| 293 | + file_path.text = "{}".format(file_name) |
| 294 | + ET.ElementTree(root) |
| 295 | + return root |
| 296 | + |
282 | 297 | class NmapScanTechniques(Nmap): |
283 | 298 | """ |
284 | 299 | Extends Nmap to include nmap commands |
|
0 commit comments