-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(EC2): Add new check for security group port restrictions (#4594)
- Loading branch information
1 parent
e7d0d49
commit 49ff901
Showing
9 changed files
with
618 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
34 changes: 34 additions & 0 deletions
34
..._ports/ec2_securitygroup_allow_ingress_from_internet_to_high_risk_tcp_ports.metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"Provider": "aws", | ||
"CheckID": "ec2_securitygroup_allow_ingress_from_internet_to_high_risk_tcp_ports", | ||
"CheckTitle": "Ensure no security groups allow ingress from 0.0.0.0/0 or ::/0 to high risk ports.", | ||
"CheckType": [ | ||
"Infrastructure Security" | ||
], | ||
"ServiceName": "ec2", | ||
"SubServiceName": "securitygroup", | ||
"ResourceIdTemplate": "arn:partition:service:region:account-id:resource-id", | ||
"Severity": "critical", | ||
"ResourceType": "AwsEc2SecurityGroup", | ||
"Description": "Ensure no security groups allow ingress from 0.0.0.0/0 or ::/0 to ports 25(SMTP), 110(POP3), 135(RCP), 143(IMAP), 445(CIFS), 3000(Go, Node.js, and Ruby web developemnt frameworks), 4333(ahsp), 5000(Python web development frameworks), 5500(fcp-addr-srvr1), 8080(proxy), 8088(legacy HTTP port).", | ||
"Risk": "If Security groups are not properly configured the attack surface is increased.", | ||
"RelatedUrl": "", | ||
"Remediation": { | ||
"Code": { | ||
"CLI": "", | ||
"NativeIaC": "", | ||
"Other": "", | ||
"Terraform": "" | ||
}, | ||
"Recommendation": { | ||
"Text": "Use a Zero Trust approach. Narrow ingress traffic as much as possible. Consider north-south as well as east-west traffic.", | ||
"Url": "https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html" | ||
} | ||
}, | ||
"Categories": [ | ||
"internet-exposed" | ||
], | ||
"DependsOn": [], | ||
"RelatedTo": [], | ||
"Notes": "" | ||
} |
50 changes: 50 additions & 0 deletions
50
...gh_risk_tcp_ports/ec2_securitygroup_allow_ingress_from_internet_to_high_risk_tcp_ports.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from prowler.lib.check.models import Check, Check_Report_AWS | ||
from prowler.providers.aws.services.ec2.ec2_client import ec2_client | ||
from prowler.providers.aws.services.ec2.ec2_securitygroup_allow_ingress_from_internet_to_all_ports import ( | ||
ec2_securitygroup_allow_ingress_from_internet_to_all_ports, | ||
) | ||
from prowler.providers.aws.services.ec2.lib.security_groups import check_security_group | ||
from prowler.providers.aws.services.vpc.vpc_client import vpc_client | ||
|
||
|
||
class ec2_securitygroup_allow_ingress_from_internet_to_high_risk_tcp_ports(Check): | ||
def execute(self): | ||
findings = [] | ||
for security_group_arn, security_group in ec2_client.security_groups.items(): | ||
# Check if ignoring flag is set and if the VPC and the SG is in use | ||
if ec2_client.provider.scan_unused_services or ( | ||
security_group.vpc_id in vpc_client.vpcs | ||
and vpc_client.vpcs[security_group.vpc_id].in_use | ||
and len(security_group.network_interfaces) > 0 | ||
): | ||
check_ports = ec2_client.audit_config.get( | ||
"ec2_high_risk_ports", | ||
[25, 110, 135, 143, 445, 3000, 4333, 5000, 5500, 8080, 8088], | ||
) | ||
for port in check_ports: | ||
report = Check_Report_AWS(self.metadata()) | ||
report.region = security_group.region | ||
report.resource_details = security_group.name | ||
report.resource_id = security_group.id | ||
report.resource_arn = security_group_arn | ||
report.resource_tags = security_group.tags | ||
report.status = "PASS" | ||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) does not have port {port} open to the Internet." | ||
# only proceed if check "..._to_all_ports" did not run or did not FAIL to avoid to report open ports twice | ||
if not ec2_client.is_failed_check( | ||
ec2_securitygroup_allow_ingress_from_internet_to_all_ports.__name__, | ||
security_group_arn, | ||
): | ||
# Loop through every security group's ingress rule and check it | ||
for ingress_rule in security_group.ingress_rules: | ||
if check_security_group( | ||
ingress_rule, "tcp", [port], any_address=True | ||
): | ||
report.status = "FAIL" | ||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has port {port} (high risk port) open to the Internet." | ||
break | ||
else: | ||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has all ports open to the Internet and therefore was not checked against port {port}." | ||
findings.append(report) | ||
|
||
return findings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,4 +92,3 @@ eks_required_log_types: | |
"controllerManager", | ||
"scheduler", | ||
] | ||
|
Oops, something went wrong.