Skip to content

Commit 5e14cf4

Browse files
authored
Merge pull request #724 from 0xdabbad00/check_access_analyzer_is_enabled
Check for access analyzer enabled
2 parents dbc20ce + b2e7727 commit 5e14cf4

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

audit_config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,10 @@ EC2_IMDSV2_NOT_ENFORCED:
376376
title: IMDSv2 not enforced
377377
description: The original metadata service that allows EC2s to assume IAM roles could allow an attacker to take over that role if they were able to find an SSRF vulnerability or proxy functionality on the instance. IMDSv2 should be enforced and not optional.
378378
severity: Medium
379-
group: EC2
379+
group: EC2
380+
381+
ACCESSANALYZER_OFF:
382+
title: Access Analyzer off
383+
description: Access Analyzer is a free service that can tell you when resources are public or shared with unexpected accounts.
384+
severity: Medium
385+
group: AccessAnalyzer

collect_commands.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,5 @@
394394
- Service: route53
395395
Request: list-hosted-zones-by-vpc
396396
Custom_collection: True
397+
- Service: accessanalyzer
398+
Request: list-analyzers

shared/audit.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ def audit_guardduty(findings, region):
208208
findings.add(Finding(region, "GUARDDUTY_OFF", None, None))
209209

210210

211+
def audit_accessanalyzer(findings, region):
212+
analyzer_list_json = query_aws(
213+
region.account, "accessanalzyer-list-analyzers", region
214+
)
215+
if not analyzer_list_json:
216+
# Access Analyzer must not exist in this region (or the collect data is old)
217+
return
218+
is_enabled = False
219+
for analyzer in analyzer_list_json["analyzers"]:
220+
if analyzer["status"] == "ACTIVE":
221+
is_enabled = True
222+
if not is_enabled:
223+
findings.add(Finding(region, "ACCESSANALYZER_OFF", None, None))
224+
225+
211226
def audit_iam(findings, region):
212227
# By calling the code to find the admins, we'll excercise the code that finds problems.
213228
find_admins_in_account(region, findings)
@@ -755,10 +770,10 @@ def audit_ec2(findings, region):
755770
if instance.get("State", {}).get("Name", "") == "terminated":
756771
# Ignore EC2's that are off
757772
continue
758-
773+
759774
# Check for IMDSv2 enforced
760-
if instance.get("MetadataOptions", {}).get('HttpEndpoint', '') == 'enabled':
761-
if instance["MetadataOptions"].get('HttpTokens', '') == 'optional':
775+
if instance.get("MetadataOptions", {}).get("HttpEndpoint", "") == "enabled":
776+
if instance["MetadataOptions"].get("HttpTokens", "") == "optional":
762777
findings.add(
763778
Finding(
764779
region,
@@ -771,7 +786,6 @@ def audit_ec2(findings, region):
771786
)
772787
)
773788

774-
775789
# Check for old instances
776790
if instance.get("LaunchTime", "") != "":
777791
MAX_RESOURCE_AGE_DAYS = 365
@@ -1120,6 +1134,7 @@ def audit(accounts):
11201134
audit_cloudfront(findings, region)
11211135
audit_s3_block_policy(findings, region)
11221136
audit_guardduty(findings, region)
1137+
audit_accessanalyzer(findings, region)
11231138
audit_ebs_snapshots(findings, region)
11241139
audit_rds_snapshots(findings, region)
11251140
audit_rds(findings, region)

0 commit comments

Comments
 (0)