def find_dns(self): FileHelper.check_directory(output_directory=self.output_directory) output_file = open(self.output_file, 'w') output_targets = open(self.output_targets, 'w') targets = FileHelper.load_targets(self.target_hosts, self.output_directory, self.quiet) FileHelper.check_file(targets) try: target_file = open(targets, 'r') print("[*] Loaded targets from: %s" % targets) except FileExistsError as err: print("[!] Unable to load: %s" % targets) raise err print("[*] Loaded targets from: %s" % targets) print("[+] Enumerating TCP port 53 over targets to find dns servers") for ip_address in target_file: self.hostcount += 1 ip_address = ip_address.strip() ip_address = ip_address.rstrip() print(" [>] Testing %s for DNS" % ip_address) DNSSCAN = "nmap -n -sV -Pn -vv -p53 %s" % (ip_address) results = run_scan(DNSSCAN) lines = results.split("\n") for line in lines: line = line.strip() line = line.rstrip() if (("53/tcp" in line) and ("open" in line) and ("Discovered" not in line)): print(" [=] Found DNS service running on: %s" % (ip_address)) output_file.write( "[*] Found DNS service running on: %s\n" % (ip_address)) output_file.write(" [>] %s\n" % (line)) output_targets.write("%s\n" % (ip_address)) self.dns_server_list.append(ip_address) self.dnscount += 1 print("[*] Found %s DNS servers within %s hosts" % (str(self.dnscount), str(self.hostcount))) output_file.close() output_targets.close() target_file.close() return '' if len(self.dns_server_list) == 0 else ','.join( self.dns_server_list)
def hostname_scan(self): FileHelper.check_directory(self.output_directory) FileHelper.check_file(self.output_file) f = open(self.output_file, 'w') print("[+] Writing hostnames to: %s" % self.output_file) SWEEP = '' if (os.path.isfile(self.target_hosts)): SWEEP = "nbtscan -q -f %s" % (self.target_hosts) else: SWEEP = "nbtscan -q %s" % (self.target_hosts) results = run_scan(SWEEP) lines = results.split("\n") for line in lines: line = line.strip() line = line.rstrip() # Final line is blank which causes list index issues if we don't # continue past it. if " " not in line: continue while " " in line: line = line.replace(" ", " ") ip_address = line.split(" ")[0] host = line.split(" ")[1] if (self.hostnames > 0): f.write('\n') print(" [>] Discovered hostname: %s (%s)" % (host, ip_address)) f.write("%s - %s" % (host, ip_address)) self.hostnames += 1 print("[*] Found %s hostnames." % (self.hostnames)) print("[*] Created hostname list %s" % (self.output_file)) f.close()
def target_file(self): targets = FileHelper.load_targets(self.target_hosts, self.output_directory, self.quiet) FileHelper.check_file(targets) try: target_file = open(targets, 'r') print(f"[*] Loaded targets from: {targets}") except FileNotFoundError as err: print(f"[!] Unable to load: {targets}") raise err for ip_address in target_file: ip_address = ip_address.strip() snmp_directory = f"{self.output_directory}/{ip_address}/scans/snmp/" FileHelper.check_directory(output_directory=snmp_directory) jobs = [] p = multiprocessing.Process(target=SnmpWalk.snmp_scans) jobs.append(p) p.start() target_file.close()
def target_file(self): targets = FileHelper.load_targets(self.target_hosts, self.output_directory, self.quiet) FileHelper.check_file(targets) try: target_file = open(targets, 'r') print(f"[*] Loaded targets from: {targets}") except FileExistsError as err: print(f"[!] Unable to load: {targets}") raise err for ip_address in target_file: ip_address = ip_address.strip() FileHelper.create_dir_structure(ip_address, self.output_directory) nmap_directory = f"{self.output_directory}/{ip_address}/scans" FileHelper.check_directory(output_directory=nmap_directory) jobs = [] p = multiprocessing.Process(target=self.nmap_scan) jobs.append(p) p.start() target_file.close()
def test_check_file(self): res = FileHelper.check_file(self.OUTPUT_FILE) self.assertIsNotNone(res) self.assertTrue(os.path.exists(res)) self.assertTrue(os.path.isfile(res)) os.remove(self.OUTPUT_FILE)