# Ensure no EC2 instances allow ingress from the internet to TCP port 139 or 445 (CIFS).

- Source: https://support.icompaas.com/support/solutions/articles/62000233591-ensure-no-ec2-instances-allow-ingress-from-the-internet-to-tcp-port-139-or-445-cifs-
- Section: [Solutions](https://support.icompaas.com/support/solutions) › [AWS Checks New Version](https://support.icompaas.com/support/solutions/62000112673) › [AWS New Checks](https://support.icompaas.com/support/solutions/folders/62000169206)
- Last updated: 2026-05-29
- Publisher: iCompaas, Inc. (https://www.icompaas.com)

# **Profile Applicability:**

**Level : 1**

### Description: 

This check ensures that no EC2 instances in your AWS environment allow ingress (incoming) traffic from the internet to TCP ports 139 or 445, which are commonly associated with the Server Message Block (SMB) protocol. Allowing such traffic without restrictions can expose your instances to unauthorized access and potential exploits.

### Rationale:

Ports 139 and 445 are used by the SMB protocol for file sharing and network communication. Exposing these ports to the internet increases the risk of attacks, such as the WannaCry ransomware exploit, which targeted vulnerabilities in SMB services. Restricting access to these ports helps protect your instances from unauthorized access and potential exploits.

### Impact:

-   Security: Unauthorized access to EC2 instances can lead to data breaches, service disruptions, or system compromises.
    
-   Compliance: Failure to restrict access to these ports may violate security standards and compliance requirements (e.g., PCI-DSS, HIPAA, SOC 2).
    
-   Service Downtime: Exploits targeting these ports can lead to service outages or security incidents affecting resource availability.
    

### Default Value: 

By default, security groups in AWS do not allow inbound traffic on ports 139 and 445. However, custom security group configurations might have rules that allow ingress to these ports.

### Pre-Requisites:

-   AWS Management Console access or AWS CLI installed with appropriate permissions to describe and modify security group rules.
    
-   Familiarity with security best practices and the SMB protocol.
    

### **Remediation**

### Test Plan:

#### Using AWS Console:

1.  Sign in to the AWS Management Console.
    
2.  Navigate to the EC2 dashboard.
    

     ![](https://support.icompaas.com/assets/kb/66c69051d9dece17.png)

3.   under Network & Security, choose Security Groups.
    

         ![](https://support.icompaas.com/assets/kb/a5bdd1f837e52df3.png)

4.  Select each security group and review the Inbound Rules.
    

    ![](https://support.icompaas.com/assets/kb/45908e857575fc11.png)

5.  Verify that no rules allow ingress from 0.0.0.0/0 or ::/0 to ports 139 or 445.
    

   ![](https://support.icompaas.com/assets/kb/31c01bffe0c835b3.png)

6.  If such rules exist, they should be modified or removed.
    

    ![](https://support.icompaas.com/assets/kb/8154e7239cff0950.png)

#### Using AWS CLI:

Run the following command to list all security groups in your AWS region:

aws ec2 describe-security-groups --query 'SecurityGroups\[\*\].{ID:GroupId,Name:GroupName,Ingress:IpPermissions}'

1.  For each security group, check the inbound rules for any entries allowing ingress to ports 139 or 445 from 0.0.0.0/0 or ::/0.
    
2.  If such entries exist, they should be modified or removed.
    

### Implementation Plan:

#### Using AWS Console:

1.  Sign in to the AWS Management Console.
    
2.  Navigate to the EC2 dashboard
    

      ![](https://support.icompaas.com/assets/kb/603ec8e450006a41.png)

3.  go to Security Groups.
    

         ![](https://support.icompaas.com/assets/kb/46d50585ced3b2ae.png)

4.  Select each security group and review the Inbound Rules.
    

     ![](https://support.icompaas.com/assets/kb/d02d0cdd5267e2d8.png)

5.  If any rule allows ingress from 0.0.0.0/0 or ::/0 to ports 139 or 445:
    
    -   Click Edit inbound rules.
        

  ![](https://support.icompaas.com/assets/kb/027142ede76bc281.png)

-   Locate and delete the rule allowing access to these ports.
    

    ![](https://support.icompaas.com/assets/kb/bc22dd76305852cc.png)

-   Click Save rules.
    

  ![](https://support.icompaas.com/assets/kb/1e21936b1ac43456.png)

#### Using AWS CLI:

To revoke the ingress rule allowing access to ports 139 or 445 from 0.0.0.0/0, run:  

aws ec2 revoke-security-group-ingress --group-id <security-group-id> --protocol tcp --port 139 --cidr 0.0.0.0/0
aws ec2 revoke-security-group-ingress --group-id <security-group-id> --protocol tcp --port 445 --cidr 0.0.0.0/0

1.  Replace <security-group-id> with the ID of your security group.
    

### Backout Plan: 

If you restrict internet access to TCP ports 139 or 445 for EC2 instances but need to revert:

Using Console:

-   Go to EC2 > Security Groups.
    
-   Re-add inbound rules for ports 139 and 445, allowing 0.0.0.0/0 or ::/0 as the source.
    

Using CLI:

Use this command to re-add rules:

aws ec2 authorize-security-group-ingress \\
--group-id <security-group-id> \\
--protocol tcp \\
--port 139-445 \\
--cidr 0.0.0.0/0

### References:

-   Unrestricted Security Group Ingress on Uncommon Ports
    
-   Security group exposes risky ports to the internet
    
-   AWS EC2 instance allows public ingress access on SMB port 445
    

### **CIS Controls**

| **Version** | **Control ID** | **Control Description** | **IG1** | **IG2** | **IG3** |
| --- | --- | --- | --- | --- | --- |
| **v8** | **4.4** | Implement and manage a firewall on servers to restrict unauthorized access. | ● | ● | ● |
| **v8** | **4.5** | Protect network communications by encrypting sensitive data and restricting access to trusted IP ranges. | ● | ● | ● |
| **v8** | **13.4** | Manage network boundaries by implementing access controls such as firewalls and Security Groups. | ● | ● | ● |

## Related compliance guidance

- [SOC 2 compliance: a practical implementation guide for cloud-native SaaS teams](https://support.icompaas.com/compliance/soc-2-trust-services-criteria): Configuration checks like this one are the technical half of a SOC 2 / ISO 27001 programme — the guide shows where they fit, what else an auditor expects, and how to evidence them.
- [ISO/IEC 27001:2022 compliance: a practical implementation guide](https://support.icompaas.com/compliance/iso-27001-2022): ISO 27001 Annex A.8 (technological controls) is where cloud hardening evidence lands; the guide shows how to run the ISMS around it.
