Amazon EC2

Restricted Ports Open to Public

This plugin determines if there are open ports in EC2 Security Groups other than the whitelisted range.

Risk Level: High

Description

This plugin determines if there are open ports in EC2 Security Groups other than the whitelisted range.

To minimize false positives, this plugin reports only those security groups with public IP associated with any of its network interfaces.

Configuration Parameters


Whitelisted Open Ports: This parameter denotes the whitelisted ports which, if open to the public , do not pose any security threat. Example: tcp:80,tcp:443,tcp:80-443. An alert is generated if the security group has open ports other than the whitelisted ones. 

By default, the value is empty, therefore it will return vulnerability alert for all the open port ranges. 

About the Service

Amazon EC2: Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. With the EC2 instance, you can launch as many virtual servers as you need, configure security and networking, and manage storage without worrying about the hardware needs of the process. Security Groups act as a firewall for an EC2 instance to control the incoming and outgoing traffic. You can read more about security groups here.

Impact

Security Groups act as a firewall for the EC2 instances to control the incoming and outgoing traffic. There are rules defined under security groups that can allow specific IP addresses to access the EC2 instance with the protocol and the Ports specified.

Exposed ports can pose a serious security threat. Attackers can scan these ports and exploit the vulnerabilities of the services running on the public ports.

Steps to Reproduce

Using AWS Console-

  1. Log In to your AWS Console.
  2. Open the EC2 Management Console. You can use this link (https://console.aws.amazon.com/ec2) to navigate directly if already logged in. 
  3. Move to the Security Group in the Network and Security section from the left navigation pane.
  4. From the list of security groups, choose one by clicking on its Security group ID.
  5. The Inbound rules tab will be selected which has a list of rules for the security group. Investigate the Source column, and find the rules that have the source set to Anywhere (0.0.0.0/0 or ::/0). Similarly, find if the Type and Port set is in the whitelisted list or not. If not, then unrestricted access is allowed for vulnerable ports.
  6. Repeat steps 4 to 5 for all the Security Groups you want to investigate.

Steps for Remediation

Modify the security group and permit only required IP addresses to access the insecure open ports:

  1. Log In to your AWS Console.
  2. Open the EC2 Management Console. You can use this link (https://console.aws.amazon.com/ec2) to navigate directly if already logged in. 
  3. Move to the Security Group in the Network and Security section from the left navigation pane.
  4. You will find a list of Security Groups available. From the list, choose the vulnerable security group by clicking on its Security group ID.
  5. The Inbound rules tab will be selected along with a list of rules for the security group. Click on the Edit Inbound Rules button on the right.
  6. From the list of rules with insecure Port range, click on the close button beside the (0.0.0.0/0 or ::/0) in the Source column. It will clear all the IP addresses allowed to access the instance. From the Source drop-down menu, select Custom and enter all the IP addresses you want to give access to following the protocol.
  7. To allow only your IP to access the instance, select the My IP option. You can read more about all the options available here.
  8. Click on Preview Changes to preview the changes, and Save rules to save them.
  9. Repeat steps 4 to 8 for all the Security Groups you want to fix.