Exemple #1
0
 def _test_bool_env_method(self, method_name: str, env: Environment, config: Dict, expected_result: bool):
     env._config = EnvironmentConfig.get_from_json(json.dumps(config))
     method = getattr(env, method_name)
     if expected_result:
         self.assertTrue(method())
     else:
         self.assertFalse(method())
Exemple #2
0
def initialize_from_file(file_path):
    try:
        config = EnvironmentConfig(file_path)

        __env_type = config.server_config
        set_env(__env_type, config)
        # noinspection PyUnresolvedReferences
        logger.info("Monkey's env is: {0}".format(env.__class__.__name__))
    except Exception:
        logger.error("Failed initializing environment", exc_info=True)
        raise
Exemple #3
0
    def _prepare_finding(issue, region):
        findings_dict = {
            'island_cross_segment':
            AWSExporter._handle_island_cross_segment_issue,
            'ssh': AWSExporter._handle_ssh_issue,
            'shellshock': AWSExporter._handle_shellshock_issue,
            'tunnel': AWSExporter._handle_tunnel_issue,
            'elastic': AWSExporter._handle_elastic_issue,
            'smb_password': AWSExporter._handle_smb_password_issue,
            'smb_pth': AWSExporter._handle_smb_pth_issue,
            'sambacry': AWSExporter._handle_sambacry_issue,
            'shared_passwords': AWSExporter._handle_shared_passwords_issue,
            'wmi_password': AWSExporter._handle_wmi_password_issue,
            'wmi_pth': AWSExporter._handle_wmi_pth_issue,
            'ssh_key': AWSExporter._handle_ssh_key_issue,
            'shared_passwords_domain':
            AWSExporter._handle_shared_passwords_domain_issue,
            'shared_admins_domain':
            AWSExporter._handle_shared_admins_domain_issue,
            'strong_users_on_crit':
            AWSExporter._handle_strong_users_on_crit_issue,
            'struts2': AWSExporter._handle_struts2_issue,
            'weblogic': AWSExporter._handle_weblogic_issue,
            'hadoop': AWSExporter._handle_hadoop_issue,
            # azure and conficker are not relevant issues for an AWS env
        }

        configured_product_arn = EnvironmentConfig.get_from_file().aws.get(
            'sec_hub_product_arn', '')
        product_arn = 'arn:aws:securityhub:{region}:{arn}'.format(
            region=region, arn=configured_product_arn)
        instance_arn = 'arn:aws:ec2:' + str(region) + ':instance:{instance_id}'
        # Not suppressing error here on purpose.
        account_id = AwsInstance().get_account_id()
        logger.debug("aws account id acquired: {}".format(account_id))

        finding = {
            "SchemaVersion": "2018-10-08",
            "Id": uuid.uuid4().hex,
            "ProductArn": product_arn,
            "GeneratorId": issue['type'],
            "AwsAccountId": account_id,
            "RecordState": "ACTIVE",
            "Types": ["Software and Configuration Checks/Vulnerabilities/CVE"],
            "CreatedAt": datetime.now().isoformat() + 'Z',
            "UpdatedAt": datetime.now().isoformat() + 'Z',
        }
        return AWSExporter.merge_two_dicts(
            finding, findings_dict[issue['type']](issue, instance_arn))
Exemple #4
0
}

env = None


def set_env(env_type: str, env_config: EnvironmentConfig):
    global env
    if env_type in ENV_DICT:
        env = ENV_DICT[env_type](env_config)


def set_to_standard():
    global env
    if env:
        env_config = env.get_config()
        env_config.server_config = 'standard'
        set_env('standard', env_config)
        env.save_config()
        user_store.UserStore.set_users(env.get_auth_users())


try:
    config = EnvironmentConfig.get_from_file()
    __env_type = config.server_config
    set_env(__env_type, config)
    # noinspection PyUnresolvedReferences
    logger.info('Monkey\'s env is: {0}'.format(env.__class__.__name__))
except Exception:
    logger.error('Failed initializing environment', exc_info=True)
    raise
Exemple #5
0
 def __init__(self):
     config = EnvironmentConfig('test', 'test', UserCreds('test_user', 'test_secret'))
     super().__init__(config)
Exemple #6
0
 def __init__(self):
     config = EnvironmentConfig('test', 'test', UserCreds())
     super().__init__(config)