Skip to main content

Triage and Remediation

Remediation

Using Console

Here are the step-by-step instructions to remediate the Security Group Port Range misconfiguration for AWS using the AWS console:
  1. Log in to your AWS console.
  2. Navigate to the EC2 dashboard.
  3. Click on the “Security Groups” option on the left-hand side of the screen.
  4. Select the affected security group.
  5. Click on the “Inbound Rules” tab.
  6. Identify the rule with the incorrect port range.
  7. Click on the “Edit” button for that rule.
  8. Update the port range to the appropriate range.
  9. Click on the “Save” button to save the changes.
  10. Verify that the changes have been applied by confirming that the correct port range is now listed in the security group’s inbound rules.
It is recommended to regularly review and update security group rules to ensure that they are configured correctly for your organization’s needs.

The remediation steps for Security Group Port Range misconfiguration in AWS using AWS CLI are as follows:
  1. Identify the security group that has the misconfigured port range. You can use the following command to list all the security groups in your AWS account:
  2. Once you have identified the security group, use the following command to update the security group and remove the misconfigured port range:
    Replace <security-group-id> with the ID of the security group that has the misconfigured port range, and <port-range> with the range of ports that need to be removed. For example, if the security group ID is sg-1234567890 and the misconfigured port range is 0-65535, the command would be:
  3. Verify that the misconfigured port range has been removed by using the following command to describe the security group:
    Replace <security-group-id> with the ID of the security group that you updated. Verify that the misconfigured port range is no longer listed in the security group rules.
By following these steps, you can remediate the Security Group Port Range misconfiguration in AWS using AWS CLI.
To remediate the Security Group Port Range misconfiguration in AWS using Python, follow these steps:
  1. First, you need to identify the security group that has the misconfigured port range. You can do this by using the AWS SDK for Python (Boto3) to list all the security groups in your account and filter them based on the port range that is misconfigured.
Here’s an example code snippet that lists all the security groups in your account and filters them based on a specific port range:
In this example, we are filtering the security groups based on the SSH port (port 22), but you can modify the code to filter based on other port ranges as well.
  1. Once you have identified the security groups that have the misconfigured port range, you need to update the security group rules to allow only the required ports. You can do this by using the authorize_security_group_ingress and revoke_security_group_ingress methods of the ec2 client.
Here’s an example code snippet that updates the security group rules to allow only the required ports:
In this example, we are allowing only HTTP (port 80) and HTTPS (port 443) traffic to the security groups that have the misconfigured port range. You can modify the code to allow other ports as well.
  1. Finally, you should verify that the security group rules have been updated correctly. You can do this by using the describe_security_groups method of the ec2 client to retrieve the security group rules and checking that only the required ports are allowed.
Here’s an example code snippet that verifies the updated security group rules:
In this example, we are checking that only HTTP (port 80) and HTTPS (port 443) traffic is allowed in the security groups that have the misconfigured port range. If any other port is still allowed, the code will print a message indicating that the security group still has a misconfigured port range.
Changing the rule this way mirrors the CLI remediation: it revokes the wide <from_port>-<to_port> rule and authorizes a narrower <specific_port_or_range> from the intended source; this can disrupt connectivity if you remove ports the application actually needs, so validate requirements first.terraform plan should show the original wide aws_vpc_security_group_ingress_rule being destroyed (or its from_port/to_port/source arguments changing) and a new or updated aws_vpc_security_group_ingress_rule with the restricted port or narrow range being created/applied, while the aws_security_group itself remains in place.