Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Rule] Adding Coverage for AWS IAM Create User via Assumed Role on EC2 Instance #4244

Merged

Conversation

terrancedejesus
Copy link
Contributor

@terrancedejesus terrancedejesus commented Nov 4, 2024

Pull Request

Issue link(s):

Summary - What I changed

Adding detection coverage for AWS IAM Create User via Assumed Role on EC2 Instance.

Detects the creation of an AWS Identity and Access Management (IAM) user initiated by an assumed role on an EC2 instance. Assumed roles allow users or services to temporarily adopt different AWS permissions, but the creation of IAM users through these roles—particularly from within EC2 instances—may indicate a compromised instance. Adversaries might exploit such permissions to establish persistence by creating new IAM users under unauthorized conditions.

Additional information:

  • AssumedRole identity in AWS typically have pre-determined permissions via policies attached by IAM admins. These can be custom permission policies or default via AWS. If PLoP is not practiced, for example, iam:*, adversaries whom land on that EC2 instance can use native AWS-CLI to create users and even attach policies. It is more common and best practices to create users via IAM console in AWS or remotely by an admin.
  • i- in aws.cloudtrail.user_identity.arn helps distinguish where the user was created from, specifically an EC2 instance.

Note

This rule is a New Terms rule to reduce potential false-positives where it may be common for users to be added by an admin or programmatically on an EC2 instance. However, this is still rather unusual and should be investigated.

How To Test

Screenshot 2024-11-04 at 10 55 43 AM

Checklist

  • Added a label for the type of pr: bug, enhancement, schema, Rule: New, Rule: Deprecation, Rule: Tuning, Hunt: New, or Hunt: Tuning so guidelines can be generated
  • Added the meta:rapid-merge label if planning to merge within 24 hours
  • Secret and sensitive material has been managed correctly
  • Automated testing was updated or added to match the most common scenarios
  • Documentation and comments were added for features that require explanation

Contributor checklist

@terrancedejesus terrancedejesus added Integration: AWS AWS related rules Domain: Cloud Rule: New Proposal for new rule labels Nov 4, 2024
@terrancedejesus terrancedejesus self-assigned this Nov 4, 2024
@protectionsmachine
Copy link
Collaborator

Rule: New - Guidelines

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

Documentation and Context

  • Detailed description of the rule.
  • List any new fields required in ECS/data sources.
  • Link related issues or PRs.
  • Include references.

Rule Metadata Checks

  • creation_date matches the date of creation PR initially merged.
  • min_stack_version should support the widest stack versions.
  • name and description should be descriptive and not include typos.
  • query should be inclusive, not overly exclusive, considering performance for diverse environments. Non ecs fields should be added to non-ecs-schema.json if not available in an integration.
  • min_stack_comments and min_stack_version should be included if the rule is only compatible starting from a specific stack version.
  • index pattern should be neither too specific nor too vague, ensuring it accurately matches the relevant data stream (e.g., use logs-endpoint.process-* for process data).
  • integration should align with the index. If the integration is newly introduced, ensure the manifest, schemas, and new_rule.yaml template are updated.
  • setup should include the necessary steps to configure the integration.
  • note should include any additional information (e.g. Triage and analysis investigation guides, timeline templates).
  • tags should be relevant to the threat and align/added to the EXPECTED_RULE_TAGS in the definitions.py file.
  • threat, techniques, and subtechniques should map to ATT&CK always if possible.

New BBR Rules

  • building_block_type should be included if the rule is a building block and the rule should be located in the rules_building_block folder.
  • bypass_bbr_timing should be included if adding custom lookback timing to the rule.

Testing and Validation

  • Provide evidence of testing and detecting the expected threat.
  • Check for existence of coverage to prevent duplication.

@terrancedejesus terrancedejesus marked this pull request as ready for review November 4, 2024 16:00
@imays11
Copy link
Contributor

imays11 commented Nov 5, 2024

This existing rule covers this behavior but is very noisy. Perhaps instead of creating a new rule here we can tune the existing one to either exclude the more noisy iam event.actions like GetRole SimulatePrincipalPolicy GetPolicyVersion, etc. (these 3 make up 61% of alerts in telemetry). Or we could only include the more suspicious and dangerous iam event.actions like CreateUser CreateAccessKey AttachUserPolicy etc.

Copy link
Contributor

@Aegrah Aegrah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule looks good to me, however, might be good to address @imays11 comment, as tuning a rule to add additional coverage might be a better approach than adding a new rule!

