AWS IAM Customer-Managed Policy Attached to Role by Rare User
Detects when an AWS Identity and Access Management (IAM) customer-managed policy is attached to a role by an unusual or unauthorized user. Customer-managed policies are policies created and controlled within an AWS account, granting specific permissions to roles or users when attached. This rule identifies potential privilege escalation by flagging cases where a customer-managed policy is attached to a role by an unexpected actor, which could signal unauthorized access or misuse. Attackers may attach policies to roles to expand permissions and elevate their privileges within the AWS environment. This is a New Terms rule that uses the "cloud.account.id", "user.name" and "entity.target.id" fields to check if the combination of the actor identity and target role name has not been seen before.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2024/11/04"
3integration = ["aws"]
4maturity = "production"
5updated_date = "2026/01/22"
6min_stack_comments = "New entity classification fields added: entity.target.id"
7min_stack_version = "9.2.0"
8
9[rule]
10author = ["Elastic"]
11description = """
12Detects when an AWS Identity and Access Management (IAM) customer-managed policy is attached to a role by an unusual or
13unauthorized user. Customer-managed policies are policies created and controlled within an AWS account, granting
14specific permissions to roles or users when attached. This rule identifies potential privilege escalation by flagging
15cases where a customer-managed policy is attached to a role by an unexpected actor, which could signal unauthorized
16access or misuse. Attackers may attach policies to roles to expand permissions and elevate their privileges within the
17AWS environment. This is a New Terms rule that uses the "cloud.account.id", "user.name" and "entity.target.id" fields to
18check if the combination of the actor identity and target role name has not been seen before.
19"""
20false_positives = [
21 """
22 Legitimate IAM administrators may attach customer-managed policies to roles for various reasons, such as granting
23 temporary permissions or updating existing policies. Ensure that the user attaching the policy is authorized to do
24 so and that the action is expected.
25 """,
26]
27from = "now-6m"
28index = ["logs-aws.cloudtrail-*"]
29language = "kuery"
30license = "Elastic License v2"
31name = "AWS IAM Customer-Managed Policy Attached to Role by Rare User"
32note = """## Triage and analysis
33
34### Investigating AWS IAM Customer-Managed Policy Attached to Role by Rare User
35
36This rule detects when a customer-managed IAM policy is attached to a role by an unusual or unauthorized user. This activity may indicate a potential privilege escalation attempt within the AWS environment. Adversaries could attach policies to roles to expand permissions, thereby increasing their capabilities and achieving elevated access.
37
38#### Possible Investigation Steps
39
40- **Identify the Initiating User and Target Role**:
41 - **User Identity**: Examine the `aws.cloudtrail.user_identity.arn` field to determine the user who initiated the policy attachment. Confirm if this user typically has permissions to modify IAM roles and if their activity is consistent with their usual responsibilities.
42 - **Target Role**: Review `entity.target.id` to identify the role to which the policy was attached. Assess whether modifying this role is expected for this user or if this action is unusual in your environment.
43
44- **Analyze the Attached Policy**:
45 - **Policy ARN**: Inspect the `aws.cloudtrail.request_parameters` field to identify the specific customer-managed policy attached to the role. Evaluate if this policy grants sensitive permissions, especially permissions that could enable privileged actions or data access.
46 - **Policy Permissions**: Examine the policy content to determine the scope of permissions granted. Policies enabling actions like `s3:*`, `ec2:*`, or `iam:*` could be leveraged for broader access, persistence, or lateral movement.
47
48- **Review Source and User Agent Details**:
49 - **Source IP and Location**: Analyze the `source.ip` and `source.geo` fields to confirm the IP address and geographic location where the policy attachment originated. Verify if this matches expected locations for the initiating user.
50 - **User Agent Analysis**: Examine `user_agent.original` to determine if AWS CLI, SDK, or other tooling was used to perform this action. Tool identifiers like `aws-cli` or `boto3` may indicate automation, while others may suggest interactive sessions.
51
52- **Evaluate Anomalous Behavior Patterns**:
53 - **User’s Historical Activity**: Check if the initiating user has a history of attaching policies to roles. An unusual pattern in policy attachments could indicate suspicious behavior, especially if the user lacks authorization.
54 - **Role Modification History**: Investigate if the targeted role is frequently modified by this or other users. Repeated, unauthorized modifications to a role could signal an attempt to maintain elevated access.
55
56- **Correlate with Related CloudTrail Events**:
57 - **Other IAM or CloudTrail Activities**: Look for recent actions associated with the same user or role by reviewing `event.action` and `event.provider` to identify which AWS services were accessed. This may provide context on the user’s intent or additional actions taken.
58 - **Broader Suspicious Patterns**: Identify if similar anomalous events have recently occurred, potentially suggesting a coordinated or escalating attack pattern within the AWS account.
59
60### False Positive Analysis
61
62- **Authorized Administrative Actions**: IAM administrators may legitimately attach policies to roles as part of routine role management. Verify if the user is authorized and if the activity aligns with expected administrative tasks.
63- **Role-Specific Modifications**: Roles that frequently undergo policy updates may trigger this rule during standard operations. Consider monitoring for patterns or establishing known exceptions for specific users or roles where appropriate.
64
65### Response and Remediation
66
67- **Immediate Access Review**: If the policy attachment is unauthorized, consider detaching the policy and reviewing the permissions granted to the initiating user.
68- **Restrict Role Modification Permissions**: Limit which users or roles can attach policies to critical IAM roles. Apply least privilege principles to reduce the risk of unauthorized policy changes.
69- **Enhance Monitoring and Alerts**: Enable real-time alerts and monitoring on IAM policy modifications to detect similar actions promptly.
70- **Regular Policy Audits**: Conduct periodic audits of IAM policies and role permissions to ensure that unauthorized changes are quickly identified and addressed.
71
72### Additional Information
73
74For more information on managing IAM policies and roles in AWS environments, refer to the [AWS IAM Documentation](https://docs.aws.amazon.com/IAM/latest/APIReference/API_AttachRolePolicy.html) and AWS security best practices.
75"""
76references = ["https://docs.aws.amazon.com/IAM/latest/APIReference/API_AttachRolePolicy.html"]
77risk_score = 21
78rule_id = "f6d07a70-9ad0-11ef-954f-f661ea17fbcd"
79severity = "low"
80tags = [
81 "Domain: Cloud",
82 "Data Source: AWS",
83 "Data Source: Amazon Web Services",
84 "Data Source: AWS IAM",
85 "Resources: Investigation Guide",
86 "Use Case: Identity and Access Audit",
87 "Tactic: Privilege Escalation",
88]
89timestamp_override = "event.ingested"
90type = "new_terms"
91
92query = '''
93event.dataset: "aws.cloudtrail"
94 and event.provider: "iam.amazonaws.com"
95 and event.action: "AttachRolePolicy"
96 and event.outcome: "success"
97 and not related.entity: arn\:aws\:iam\:\:aws\:policy*
98'''
99
100
101[[rule.threat]]
102framework = "MITRE ATT&CK"
103[[rule.threat.technique]]
104id = "T1548"
105name = "Abuse Elevation Control Mechanism"
106reference = "https://attack.mitre.org/techniques/T1548/"
107[[rule.threat.technique.subtechnique]]
108id = "T1548.005"
109name = "Temporary Elevated Cloud Access"
110reference = "https://attack.mitre.org/techniques/T1548/005/"
111
112
113
114[rule.threat.tactic]
115id = "TA0004"
116name = "Privilege Escalation"
117reference = "https://attack.mitre.org/tactics/TA0004/"
118
119[rule.investigation_fields]
120field_names = [
121 "@timestamp",
122 "user.name",
123 "user_agent.original",
124 "source.ip",
125 "aws.cloudtrail.user_identity.arn",
126 "aws.cloudtrail.user_identity.type",
127 "entity.target.id",
128 "event.action",
129 "event.outcome",
130 "cloud.account.id",
131 "cloud.region",
132 "aws.cloudtrail.request_parameters",
133]
134
135[rule.new_terms]
136field = "new_terms_fields"
137value = ["cloud.account.id", "user.name", "entity.target.id"]
138[[rule.new_terms.history_window_start]]
139field = "history_window_start"
140value = "now-7d"
Triage and analysis
Investigating AWS IAM Customer-Managed Policy Attached to Role by Rare User
This rule detects when a customer-managed IAM policy is attached to a role by an unusual or unauthorized user. This activity may indicate a potential privilege escalation attempt within the AWS environment. Adversaries could attach policies to roles to expand permissions, thereby increasing their capabilities and achieving elevated access.
Possible Investigation Steps
-
Identify the Initiating User and Target Role:
- User Identity: Examine the
aws.cloudtrail.user_identity.arnfield to determine the user who initiated the policy attachment. Confirm if this user typically has permissions to modify IAM roles and if their activity is consistent with their usual responsibilities. - Target Role: Review
entity.target.idto identify the role to which the policy was attached. Assess whether modifying this role is expected for this user or if this action is unusual in your environment.
- User Identity: Examine the
-
Analyze the Attached Policy:
- Policy ARN: Inspect the
aws.cloudtrail.request_parametersfield to identify the specific customer-managed policy attached to the role. Evaluate if this policy grants sensitive permissions, especially permissions that could enable privileged actions or data access. - Policy Permissions: Examine the policy content to determine the scope of permissions granted. Policies enabling actions like
s3:*,ec2:*, oriam:*could be leveraged for broader access, persistence, or lateral movement.
- Policy ARN: Inspect the
-
Review Source and User Agent Details:
- Source IP and Location: Analyze the
source.ipandsource.geofields to confirm the IP address and geographic location where the policy attachment originated. Verify if this matches expected locations for the initiating user. - User Agent Analysis: Examine
user_agent.originalto determine if AWS CLI, SDK, or other tooling was used to perform this action. Tool identifiers likeaws-cliorboto3may indicate automation, while others may suggest interactive sessions.
- Source IP and Location: Analyze the
-
Evaluate Anomalous Behavior Patterns:
- User’s Historical Activity: Check if the initiating user has a history of attaching policies to roles. An unusual pattern in policy attachments could indicate suspicious behavior, especially if the user lacks authorization.
- Role Modification History: Investigate if the targeted role is frequently modified by this or other users. Repeated, unauthorized modifications to a role could signal an attempt to maintain elevated access.
-
Correlate with Related CloudTrail Events:
- Other IAM or CloudTrail Activities: Look for recent actions associated with the same user or role by reviewing
event.actionandevent.providerto identify which AWS services were accessed. This may provide context on the user’s intent or additional actions taken. - Broader Suspicious Patterns: Identify if similar anomalous events have recently occurred, potentially suggesting a coordinated or escalating attack pattern within the AWS account.
- Other IAM or CloudTrail Activities: Look for recent actions associated with the same user or role by reviewing
False Positive Analysis
- Authorized Administrative Actions: IAM administrators may legitimately attach policies to roles as part of routine role management. Verify if the user is authorized and if the activity aligns with expected administrative tasks.
- Role-Specific Modifications: Roles that frequently undergo policy updates may trigger this rule during standard operations. Consider monitoring for patterns or establishing known exceptions for specific users or roles where appropriate.
Response and Remediation
- Immediate Access Review: If the policy attachment is unauthorized, consider detaching the policy and reviewing the permissions granted to the initiating user.
- Restrict Role Modification Permissions: Limit which users or roles can attach policies to critical IAM roles. Apply least privilege principles to reduce the risk of unauthorized policy changes.
- Enhance Monitoring and Alerts: Enable real-time alerts and monitoring on IAM policy modifications to detect similar actions promptly.
- Regular Policy Audits: Conduct periodic audits of IAM policies and role permissions to ensure that unauthorized changes are quickly identified and addressed.
Additional Information
For more information on managing IAM policies and roles in AWS environments, refer to the AWS IAM Documentation and AWS security best practices.
References
Related rules
- AWS IAM Assume Role Policy Update
- AWS IAM AdministratorAccess Policy Attached to Group
- AWS IAM AdministratorAccess Policy Attached to Role
- AWS IAM AdministratorAccess Policy Attached to User
- AWS IAM SAML Provider Updated