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 rules] AWS IAM AdministratorAccess Policy Attached to : User, Group, Role(es|ql) #3735

Merged

Conversation

imays11
Copy link
Contributor

@imays11 imays11 commented May 31, 2024

Issues

Summary

Identifies the use of iam:AttachUserPolicy, iam:AttachGroupPolicy, and iam:AttachRolePolicy API functions, which are used to attach user policies to user accounts, groups and roles in AWS. Specifically, these rules use ES|QL to dissect the aws.cloudtrail.request_parameters field to isolate the policyName and alert on the AdministrativeAccess AWS managed policy, which grants an identity full administrative access over all AWS services and resources. While there are legitimate use-cases, such highly privileged access should be closely monitored and any usage of this policy should be verified for validity.

AttachUserPolicy

Screenshot AttachUserPolicy

AttachGroupPolicy

Screenshot AttachGroupPolicy

AttachRolePolicy

Screenshot AttachRolePolicy

@imays11 imays11 added Integration: AWS AWS related rules Domain: Cloud Rule: New Proposal for new rule labels May 31, 2024
@imays11 imays11 self-assigned this May 31, 2024
@imays11 imays11 marked this pull request as draft May 31, 2024 17:41
@imays11 imays11 changed the title [New rule] AWS IAM AdministratorAccess Policy Attached to User (es|ql) [New rules] AWS IAM AdministratorAccess Policy Attached to : User, Group, Role, new User(es|ql) May 31, 2024
@imays11 imays11 changed the title [New rules] AWS IAM AdministratorAccess Policy Attached to : User, Group, Role, new User(es|ql) [New rules] AWS IAM AdministratorAccess Policy Attached to : User, Group, Role(es|ql) May 31, 2024
@imays11 imays11 marked this pull request as ready for review May 31, 2024 21:25
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.

LGTM, nice ES|QL work!

Co-authored-by: Ruben Groenewoud <78494512+Aegrah@users.noreply.github.com>
Comment on lines +102 to +107
from logs-aws.cloudtrail-*
| where event.provider == "iam.amazonaws.com" and event.action == "AttachUserPolicy" and event.outcome == "success"
| dissect aws.cloudtrail.request_parameters "{%{?policyArn}=%{?arn}:%{?aws}:%{?iam}::%{?aws}:%{?policy}/%{policyName},%{?userName}=%{target.userName}}"
| where policyName == "AdministratorAccess"
| keep @timestamp, aws.cloudtrail.user_identity.arn, aws.cloudtrail.user_identity.access_key_id, event.action, policyName, target.userName, user_agent.original, source.address, source.geo.location
| sort aws.cloudtrail.user_identity.arn
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on collapsing into one rule with a query like the following?

from logs-aws.cloudtrail-*
| where event.provider == "iam.amazonaws.com" and event.action in ("AttachUserPolicy", "AttachRolePolicy", "AttachGroupPolicy") and event.outcome == "success"
| where aws.cloudtrail.request_parameters rlike "(.*)AdministratorAccess(.*)"
| keep @timestamp, aws.cloudtrail.user_identity.arn, aws.cloudtrail.user_identity.access_key_id, event.action, aws.cloudtrail.request_parameters, user_agent.original, source.address, source.geo.location
| sort aws.cloudtrail.user_identity.arn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did consider this and thought keeping them seperate may be better for clients to disable or add exclusions if needed since all 3 have slightly different use-cases. For example, I could see the creation of roles with AdministratorAccess being used as a safer method when necessary since those requested credentials are temporary, vs. granting individual users the AdministratorAccess policy with long-standing credentials. In this case someone may want to disable the AttachRolePolicy rule but keep the AttachUserPolicy.

Copy link
Contributor

@terrancedejesus terrancedejesus left a comment

Choose a reason for hiding this comment

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

Approving. Left a comment about potentially collapsing into one rule. Your call, but these are great additions!

@imays11 imays11 merged commit e1cbf9f into main Jun 7, 2024
9 checks passed
@imays11 imays11 deleted the new_rule_aws_iam_administratoraccess_policy_attached_to_user branch June 7, 2024 22:31
protectionsmachine pushed a commit that referenced this pull request Jun 7, 2024
…oup, Role(es|ql) (#3735)

* [New Rule] AWS IAM AdministratorAccess Policy Attached to User

issue...

* add source.address and source.geo.location

* fix threat tactic ids

* AdministratorAccess Policy Attached to Group

* AdminstratoAccess Policy Attached to Role

* reduce severity to medium

Co-authored-by: Ruben Groenewoud <78494512+Aegrah@users.noreply.github.com>

---------

Co-authored-by: Ruben Groenewoud <78494512+Aegrah@users.noreply.github.com>

(cherry picked from commit e1cbf9f)
protectionsmachine pushed a commit that referenced this pull request Jun 7, 2024
…oup, Role(es|ql) (#3735)

* [New Rule] AWS IAM AdministratorAccess Policy Attached to User

issue...

* add source.address and source.geo.location

* fix threat tactic ids

* AdministratorAccess Policy Attached to Group

* AdminstratoAccess Policy Attached to Role

* reduce severity to medium

Co-authored-by: Ruben Groenewoud <78494512+Aegrah@users.noreply.github.com>

---------

Co-authored-by: Ruben Groenewoud <78494512+Aegrah@users.noreply.github.com>

(cherry picked from commit e1cbf9f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants