perform the nmap scan
(host, nmap_path, ports=None, arguments=None)
| 116 | |
| 117 | |
| 118 | def do_scan(host, nmap_path, ports=None, arguments=None): |
| 119 | """ |
| 120 | perform the nmap scan |
| 121 | """ |
| 122 | if arguments is None: |
| 123 | arguments = "-sV" |
| 124 | launch_arguments = [ |
| 125 | nmap_path, '-oX', '-', host, |
| 126 | '-p ' + ports if ports is not None else "", |
| 127 | ] + arguments |
| 128 | to_launch = [] |
| 129 | for item in launch_arguments: |
| 130 | if not item == "": |
| 131 | to_launch.append(item) |
| 132 | lib.output.info("launching nmap scan against {} ({})".format(host, " ".join(to_launch))) |
| 133 | process = subprocess.Popen( |
| 134 | launch_arguments, bufsize=10000, stdin=subprocess.PIPE, |
| 135 | stdout=subprocess.PIPE, stderr=subprocess.PIPE |
| 136 | ) |
| 137 | output, error = process.communicate() |
| 138 | output_data = bytes.decode(output) |
| 139 | nmap_error = bytes.decode(error) |
| 140 | nmap_error_tracestack = [] |
| 141 | nmap_warn_tracestack = [] |
| 142 | if len(nmap_error) > 0: |
| 143 | for line in nmap_error.split(os.linesep): |
| 144 | if len(line) != 0: |
| 145 | if lib.settings.NMAP_ERROR_REGEX_WARNING.search(line) is not None: |
| 146 | nmap_warn_tracestack.append(line + os.linesep) |
| 147 | else: |
| 148 | nmap_error_tracestack.append(line + os.linesep) |
| 149 | write_data(host, output_data, is_xml=True) |
| 150 | return output_data, "".join(nmap_warn_tracestack), "".join(nmap_error_tracestack) |
| 151 | |
| 152 | |
| 153 | def parse_xml_output(output, warnings, error): |
nothing calls this directly
no test coverage detected