elastic / detection-rules

https://www.elastic.co/guide/en/security/current/detection-engine-overview.html
Other
1.92k stars 492 forks source link

[New Rule] AWS IAM User or Role Created Cloudformation Stack for First Time #3923

Closed imays11 closed 2 months ago

imays11 commented 2 months ago

Issue link(s):

Summary - What I changed

This rule detects the first time a principal calls AWS Cloudwatch CreateStack or CreateStackSet API. Cloudformation is used to create a single collection of cloud resources called a stack, via a defined template file. An attacker with the appropriate privileges could leverage Cloudformation to create specific resources needed to further exploit the environment. This is a new terms rule that looks for the first instance of this behavior in the last 10 days for a role or IAM user within a particular account.

--

The fields chosen for new_terms is very intentional here. I needed to account for both Roles and IAM user types. The problem with Roles and new_terms is that there is a session_name attached to the role_name which is different every time a new session is created using that particular role. This means for fields like user.id or aws.cloudtrail.user_identity.arn, we can't isolate the role name itself, instead we are capturing the role name and the session name which will mean lots of false positives because every role.name+session.name combination will appear to be "new". I could utilize aws.cloudtrail.user_identity.session_context.session_issuer.arn if I were only concerned with capturing events from AssumedRoles, but since I want to capture events for long-term IAM users as well, this field won't work as it's only created when Roles are assumed. This leaves us with user.name field. The only problem here was that in an "Organization" there can be several different accounts with different cloud.account.ids all being monitored through the same Cloudtrail logs. IAM User and Role names can be duplicated across different accounts, which might create false positives if those logs are being ingested together. To correct for this I am using both user.name and cloud.account.id as the new_terms_fields value so that ideally this rule will trigger for the first time occurance of a unique role/user name + cloud.account.id combination.

Screenshot 2024-07-25 at 2 35 05 AM

Checklist

protectionsmachine commented 2 months ago

Rule: New - Guidelines

These guidelines serve as a reminder set of considerations when proposing a new rule.

Documentation and Context

Rule Metadata Checks

New BBR Rules

Testing and Validation