Skip to content

Commit cb65614

Browse files
removing 'AWS EC2 Instance Interaction with IAM Service' rule tuning
1 parent ab5f491 commit cb65614

File tree

1 file changed

+24
-102
lines changed

1 file changed

+24
-102
lines changed

rules/integrations/aws/persistence_ec2_instance_request_to_iam_service.toml

Lines changed: 24 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,132 +2,48 @@
22
creation_date = "2024/07/24"
33
integration = ["aws"]
44
maturity = "production"
5-
updated_date = "2024/11/04"
5+
updated_date = "2024/07/24"
66

77
[rule]
88
author = ["Elastic"]
99
description = """
10-
Identifies when an EC2 instance interacts with the AWS IAM service via an assumed role. This is uncommon behavior and
11-
could indicate an attacker using compromised credentials to further exploit an environment. For example, an assumed role
12-
could be used to create new users for persistence or add permissions for privilege escalation. An EC2 instance assumes a
13-
role using their EC2 ID as the session name. This rule looks for the pattern "i-" which is the beginning pattern for
14-
assumed role sessions started by an EC2 instance.
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.
1511
"""
16-
false_positives = [
17-
"""
18-
Administrators may use EC2 instances to interact with IAM services as part of an automation workflow, ensure
19-
validity of the triggered event and include exceptions where necessary.
20-
""",
21-
]
22-
from = "now-9m"
23-
language = "esql"
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."]
13+
from = "now-6m"
14+
index = ["filebeat-*", "logs-aws.cloudtrail-*"]
15+
language = "eql"
2416
license = "Elastic License v2"
2517
name = "AWS EC2 Instance Interaction with IAM Service"
26-
note = """## Triage and Analysis
27-
28-
### Investigating AWS EC2 Instance Interaction with IAM Service via Assumed Role
29-
30-
This detection rule identifies instances where an EC2 instance interacts with AWS IAM services through an assumed role. This type of activity is unusual and may indicate that an attacker is attempting to further exploit the environment using compromised EC2 instance credentials. Potentially, an attacker could use this access to escalate privileges or create new users and roles for persistence.
31-
32-
#### Possible Investigation Steps
33-
34-
- **Examine the Assumed Role and Initiating Instance**:
35-
- **Role and Instance**: Check the `aws.cloudtrail.user_identity.arn` field to identify the specific EC2 instance and role involved in this activity (e.g., `arn:aws:sts::[account-id]:assumed-role/[role-name]/[instance-id]`).
36-
- **Session Context**: Review the `aws.cloudtrail.user_identity.session_context` for details about the session creation and `mfa_authenticated` status, if available.
37-
38-
- **Identify the Action Performed**:
39-
- **API Call**: Inspect `event.action` for the specific IAM API operation performed (e.g., `ListRoles`, `CreateUser`). This can provide insights into the level of permissions the instance is attempting to access.
40-
- **Analyze Permissions**: Evaluate if the IAM role allows actions that the EC2 instance wouldn’t typically need. Roles with broad IAM permissions could indicate an overprivileged role or an attempt to escalate permissions.
41-
42-
- **Verify the Source of the Activity**:
43-
- **Source IP and Location**: Check `source.ip` and `source.geo` fields to verify the origin of the request. Unusual locations could indicate unauthorized access.
44-
- **User Agent**: Review `user_agent.original` to determine the tooling used. Expected values may include AWS CLI or SDKs, while unexpected user agents might point toward unusual or malicious usage.
45-
46-
- **Determine the Intent and Frequency of Similar Events**:
47-
- **Previous Events**: Review CloudTrail logs to see if this EC2 instance or role has a history of interacting with IAM services, which may establish a baseline of normal or unusual behavior.
48-
- **Multiple Actions**: Investigate if other IAM-related actions, such as `CreateUser` or `AttachRolePolicy`, have been called from this EC2 instance recently, indicating an attempt to escalate privileges or establish persistence.
49-
50-
### False Positive Analysis
51-
52-
- **Automation and Maintenance Tasks**: Some automation or administrative workflows might use EC2 instances to interact with IAM services. Verify if this event aligns with legitimate automation processes and consider excluding known workflows to reduce false positives.
53-
- **Expected Patterns**: For environments with automation, verify if EC2 instances routinely assume roles to perform IAM-related tasks, and if so, document these patterns for future reference.
54-
55-
### Response and Remediation
56-
57-
- **Access Review**: If unauthorized access is suspected, review and limit the EC2 instance's IAM permissions, especially roles allowing IAM-related actions.
58-
- **Role Management**: Confirm the role’s permissions align with its intended purpose and remove any overly permissive policies that may allow privilege escalation or persistence.
59-
- **Alerting and Monitoring**: Consider setting up real-time alerts for similar IAM actions by EC2 instances, especially actions that involve privilege escalation or persistence techniques.
60-
- **Policy Update**: Apply least privilege principles for IAM roles associated with EC2 instances to minimize potential exploitation risks.
61-
62-
### Additional Information
63-
64-
Refer to the [AWS IAM documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) and AWS best practices for IAM role usage to further understand secure role configurations.
65-
"""
66-
references = ["https://redcanary.com/blog/aws-sts/"]
18+
references = [
19+
"https://redcanary.com/blog/aws-sts/",
20+
]
6721
risk_score = 47
6822
rule_id = "a44bcb58-5109-4870-a7c6-11f5fe7dd4b1"
6923
severity = "medium"
7024
tags = [
7125
"Domain: Cloud",
7226
"Data Source: AWS",
7327
"Data Source: Amazon Web Services",
28+
"Data Source: AWS EC2",
7429
"Data Source: AWS IAM",
7530
"Use Case: Identity and Access Audit",
7631
"Tactic: Privilege Escalation",
7732
"Tactic: Persistence",
7833
]
7934
timestamp_override = "event.ingested"
80-
type = "esql"
35+
type = "eql"
8136

