def test_write_recommendations(self): FileHelper.write_recommendations(results=self.SAMPLE_NMAP, ip_address=self.HOST, outputdir=self.OUTPUT_DIR) res_dir = f'{self.OUTPUT_DIR}/{self.HOST}' self.assertTrue(os.path.exists(f'{res_dir}_findings.txt')) os.remove(f'{res_dir}_findings.txt')
def nmap_scan(self): print(f"[+] Starting quick nmap scan for {self.target_hosts}") flags = FileHelper.get_config_options('nmap', 'quickscan') QUICKSCAN = f"nmap {flags} {self.target_hosts} -oA '{self.nmap_directory}.quick'" quickresults = run_scan(QUICKSCAN) FileHelper.write_recommendations(quickresults, self.target_hosts, self.output_directory) print(f"[*] TCP quick scans completed for {self.target_hosts}") if (self.quick): return if self.dns_server: print( f"[+] Starting detailed TCP{('' if self.no_udp_service_scan is True else '/UDP')} nmap scans for {self.target_hosts} using DNS Server {self.dns_server}" ) print("[+] Using DNS server %s" % (self.dns_server)) flags = FileHelper.get_config_options("nmap", "tcpscan") TCPSCAN = f"nmap {flags} --dns-servers {self.dns_server} -oN '{self.nmap_directory}.nmap' -oX '{self.nmap_directory}/scan_import.xml' {self.target_hosts}" flags = FileHelper.get_config_options("nmap", "dnsudpscan") UDPSCAN = f"nmap {flags} --dns-servers {self.dns_server} -oN '{self.nmap_directory}U.nmap' -oX '{self.nmap_directory}/UDP_scan_import.xml' {self.target_hosts}" else: print( f"[+] Starting detailed TCP{('' if self.no_udp_service_scan is True else '/UDP')} nmap scans for {self.target_hosts}" ) flags = FileHelper.get_config_options("nmap", "tcpscan") TCPSCAN = f"nmap {flags} -oN '{self.nmap_directory}.nmap' -oX '{self.nmap_directory}/scan_import.xml' {self.target_hosts}" flags = FileHelper.get_config_options("nmap", "udpscan") UDPSCAN = f"nmap {flags} {self.target_hosts} -oA '{self.nmap_directory}-udp'" if self.no_udp_service_scan: udpresult = "" else: udpresult = run_scan(UDPSCAN) tcpresults = run_scan(TCPSCAN) FileHelper.write_recommendations(tcpresults + udpresult, self.target_hosts, self.output_directory) print( f"[*] TCP{('' if self.no_udp_service_scan is True else '/UDP')} scans completed for {self.target_hosts}" )