mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
feat(regions): add regions to resources (#1285)
This commit is contained in:
@@ -5,31 +5,19 @@ from providers.aws.services.ec2.ec2_service import ec2_client
|
||||
class ec2_ebs_public_snapshot(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.snapshots:
|
||||
for snapshot in regional_client.snapshots:
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
if not snapshot.public:
|
||||
report.status = "PASS"
|
||||
report.status_extended = (
|
||||
f"EBS Snapshot {snapshot.id} is not Public"
|
||||
)
|
||||
report.resource_id = snapshot.id
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = (
|
||||
f"EBS Snapshot {snapshot.id} is currently Public"
|
||||
)
|
||||
report.resource_id = snapshot.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
for snapshot in ec2_client.snapshots:
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = snapshot.region
|
||||
if not snapshot.public:
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 EBS snapshots"
|
||||
report.region = region
|
||||
|
||||
findings.append(report)
|
||||
report.status_extended = f"EBS Snapshot {snapshot.id} is not Public"
|
||||
report.resource_id = snapshot.id
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = (
|
||||
f"EBS Snapshot {snapshot.id} is currently Public"
|
||||
)
|
||||
report.resource_id = snapshot.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -5,31 +5,17 @@ from providers.aws.services.ec2.ec2_service import ec2_client
|
||||
class ec2_ebs_snapshots_encrypted(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.snapshots:
|
||||
for snapshot in regional_client.snapshots:
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
if snapshot.encrypted:
|
||||
report.status = "PASS"
|
||||
report.status_extended = (
|
||||
f"EBS Snapshot {snapshot.id} is encrypted"
|
||||
)
|
||||
report.resource_id = snapshot.id
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = (
|
||||
f"EBS Snapshot {snapshot.id} is unencrypted"
|
||||
)
|
||||
report.resource_id = snapshot.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
for snapshot in ec2_client.snapshots:
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = snapshot.region
|
||||
if snapshot.encrypted:
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 EBS snapshots"
|
||||
report.region = region
|
||||
|
||||
findings.append(report)
|
||||
report.status_extended = f"EBS Snapshot {snapshot.id} is encrypted"
|
||||
report.resource_id = snapshot.id
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"EBS Snapshot {snapshot.id} is unencrypted"
|
||||
report.resource_id = snapshot.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -5,29 +5,19 @@ from providers.aws.services.ec2.ec2_service import ec2_client
|
||||
class ec2_instance_public_ip(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.instances:
|
||||
for instance in regional_client.instances:
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
if instance.public_ip:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"EC2 instance {instance.id} has a Public IP: {instance.public_ip} ({instance.public_dns})."
|
||||
report.resource_id = instance.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = (
|
||||
f"EC2 instance {instance.id} has not a Public IP."
|
||||
)
|
||||
report.resource_id = instance.id
|
||||
findings.append(report)
|
||||
for instance in ec2_client.instances:
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = instance.region
|
||||
if instance.public_ip:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"EC2 instance {instance.id} has a Public IP: {instance.public_ip} ({instance.public_dns})."
|
||||
report.resource_id = instance.id
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 instances."
|
||||
report.region = region
|
||||
|
||||
findings.append(report)
|
||||
report.status_extended = (
|
||||
f"EC2 instance {instance.id} has not a Public IP."
|
||||
)
|
||||
report.resource_id = instance.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -6,40 +6,32 @@ class ec2_networkacl_allow_ingress_tcp_port_22(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
check_port = 22
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.network_acls:
|
||||
for network_acl in regional_client.network_acls:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
for entry in network_acl.entries:
|
||||
if (
|
||||
entry["CidrBlock"] == "0.0.0.0/0"
|
||||
and entry["RuleAction"] == "allow"
|
||||
and not entry["Egress"]
|
||||
and "PortRange" in entry
|
||||
and entry["Protocol"] == "6" # 6 relates to tcp protocol
|
||||
):
|
||||
if (
|
||||
entry["PortRange"]["From"] == check_port
|
||||
and entry["PortRange"]["To"] == check_port
|
||||
):
|
||||
public = True
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Network ACL {network_acl.id} has SSH port 22 open to the Internet."
|
||||
report.resource_id = network_acl.id
|
||||
if not public:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Network ACL {network_acl.id} has not SSH port 22 open to the Internet."
|
||||
report.resource_id = network_acl.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
for network_acl in ec2_client.network_acls:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = network_acl.region
|
||||
for entry in network_acl.entries:
|
||||
if (
|
||||
entry["CidrBlock"] == "0.0.0.0/0"
|
||||
and entry["RuleAction"] == "allow"
|
||||
and not entry["Egress"]
|
||||
):
|
||||
if entry["Protocol"] == "-1":
|
||||
public = True
|
||||
elif (
|
||||
entry["PortRange"]["From"] == check_port
|
||||
and entry["PortRange"]["To"] == check_port
|
||||
and entry["Protocol"] == "6"
|
||||
):
|
||||
public = True
|
||||
if not public:
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 network acls."
|
||||
report.region = region
|
||||
|
||||
findings.append(report)
|
||||
report.status_extended = f"Network ACL {network_acl.id} has not SSH port 22 open to the Internet."
|
||||
report.resource_id = network_acl.id
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Network ACL {network_acl.id} has SSH port 22 open to the Internet."
|
||||
report.resource_id = network_acl.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -6,40 +6,32 @@ class ec2_networkacl_allow_ingress_tcp_port_3389(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
check_port = 3389
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.network_acls:
|
||||
for network_acl in regional_client.network_acls:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
for entry in network_acl.entries:
|
||||
if (
|
||||
entry["CidrBlock"] == "0.0.0.0/0"
|
||||
and entry["RuleAction"] == "allow"
|
||||
and not entry["Egress"]
|
||||
and "PortRange" in entry
|
||||
and entry["Protocol"] == "6" # 6 relates to tcp protocol
|
||||
):
|
||||
if (
|
||||
entry["PortRange"]["From"] == check_port
|
||||
and entry["PortRange"]["To"] == check_port
|
||||
):
|
||||
public = True
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Network ACL {network_acl.id} has Microsoft RDP port 3389 open to the Internet."
|
||||
report.resource_id = network_acl.id
|
||||
if not public:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Network ACL {network_acl.id} has not Microsoft RDP port 3389 open to the Internet."
|
||||
report.resource_id = network_acl.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
for network_acl in ec2_client.network_acls:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = network_acl.region
|
||||
for entry in network_acl.entries:
|
||||
if (
|
||||
entry["CidrBlock"] == "0.0.0.0/0"
|
||||
and entry["RuleAction"] == "allow"
|
||||
and not entry["Egress"]
|
||||
):
|
||||
if entry["Protocol"] == "-1":
|
||||
public = True
|
||||
elif (
|
||||
entry["PortRange"]["From"] == check_port
|
||||
and entry["PortRange"]["To"] == check_port
|
||||
and entry["Protocol"] == "6"
|
||||
):
|
||||
public = True
|
||||
if not public:
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 network acls."
|
||||
report.region = region
|
||||
|
||||
findings.append(report)
|
||||
report.status_extended = f"Network ACL {network_acl.id} has not Microsoft RDP port 3389 open to the Internet."
|
||||
report.resource_id = network_acl.id
|
||||
else:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Network ACL {network_acl.id} has Microsoft RDP port 3389 open to the Internet."
|
||||
report.resource_id = network_acl.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -5,32 +5,22 @@ from providers.aws.services.ec2.ec2_service import check_security_group, ec2_cli
|
||||
class ec2_securitygroup_allow_ingress_from_internet_to_any_port(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.security_groups:
|
||||
for security_group in regional_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "-1")
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has all ports open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not all ports open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 security groups."
|
||||
report.region = region
|
||||
|
||||
for security_group in ec2_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = security_group.region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "-1")
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has all ports open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not all ports open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -6,32 +6,22 @@ class ec2_securitygroup_allow_ingress_from_internet_to_tcp_port_22(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
check_ports = [22]
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.security_groups:
|
||||
for security_group in regional_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "tcp", check_ports)
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has the SSH port 22 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not SSH port 22 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 security groups."
|
||||
report.region = region
|
||||
|
||||
for security_group in ec2_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = security_group.region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "tcp", check_ports)
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has the SSH port 22 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not SSH port 22 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -1,37 +1,26 @@
|
||||
from lib.check.models import Check, Check_Report
|
||||
from providers.aws.services.ec2.ec2_service import check_security_group, ec2_client
|
||||
|
||||
|
||||
class ec2_securitygroup_allow_ingress_from_internet_to_tcp_port_3389(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
check_ports = [3389]
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.security_groups:
|
||||
for security_group in regional_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "tcp", check_ports)
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not Microsoft RDP port 3389 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not Microsoft RDP port 3389 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 security groups."
|
||||
report.region = region
|
||||
|
||||
for security_group in ec2_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = security_group.region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "tcp", check_ports)
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has Microsoft RDP port 3389 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not Microsoft RDP port 3389 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -1,37 +1,26 @@
|
||||
from lib.check.models import Check, Check_Report
|
||||
from providers.aws.services.ec2.ec2_service import check_security_group, ec2_client
|
||||
|
||||
|
||||
class ec2_securitygroup_allow_ingress_from_internet_to_tcp_port_mysql_3306(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
check_ports = [3306]
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.security_groups:
|
||||
for security_group in regional_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "tcp", check_ports)
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has the MySQL port 3306 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not MySQL port 3306 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 security groups."
|
||||
report.region = region
|
||||
|
||||
for security_group in ec2_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = security_group.region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "tcp", check_ports)
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has the MySQL port 3306 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not MySQL port 3306 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
|
||||
@@ -1,37 +1,26 @@
|
||||
from lib.check.models import Check, Check_Report
|
||||
from providers.aws.services.ec2.ec2_service import check_security_group, ec2_client
|
||||
|
||||
|
||||
class ec2_securitygroup_allow_ingress_from_internet_to_tcp_port_oracle_1521_2483(Check):
|
||||
def execute(self):
|
||||
findings = []
|
||||
check_ports = [1521, 2483]
|
||||
for regional_client in ec2_client.regional_clients:
|
||||
region = regional_client.region
|
||||
if regional_client.security_groups:
|
||||
for security_group in regional_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "tcp", check_ports)
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has Oracle ports 1521 and 2483 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not Oracle ports 1521 and 2483 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
else:
|
||||
report = Check_Report(self.metadata)
|
||||
report.status = "PASS"
|
||||
report.status_extended = "There are no EC2 security groups."
|
||||
report.region = region
|
||||
|
||||
for security_group in ec2_client.security_groups:
|
||||
public = False
|
||||
report = Check_Report(self.metadata)
|
||||
report.region = security_group.region
|
||||
# Loop through every security group's ingress rule and check it
|
||||
for ingress_rule in security_group.ingress_rules:
|
||||
public = check_security_group(ingress_rule, "tcp", check_ports)
|
||||
# Check
|
||||
if public:
|
||||
report.status = "FAIL"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has Oracle ports 1521 and 2483 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
else:
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has not Oracle ports 1521 and 2483 open to the Internet."
|
||||
report.resource_id = security_group.id
|
||||
findings.append(report)
|
||||
|
||||
return findings
|
||||
return findings
|
||||
@@ -13,18 +13,22 @@ class EC2:
|
||||
self.session = audit_info.audit_session
|
||||
self.audited_account = audit_info.audited_account
|
||||
self.regional_clients = generate_regional_clients(self.service, audit_info)
|
||||
self.instances = []
|
||||
self.__threading_call__(self.__describe_instances__)
|
||||
self.security_groups = []
|
||||
self.__threading_call__(self.__describe_security_groups__)
|
||||
self.network_acls = []
|
||||
self.__threading_call__(self.__describe_network_acls__)
|
||||
self.snapshots = []
|
||||
self.__threading_call__(self.__describe_snapshots__)
|
||||
self.__threading_call__(self.__get_snapshot_public__)
|
||||
self.__get_snapshot_public__()
|
||||
|
||||
def __get_session__(self):
|
||||
return self.session
|
||||
|
||||
def __threading_call__(self, call):
|
||||
threads = []
|
||||
for regional_client in self.regional_clients:
|
||||
for regional_client in self.regional_clients.values():
|
||||
threads.append(threading.Thread(target=call, args=(regional_client,)))
|
||||
for t in threads:
|
||||
t.start()
|
||||
@@ -37,7 +41,6 @@ class EC2:
|
||||
describe_instances_paginator = regional_client.get_paginator(
|
||||
"describe_instances"
|
||||
)
|
||||
instances = []
|
||||
for page in describe_instances_paginator.paginate():
|
||||
for reservation in page["Reservations"]:
|
||||
for instance in reservation["Instances"]:
|
||||
@@ -45,9 +48,10 @@ class EC2:
|
||||
"PublicDnsName" in instance
|
||||
and "PublicIpAddress" in instance
|
||||
):
|
||||
instances.append(
|
||||
self.instances.append(
|
||||
Instance(
|
||||
instance["InstanceId"],
|
||||
regional_client.region,
|
||||
instance["InstanceType"],
|
||||
instance["ImageId"],
|
||||
instance["LaunchTime"],
|
||||
@@ -58,9 +62,10 @@ class EC2:
|
||||
)
|
||||
)
|
||||
else:
|
||||
instances.append(
|
||||
self.instances.append(
|
||||
Instance(
|
||||
instance["InstanceId"],
|
||||
regional_client.region,
|
||||
instance["InstanceType"],
|
||||
instance["ImageId"],
|
||||
instance["LaunchTime"],
|
||||
@@ -74,9 +79,6 @@ class EC2:
|
||||
logger.error(
|
||||
f"{regional_client.region} -- {error.__class__.__name__}: {error}"
|
||||
)
|
||||
regional_client.instances = []
|
||||
else:
|
||||
regional_client.instances = instances
|
||||
|
||||
def __describe_security_groups__(self, regional_client):
|
||||
logger.info("EC2 - Describing Security Groups...")
|
||||
@@ -84,12 +86,12 @@ class EC2:
|
||||
describe_security_groups_paginator = regional_client.get_paginator(
|
||||
"describe_security_groups"
|
||||
)
|
||||
security_groups = []
|
||||
for page in describe_security_groups_paginator.paginate():
|
||||
for sg in page["SecurityGroups"]:
|
||||
security_groups.append(
|
||||
self.security_groups.append(
|
||||
SecurityGroup(
|
||||
sg["GroupName"],
|
||||
regional_client.region,
|
||||
sg["GroupId"],
|
||||
sg["IpPermissions"],
|
||||
sg["IpPermissionsEgress"],
|
||||
@@ -99,9 +101,6 @@ class EC2:
|
||||
logger.error(
|
||||
f"{regional_client.region} -- {error.__class__.__name__}: {error}"
|
||||
)
|
||||
regional_client.security_groups = []
|
||||
else:
|
||||
regional_client.security_groups = security_groups
|
||||
|
||||
def __describe_network_acls__(self, regional_client):
|
||||
logger.info("EC2 - Describing Security Groups...")
|
||||
@@ -109,19 +108,19 @@ class EC2:
|
||||
describe_network_acls_paginator = regional_client.get_paginator(
|
||||
"describe_network_acls"
|
||||
)
|
||||
network_acls = []
|
||||
for page in describe_network_acls_paginator.paginate():
|
||||
for nacl in page["NetworkAcls"]:
|
||||
network_acls.append(
|
||||
NetworkACL(nacl["NetworkAclId"], nacl["Entries"])
|
||||
self.network_acls.append(
|
||||
NetworkACL(
|
||||
nacl["NetworkAclId"],
|
||||
regional_client.region,
|
||||
nacl["Entries"],
|
||||
)
|
||||
)
|
||||
except Exception as error:
|
||||
logger.error(
|
||||
f"{regional_client.region} -- {error.__class__.__name__}: {error}"
|
||||
)
|
||||
regional_client.network_acls = []
|
||||
else:
|
||||
regional_client.network_acls = network_acls
|
||||
|
||||
def __describe_snapshots__(self, regional_client):
|
||||
logger.info("EC2 - Describing Snapshots...")
|
||||
@@ -129,7 +128,6 @@ class EC2:
|
||||
describe_snapshots_paginator = regional_client.get_paginator(
|
||||
"describe_snapshots"
|
||||
)
|
||||
snapshots = []
|
||||
encrypted = False
|
||||
for page in describe_snapshots_paginator.paginate(
|
||||
OwnerIds=[self.audited_account]
|
||||
@@ -137,36 +135,36 @@ class EC2:
|
||||
for snapshot in page["Snapshots"]:
|
||||
if snapshot["Encrypted"]:
|
||||
encrypted = True
|
||||
snapshots.append(Snapshot(snapshot["SnapshotId"], encrypted))
|
||||
self.snapshots.append(
|
||||
Snapshot(
|
||||
snapshot["SnapshotId"], regional_client.region, encrypted
|
||||
)
|
||||
)
|
||||
except Exception as error:
|
||||
logger.error(
|
||||
f"{regional_client.region} -- {error.__class__.__name__}: {error}"
|
||||
)
|
||||
regional_client.snapshots = []
|
||||
else:
|
||||
regional_client.snapshots = snapshots
|
||||
|
||||
def __get_snapshot_public__(self, regional_client):
|
||||
def __get_snapshot_public__(self):
|
||||
logger.info("EC2 - Get snapshots encryption...")
|
||||
try:
|
||||
if hasattr(regional_client, "snapshots"):
|
||||
for snapshot in regional_client.snapshots:
|
||||
snapshot_public = regional_client.describe_snapshot_attribute(
|
||||
Attribute="createVolumePermission", SnapshotId=snapshot.id
|
||||
)
|
||||
for permission in snapshot_public["CreateVolumePermissions"]:
|
||||
if "Group" in permission:
|
||||
if permission["Group"] == "all":
|
||||
snapshot.public = True
|
||||
for snapshot in self.snapshots:
|
||||
regional_client = self.regional_clients[snapshot.region]
|
||||
snapshot_public = regional_client.describe_snapshot_attribute(
|
||||
Attribute="createVolumePermission", SnapshotId=snapshot.id
|
||||
)
|
||||
for permission in snapshot_public["CreateVolumePermissions"]:
|
||||
if "Group" in permission:
|
||||
if permission["Group"] == "all":
|
||||
snapshot.public = True
|
||||
except Exception as error:
|
||||
logger.error(
|
||||
f"{regional_client.region} -- {error.__class__.__name__}: {error}"
|
||||
)
|
||||
logger.error(f"{error.__class__.__name__}: {error}")
|
||||
|
||||
|
||||
@dataclass
|
||||
class Instance:
|
||||
id: str
|
||||
region: str
|
||||
type: str
|
||||
image_id: str
|
||||
launch_time: str
|
||||
@@ -178,6 +176,7 @@ class Instance:
|
||||
def __init__(
|
||||
self,
|
||||
id,
|
||||
region,
|
||||
type,
|
||||
image_id,
|
||||
launch_time,
|
||||
@@ -187,6 +186,7 @@ class Instance:
|
||||
public_ip,
|
||||
):
|
||||
self.id = id
|
||||
self.region = region
|
||||
self.type = type
|
||||
self.image_id = image_id
|
||||
self.launch_time = launch_time
|
||||
@@ -199,11 +199,13 @@ class Instance:
|
||||
@dataclass
|
||||
class Snapshot:
|
||||
id: str
|
||||
region: str
|
||||
encrypted: bool
|
||||
public: bool
|
||||
|
||||
def __init__(self, id, encrypted):
|
||||
def __init__(self, id, region, encrypted):
|
||||
self.id = id
|
||||
self.region = region
|
||||
self.encrypted = encrypted
|
||||
self.public = False
|
||||
|
||||
@@ -211,12 +213,14 @@ class Snapshot:
|
||||
@dataclass
|
||||
class SecurityGroup:
|
||||
name: str
|
||||
region: str
|
||||
id: str
|
||||
ingress_rules: list[dict]
|
||||
egress_rules: list[dict]
|
||||
|
||||
def __init__(self, name, id, ingress_rules, egress_rules):
|
||||
def __init__(self, name, region, id, ingress_rules, egress_rules):
|
||||
self.name = name
|
||||
self.region = region
|
||||
self.id = id
|
||||
self.ingress_rules = ingress_rules
|
||||
self.egress_rules = egress_rules
|
||||
@@ -227,8 +231,9 @@ class NetworkACL:
|
||||
id: str
|
||||
entries: list[dict]
|
||||
|
||||
def __init__(self, id, entries):
|
||||
def __init__(self, id, region, entries):
|
||||
self.id = id
|
||||
self.region = region
|
||||
self.entries = entries
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user