forked from p15670423/monkey
Renamed cloud providers enum to camel case
This commit is contained in:
parent
8cd3834fe4
commit
eaf9b6a8d1
|
@ -1,7 +1,7 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
class PROVIDERS(Enum):
|
class CloudProviders(Enum):
|
||||||
AWS = 'aws'
|
AWS = 'aws'
|
||||||
AZURE = 'azure'
|
AZURE = 'azure'
|
||||||
GCP = 'gcp'
|
GCP = 'gcp'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from common.cloud.aws.aws_instance import AwsInstance
|
from common.cloud.aws.aws_instance import AwsInstance
|
||||||
from common.cloud.scoutsuite_consts import PROVIDERS
|
from common.cloud.scoutsuite_consts import CloudProviders
|
||||||
from common.common_consts.system_info_collectors_names import AWS_COLLECTOR
|
from common.common_consts.system_info_collectors_names import AWS_COLLECTOR
|
||||||
from common.network.network_utils import is_running_on_island
|
from common.network.network_utils import is_running_on_island
|
||||||
from infection_monkey.system_info.collectors.scoutsuite_collector.scoutsuite_collector import scan_cloud_security
|
from infection_monkey.system_info.collectors.scoutsuite_collector.scoutsuite_collector import scan_cloud_security
|
||||||
|
@ -21,7 +21,7 @@ class AwsCollector(SystemInfoCollector):
|
||||||
logger.info("Collecting AWS info")
|
logger.info("Collecting AWS info")
|
||||||
if is_running_on_island():
|
if is_running_on_island():
|
||||||
logger.info("Attempting to scan AWS security with ScoutSuite.")
|
logger.info("Attempting to scan AWS security with ScoutSuite.")
|
||||||
scan_cloud_security(cloud_type=PROVIDERS.AWS)
|
scan_cloud_security(cloud_type=CloudProviders.AWS)
|
||||||
else:
|
else:
|
||||||
logger.info("Didn't scan AWS security with ScoutSuite, because not on island.")
|
logger.info("Didn't scan AWS security with ScoutSuite, because not on island.")
|
||||||
aws = AwsInstance()
|
aws = AwsInstance()
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import infection_monkey.system_info.collectors.scoutsuite_collector.scoutsuite_api as scoutsuite_api
|
import infection_monkey.system_info.collectors.scoutsuite_collector.scoutsuite_api as scoutsuite_api
|
||||||
from common.cloud.scoutsuite_consts import PROVIDERS
|
from common.cloud.scoutsuite_consts import CloudProviders
|
||||||
from infection_monkey.config import WormConfiguration
|
from infection_monkey.config import WormConfiguration
|
||||||
from infection_monkey.telemetry.scoutsuite_telem import ScoutSuiteTelem
|
from infection_monkey.telemetry.scoutsuite_telem import ScoutSuiteTelem
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def scan_cloud_security(cloud_type: PROVIDERS):
|
def scan_cloud_security(cloud_type: CloudProviders):
|
||||||
try:
|
try:
|
||||||
results = run_scoutsuite(cloud_type.value)
|
results = run_scoutsuite(cloud_type.value)
|
||||||
if isinstance(results, dict) and 'error' in results and results['error']:
|
if isinstance(results, dict) and 'error' in results and results['error']:
|
||||||
|
|
|
@ -24,7 +24,7 @@ class BaseTelem(object, metaclass=abc.ABCMeta):
|
||||||
"""
|
"""
|
||||||
data = self.get_data()
|
data = self.get_data()
|
||||||
serialized_data = json.dumps(data, cls=self.json_encoder)
|
serialized_data = json.dumps(data, cls=self.json_encoder)
|
||||||
self.log_telem_sending(serialized_data, log_data)
|
self._log_telem_sending(serialized_data, log_data)
|
||||||
ControlClient.send_telemetry(self.telem_category, serialized_data)
|
ControlClient.send_telemetry(self.telem_category, serialized_data)
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
@ -38,10 +38,10 @@ class BaseTelem(object, metaclass=abc.ABCMeta):
|
||||||
def json_encoder(self):
|
def json_encoder(self):
|
||||||
return json.JSONEncoder
|
return json.JSONEncoder
|
||||||
|
|
||||||
def log_telem_sending(self, serialized_data: str, log_data=True):
|
def _log_telem_sending(self, serialized_data: str, log_data=True):
|
||||||
logger.debug(f"Sending {self.telem_category} telemetry.")
|
logger.debug(f"Sending {self.telem_category} telemetry.")
|
||||||
if log_data:
|
if log_data:
|
||||||
logger.debug(f"Telemetry contents: {BaseTelem.truncate_data(serialized_data)}")
|
logger.debug(f"Telemetry contents: {BaseTelem._truncate_data(serialized_data)}")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
@ -52,7 +52,7 @@ class BaseTelem(object, metaclass=abc.ABCMeta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def truncate_data(data: str):
|
def _truncate_data(data: str):
|
||||||
if len(data) <= LOGGED_DATA_LENGTH:
|
if len(data) <= LOGGED_DATA_LENGTH:
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,7 +3,7 @@ import json
|
||||||
import flask_restful
|
import flask_restful
|
||||||
from flask import request
|
from flask import request
|
||||||
|
|
||||||
from common.cloud.scoutsuite_consts import PROVIDERS
|
from common.cloud.scoutsuite_consts import CloudProviders
|
||||||
from common.utils.exceptions import InvalidAWSKeys
|
from common.utils.exceptions import InvalidAWSKeys
|
||||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||||
from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_auth_service import (is_cloud_authentication_setup,
|
from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_auth_service import (is_cloud_authentication_setup,
|
||||||
|
@ -13,18 +13,18 @@ from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_auth_service imp
|
||||||
class ScoutSuiteAuth(flask_restful.Resource):
|
class ScoutSuiteAuth(flask_restful.Resource):
|
||||||
|
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def get(self, provider: PROVIDERS):
|
def get(self, provider: CloudProviders):
|
||||||
if provider == PROVIDERS.AWS.value:
|
if provider == CloudProviders.AWS.value:
|
||||||
is_setup, message = is_cloud_authentication_setup(provider)
|
is_setup, message = is_cloud_authentication_setup(provider)
|
||||||
return {'is_setup': is_setup, 'message': message}
|
return {'is_setup': is_setup, 'message': message}
|
||||||
else:
|
else:
|
||||||
return {'is_setup': False, 'message': ''}
|
return {'is_setup': False, 'message': ''}
|
||||||
|
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def post(self, provider: PROVIDERS):
|
def post(self, provider: CloudProviders):
|
||||||
key_info = json.loads(request.data)
|
key_info = json.loads(request.data)
|
||||||
error_msg = ''
|
error_msg = ''
|
||||||
if provider == PROVIDERS.AWS.value:
|
if provider == CloudProviders.AWS.value:
|
||||||
try:
|
try:
|
||||||
set_aws_keys(access_key_id=key_info['accessKeyId'],
|
set_aws_keys(access_key_id=key_info['accessKeyId'],
|
||||||
secret_access_key=key_info['secretAccessKey'],
|
secret_access_key=key_info['secretAccessKey'],
|
||||||
|
|
|
@ -3,7 +3,7 @@ import sys
|
||||||
from pathlib import PurePath
|
from pathlib import PurePath
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
from common.cloud.scoutsuite_consts import PROVIDERS
|
from common.cloud.scoutsuite_consts import CloudProviders
|
||||||
from common.utils.exceptions import InvalidAWSKeys
|
from common.utils.exceptions import InvalidAWSKeys
|
||||||
from monkey_island.cc.encryptor import encryptor
|
from monkey_island.cc.encryptor import encryptor
|
||||||
from monkey_island.cc.services.config import ConfigService
|
from monkey_island.cc.services.config import ConfigService
|
||||||
|
@ -20,8 +20,8 @@ def _add_scoutsuite_to_python_path():
|
||||||
_add_scoutsuite_to_python_path()
|
_add_scoutsuite_to_python_path()
|
||||||
|
|
||||||
|
|
||||||
def is_cloud_authentication_setup(provider: PROVIDERS) -> Tuple[bool, str]:
|
def is_cloud_authentication_setup(provider: CloudProviders) -> Tuple[bool, str]:
|
||||||
if provider == PROVIDERS.AWS.value:
|
if provider == CloudProviders.AWS.value:
|
||||||
if is_aws_keys_setup():
|
if is_aws_keys_setup():
|
||||||
return True, "AWS keys already setup. Run Monkey on Island to start the scan."
|
return True, "AWS keys already setup. Run Monkey on Island to start the scan."
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,7 @@ class ZeroTrustService:
|
||||||
if pillar in test_info[zero_trust_consts.PILLARS_KEY]:
|
if pillar in test_info[zero_trust_consts.PILLARS_KEY]:
|
||||||
pillar_grade[finding.status] += 1
|
pillar_grade[finding.status] += 1
|
||||||
|
|
||||||
pillar_grade[zero_trust_consts.STATUS_UNEXECUTED] = sum(1 for condition in
|
pillar_grade[zero_trust_consts.STATUS_UNEXECUTED] = list(test_unexecuted.values()).count(True)
|
||||||
list(test_unexecuted.values()) if condition)
|
|
||||||
|
|
||||||
return pillar_grade
|
return pillar_grade
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue