AWS EC2 Instance Launched With User Data by Rare User
Description
Identifies the first time, within a lookback window, an identity launches an EC2 instance that includes user data via the "RunInstances" API. Adversaries supply user data to execute code automatically on instance boot (cloud-init), enabling command execution, persistence, or credential theft from a newly created, attacker-controlled instance. This is a New Terms rule detecting a rare occurrence of the "cloud.account.id", "user.name", and "source.as.organization.name" tuple for instance launches carrying user data.
Query · kuery
data_stream.dataset: "aws.cloudtrail"
and event.provider: "ec2.amazonaws.com"
and event.action: "RunInstances"
and event.outcome: "success"
and source.ip: *
and cloud.account.id: *
and user.name: *
and aws.cloudtrail.request_parameters: *userData*
and source.as.organization.name: (
* and not (
"Google LLC" or "Amazon.com, Inc." or "Microsoft Corporation" or "GOOGLE-CLOUD-PLATFORM"
or "MICROSOFT-CORP-MSN-AS-BLOCK" or "AMAZON-AES" or "AMAZON-02"
)
)
and not aws.cloudtrail.user_identity.invoked_by: ("autoscaling.amazonaws.com" or "cloudformation.amazonaws.com")
and not user_agent.original: (*Terraform*)
Investigation fields
Pivot points the source recommends for triage.
@timestampuser.nameuser_agent.originalsource.ipsource.as.organization.nameaws.cloudtrail.user_identity.arnaws.cloudtrail.user_identity.typeaws.cloudtrail.user_identity.access_key_idevent.actionevent.outcomeevent.providercloud.account.idcloud.regionaws.cloudtrail.request_parameters
Known false positives
- Infrastructure-as-code pipelines, auto scaling, and launch-template-driven deployments routinely launch instances with user data. Terraform and service-invoked (Auto Scaling, CloudFormation) launches are excluded, but other automation or administrators bootstrapping instances may generate first-seen matches that warrant review.
Analyst notes
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating AWS EC2 Instance Launched With User Data by Rare User
EC2 user data is a script or directive block executed by cloud-init on first boot. Adversaries with ec2:RunInstances embed user data to run commands as root on a freshly launched instance, which can be used for execution, persistence, mining, or to abuse the instance role credentials via IMDS.
This rule uses New Terms to detect when an identity launches a user-data-bearing instance from an account, principal, and network-origin combination not seen in the configured history window. CloudTrail redacts the user data value but preserves the userData request parameter key.
Possible investigation steps
- Confirm who
user.nameandaws.cloudtrail.user_identity.arnrepresent and whether launching instances with bootstrap user data is expected for that principal. - Review
source.ip,source.as.organization.name, and geolocation, and whether the call aligns with normal egress for that principal. - Inspect
aws.cloudtrail.request_parametersfor theimageId, instance profile (iamInstanceProfile), and networking; retrieve and review the instance user data from the EC2 console orDescribeInstanceAttribute. - Correlate with the launched instance's subsequent endpoint telemetry, IMDS credential use, and any follow-on API activity from the instance role.
False positive analysis
- Documented deployment or platform roles launching instances with bootstrap user data; add exceptions by ARN or user agent if needed.
- Golden-image or bake pipelines not covered by the Terraform/service exclusions; confirm the pipeline and operator.
Response and remediation
- If unexpected, terminate or isolate the instance, capture the user data and instance role activity, rotate credentials for the implicated principal and the instance role, and tighten least privilege on
ec2:RunInstancesandiam:PassRole.