id: nacl-open-inbound
info:
  name: Open Inbound NACL Traffic
  author: princechaddha
  severity: medium
  description: |
    Checks for Amazon VPC Network ACLs with inbound rules allowing traffic from all IPs across all ports, increasing the risk of unauthorized access.
  impact: |
    Allows unrestricted access to resources within the subnet, potentially exposing sensitive data or services to unauthorized users.
  remediation: |
    Restrict Network ACL inbound rules to only allow necessary IP ranges and ports as per the Principle of Least Privilege.
  reference:
    - https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html
  metadata:
    max-request: 2
  tags: cloud,devops,aws,amazon,vpc,aws-cloud-config
variables:
  region: "us-east-1"

flow: |
  code(1)
  for(let NACLIDs of iterate(template.nacls)){
    set("naclid", NACLIDs)
    code(2)
  }

self-contained: true
code:
  - engine:
      - sh
      - bash
    source: |
      aws ec2 describe-network-acls --region $region --query 'NetworkAcls[*].NetworkAclId' --output json

    extractors:
      - type: json
        name: nacls
        internal: true
        json:
          - '.[]'

  - engine:
      - sh
      - bash
    source: |
         aws ec2 describe-network-acls --region $region --network-acl-ids $naclid --query 'NetworkAcls[*].Entries[?(RuleAction==`allow`) && (Egress==`false`)] | []'

    matchers-condition: and
    matchers:
      - type: word
        words:
          - "allow"
        condition: and

      - type: word
        words:
          - "PortRange"
        negative: true

    extractors:
      - type: dsl
        dsl:
          - '"Access to the VPC subnets associated with your NACL " + naclid + " is not restricted."'
# digest: 4a0a00473045022038258a9ed742e00db36fcc2c517562a509834fddfd0ff2f229c0de8ce3d93038022100f1b4b3278f9e9987c7aa831106f107e16c7053eff871cc90f2cd512eda8671d1:922c64590222798bb761d5b6d8e72950