AWS EC2 Instance Profile Associated with Running Instance
Description
Identifies when an IAM instance profile is associated with a running EC2 instance or replaces the existing association.
These APIs change which role credentials the instance obtains via the instance metadata service without terminating the
instance. Attackers who can call AssociateIamInstanceProfile or ReplaceIamInstanceProfile may attach a more
privileged role to a workload they control, enabling privilege escalation or lateral movement from the instance.
Query · kuery
event.dataset: "aws.cloudtrail"
and event.provider: "ec2.amazonaws.com"
and event.action: ("AssociateIamInstanceProfile" or "ReplaceIamInstanceProfile")
and event.outcome: "success"
and not aws.cloudtrail.user_identity.type: "AWSService"
and not aws.cloudtrail.user_identity.invoked_by: "ssm.amazonaws.com"
Investigation fields
Pivot points the source recommends for triage.
@timestampuser.nameuser_agent.originalsource.ipaws.cloudtrail.user_identity.arnaws.cloudtrail.user_identity.typeaws.cloudtrail.user_identity.access_key_idaws.cloudtrail.resources.arnaws.cloudtrail.resources.typeevent.actionevent.outcomecloud.account.idcloud.regionaws.cloudtrail.request_parametersaws.cloudtrail.response_elements
Known false positives
- Blue/green deployments, instance remediation, and automation may rebind instance profiles intentionally. Confirm the instance id, new `iamInstanceProfile` or `IamInstanceProfile` ARN, and change records. Exclude known automation roles after validation.
Analyst notes
Investigating AWS EC2 Instance Profile Associated with Running Instance
AssociateIamInstanceProfile adds an instance profile to a running instance (where none was set at launch).
ReplaceIamInstanceProfile swaps the association. Both require ec2:AssociateIamInstanceProfile /
ec2:ReplaceIamInstanceProfile and typically iam:PassRole on the target instance profile’s role.
Possible investigation steps
- Parse
aws.cloudtrail.request_parametersforinstanceIdand instance profile name or ARN. - Identify the IAM role behind the profile and compare its policies to the prior role (if any).
- Map the instance to owner, application, and sensitivity; check for recent compromise indicators (SSRF to IMDS,
unusual
AssumeRolefrom the instance role). - Review
aws.cloudtrail.user_identity.arn,source.ip, anduser_agent.original.
False positive analysis
- Legitimate fixes for missing or wrong profiles at launch; verify with service owners.
Response and remediation
- If unauthorized: disassociate or replace with the correct profile, revoke
PassRole/ec2permissions from the actor, and rotate credentials that may have been issued from the over-privileged role.