Skip to content

Commit 1c9177e

Browse files
[New Rule] Adding Coverage for AWS IAM Create User via Assumed Role 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
1 parent d5f36b3 commit 1c9177e

File tree

2 files changed

+171
-20
lines changed

2 files changed

+171
-20
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
[metadata]
2+
creation_date = "2024/11/04"
3+
integration = ["aws"]
4+
maturity = "production"
5+
updated_date = "2024/11/04"
6+
7+
[rule]
8+
author = ["Elastic"]
9+
description = """
10+
Detects the creation of an AWS Identity and Access Management (IAM) user initiated by an assumed role on an EC2
11+
instance. Assumed roles allow users or services to temporarily adopt different AWS permissions, but the creation of IAM
12+
users through these roles—particularly from within EC2 instances—may indicate a compromised instance. Adversaries might
13+
exploit such permissions to establish persistence by creating new IAM users under unauthorized conditions.
14+
"""
15+
false_positives = [
16+
"""
17+
Assumed roles may be used by legitimate automated systems to create IAM users for specific workflows. Verify if this
18+
event aligns with known automation activities. If the action is routine for specific roles or user agents (e.g.,
19+
`aws-cli`, `boto3`), consider adding those roles or user agents to a monitored exception list for streamlined
20+
review.
21+
""",
22+
]
23+
from = "now-9m"
24+
index = ["filebeat-*", "logs-aws.cloudtrail-*"]
25+
language = "kuery"
26+
license = "Elastic License v2"
27+
name = "AWS IAM Create User via Assumed Role on EC2 Instance"
28+
note = """## Triage and Analysis
29+
30+
### Investigating AWS IAM User Creation via Assumed Role on an EC2 Instance
31+
32+
This rule detects when an AWS Identity and Access Management (IAM) user is created through an assumed role on an EC2 instance. This action may indicate a potentially compromised instance where an adversary could be using the instance’s permissions to create a new IAM user, enabling persistent unauthorized access.
33+
34+
#### Possible Investigation Steps
35+
36+
- **Identify the Assumed Role and Initiating Instance**:
37+
- **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.
39+
40+
- **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.
42+
- **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.
43+
44+
- **Check User Agent and Tooling**:
45+
- **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.
47+
48+
- **Evaluate for Persistence Indicators**:
49+
- **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.
50+
- **Automated Role Patterns**: If the assumed role or instance typically creates IAM users for automation purposes, validate this action against historical records to confirm if the event is consistent with normal patterns.
51+
52+
- **Review Related CloudTrail Events**:
53+
- **Additional IAM Actions**: Investigate for other recent IAM or CloudTrail events tied to this role or instance, especially `CreateAccessKey` or `AttachUserPolicy` actions. These could signal further attempts to empower or utilize the newly created user.
54+
- **Correlate with Other Suspicious Activities**: Determine if other roles or instances recently initiated similar unusual actions, such as privilege escalations or data access.
55+
56+
### False Positive Analysis
57+
58+
- **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.
60+
61+
### Response and Remediation
62+
63+
- **Immediate Access Review**: If user creation was unauthorized, restrict the assumed role’s permissions to prevent further user creation.
64+
- **Delete Unauthorized Users**: Confirm and remove any unauthorized IAM users, adjusting IAM policies to reduce similar risks.
65+
- **Enhance Monitoring and Alerts**: Enable enhanced logging or real-time alerts for this role or instance to detect further unauthorized access attempts.
66+
- **Policy Update**: Consider updating IAM policies associated with roles on EC2 instances to limit sensitive actions like IAM user creation.
67+
68+
### Additional Information
69+
70+
For further guidance on managing IAM roles and permissions within AWS environments, refer to the [AWS IAM documentation](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateUser.html) and AWS best practices for security.
71+
"""
72+
references = [
73+
"https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateUser.html",
74+
"https://www.dionach.com/en-us/breaking-into-the-cloud-red-team-tactics-for-aws-compromise/",
75+
]
76+
risk_score = 47
77+
rule_id = "f7a1c536-9ac0-11ef-9911-f661ea17fbcd"
78+
severity = "medium"
79+
tags = [
80+
"Domain: Cloud",
81+
"Data Source: AWS",
82+
"Data Source: Amazon Web Services",
83+
"Data Source: AWS IAM",
84+
"Use Case: Identity and Access Audit",
85+
"Tactic: Persistence",
86+
]
87+
timestamp_override = "event.ingested"
88+
type = "new_terms"
89+
90+
query = '''
91+
event.dataset: "aws.cloudtrail"
92+
and event.provider: "iam.amazonaws.com"
93+
and event.action: "CreateUser"
94+
and event.outcome: "success"
95+
and aws.cloudtrail.user_identity.type: "AssumedRole"
96+
and aws.cloudtrail.user_identity.arn: *i-*
97+
'''
98+
99+
100+
[[rule.threat]]
101+
framework = "MITRE ATT&CK"
102+
[[rule.threat.technique]]
103+
id = "T1136"
104+
name = "Create Account"
105+
reference = "https://attack.mitre.org/techniques/T1136/"
106+
[[rule.threat.technique.subtechnique]]
107+
id = "T1136.003"
108+
name = "Cloud Account"
109+
reference = "https://attack.mitre.org/techniques/T1136/003/"
110+
111+
112+
113+
[rule.threat.tactic]
114+
id = "TA0003"
115+
name = "Persistence"
116+
reference = "https://attack.mitre.org/tactics/TA0003/"
117+
118+
[rule.new_terms]
119+
field = "new_terms_fields"
120+
value = ["aws.cloudtrail.user_identity.arn"]
121+
[[rule.new_terms.history_window_start]]
122+
field = "history_window_start"
123+
value = "now-14d"
124+
125+

