Skip to content

Commit d37562f

Browse files
new hunt 'AWS IAM Unusual AWS Access Key Usage for User'
1 parent d3c05a0 commit d37562f

File tree

4 files changed

+119
-2
lines changed

4 files changed

+119
-2
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# AWS IAM Unusual AWS Access Key Usage for User
2+
3+
---
4+
5+
## Metadata
6+
7+
- **Author:** Elastic
8+
- **Description:** This hunting query gathers data from AWS CloudTrail logs to identify unusual AWS access key usage for a user. By detecting instances where an access key is used infrequently for a specific AWS event, this query helps identify potential misuse or abuse of AWS access keys. Adversaries may use access keys to gain unauthorized access to AWS resources, exfiltrate data, or perform other malicious activities within the environment.
9+
10+
- **UUID:** `18ce3dbc-b1b3-11ef-9e63-f661ea17fbce`
11+
- **Integration:** [aws.cloudtrail](https://docs.elastic.co/integrations/aws/cloudtrail)
12+
- **Language:** `[ES|QL]`
13+
- **Source File:** [AWS IAM Unusual AWS Access Key Usage for User](../queries/iam_unusual_access_key_usage_for_user.toml)
14+
15+
## Query
16+
17+
```sql
18+
FROM logs-aws.cloudtrail*
19+
// Limit the search to the last 14 days
20+
| WHERE @timestamp > now() - 14 day
21+
| WHERE
22+
// Filter for successful AWS CloudTrail events
23+
event.dataset == "aws.cloudtrail"
24+
and event.outcome == "success"
25+
26+
// Filter for AWS CloudTrail events with user identity and access key information
27+
and aws.cloudtrail.user_identity.access_key_id IS NOT NULL
28+
and aws.cloudtrail.resources.arn IS NOT NULL
29+
30+
// Ignore GetObject events
31+
and event.action NOT IN ("GetObject")
32+
33+
// Create a daily bucket for the events
34+
| EVAL daily_buckets = DATE_TRUNC(1 days, @timestamp)
35+
| STATS
36+
// Count the number of events for each daily bucket, user identity, access key, resource, and action
37+
api_counts = count(*) by daily_buckets, aws.cloudtrail.user_identity.arn, aws.cloudtrail.user_identity.access_key_id, aws.cloudtrail.resources.arn, event.action
38+
39+
// Filter for access keys with less than 2 API calls per day
40+
| WHERE api_counts < 2
41+
| SORT api_counts ASC
42+
```
43+
44+
## Notes
45+
46+
- Review the `aws.cloudtrail.user_identity.arn` and `aws.cloudtrail.user_identity.access_key_id` fields to identify the user and access key involved in the unusual access key usage.
47+
- Review the infrequente AWS events (`event.action`), associated with the access key to determine the potential impact of the unusual access key usage.
48+
- Within AWS, determine is the access key is temporary or permanent and if it is associated with a specific user or role.
49+
- If the access key is associated with a specific role, review the permissions and policies associated with the role to determine the potential impact of the unusual access key usage.
50+
- If the access key is associated with an assumed role, review the resources assigned to the role. Consider pivoting on EC2 or Lambda-based roles if identified and examine session metadata within the last 24-hours.
51+
- Consider reviewing the `source.address` field to identify the IP address of the actor responsible for the unusual access key usage.
52+
- If the access key is perminant and tied to a user or role, consider rotating the access key to prevent further unauthorized access.
53+
54+
## MITRE ATT&CK Techniques
55+
56+
- [T1078.004](https://attack.mitre.org/techniques/T1078/004)
57+
58+
## License
59+
60+
- `Elastic License v2`
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[hunt]
2+
author = "Elastic"
3+
description = """
4+
This hunting query gathers data from AWS CloudTrail logs to identify unusual AWS access key usage for a user. By detecting instances where an access key is used infrequently for a specific AWS event, this query helps identify potential misuse or abuse of AWS access keys. Adversaries may use access keys to gain unauthorized access to AWS resources, exfiltrate data, or perform other malicious activities within the environment.
5+
"""
6+
integration = ["aws.cloudtrail"]
7+
uuid = "18ce3dbc-b1b3-11ef-9e63-f661ea17fbce"
8+
name = "AWS IAM Unusual AWS Access Key Usage for User"
9+
language = ["ES|QL"]
10+
license = "Elastic License v2"
11+
notes = [
12+
"Review the `aws.cloudtrail.user_identity.arn` and `aws.cloudtrail.user_identity.access_key_id` fields to identify the user and access key involved in the unusual access key usage.",
13+
"Review the infrequente AWS events (`event.action`), associated with the access key to determine the potential impact of the unusual access key usage.",
14+
"Within AWS, determine is the access key is temporary or permanent and if it is associated with a specific user or role.",
15+
"If the access key is associated with a specific role, review the permissions and policies associated with the role to determine the potential impact of the unusual access key usage.",
16+
"If the access key is associated with an assumed role, review the resources assigned to the role. Consider pivoting on EC2 or Lambda-based roles if identified and examine session metadata within the last 24-hours.",
17+
"Consider reviewing the `source.address` field to identify the IP address of the actor responsible for the unusual access key usage.",
18+
"If the access key is perminant and tied to a user or role, consider rotating the access key to prevent further unauthorized access."
19+
]
20+
mitre = ['T1078.004']
21+
query = [
22+
'''
23+
FROM logs-aws.cloudtrail*
24+
// Limit the search to the last 14 days
25+
| WHERE @timestamp > now() - 14 day
26+
| WHERE
27+
// Filter for successful AWS CloudTrail events
28+
event.dataset == "aws.cloudtrail"
29+
and event.outcome == "success"
30+
31+
// Filter for AWS CloudTrail events with user identity and access key information
32+
and aws.cloudtrail.user_identity.access_key_id IS NOT NULL
33+
and aws.cloudtrail.resources.arn IS NOT NULL
34+
35+
// Ignore GetObject events
36+
and event.action NOT IN ("GetObject")
37+
38+
// Filter out known service roles; expand this as needed
39+
and NOT aws.cloudtrail.user_identity.arn LIKE "*AWSServiceRoleForConfig*"
40+
and NOT aws.cloudtrail.user_identity.arn LIKE "*Elastic-Cloud-Security-Posture*"
41+
and NOT aws.cloudtrail.user_identity.arn LIKE "*AmazonSSMRoleForInstancesQuickSetup*"
42+
43+
| STATS
44+
// Count the number of events for each daily bucket, user identity, access key, resource, and action
45+
api_counts = count(*) by aws.cloudtrail.user_identity.arn, aws.cloudtrail.user_identity.access_key_id, event.action
46+
47+
// Filter for access keys with less than 2 API calls per day
48+
| WHERE api_counts < 2
49+
| SORT api_counts ASC
50+
'''
51+
]

hunting/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ 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)
7+
- [AWS IAM Customer-Managed Policy Attachment to Existing Roles](./aws/docs/iam_customer_managed_policies_attached_to_existing_roles.md) (ES|QL)
8+
- [AWS IAM Unusual AWS Access Key Usage for User](./aws/docs/iam_unusual_access_key_usage_for_user.md) (ES|QL)
89
- [EC2 Modify Instance Attribute User Data](./aws/docs/ec2_modify_instance_attribute_user_data.md) (ES|QL)
910
- [EC2 Suspicious Get User Password Request](./aws/docs/ec2_suspicious_get_user_password_request.md) (ES|QL)
1011
- [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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,15 @@ aws:
365365
mitre:
366366
- T1550.001
367367
418baaf2-9ae1-11ef-be63-f661ea17fbcd:
368-
name: AWS IAM Customer-Managed Policy Attachment for Privilege Escalation
368+
name: AWS IAM Customer-Managed Policy Attachment to Existing Roles
369369
path: ./aws/queries/iam_customer_managed_policies_attached_to_existing_roles.toml
370370
mitre:
371371
- T1548.005
372+
18ce3dbc-b1b3-11ef-9e63-f661ea17fbce:
373+
name: AWS IAM Unusual AWS Access Key Usage for User
374+
path: ./aws/queries/iam_unusual_access_key_usage_for_user.toml
375+
mitre:
376+
- T1078.004
372377
windows:
373378
44e6adc6-e183-4bfa-b06d-db41669641fa:
374379
name: Rundll32 Execution Aggregated by Command Line

0 commit comments

Comments
 (0)