AWS EC2 Instance Launched With User Data by Rare User

edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

AWS EC2 Instance Launched With User Data by Rare User

edit

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.

Rule type: new_terms

Rule indices:

  • logs-aws.cloudtrail-*

Severity: medium

Risk score: 47

Runs every: 5m

Searches indices from: now-6m (Date Math format, see also Additional look-back time)

Maximum alerts per execution: 100

References:

Tags:

  • Domain: Cloud
  • Data Source: AWS
  • Data Source: Amazon Web Services
  • Platform: AWS
  • Data Source: AWS CloudTrail
  • Service: AWS EC2
  • Tactic: Defense Evasion
  • Rule Type: New Terms
  • Resources: Investigation Guide

Version: 1

Rule authors:

  • Elastic

Rule license: Elastic License v2

Investigation guide

edit

Triage and analysis

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.name and aws.cloudtrail.user_identity.arn represent 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_parameters for the imageId, instance profile (iamInstanceProfile), and networking; retrieve and review the instance user data from the EC2 console or DescribeInstanceAttribute.
  • 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:RunInstances and iam:PassRole.

Additional information

Rule query

edit
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*)

Framework: MITRE ATT&CKTM