Skip to content

Commit

Permalink
Bugfixes and some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
svkirillov committed Apr 4, 2020
1 parent 1d21e23 commit ecce702
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
29 changes: 17 additions & 12 deletions grinder/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"],
)
Expand Down
6 changes: 3 additions & 3 deletions grinder/defaultvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions queries/masscan_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit ecce702

Please sign in to comment.