Exemplo n.º 1
0
 def target_ip(self):
     print(f"[*] Loaded single target: {self.target_hosts}")
     FileHelper.check_directory(output_directory=self.snmp_directory)
     jobs = []
     p = multiprocessing.Process(target=SnmpWalk.snmp_scans)
     jobs.append(p)
     p.start()
Exemplo n.º 2
0
    def snmp_walk(self):
        FileHelper.check_directory(output_directory=self.output_directory)

        if (self.valid_ip(self.target_hosts)):
            self.target_ip()
        else:
            self.target_file()
Exemplo n.º 3
0
 def target_ip(self):
     print(f"[*] Loaded single target: {self.target_hosts}")
     target_hosts = self.target_hosts.strip()
     FileHelper.create_dir_structure(target_hosts, self.output_directory)
     FileHelper.check_directory(output_directory=self.nmap_directory)
     jobs = []
     p = multiprocessing.Process(target=self.nmap_scan)
     jobs.append(p)
     p.start()
Exemplo n.º 4
0
 def test_check_directory(self):
     res = FileHelper.check_directory(output_directory=self.OUTPUT_DIR)
     self.assertIsNotNone(res)
     self.assertTrue(os.path.exists(res))
     self.assertTrue(os.path.isdir(res))
     self.assertFalse(os.path.exists(self.INVALID_DIR))
     res2 = FileHelper.check_directory(output_directory=self.INVALID_DIR)
     self.assertTrue(os.path.exists(res2))
     self.assertTrue(os.path.isdir(res2))
     os.rmdir(res2)
Exemplo n.º 5
0
    def ping_sweeper(self):
        FileHelper.check_directory(output_directory=self.output_directory)
        print("[+] Performing ping sweep over %s" % self.target_hosts)

        self.call_nmap_sweep()
        self.parse_nmap_output_for_live_hosts()
        self.write_live_hosts_list_to_file()

        for ip_address in self.live_hosts:
            print("   [>] Discovered host: %s" % (ip_address))

        print("[*] Found %s live hosts" % (len(self.live_hosts)))
        print("[*] Created target list %s" % (self.output_file))
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
    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()
Exemplo n.º 9
0
    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()