Now suppressing exceptions in cloud info collection as well

This commit is contained in:
Shay Nehmad 2019-10-13 10:55:55 +03:00
parent 74dbb053a6
commit 177e1ea990
1 changed files with 32 additions and 22 deletions

View File

@ -113,7 +113,7 @@ class InfoCollector(object):
:return: None. Updates class information :return: None. Updates class information
""" """
LOG.debug("Reading subnets") LOG.debug("Reading subnets")
self.info['network_info'] =\ self.info['network_info'] = \
{ {
'networks': get_host_subnets(), 'networks': get_host_subnets(),
'netstat': NetstatCollector.get_netstat_info() 'netstat': NetstatCollector.get_netstat_info()
@ -122,28 +122,38 @@ class InfoCollector(object):
def get_azure_info(self): def get_azure_info(self):
""" """
Adds credentials possibly stolen from an Azure VM instance (if we're on one) Adds credentials possibly stolen from an Azure VM instance (if we're on one)
Updates the credentials structure, creating it if neccesary (compat with mimikatz) Updates the credentials structure, creating it if necessary (compat with mimikatz)
:return: None. Updates class information :return: None. Updates class information
""" """
from infection_monkey.config import WormConfiguration # noinspection PyBroadException
if not WormConfiguration.extract_azure_creds: try:
return from infection_monkey.config import WormConfiguration
LOG.debug("Harvesting creds if on an Azure machine") if not WormConfiguration.extract_azure_creds:
azure_collector = AzureCollector() return
if 'credentials' not in self.info: LOG.debug("Harvesting creds if on an Azure machine")
self.info["credentials"] = {} azure_collector = AzureCollector()
azure_creds = azure_collector.extract_stored_credentials() if 'credentials' not in self.info:
for cred in azure_creds: self.info["credentials"] = {}
username = cred[0] azure_creds = azure_collector.extract_stored_credentials()
password = cred[1] for cred in azure_creds:
if username not in self.info["credentials"]: username = cred[0]
self.info["credentials"][username] = {} password = cred[1]
# we might be losing passwords in case of multiple reset attempts on same username if username not in self.info["credentials"]:
# or in case another collector already filled in a password for this user self.info["credentials"][username] = {}
self.info["credentials"][username]['password'] = password # we might be losing passwords in case of multiple reset attempts on same username
if len(azure_creds) != 0: # or in case another collector already filled in a password for this user
self.info["Azure"] = {} self.info["credentials"][username]['password'] = password
self.info["Azure"]['usernames'] = [cred[0] for cred in azure_creds] if len(azure_creds) != 0:
self.info["Azure"] = {}
self.info["Azure"]['usernames'] = [cred[0] for cred in azure_creds]
except Exception:
# If we failed to collect azure info, no reason to fail all the collection. Log and continue.
LOG.error("Failed collecting Azure info.", exc_info=True)
def get_aws_info(self): def get_aws_info(self):
self.info['aws'] = AwsCollector().get_aws_info() # noinspection PyBroadException
try:
self.info['aws'] = AwsCollector().get_aws_info()
except Exception:
# If we failed to collect aws info, no reason to fail all the collection. Log and continue.
LOG.error("Failed collecting AWS info.", exc_info=True)