diff --git a/prowler/providers/aws/services/awslambda/awslambda_service.py b/prowler/providers/aws/services/awslambda/awslambda_service.py index 52c7cb50d3..f9c74dddc6 100644 --- a/prowler/providers/aws/services/awslambda/awslambda_service.py +++ b/prowler/providers/aws/services/awslambda/awslambda_service.py @@ -46,7 +46,9 @@ class Lambda: for function in page["Functions"]: lambda_name = function["FunctionName"] lambda_arn = function["FunctionArn"] - lambda_runtime = function["Runtime"] + lambda_runtime = None + if "Runtime" in function: + lambda_runtime = function["Runtime"] self.functions[lambda_name] = Function( name=lambda_name, arn=lambda_arn, diff --git a/prowler/providers/aws/services/cloudwatch/cloudwatch_service.py b/prowler/providers/aws/services/cloudwatch/cloudwatch_service.py index e6b4f28cf6..6b9df1c6be 100644 --- a/prowler/providers/aws/services/cloudwatch/cloudwatch_service.py +++ b/prowler/providers/aws/services/cloudwatch/cloudwatch_service.py @@ -38,11 +38,14 @@ class CloudWatch: describe_alarms_paginator = regional_client.get_paginator("describe_alarms") for page in describe_alarms_paginator.paginate(): for alarm in page["MetricAlarms"]: + metric_name = None + if "MetricName" in alarm: + metric_name = alarm["MetricName"] self.metric_alarms.append( MetricAlarm( alarm["AlarmArn"], alarm["AlarmName"], - alarm["MetricName"], + metric_name, alarm["Namespace"], regional_client.region, ) diff --git a/prowler/providers/aws/services/ec2/ec2_service.py b/prowler/providers/aws/services/ec2/ec2_service.py index 5b66bcac4c..383a56cd4d 100644 --- a/prowler/providers/aws/services/ec2/ec2_service.py +++ b/prowler/providers/aws/services/ec2/ec2_service.py @@ -67,29 +67,46 @@ class EC2: "PublicDnsName" in instance and "PublicIpAddress" in instance ): - public_dns = instance["PublicDnsName"] - public_ip = instance["PublicIpAddress"] - if "IamInstanceProfile" in instance: - instance_profile = instance["IamInstanceProfile"] + http_tokens = None + http_endpoint = None + public_dns = None + public_ip = None + private_ip = None + instance_profile = None + if "MetadataOptions" in instance: + http_tokens = instance["MetadataOptions"]["HttpTokens"] + http_endpoint = instance["MetadataOptions"][ + "HttpEndpoint" + ] + if ( + "PublicDnsName" in instance + and "PublicIpAddress" in instance + ): + public_dns = instance["PublicDnsName"] + public_ip = instance["PublicIpAddress"] + if "PrivateIpAddress" in instance: + private_ip = instance["PrivateIpAddress"] + if "IamInstanceProfile" in instance: + instance_profile = instance["IamInstanceProfile"] - self.instances.append( - Instance( - instance["InstanceId"], - arn, - instance["State"]["Name"], - regional_client.region, - instance["InstanceType"], - instance["ImageId"], - instance["LaunchTime"], - instance["PrivateDnsName"], - instance["PrivateIpAddress"], - public_dns, - public_ip, - http_tokens, - http_endpoint, - instance_profile, + self.instances.append( + Instance( + instance["InstanceId"], + arn, + instance["State"]["Name"], + regional_client.region, + instance["InstanceType"], + instance["ImageId"], + instance["LaunchTime"], + instance["PrivateDnsName"], + private_ip, + public_dns, + public_ip, + http_tokens, + http_endpoint, + instance_profile, + ) ) - ) except Exception as error: logger.error( f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}" diff --git a/prowler/providers/aws/services/emr/emr_service.py b/prowler/providers/aws/services/emr/emr_service.py index 6826a04f27..f1795caec9 100644 --- a/prowler/providers/aws/services/emr/emr_service.py +++ b/prowler/providers/aws/services/emr/emr_service.py @@ -72,9 +72,14 @@ class EMR: master_node_security_group = cluster_info["Cluster"][ "Ec2InstanceAttributes" ]["EmrManagedMasterSecurityGroup"] - master_node_additional_security_groups = cluster_info["Cluster"][ - "Ec2InstanceAttributes" - ]["AdditionalMasterSecurityGroups"] + master_node_additional_security_groups = None + if ( + "AdditionalMasterSecurityGroups" + in cluster_info["Cluster"]["Ec2InstanceAttributes"] + ): + master_node_additional_security_groups = cluster_info[ + "Cluster" + ]["Ec2InstanceAttributes"]["AdditionalMasterSecurityGroups"] self.clusters[cluster.id].master = Node( security_group_id=master_node_security_group, additional_security_groups_id=master_node_additional_security_groups, diff --git a/prowler/providers/aws/services/s3/s3_service.py b/prowler/providers/aws/services/s3/s3_service.py index d68421199a..fbd6278ead 100644 --- a/prowler/providers/aws/services/s3/s3_service.py +++ b/prowler/providers/aws/services/s3/s3_service.py @@ -38,8 +38,8 @@ class S3: def __list_buckets__(self, audit_info): logger.info("S3 - Listing buckets...") + buckets = [] try: - buckets = [] list_buckets = self.client.list_buckets() for bucket in list_buckets["Buckets"]: try: @@ -60,11 +60,11 @@ class S3: logger.error( f"{bucket_region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}" ) - return buckets except Exception as error: logger.error( f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}" ) + return buckets def __get_bucket_versioning__(self, bucket): logger.info("S3 - Get buckets versioning...")