From ecce70213c03f8bb4c90a18468a8a7ef51e310f8 Mon Sep 17 00:00:00 2001 From: Simon Kirillov Date: Sat, 4 Apr 2020 21:45:51 +0700 Subject: [PATCH] Bugfixes and some improvements --- grinder/core.py | 29 +++++++++++++++++------------ grinder/defaultvalues.py | 6 +++--- queries/masscan_example.json | 4 ++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/grinder/core.py b/grinder/core.py index ffc60bc..7e79f6c 100644 --- a/grinder/core.py +++ b/grinder/core.py @@ -859,7 +859,7 @@ def __parse_current_host_censys_results( ) @exception_handler(expected_exception=GrinderCoreHostMasscanResultsError) - def __parse_masscan_results(self, hosts: dict, product_info: dict) -> None: + def __parse_masscan_results(self, hosts: dict, query: str, product_info: dict) -> None: """ Parse raw results from Masscan. Results were received from MasscanConnector module. @@ -869,11 +869,11 @@ def __parse_masscan_results(self, hosts: dict, product_info: dict) -> None: :return: None """ for host in hosts.keys(): - ports = ",".join([str(p) for p in hosts.get(host).get("tcp").keys()]) + ports = ",".join([str(p) for p in hosts.get(host, {}).get("tcp", {}).keys()]) host_info = HostInfo( product=product_info.get("product", "Unknown product"), vendor=product_info.get("vendor", "Unknown vendor"), - query="", + query=query, port=ports, proto="", ip=host, @@ -1157,22 +1157,27 @@ def __process_current_product_queries(self, product_info: dict) -> None: for query_index, query_info in enumerate( product_info.get("masscan_settings") or [] ): + if not query_info.get("hosts"): + print("Hosts field is empty, skip this search") + continue + + query_info["hosts"] = str(ip_network(query_info.get("hosts"), False)) + hosts = query_info.get("hosts") - ports = query_info.get("ports") - rate = query_info.get("rate") + ports = query_info.get("ports", DefaultMasscanScanValues.PORTS) + rate = query_info.get("rate", DefaultMasscanScanValues.RATE) + cprint( f"{query_index} / {len_of_masscan_settings} :: " - f"Current Masscan scan is: {hosts or 'Empty query field'}", + f"Current Masscan scan is: {hosts}", "blue", attrs=["bold"], ) - if not hosts: - print("Hosts field is empty, skip this search") - continue + masscan_raw_results = self.masscan_scan( - hosts, ports, arguments=f"--rate {rate}" + hosts, ports, rate=rate ) - self.__parse_masscan_results(masscan_raw_results, product_info) + self.__parse_masscan_results(masscan_raw_results, hosts, product_info) @exception_handler(expected_exception=GrinderCoreTlsScanner) def tls_scan(self, scanner_path: str) -> None: @@ -1314,7 +1319,7 @@ def masscan_scan( """ cprint("Start Masscan scanning", "blue", attrs=["bold"]) cprint( - f'Masscan scan arguments: {arguments}, rate "{str(rate)}", hosts: "{str(hosts)}", ports: "{str(ports)}"', + f'Masscan scan arguments: {arguments or None}, rate "{str(rate)}", hosts: "{str(hosts)}", ports: "{str(ports)}"', "blue", attrs=["bold"], ) diff --git a/grinder/defaultvalues.py b/grinder/defaultvalues.py index 5a91ef9..a54c0a0 100644 --- a/grinder/defaultvalues.py +++ b/grinder/defaultvalues.py @@ -116,10 +116,10 @@ class DefaultMasscanScanValues: Default values for Masscan scan itself """ - PORTS = None + PORTS = "1-1024" TOP_PORTS = None - RATE = 5000 - ARGUMENTS = None + RATE = 1000 + ARGUMENTS = "" SUDO = True diff --git a/queries/masscan_example.json b/queries/masscan_example.json index 8e6f71b..51d5d65 100644 --- a/queries/masscan_example.json +++ b/queries/masscan_example.json @@ -6,9 +6,9 @@ "censys_queries": [], "masscan_settings": [ { - "hosts": "87.250.250.96/28", + "hosts": "87.250.250.96/27", "ports": "1-1024", - "rate": "10000" + "rate": "1000" } ], "scripts": {