@terrancedejesus
Copy link
Contributor Author

This existing rule covers this behavior but is very noisy. Perhaps instead of creating a new rule here we can tune the existing one to either exclude the more noisy iam event.actions like GetRole SimulatePrincipalPolicy GetPolicyVersion, etc. (these 3 make up 61% of alerts in telemetry). Or we could only include the more suspicious and dangerous iam event.actions like CreateUser CreateAccessKey AttachUserPolicy etc.

@imays11 thank you for taking the time to discuss this morning. Our solution moving forward is to adjust the existing rule you mentioned to be a BBR and modify the filters to focus on IAM changes via event action. The purpose is to be able to at least document anytime an assumed role from an EC2 instance makes changes to IAM resources. We will then move forward with creating this rule as a specific threat-centric scenario.

@botelastic botelastic bot added the bbr Building Block Rules label Nov 5, 2024
Copy link
Contributor

@imays11 imays11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@terrancedejesus terrancedejesus added the Rule: Tuning tweaking or tuning an existing rule label Nov 6, 2024
@terrancedejesus terrancedejesus merged commit 1c9177e into main Nov 6, 2024
13 checks passed
@terrancedejesus terrancedejesus deleted the new-rule-aws-user-created-from-assumed-role-via-cli branch November 6, 2024 16:28
protectionsmachine pushed a commit that referenced this pull request Nov 6, 2024
…on EC2 Instance` (#4244)

* adding new rule 'AWS IAM Create User via Assumed Role on EC2 Instance'

* adding false-positive note

* changed file name

* added event.provider

* tuned 'AWS EC2 Instance Interaction with IAM Service' to be BBR

* updated query

* added BBR tag

* moved rule to BBR

* fixed BBR query

* moved rule to BBR

(cherry picked from commit 1c9177e)
protectionsmachine pushed a commit that referenced this pull request Nov 6, 2024
…on EC2 Instance` (#4244)

* adding new rule 'AWS IAM Create User via Assumed Role on EC2 Instance'

* adding false-positive note

* changed file name

* added event.provider

* tuned 'AWS EC2 Instance Interaction with IAM Service' to be BBR

* updated query

* added BBR tag

* moved rule to BBR

* fixed BBR query

* moved rule to BBR

(cherry picked from commit 1c9177e)
protectionsmachine pushed a commit that referenced this pull request Nov 6, 2024
…on EC2 Instance` (#4244)

* adding new rule 'AWS IAM Create User via Assumed Role on EC2 Instance'

* adding false-positive note

* changed file name

* added event.provider

* tuned 'AWS EC2 Instance Interaction with IAM Service' to be BBR

* updated query

* added BBR tag

* moved rule to BBR

* fixed BBR query

* moved rule to BBR

(cherry picked from commit 1c9177e)
protectionsmachine pushed a commit that referenced this pull request Nov 6, 2024
…on EC2 Instance` (#4244)

* adding new rule 'AWS IAM Create User via Assumed Role on EC2 Instance'

* adding false-positive note

* changed file name

* added event.provider

* tuned 'AWS EC2 Instance Interaction with IAM Service' to be BBR

* updated query

* added BBR tag

* moved rule to BBR

* fixed BBR query

* moved rule to BBR

(cherry picked from commit 1c9177e)
protectionsmachine pushed a commit that referenced this pull request Nov 6, 2024
…on EC2 Instance` (#4244)

* adding new rule 'AWS IAM Create User via Assumed Role on EC2 Instance'

* adding false-positive note

* changed file name

* added event.provider

* tuned 'AWS EC2 Instance Interaction with IAM Service' to be BBR

* updated query

* added BBR tag

* moved rule to BBR

* fixed BBR query

* moved rule to BBR

(cherry picked from commit 1c9177e)
protectionsmachine pushed a commit that referenced this pull request Nov 6, 2024
…on EC2 Instance` (#4244)

* adding new rule 'AWS IAM Create User via Assumed Role on EC2 Instance'

* adding false-positive note

* changed file name

* added event.provider

* tuned 'AWS EC2 Instance Interaction with IAM Service' to be BBR

* updated query

* added BBR tag

* moved rule to BBR

* fixed BBR query

* moved rule to BBR

(cherry picked from commit 1c9177e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport: auto bbr Building Block Rules Domain: Cloud Integration: AWS AWS related rules Rule: New Proposal for new rule Rule: Tuning tweaking or tuning an existing rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants