Information
Security groups provide stateful filtering of ingress and egress network traffic to AWS resources. It is recommended that no security group allows unrestricted ingress access to remote server administration ports, such as SSH on port 22 and RDP on port 3389, using either the TCP (6), UDP (17), or ALL (-1) protocols.
Public access to remote server administration ports, such as 22 (when used for SSH, not SFTP) and 3389, increases the attack surface of resources and unnecessarily raises the risk of resource compromise.
Solution
From Console:
Perform the following to implement the prescribed state:
- Login to the AWS VPC Console at https://console.aws.amazon.com/vpc/home.
- In the left pane, click Security Groups.
- For each security group, perform the following:
- Select the security group.
- Click the Inbound Rules tab.
- Click the Edit inbound rules button.
- Identify the rules to be edited or removed.
- Either A) update the Source field to a range other than 0.0.0.0/0, or B) click Delete to remove the offending inbound rule.
- Click Save rules.
From Command Line:
- Check all security groups for insecure inbound rules allowing traffic from 0.0.0.0/0:
aws ec2 describe-security-group-rules --query 'SecurityGroupRules[?CidrIpv4 == "0.0.0.0/0" && IsEgress == `false`]' --output json
- Delete the insecure rule(s) based on their rule ID:
aws ec2 delete-security-group-rules --group-id <security_group_id> --security-group-rule-ids <rule_id_to_delete>
- Recreate necessary security group rules:
aws ec2 authorize-security-group-ingress --group-id <security_group_id> --protocol <tcp'udp'icmp or all> --port <port> --cidr <souce_cidr>
Impact:
When updating an existing environment, ensure that administrators have access to remote server administration ports through another mechanism before removing access by deleting the 0.0.0.0/0 inbound rule.