Skip to main content

Triage and Remediation

Remediation

Using Console

Below are step‑by‑step instructions to remove unrestricted inbound access from default Security Groups in AWS using the AWS Management Console.

1. Identify default Security Groups

  1. Sign in to the AWS Management Console.
  2. Go to EC2:
    • In the services search bar, type EC2 and click EC2.
  3. In the left navigation pane, under Network & Security, click Security Groups.
  4. In the Security Groups list:
    • Add the column Group Name and VPC ID if not visible.
    • Default Security Groups typically have Group Name like default and Description: “default VPC security group”.
  5. You can also filter:
    • In the search bar, type: group-name = default
      This will show one default Security Group per VPC.

2. Check for unrestricted inbound rules

For each default Security Group:
  1. Select the Security Group.
  2. At the bottom, open the Inbound rules tab.
  3. Look for any rules that:
    • Have Type = All traffic, All TCP, All UDP, or specific ports like SSH (22), RDP (3389), HTTP (80), HTTPS (443) etc.
    • And Source = 0.0.0.0/0 (IPv4) and/or ::/0 (IPv6).
      These are “unrestricted inbound” rules.

3. Remove or restrict inbound rules on the default Security Group

You cannot delete the default Security Group, but you can change its rules.
  1. With the default Security Group selected, click Edit inbound rules.
  2. For each rule that has Source 0.0.0.0/0 or ::/0:
    • Either:
      • Delete the rule (click the trash icon), or
      • Change Source to something more restrictive, e.g.:
        • A specific CIDR like 10.0.0.0/16 (your internal network),
        • Or a specific IP such as 203.0.113.10/32 (admin workstation).
  3. If you do not need any inbound traffic via the default SG:
    • Remove all inbound rules, leaving the inbound rules list empty.
  4. Click Save rules.
Repeat this for the default Security Group in every VPC in your account/region.

4. Ensure new resources don’t rely on the default SG for inbound access

  1. When launching new EC2 instances:
    • In Step: Configure Security Group (or equivalent in the console wizard), do not select the default Security Group for publicly exposed services.
    • Instead, create/choose a dedicated SG with only the specific ports and IP ranges needed.
  2. For existing instances that rely on the default SG for inbound access:
    • Create a new Security Group with least-privilege rules.
    • Attach the new SG to the instance:
      • Select the instance → ActionsSecurityChange security groups.
      • Add the new SG and (optionally) remove the default SG.
      • Click Apply.

5. (Optional) Check outbound rules on default SG

Best practice is to also restrict outbound where needed:
  1. Select the default Security Group.
  2. Open Outbound rules.
  3. Click Edit outbound rules.
  4. Remove or tighten any 0.0.0.0/0 or ::/0 rules if your policy requires restricted egress.
  5. Click Save rules.

By completing the above steps for each default Security Group in each VPC, you will have removed unrestricted inbound access while keeping the default SG itself (which cannot be deleted).
Below are concise, step‑by‑step AWS CLI instructions to lock down default Security Groups so they don’t allow unrestricted (0.0.0.0/0 or ::/0) inbound access.

1. Identify all default Security Groups

Keep the GroupId values; you’ll need them for the next steps.

2. Review current inbound rules for a specific default Security Group

Replace <sg-id> with the Security Group ID:
Look for any rules where:
  • IpRanges[].CidrIp is 0.0.0.0/0
  • Ipv6Ranges[].CidrIpv6 is ::/0

3. Revoke unrestricted IPv4 inbound rules

This example revokes all IPv4 inbound rules from the default SG that are open to 0.0.0.0/0.
First get those rules in a form the CLI can accept:
If ipv4-open-rules.json is not empty, run:

4. Revoke unrestricted IPv6 inbound rules

Similarly for IPv6 (::/0):
If ipv6-open-rules.json is not empty:

5. Repeat for all default Security Groups

Loop over all default SGs in a shell (bash example):

6. (Optional) Add restricted inbound rules instead

Example: allow SSH only from a corporate CIDR (replace 203.0.113.0/24):
This ensures the default Security Groups no longer allow unrestricted inbound access.
Below is a step‑by‑step approach plus a ready‑to‑run Python (boto3) script that:
  1. Finds all default security groups in all regions.
  2. Removes any inbound rules that allow unrestricted access (0.0.0.0/0 or ::/0).

Prerequisites

  • AWS credentials configured (e.g., ~/.aws/credentials or environment variables).
  • Python 3.x
  • boto3 installed:

Remediation Logic

  1. Enumerate all AWS regions.
  2. For each region:
    • Get all security groups where GroupName == 'default'.
    • Inspect IpPermissions (inbound rules).
    • For each permission, check if any of:
      • IpRanges has CidrIp == '0.0.0.0/0'
      • Ipv6Ranges has CidrIpv6 == '::/0'
    • Build a permission structure that includes only the unrestricted ranges to be removed.
    • Call revoke_security_group_ingress with those specific ranges.

Python Script (boto3)


How to Run

  1. Save as fix_default_sg_unrestricted.py.
  2. Run:
  3. Verify by checking default security groups in the AWS Console or via:
This script only removes unrestricted inbound from default security groups and leaves other (more specific) rules intact.
This configuration manages the existing default security group in-place (no replacement of the SG itself; Terraform will just remove any existing unrestricted ingress rules).Verification: terraform plan should show all existing ingress rules on the default security group being removed (or replaced with the empty set) and only the specified egress rule(s) present.