8237
query = '''
83-
from logs-aws.cloudtrail* metadata _id, _version, _index
84-
85-
| where
86-
event.dataset == "aws.cloudtrail"
87-
and event.provider == "iam.amazonaws.com"
88-
89-
// filter for assumed role sessions started by an EC2 instance
90-
and aws.cloudtrail.user_identity.type == "AssumedRole"
91-
and user.id like """*:i-*"""
92-
93-
// extract the owner and actor from the ARN
94-
| dissect aws.cloudtrail.user_identity.arn "%{}::%{owner}:%{identity_type}/%{actor}"
95-
| eval
96-
// filter out AWS, Elastic, Datadog, and Wiz service roles by ARN
97-
aws_vendor = starts_with(actor, "AWSServiceRoleForConfig"),
98-
elastic_vendor = starts_with(actor, "Elastic"),
99-
datadog_vendor = starts_with(actor, "DataDog"),
100-
wiz_vendor = starts_with(actor, "Wiz")
101-
| where
102-
aws_vendor != true and
103-
elastic_vendor != true and
104-
datadog_vendor != true and
105-
wiz_vendor != true
106-
| keep
107-
@timestamp,
108-
event.provider,
109-
event.action,
110-
aws.cloudtrail.user_identity.arn,
111-
user.id,
112-
owner,
113-
actor,
114-
aws.cloudtrail.request_parameters,
115-
aws.cloudtrail.response_elements
38+
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-")
11642
'''
11743

11844

11945
[[rule.threat]]
12046
framework = "MITRE ATT&CK"
121-
[[rule.threat.technique]]
122-
id = "T1078"
123-
name = "Valid Accounts"
124-
reference = "https://attack.mitre.org/techniques/T1078/"
125-
[[rule.threat.technique.subtechnique]]
126-
id = "T1078.004"
127-
name = "Cloud Accounts"
128-
reference = "https://attack.mitre.org/techniques/T1078/004/"
129-
130-
13147
[[rule.threat.technique]]
13248
id = "T1098"
13349
name = "Account Manipulation"
@@ -136,23 +52,29 @@ reference = "https://attack.mitre.org/techniques/T1098/"
13652
id = "T1098.001"
13753
name = "Additional Cloud Credentials"
13854
reference = "https://attack.mitre.org/techniques/T1098/001/"
139-
14055
[[rule.threat.technique.subtechnique]]
14156
id = "T1098.003"
14257
name = "Additional Cloud Roles"
14358
reference = "https://attack.mitre.org/techniques/T1098/003/"
14459

145-
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/"
14668

14769
[rule.threat.tactic]
14870
id = "TA0003"
14971
name = "Persistence"
15072
reference = "https://attack.mitre.org/tactics/TA0003/"
73+
15174
[[rule.threat]]
15275
framework = "MITRE ATT&CK"
15376

15477
[rule.threat.tactic]
15578
id = "TA0004"
15679
name = "Privilege Escalation"
15780
reference = "https://attack.mitre.org/tactics/TA0004/"
158-

0 commit comments

Comments
 (0)