rules/integrations/aws/persistence_ec2_instance_request_to_iam_service.toml renamed to rules_building_block/persistence_iam_instance_request_to_iam_service.toml

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
[metadata]
2+
bypass_bbr_timing = true
23
creation_date = "2024/07/24"
34
integration = ["aws"]
45
maturity = "production"
5-
updated_date = "2024/07/24"
6+
updated_date = "2024/11/05"
67

78
[rule]
89
author = ["Elastic"]
10+
building_block_type = "default"
911
description = """
10-
Identifies when an EC2 instance interacts with the AWS IAM service via an assumed role. This is uncommon behavior and could indicate an attacker using compromised credentials to further exploit an environment. For example, an assumed role could be used to create new users for persistence or add permissions for privilege escalation. An EC2 instance assumes a role using their EC2 ID as the session name. This rule looks for the pattern "i-" which is the beginning pattern for assumed role sessions started by an EC2 instance.
12+
Identifies when an EC2 instance interacts with the AWS IAM service via an assumed role. This is uncommon behavior and
13+
could indicate an attacker using compromised credentials to further exploit an environment. For example, an assumed role
14+
could be used to create new users for persistence or add permissions for privilege escalation. An EC2 instance assumes a
15+
role using their EC2 ID as the session name. This rule looks for the pattern "i-" which is the beginning pattern for
16+
assumed role sessions started by an EC2 instance. This is a [building
17+
block](https://www.elastic.co/guide/en/security/current/building-block-rule.html) rule and does not generate alerts on
18+
its own. It is meant to be used for correlation with other rules to detect suspicious activity.
1119
"""
12-
false_positives = ["Administrators may use EC2 instances to interact with IAM services as part of an automation workflow, ensure validity of the triggered event and include exceptions where necessary."]
20+
false_positives = [
21+
"""
22+
Administrators may use EC2 instances to interact with IAM services as part of an automation workflow, ensure
23+
validity of the triggered event and include exceptions where necessary.
24+
""",
25+
]
1326
from = "now-6m"
1427
index = ["filebeat-*", "logs-aws.cloudtrail-*"]
1528
language = "eql"
1629
license = "Elastic License v2"
1730
name = "AWS EC2 Instance Interaction with IAM Service"
18-
references = [
19-
"https://redcanary.com/blog/aws-sts/",
20-
]
21-
risk_score = 47
31+
references = ["https://redcanary.com/blog/aws-sts/"]
32+
risk_score = 21
2233
rule_id = "a44bcb58-5109-4870-a7c6-11f5fe7dd4b1"
23-
severity = "medium"
34+
severity = "low"
2435
tags = [
2536
"Domain: Cloud",
2637
"Data Source: AWS",
@@ -30,20 +41,42 @@ tags = [
3041
"Use Case: Identity and Access Audit",
3142
"Tactic: Privilege Escalation",
3243
"Tactic: Persistence",
44+
"Rule Type: BBR",
3345
]
3446
timestamp_override = "event.ingested"
3547
type = "eql"
3648

3749
query = '''
3850
any where event.dataset == "aws.cloudtrail"
39-
and event.provider == "iam.amazonaws.com"
40-
and aws.cloudtrail.user_identity.type == "AssumedRole"
41-
and stringContains (user.id, ":i-")
51+
and event.provider == "iam.amazonaws.com"
52+
and aws.cloudtrail.user_identity.type == "AssumedRole"
53+
and stringContains(user.id, ":i-")
54+
and (
55+
startsWith(event.action, "Update")
56+
or startsWith(event.action, "Attach")
57+
or startsWith(event.action, "Detach")
58+
or startsWith(event.action, "Create")
59+
or startsWith(event.action, "Delete")
60+
or startsWith(event.action, "Add")
61+
or startsWith(event.action, "Remove")
62+
or startsWith(event.action, "Put")
63+
or startsWith(event.action, "Tag")
64+
)
4265
'''
4366

4467

4568
[[rule.threat]]
4669
framework = "MITRE ATT&CK"
70+
[[rule.threat.technique]]
71+
id = "T1078"
72+
name = "Valid Accounts"
73+
reference = "https://attack.mitre.org/techniques/T1078/"
74+
[[rule.threat.technique.subtechnique]]
75+
id = "T1078.004"
76+
name = "Cloud Accounts"
77+
reference = "https://attack.mitre.org/techniques/T1078/004/"
78+
79+
4780
[[rule.threat.technique]]
4881
id = "T1098"
4982
name = "Account Manipulation"
@@ -52,25 +85,18 @@ reference = "https://attack.mitre.org/techniques/T1098/"
5285
id = "T1098.001"
5386
name = "Additional Cloud Credentials"
5487
reference = "https://attack.mitre.org/techniques/T1098/001/"
88+
5589
[[rule.threat.technique.subtechnique]]
5690
id = "T1098.003"
5791
name = "Additional Cloud Roles"
5892
reference = "https://attack.mitre.org/techniques/T1098/003/"
5993

60-
[[rule.threat.technique]]
61-
id = "T1078"
62-
name = "Valid Accounts"
63-
reference = "https://attack.mitre.org/techniques/T1078/"
64-
[[rule.threat.technique.subtechnique]]
65-
id = "T1078.004"
66-
name = "Cloud Accounts"
67-
reference = "https://attack.mitre.org/techniques/T1078/004/"
94+
6895

6996
[rule.threat.tactic]
7097
id = "TA0003"
7198
name = "Persistence"
7299
reference = "https://attack.mitre.org/tactics/TA0003/"
73-
74100
[[rule.threat]]
75101
framework = "MITRE ATT&CK"
76102

0 commit comments

Comments
 (0)