AWS IAM User Created Access Keys For Another User
An adversary with access to a set of compromised credentials may attempt to persist or escalate privileges by
creating a new set of credentials for an existing user. This rule looks for use of the IAM CreateAccessKey
API operation
to create new programmatic access keys for another IAM user.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2024/06/13"
3integration = ["aws"]
4maturity = "production"
5updated_date = "2024/12/10"
6min_stack_comments = "ES|QL rule type in technical preview as of 8.13"
7min_stack_version = "8.13.0"
8
9[rule]
10author = ["Elastic"]
11description = """
12An adversary with access to a set of compromised credentials may attempt to persist or escalate privileges by
13creating a new set of credentials for an existing user. This rule looks for use of the IAM `CreateAccessKey` API operation
14to create new programmatic access keys for another IAM user.
15"""
16false_positives = [
17 """
18 While this can be normal behavior, it should be investigated to ensure validity.
19 Verify whether the user identity should be using the IAM `CreateAccessKey` for the targeted user.
20 """,
21]
22from = "now-6m"
23language = "esql"
24license = "Elastic License v2"
25name = "AWS IAM User Created Access Keys For Another User"
26note = """## Triage and analysis
27
28### Investigating AWS IAM User Created Access Keys For Another User
29
30AWS access keys created for IAM users or root user are long-term credentials that provide programmatic access to AWS.
31With access to the `iam:CreateAccessKey` permission, a set of compromised credentials could be used to create a new
32set of credentials for another user for privilege escalation or as a means of persistence. This rule uses [ES|QL](https://www.elastic.co/guide/en/security/master/rules-ui-create.html#create-esql-rule)
33to look for use of the `CreateAccessKey` operation where the user.name is different from the user.target.name.
34
35
36#### Possible investigation steps
37
38- Identify both related accounts and their role in the environment.
39- Review IAM permission policies for the user identities.
40- Identify the applications or users that should use these accounts.
41- Investigate other alerts associated with the accounts during the past 48 hours.
42- Investigate abnormal values in the `user_agent.original` field by comparing them with the intended and authorized usage and historical data. Suspicious user agent values include non-SDK, AWS CLI, custom user agents, etc.
43- Contact the account owners and confirm whether they are aware of this activity.
44- Considering the source IP address and geolocation of the user who issued the command:
45 - Do they look normal for the calling user?
46 - If the source is an EC2 IP address, is it associated with an EC2 instance in one of your accounts or is the source IP from an EC2 instance that's not under your control?
47 - If it is an authorized EC2 instance, is the activity associated with normal behavior for the instance role or roles? Are there any other alerts or signs of suspicious activity involving this instance?
48- If you suspect the account has been compromised, scope potentially compromised assets by tracking servers, services, and data accessed by the account in the last 24 hours.
49 - Determine what other API calls were made by the user.
50 - Assess whether this behavior is prevalent in the environment by looking for similar occurrences involving other users.
51
52### False positive analysis
53
54- False positives may occur due to the intended usage of the IAM `CreateAccessKey` operation. Verify the `aws.cloudtrail.user_identity.arn` should use this operation against the `user.target.name` account.
55
56### Response and remediation
57
58- Initiate the incident response process based on the outcome of the triage.
59- Disable or limit the account during the investigation and response.
60 - Rotate user credentials
61 - Remove the newly created credentials from the affected user(s)
62- Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
63 - Identify the account role in the cloud environment.
64 - Assess the criticality of affected services and servers.
65 - Work with your IT team to identify and minimize the impact on users.
66 - Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
67 - Identify any regulatory or legal ramifications related to this activity.
68- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified.
69 - Rotate secrets or delete API keys as needed to revoke the attacker's access to the environment.
70 - Work with your IT teams to minimize the impact on business operations during these actions.
71- Remove unauthorized new accounts, and request password resets for other IAM users.
72- Consider enabling multi-factor authentication for users.
73- Review the permissions assigned to the implicated user to ensure that the least privilege principle is being followed.
74- Implement security best practices [outlined](https://aws.amazon.com/premiumsupport/knowledge-center/security-best-practices/) by AWS.
75- Take the actions needed to return affected systems, data, or services to their normal operational levels.
76- Identify the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
77- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
78"""
79references = [
80 "https://hackingthe.cloud/aws/exploitation/iam_privilege_escalation/#iamcreateaccesskey",
81 "https://cloud.hacktricks.xyz/pentesting-cloud/aws-security/aws-persistence/aws-iam-persistence",
82 "https://permiso.io/blog/lucr-3-scattered-spider-getting-saas-y-in-the-cloud",
83 "https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateAccessKey.html",
84]
85risk_score = 47
86rule_id = "696015ef-718e-40ff-ac4a-cc2ba88dbeeb"
87severity = "medium"
88tags = [
89 "Domain: Cloud",
90 "Data Source: AWS",
91 "Data Source: Amazon Web Services",
92 "Data Source: AWS IAM",
93 "Use Case: Identity and Access Audit",
94 "Tactic: Privilege Escalation",
95 "Tactic: Persistence",
96 "Resources: Investigation Guide",
97]
98timestamp_override = "event.ingested"
99type = "esql"
100
101query = '''
102from logs-aws.cloudtrail-* metadata _id, _version, _index
103| where event.provider == "iam.amazonaws.com"
104 and event.action == "CreateAccessKey"
105 and event.outcome == "success"
106 and user.name != user.target.name
107| keep
108 @timestamp,
109 cloud.region,
110 event.provider,
111 event.action,
112 event.outcome,
113 user.name,
114 source.address,
115 user.target.name,
116 user_agent.original,
117 aws.cloudtrail.request_parameters,
118 aws.cloudtrail.response_elements,
119 aws.cloudtrail.user_identity.arn,
120 aws.cloudtrail.user_identity.type
121'''
122
123[rule.investigation_fields]
124field_names = [
125 "@timestamp",
126 "user.name",
127 "source.address",
128 "aws.cloudtrail.user_identity.arn",
129 "aws.cloudtrail.user_identity.type",
130 "user_agent.original",
131 "user.target.name",
132 "event.action",
133 "event.outcome",
134 "cloud.region",
135 "event.provider",
136 "aws.cloudtrail.request_parameters",
137 "aws.cloudtrail.response_elements",
138]
139
140
141[[rule.threat]]
142framework = "MITRE ATT&CK"
143[[rule.threat.technique]]
144id = "T1098"
145name = "Account Manipulation"
146reference = "https://attack.mitre.org/techniques/T1098/"
147[[rule.threat.technique.subtechnique]]
148id = "T1098.001"
149name = "Additional Cloud Credentials"
150reference = "https://attack.mitre.org/techniques/T1098/001/"
151
152[rule.threat.tactic]
153id = "TA0003"
154name = "Persistence"
155reference = "https://attack.mitre.org/tactics/TA0003/"
156
157[[rule.threat]]
158framework = "MITRE ATT&CK"
159[[rule.threat.technique]]
160id = "T1098"
161name = "Account Manipulation"
162reference = "https://attack.mitre.org/techniques/T1098/"
163[[rule.threat.technique.subtechnique]]
164id = "T1098.001"
165name = "Additional Cloud Credentials"
166reference = "https://attack.mitre.org/techniques/T1098/001/"
167
168[rule.threat.tactic]
169id = "TA0004"
170name = "Privilege Escalation"
171reference = "https://attack.mitre.org/tactics/TA0004/"
Triage and analysis
Investigating AWS IAM User Created Access Keys For Another User
AWS access keys created for IAM users or root user are long-term credentials that provide programmatic access to AWS.
With access to the iam:CreateAccessKey
permission, a set of compromised credentials could be used to create a new
set of credentials for another user for privilege escalation or as a means of persistence. This rule uses ES|QL
to look for use of the CreateAccessKey
operation where the user.name is different from the user.target.name.
Possible investigation steps
- Identify both related accounts and their role in the environment.
- Review IAM permission policies for the user identities.
- Identify the applications or users that should use these accounts.
- Investigate other alerts associated with the accounts during the past 48 hours.
- Investigate abnormal values in the
user_agent.original
field by comparing them with the intended and authorized usage and historical data. Suspicious user agent values include non-SDK, AWS CLI, custom user agents, etc. - Contact the account owners and confirm whether they are aware of this activity.
- Considering the source IP address and geolocation of the user who issued the command:
- Do they look normal for the calling user?
- If the source is an EC2 IP address, is it associated with an EC2 instance in one of your accounts or is the source IP from an EC2 instance that's not under your control?
- If it is an authorized EC2 instance, is the activity associated with normal behavior for the instance role or roles? Are there any other alerts or signs of suspicious activity involving this instance?
- If you suspect the account has been compromised, scope potentially compromised assets by tracking servers, services, and data accessed by the account in the last 24 hours.
- Determine what other API calls were made by the user.
- Assess whether this behavior is prevalent in the environment by looking for similar occurrences involving other users.
False positive analysis
- False positives may occur due to the intended usage of the IAM
CreateAccessKey
operation. Verify theaws.cloudtrail.user_identity.arn
should use this operation against theuser.target.name
account.
Response and remediation
- Initiate the incident response process based on the outcome of the triage.
- Disable or limit the account during the investigation and response.
- Rotate user credentials
- Remove the newly created credentials from the affected user(s)
- Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
- Identify the account role in the cloud environment.
- Assess the criticality of affected services and servers.
- Work with your IT team to identify and minimize the impact on users.
- Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
- Identify any regulatory or legal ramifications related to this activity.
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified.
- Rotate secrets or delete API keys as needed to revoke the attacker's access to the environment.
- Work with your IT teams to minimize the impact on business operations during these actions.
- Remove unauthorized new accounts, and request password resets for other IAM users.
- Consider enabling multi-factor authentication for users.
- Review the permissions assigned to the implicated user to ensure that the least privilege principle is being followed.
- Implement security best practices outlined by AWS.
- Take the actions needed to return affected systems, data, or services to their normal operational levels.
- Identify the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
References
Related rules
- AWS IAM AdministratorAccess Policy Attached to User
- AWS IAM AdministratorAccess Policy Attached to Group
- AWS IAM AdministratorAccess Policy Attached to Role
- AWS IAM Login Profile Added for Root
- AWS IAM Customer-Managed Policy Attached to Role by Rare User