Skip to content

Commit e22f60f

Browse files
authored
[Tuning] AWS IAM Create User via Assumed Role on EC2 Instance (#5063)
- query change : I chose to replace `aws.cloudtrail.user_identity.arn` with `user.id` and a more accurate wildcard pattern. This will reduce the chances of this rule triggering for role sessions outside of those started by EC2 instances. The wildcard pattern looks for a role session name that starts with `i-` this is because when an EC2 instance operates using it's attached Role (instance profile), the session name attached to that role name is the instance id (`i-......`). The `user.id` field appends this session name to the role name via a standard pattern `:[session_name]`, making it a more reliable field to use in this case. - small edits to description and IG - reduced execution window - reduced history window - edited highlighted fields Note: the new_terms field here remains `aws.cloudtrail.user_identity.arn` because we are only interested in assumed roles, and even more particular, only those used by an EC2 instance. This means we want to evaluate each individual instance's behavior rather than the broader behavior of the role itself. The arn field will capture each instance id (session name) alongside the role itself.
1 parent e60c345 commit e22f60f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

rules/integrations/aws/persistence_iam_create_user_via_assumed_role_on_ec2_instance.toml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
creation_date = "2024/11/04"
33
integration = ["aws"]
44
maturity = "production"
5-
updated_date = "2025/01/17"
5+
updated_date = "2025/09/04"
66

77
[rule]
88
author = ["Elastic"]
99
description = """
1010
Detects the creation of an AWS Identity and Access Management (IAM) user initiated by an assumed role on an EC2
1111
instance. Assumed roles allow users or services to temporarily adopt different AWS permissions, but the creation of IAM
12-
users through these rolesparticularly from within EC2 instancesmay indicate a compromised instance. Adversaries might
12+
users through these roles, particularly from within EC2 instances, may indicate a compromised instance. Adversaries might
1313
exploit such permissions to establish persistence by creating new IAM users under unauthorized conditions.
1414
"""
1515
false_positives = [
@@ -20,7 +20,7 @@ false_positives = [
2020
review.
2121
""",
2222
]
23-
from = "now-9m"
23+
from = "now-6m"
2424
index = ["filebeat-*", "logs-aws.cloudtrail-*"]
2525
language = "kuery"
2626
license = "Elastic License v2"
@@ -35,15 +35,14 @@ This rule detects when an AWS Identity and Access Management (IAM) user is creat
3535
3636
- **Identify the Assumed Role and Initiating Instance**:
3737
- **Role and Instance**: Examine the `aws.cloudtrail.user_identity.arn` field to determine the specific EC2 instance and role used for this action (e.g., `arn:aws:sts::[account-id]:assumed-role/[role-name]/[instance-id]`). Verify if this behavior aligns with expected usage or represents an anomaly.
38-
- **Session Context**: Check the `session_issuer` fields in `aws.cloudtrail.user_identity.session_context` for details about the role assumed by the instance, along with `mfa_authenticated` to determine if Multi-Factor Authentication (MFA) was used.
3938
4039
- **Analyze the Target IAM User**:
41-
- **New User Details**: Inspect `aws.cloudtrail.flattened.request_parameters.userName` to see the username that was created. Look at `aws.cloudtrail.flattened.response_elements.user.userName` for confirmation of successful user creation, and validate if the user is expected or authorized.
40+
- **New User Details**: Inspect `aws.cloudtrail.request_parameters` to see the username that was created. Validate if the user is expected or authorized.
4241
- **Review Creation Time and Context**: Compare the creation time (`@timestamp`) of the user with other activities from the same instance and role to assess if this creation was part of a larger chain of actions.
4342
4443
- **Check User Agent and Tooling**:
4544
- **User Agent Analysis**: Review `user_agent.original` to see if AWS CLI, SDK, or other tooling was used for this request. Identifiers such as `aws-cli`, `boto3`, or similar SDK names can indicate the method used, which may differentiate automation from interactive actions.
46-
- **Source IP and Location**: Use the `source.address` and `source.geo` fields to identify the IP address and geographic location of the event. Verify if this aligns with expected access patterns for your environment.
45+
- **Source IP and Location**: Use the `source.ip` and `source.geo` fields to identify the IP address and geographic location of the event. Verify if this aligns with expected access patterns for your environment.
4746
4847
- **Evaluate for Persistence Indicators**:
4948
- **Role Permissions**: Check the permissions associated with the assumed role (`arn:aws:iam::[account-id]:role/[role-name]`) to determine if creating IAM users is a legitimate activity for this role.
@@ -56,7 +55,7 @@ This rule detects when an AWS Identity and Access Management (IAM) user is creat
5655
### False Positive Analysis
5756
5857
- **Expected Automation**: Assumed roles may be used by legitimate automated systems that create users for specific workflows. Confirm if this event aligns with known automation activities.
59-
- **User Agent and Role Exceptions**: If this action is routine for specific roles or user agents (e.g., `aws-cli`, `boto3`), consider adding those roles or user agents to a monitored exception list for streamlined review.
58+
- **Role Exceptions**: If this action is routine for specific roles, consider adding those roles to a monitored exception list for streamlined review.
6059
6160
### Response and Remediation
6261
@@ -94,24 +93,27 @@ event.dataset: "aws.cloudtrail"
9493
and event.action: "CreateUser"
9594
and event.outcome: "success"
9695
and aws.cloudtrail.user_identity.type: "AssumedRole"
97-
and aws.cloudtrail.user_identity.arn: *i-*
96+
and user.id: *\:i-*
9897
'''
9998

10099
[rule.investigation_fields]
101100
field_names = [
102101
"@timestamp",
103102
"user.name",
104-
"source.address",
103+
"user_agent.original",
104+
"source.ip",
105105
"aws.cloudtrail.user_identity.arn",
106106
"aws.cloudtrail.user_identity.type",
107-
"user_agent.original",
107+
"aws.cloudtrail.user_identity.access_key_id",
108108
"event.action",
109109
"event.outcome",
110+
"cloud.account.id",
110111
"cloud.region",
111112
"aws.cloudtrail.request_parameters",
112113
"aws.cloudtrail.response_elements"
113114
]
114115

116+
115117
[[rule.threat]]
116118
framework = "MITRE ATT&CK"
117119
[[rule.threat.technique]]
@@ -135,6 +137,6 @@ field = "new_terms_fields"
135137
value = ["aws.cloudtrail.user_identity.arn"]
136138
[[rule.new_terms.history_window_start]]
137139
field = "history_window_start"
138-
value = "now-14d"
140+
value = "now-10d"
139141

140142

0 commit comments

Comments
 (0)