Check ID: ec2_instance_port_mongodb_exposed_to_internet
Provider: AWS
Service: ec2
Severity: CRITICAL
Categories: internet-exposed
Resource type: AwsEc2Instance

What this check verifies

EC2 instances with security groups permitting inbound TCP 27017 or 27018 (MongoDB) from 0.0.0.0/0 or ::/0 are identified, factoring the instance’s public reachability to gauge exposure.

Risk

Internet-exposed MongoDB invites scanning, brute force, and exploits leading to:
  • Data extraction (confidentiality)
  • Collection tampering or deletion (integrity)
  • DoS or ransomware disruptions (availability) A compromised DB host can also enable lateral movement within the environment.

Recommendation

Apply least privilege to MongoDB access:
  • Remove Internet-wide rules; allow only trusted sources
  • Keep DBs on private subnets without public IPs; use private connectivity or proxies
  • Enforce strong auth and TLS
  • Add segmentation and monitoring for defense in depth

Remediation

aws ec2 revoke-security-group-ingress --group-id <SECURITY_GROUP_ID> --ip-permissions '[{"IpProtocol":"tcp","FromPort":27017,"ToPort":27017,"IpRanges":[{"CidrIp":"0.0.0.0/0"}],"Ipv6Ranges":[{"CidrIpv6":"::/0"}]},{"IpProtocol":"tcp","FromPort":27018,"ToPort":27018,"IpRanges":[{"CidrIp":"0.0.0.0/0"}],"Ipv6Ranges":[{"CidrIpv6":"::/0"}]}]'

References

Where this check fires

This check runs on every scheduled scan against your AWS account. Findings appear at Cloud Security → Findings filterable by Check ID = ec2_instance_port_mongodb_exposed_to_internet. To re-evaluate after a fix, hit Run now on the account’s schedule under Cloud Security → Schedules — the next scan re-checks this control and marks the finding fixed or keeps it persistent.
← Back to AWS checks