From 1021aca65d14f3ce3d63f9df20341441f361b384 Mon Sep 17 00:00:00 2001 From: Liz Rice Date: Wed, 20 Feb 2019 17:16:32 +0000 Subject: [PATCH 1/3] Trigger HostScanEvent to scan remote or CIDR addresses --- src/modules/discovery/hosts.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/discovery/hosts.py b/src/modules/discovery/hosts.py index 4bef152..3f3988e 100644 --- a/src/modules/discovery/hosts.py +++ b/src/modules/discovery/hosts.py @@ -74,18 +74,20 @@ class FromPodHostDiscovery(Hunter): self.event = event def execute(self): - # Discover master API server from in-pod environment variable. - + # Discover cluster subnets, we'll scan all these hosts if self.is_azure_pod(): - subnets, cloud =self.azure_metadata_discovery() + subnets, cloud = self.azure_metadata_discovery() else: subnets, cloud = self.traceroute_discovery() - for subnet in subnets: logging.debug("From pod scanning subnet {0}/{1}".format(subnet[0], subnet[1])) for ip in HostDiscoveryHelpers.generate_subnet(ip=subnet[0], sn=subnet[1]): self.publish_event(NewHostEvent(host=ip, cloud=cloud)) + + # There may be other hosts to scan as well + if config.remote or config.cidr: + self.publish_event(HostScanEvent()) def is_azure_pod(self): try: From e2b5f0f5a021f552a20b39a455684d6669dde55c Mon Sep 17 00:00:00 2001 From: Liz Rice Date: Wed, 20 Feb 2019 17:39:33 +0000 Subject: [PATCH 2/3] Remove deprecation warning --- src/core/events/handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/events/handler.py b/src/core/events/handler.py index dd6e6bc..652a257 100644 --- a/src/core/events/handler.py +++ b/src/core/events/handler.py @@ -79,7 +79,7 @@ class EventQueue(Queue, object): try: hook.execute() except Exception as ex: - logging.debug(ex.message) + logging.debug(ex) self.task_done() logging.debug("closing thread...") From 645195e799d03511574c68b3b79793824945424f Mon Sep 17 00:00:00 2001 From: Liz Rice Date: Fri, 22 Feb 2019 15:40:29 +0000 Subject: [PATCH 3/3] Only do pod scan if we didn't specify an address --- src/modules/discovery/hosts.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/modules/discovery/hosts.py b/src/modules/discovery/hosts.py index 3f3988e..3912ba1 100644 --- a/src/modules/discovery/hosts.py +++ b/src/modules/discovery/hosts.py @@ -74,20 +74,21 @@ class FromPodHostDiscovery(Hunter): self.event = event def execute(self): - # Discover cluster subnets, we'll scan all these hosts - if self.is_azure_pod(): - subnets, cloud = self.azure_metadata_discovery() - else: - subnets, cloud = self.traceroute_discovery() - - for subnet in subnets: - logging.debug("From pod scanning subnet {0}/{1}".format(subnet[0], subnet[1])) - for ip in HostDiscoveryHelpers.generate_subnet(ip=subnet[0], sn=subnet[1]): - self.publish_event(NewHostEvent(host=ip, cloud=cloud)) - - # There may be other hosts to scan as well + # Scan any hosts that the user specified if config.remote or config.cidr: self.publish_event(HostScanEvent()) + else: + # Discover cluster subnets, we'll scan all these hosts + if self.is_azure_pod(): + subnets, cloud = self.azure_metadata_discovery() + else: + subnets, cloud = self.traceroute_discovery() + + for subnet in subnets: + logging.debug("From pod scanning subnet {0}/{1}".format(subnet[0], subnet[1])) + for ip in HostDiscoveryHelpers.generate_subnet(ip=subnet[0], sn=subnet[1]): + self.publish_event(NewHostEvent(host=ip, cloud=cloud)) + def is_azure_pod(self): try: @@ -118,7 +119,7 @@ class FromPodHostDiscovery(Hunter): logging.debug("From pod discovered subnet {0}/{1}".format(address, subnet if not config.quick else "24")) subnets.append([address,subnet if not config.quick else "24"]) - self.publish_event(AzureMetadataApi(cidr="{}/{}".format(address, subnet))) + self.publish_event(AzureMetadataApi(cidr="{}/{}".format(address, subnet))) return subnets, "Azure"