turbot/steampipe-mod-aws-compliance

Control: 5.2 Ensure no Network ACLs allow ingress from 0.0.0.0/0 to remote server administration ports

Description

The Network Access Control List (NACL) function provides stateless filtering of ingress and egress network traffic to AWS resources. It is recommended that no NACL 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.

Remediation

From Console:

Perform the following steps to remediate a network ACL:

  1. Login to the AWS VPC Console at https://console.aws.amazon.com/vpc/home.
  2. In the left pane, click Network ACLs.
  3. For each network ACL that needs remediation, perform the following:
    • Select the network ACL.
    • Click the Inbound Rules tab.
    • Click Edit inbound rules.
    • 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.

Usage

Run the control in your terminal:

powerpipe control run aws_compliance.control.cis_v400_5_2

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run aws_compliance.control.cis_v400_5_2 --share

SQL

This control uses a named query:

with bad_rules as (
select
network_acl_id,
count(*) as num_bad_rules,
tags,
region,
account_id
from
aws_vpc_network_acl,
jsonb_array_elements(entries) as att
where
att ->> 'Egress' = 'false' -- as per aws egress = false indicates the ingress
and (
att ->> 'CidrBlock' = '0.0.0.0/0'
or att ->> 'Ipv6CidrBlock' = '::/0'
)
and att ->> 'RuleAction' = 'allow'
and (
(
att ->> 'Protocol' = '-1' -- all traffic
and att ->> 'PortRange' is null
)
or (
(att -> 'PortRange' ->> 'From') :: int <= 22
and (att -> 'PortRange' ->> 'To') :: int >= 22
and att ->> 'Protocol' in('6', '17') -- TCP or UDP
)
or (
(att -> 'PortRange' ->> 'From') :: int <= 3389
and (att -> 'PortRange' ->> 'To') :: int >= 3389
and att ->> 'Protocol' in('6', '17') -- TCP or UDP
)
)
group by
network_acl_id,
region,
account_id,
tags
order by
network_acl_id,
region,
account_id,
tags
),
aws_vpc_network_acls as (
select
network_acl_id,
tags,
partition,
region,
account_id
from
aws_vpc_network_acl
order by
network_acl_id,
region,
account_id
)
select
'arn:' || acl.partition || ':ec2:' || acl.region || ':' || acl.account_id || ':network-acl/' || acl.network_acl_id as resource,
case
when bad_rules.network_acl_id is null then 'ok'
else 'alarm'
end as status,
case
when bad_rules.network_acl_id is null then acl.network_acl_id || ' does not allow ingress to port 22 or 3389 from 0.0.0.0/0 or ::/0.'
else acl.network_acl_id || ' contains ' || bad_rules.num_bad_rules || ' rule(s) allowing ingress to port 22 or 3389 from 0.0.0.0/0 or ::/0.'
end as reason
, acl.region, acl.account_id
from
aws_vpc_network_acls as acl
left join bad_rules on bad_rules.network_acl_id = acl.network_acl_id;

Tags