diff --git a/jfscan/__main__.py b/jfscan/__main__.py index fc48336..3dc7d3e 100755 --- a/jfscan/__main__.py +++ b/jfscan/__main__.py @@ -154,16 +154,20 @@ def main(): # Report results from masscan logger.info("dumping results") + results = [] + result_ips, result_domains = res.get_scan_results() + if arguments.only_domains is True: - results = res.get_scan_results(ips=False, domains=True) + results = result_domains elif arguments.only_ips is True: - results = res.get_scan_results(ips=True, domains=False) + results = result_ips else: - results = res.get_scan_results(ips=True, domains=True) + results = result_ips + result_domains for line in results: print(line) - + + # Save results to file if arguments.output is not None: logger.info("saving results to %s", arguments.output) utils.save_results(results, arguments.output) diff --git a/jfscan/core/resources.py b/jfscan/core/resources.py index 8bdb3b8..8a32656 100644 --- a/jfscan/core/resources.py +++ b/jfscan/core/resources.py @@ -194,7 +194,7 @@ def get_cidrs(self): return cidrs - def get_scan_results(self, ips=False, domains=False): + def get_scan_results(self): """Generates scan results in format target:port Args: @@ -206,25 +206,32 @@ def get_scan_results(self, ips=False, domains=False): """ conn = self.conn cur = conn.cursor() - results = [] - if ips is True: - rows = cur.execute( - "SELECT DISTINCT ip, port FROM scan_results" - ).fetchall() - for row in rows: - results.append(f"{row[0]}:{row[1]}") + ips = [] + domains = [] - if domains is True: - rows = cur.execute( - "SELECT DISTINCT domain, ip, port FROM scan_results\ - JOIN domains_to_scan ON domain = domains_to_scan.domain WHERE domains_to_scan.ip_rowid = (SELECT rowid FROM ips_to_scan WHERE ip = scan_results.ip) ORDER BY domain" - ).fetchall() + rows = cur.execute( + "SELECT DISTINCT ip, port FROM scan_results" + ).fetchall() + for row in rows: + ips.append(f"{row[0]}:{row[1]}") + + + rows = cur.execute( + "SELECT DISTINCT domain, ip, port FROM scan_results\ + JOIN domains_to_scan ON domain = domains_to_scan.domain WHERE domains_to_scan.ip_rowid = (SELECT rowid FROM ips_to_scan WHERE ip = scan_results.ip) ORDER BY domain" + ).fetchall() + + for row in rows: + domains.append(f"{row[0]}:{row[2]}") + + ips_unique = list(set(ips)) + domains_unique = list(set(domains)) - for row in rows: - results.append(f"{row[0]}:{row[2]}") + ips_unique.sort() + domains_unique.sort() - return list(set(results)) + return ips_unique, domains_unique def count_ips(self): """Get number of all IPs to scan, including IPs in network ranges diff --git a/jfscan/core/utils.py b/jfscan/core/utils.py index 09b7cdc..7687996 100644 --- a/jfscan/core/utils.py +++ b/jfscan/core/utils.py @@ -225,6 +225,7 @@ def load_targets(self, res, targets_file=None, target=None): target_before = _target + # Oh, just remove it already... @staticmethod def file_is_empty(file): try: diff --git a/jfscan/core/validator.py b/jfscan/core/validator.py index f26fb0e..78e0f0f 100644 --- a/jfscan/core/validator.py +++ b/jfscan/core/validator.py @@ -48,6 +48,6 @@ def is_url(url): return False @staticmethod - def is_domain(domain): + def is_domain(host): from validators import domain - return domain(domain) \ No newline at end of file + return domain(host) \ No newline at end of file