Skip to content

Commit edeefe6

Browse files
adds new hunting query
1 parent 5f82dfe commit edeefe6

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# AWS IAM Customer-Managed Policy Attachment for Privilege Escalation
2+
3+
---
4+
5+
## Metadata
6+
7+
- **Author:** Elastic
8+
- **Description:** This hunting query identifies instances where customer-managed IAM policies are attached to existing roles, potentially indicating a privilege escalation attempt. By detecting unexpected actors attaching customer-managed policies with elevated permissions to roles, this query helps identify potential abuse or misuse within AWS. Adversaries may attach these policies to gain unauthorized permissions or enable lateral movement and persistence within the environment.
9+
10+
- **UUID:** `418baaf2-9ae1-11ef-be63-f661ea17fbcd`
11+
- **Integration:** [aws.cloudtrail](https://docs.elastic.co/integrations/aws/cloudtrail)
12+
- **Language:** `[ES|QL]`
13+
- **Source File:** [AWS IAM Customer-Managed Policy Attachment for Privilege Escalation](../queries/iam_customer_managed_policies_attached_to_existing_roles.toml)
14+
15+
## Query
16+
17+
```sql
18+
from logs-aws.cloudtrail*
19+
| where
20+
event.dataset == "aws.cloudtrail"
21+
and event.provider == "iam.amazonaws.com"
22+
and event.action == "AttachRolePolicy"
23+
and event.outcome == "success"
24+
| dissect aws.cloudtrail.request_parameters "{%{}::%{owner}:%{?policy_key}/%{attached_policy_name}, %{?role_name_key}=%{target_role_name}}"
25+
| where owner != "aws"
26+
| stats
27+
actor_attaching_role_count = count(*) by aws.cloudtrail.user_identity.arn, attached_policy_name, target_role_name
28+
```
29+
30+
## Notes
31+
32+
- Review the `target_account_id` field to verify the AWS account in which the role is being modified, especially if this account is outside of your organization’s typical accounts.
33+
- Examine `aws.cloudtrail.request_parameters` for details on the role and attached policy. Customer-managed policies granting overly permissive access, such as `AdministratorAccess`, may signal unauthorized privilege escalation.
34+
- Cross-reference `event.action` values where `AttachRolePolicy` appears to further investigate attached policies that could enable lateral movement or persistence.
35+
- Evaluate `aws.cloudtrail.user_identity.arn` to confirm if the actor attaching the policy has legitimate permissions for this action. Anomalous or unauthorized actors may indicate privilege abuse.
36+
- Look for patterns of multiple `AttachRolePolicy` actions across roles by the same user or entity. High frequency of these actions could suggest an attempt to establish persistent control across roles within your AWS environment.
37+
38+
## MITRE ATT&CK Techniques
39+
40+
- [T1548.005](https://attack.mitre.org/techniques/T1548/005)
41+
42+
## License
43+
44+
- `Elastic License v2`
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[hunt]
2+
author = "Elastic"
3+
description = """
4+
This hunting query identifies instances where customer-managed IAM policies are attached to existing roles, potentially indicating a privilege escalation attempt. By detecting unexpected actors attaching customer-managed policies with elevated permissions to roles, this query helps identify potential abuse or misuse within AWS. Adversaries may attach these policies to gain unauthorized permissions or enable lateral movement and persistence within the environment.
5+
"""
6+
integration = ["aws.cloudtrail"]
7+
uuid = "418baaf2-9ae1-11ef-be63-f661ea17fbcd"
8+
name = "AWS IAM Customer-Managed Policy Attachment for Privilege Escalation"
9+
language = ["ES|QL"]
10+
license = "Elastic License v2"
11+
notes = [
12+
"Review the `target_account_id` field to verify the AWS account in which the role is being modified, especially if this account is outside of your organization’s typical accounts.",
13+
"Examine `aws.cloudtrail.request_parameters` for details on the role and attached policy. Customer-managed policies granting overly permissive access, such as `AdministratorAccess`, may signal unauthorized privilege escalation.",
14+
"Cross-reference `event.action` values where `AttachRolePolicy` appears to further investigate attached policies that could enable lateral movement or persistence.",
15+
"Evaluate `aws.cloudtrail.user_identity.arn` to confirm if the actor attaching the policy has legitimate permissions for this action. Anomalous or unauthorized actors may indicate privilege abuse.",
16+
"Look for patterns of multiple `AttachRolePolicy` actions across roles by the same user or entity. High frequency of these actions could suggest an attempt to establish persistent control across roles within your AWS environment."
17+
]
18+
mitre = ['T1548.005']
19+
query = [
20+
'''
21+
from logs-aws.cloudtrail*
22+
| where
23+
event.dataset == "aws.cloudtrail"
24+
and event.provider == "iam.amazonaws.com"
25+
and event.action == "AttachRolePolicy"
26+
and event.outcome == "success"
27+
| dissect aws.cloudtrail.request_parameters "{%{}::%{owner}:%{?policy_key}/%{attached_policy_name}, %{?role_name_key}=%{target_role_name}}"
28+
| where owner != "aws"
29+
| stats
30+
actor_attaching_role_count = count(*) by aws.cloudtrail.user_identity.arn, attached_policy_name, target_role_name
31+
'''
32+
]

hunting/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Here are the queries currently available:
44

55

66
## aws
7+
- [AWS IAM Customer-Managed Policy Attachment for Privilege Escalation](./aws/docs/iam_customer_managed_policies_attached_to_existing_roles.md) (ES|QL)
78
- [EC2 Modify Instance Attribute User Data](./aws/docs/ec2_modify_instance_attribute_user_data.md) (ES|QL)
89
- [EC2 Suspicious Get User Password Request](./aws/docs/ec2_suspicious_get_user_password_request.md) (ES|QL)
910
- [High EC2 Instance Deployment Count Attempts by Single User or Role](./aws/docs/ec2_high_instance_deployment_count_attempts.md) (ES|QL)

hunting/index.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ aws:
364364
path: ./aws/queries/sts_suspicious_federated_temporary_credential_request.toml
365365
mitre:
366366
- T1550.001
367+
418baaf2-9ae1-11ef-be63-f661ea17fbcd:
368+
name: AWS IAM Customer-Managed Policy Attachment for Privilege Escalation
369+
path: ./aws/queries/iam_customer_managed_policies_attached_to_existing_roles.toml
370+
mitre:
371+
- T1548.005
367372
windows:
368373
44e6adc6-e183-4bfa-b06d-db41669641fa:
369374
name: Rundll32 Execution Aggregated by Command Line

0 commit comments

Comments
 (0)