More Info:
Your AWS EC2 default security groups should restrict all inbound public traffic in order to enforce AWS users (EC2 administrators, resource managers, etc) to create custom security groups that exercise the rule of least privilege instead of using the default security groups.Risk Level
LowAddress
SecurityCompliance Standards
PCIDSS, MAS, APRARemediation
How to ensure default Security Group does not allow unrestricted inbound accessUsing AWS Console
- Open the AWS Management Console and navigate to the Amazon EC2 service.
- From the left navigation pane, click on “Security Groups” to view the list of security groups. (In the Cloudanix Console, navigate to “Misconfig” page and look for Affected Assets for “Default Security Groups Should Not Allow Unrestricted Inbound Access” Policy.)
- Look for the default security group in the list. By default, it is named “default” and should be associated with your VPC.
- Select the default security group by clicking on its name.
- In the “Inbound Rules” tab, review the existing inbound rules configured for the default security group.
- Identify any rules that allow unrestricted access (such as allowing all traffic from any source).
- To remove an unrestricted rule, click on the “X” button next to the rule to delete it.
- Alternatively, you can edit the rule by clicking on the “Edit” button and modifying the source IP range or protocol/port to restrict the access.
- Repeat the process for all unrestricted inbound rules until the default security group only allows the necessary and restricted inbound access.
- Once you have updated the rules, click on the “Save rules” button to apply the changes.
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are concise, console-based steps to remediate “Default Security Groups allow unrestricted inbound access” in AWS.
1. Identify default security groups with open inbound access
- Sign in to the AWS Management Console.
- Go to EC2.
- In the left navigation pane, choose Security Groups.
- In the filter/search bar, type
defaultand press Enter. - In the Group Name column, look for security groups named default (one per VPC).
- For each default SG:
- Select it and check the Inbound rules tab.
- Look for rules with:
- Type = All traffic, All ICMP, SSH, RDP, Custom TCP/UDP, etc.
- Source =
0.0.0.0/0and/or::/0(unrestricted).
2. Remove unrestricted inbound rules on the default security group
For each default security group that has0.0.0.0/0 or ::/0 in inbound rules:- Select the default security group.
- Choose the Inbound rules tab.
- Click Edit inbound rules.
- For each rule where:
- Source is
0.0.0.0/0or::/0, and - It is not needed for VPC-internal communication:
- Click the X at the end of the row to remove it.
- Source is
- Make sure that if you need instances in the same security group to talk to each other, you keep (or add) a rule like:
- Type: All traffic (or the specific required ports)
- Protocol: All (or needed)
- Port range: All (or needed)
- Source: The security group itself (select from dropdown under Custom → SG ID).
- Click Save rules.
Note: You cannot delete a default security group, only modify its rules.
3. Create and use dedicated security groups for external access
To avoid using the default SG for internet-exposed services:- In Security Groups, click Create security group.
- Enter:
- Security group name: e.g.,
web-servers-sg. - Description: e.g.,
Security group for public web servers (HTTP/HTTPS only). - VPC: Select the correct VPC.
- Security group name: e.g.,
- Under Inbound rules, add only what’s needed, with limited source ranges, for example:
- Rule 1:
- Type: HTTP
- Port: 80
- Source: Your office IP /32 or specific CIDR (not
0.0.0.0/0if possible).
- Rule 2:
- Type: HTTPS
- Port: 443
- Source: As above.
- For SSH/RDP, use:
- Type: SSH / RDP
- Source: Admin IPs only (never
0.0.0.0/0).
- Rule 1:
- Click Create security group.
- Go to Instances.
- Select the instance currently using the default security group.
- Choose Actions → Security → Change security groups.
- Check your new SG (e.g.,
web-servers-sg) and uncheck the default SG (if safe to do so). - Click Apply.
4. Confirm remediation
- Return to Security Groups.
- For each default SG:
- Confirm there are no inbound rules with
0.0.0.0/0or::/0.
- Confirm there are no inbound rules with
- Optionally, use Reachability Analyzer or test from the internet to ensure ports are no longer globally open.
Using CLI
Using CLI
Below is a concise, CLI‑only way to lock down default Security Groups so they don’t allow unrestricted inbound (0.0.0.0/0 or ::/0).Look for:
This ensures the default SG has no inbound rules (i.e., nothing is allowed in).
Similarly for IPv6:Repeat for each protocol/port combination you find with unrestricted access.
This leaves the default Security Groups without any 0.0.0.0/0 or ::/0 inbound access.
1. Identify default Security Groups that allow unrestricted inbound
IpRangeswithCidrIp: "0.0.0.0/0"Ipv6RangeswithCidrIpv6: "::/0"
2. Revoke all inbound rules on default Security Groups (safer baseline)
If you’re okay with removing all inbound rules from all default SGs in a region:3. (Optional) Only remove “unrestricted” inbound rules
If you want to keep other, more restricted rules and only remove 0.0.0.0/0 or ::/0, you need to filter the permissions. One straightforward approach is to manually revoke specific rules once you’ve inspected them.Example: remove a specific inbound rule (TCP 22 from 0.0.0.0/0) from a known default SG:4. (Optional) Add safer, restricted inbound rules
After cleanup, if you need access from a known IP/CIDR:Using Python
Using Python
Below is one straightforward way to remediate this using Python and boto3: identify default security groups that allow 0.0.0.0/0 or ::/0 inbound, then remove those rules.
1. Prerequisites
-
Install boto3:
-
Configure AWS credentials with sufficient permissions:
ec2:DescribeSecurityGroupsec2:RevokeSecurityGroupIngress
2. Python script to remove unrestricted inbound from default security groups
This script:- Enumerates all regions.
- Finds default security groups.
- Detects inbound rules with:
- IPv4:
0.0.0.0/0 - IPv6:
::/0
- IPv4:
- Revokes only those offending rules (leaves other rules intact).
3. Notes / Adjustments
- If you only want to operate in a single region, replace
get_all_regions()with a hard-coded list, e.g.regions = ["us-east-1"]. - This script only removes the
0.0.0.0/0or::/0inbound rules. It does not add replacement rules; if you need specific allowed CIDRs, add them explicitly withauthorize_security_group_ingress.
Using Terraform
Using Terraform
terraform plan should show the aws_default_security_group ingress rules from 0.0.0.0/0 (and/or ::/0) being removed and no new unrestricted inbound rules added.
