
AWS EC2 instance user data refers to scripts that run automatically when an instance starts or restarts. These scripts are commonly used for automated configuration, service initialization, and software installation.
For convenience, user data often contains sensitive information, such as plaintext access keys, database credentials, API tokens, and operational scripts. After gaining access to a cloud account, attackers frequently use API calls to remotely read the user data of EC2 instances. This allows them to obtain critical credentials or environment configurations, enabling further lateral movement, privilege escalation, or data theft.
Timely detection of such API access activities helps prevent sensitive information leaks and business risks in cloud environments.
Write detection rules to identify behavior where EC2 instance user data is accessed via APIs, with particular attention to abnormal operations involving multiple user data retrievals within a short time frame.
When writing detection queries, please ensure that the
sourceIPAddressfield is included in the output results to facilitate subsequent validation.
Data source: CloudTrail, example data:
{ "awsRegion": "ap-southeast-2", "errorCode": "Client.UnauthorizedOperation", "errorMessage": "You are not authorized to perform this operation. User: arn:aws:sts::438465128930:assumed-role/stratus-red-team-get-usr-data-role/aws-go-sdk-1749607398822003000 is not authorized to perform: ec2:DescribeInstanceAttribute on resource: arn:aws:ec2:ap-southeast-2:438465128930:instance/* because no identity-based policy allows the ec2:DescribeInstanceAttribute action. Encoded authorization failure message: ajRSxjKx8LF10zGVej0ZnDmE9sneXWwqLxUq8boJO-GCF27wz0_VsRa0hpm2R3Y0BY2ciQtGhIvuyCBnUTEQJpmosADNT914IvQf_pF_BqUHphXNwH62V84rq6yFHOnGfTYYDh3-SEC9Wz1uvpI4y8xNBt3N7EeHslo4cUeJEbqnU_j3nkCFLopXYS9wKCCgWdEjYny4A7wGjEzh_dsDX9iU-V4J_8YAS5EZevv73qvpNqAva0751myR9Lc9v5Exzix-ZlIUT849cDNw05m9k8YuqEkcbsnBT_1cg3akEDd9cidMq9VzG08gcg1rzgkTOtY5KkOr_uN8OvsbPk5nlumldxuAwXgnWCYeE3E_CMGS0hVN_r4o3NIy0UVjCjt8ZkTo2PYZ8o7qnV2Mt9qP-qm4z1jMxhcpI9YVbv3uaWC-3RUJuPx9TWF6mXUtu57hBFMGdD_upwRY-pe3wP2CnyDTAYiVe7M5-bWIZLQz2hQ9qIkM6eMFzFg4nY-lH5pG3QbJ3Ycjd4ZJqs-h73gXkHpvco5O3OVHFFkf1-ZLDp1B-cpaICHMq-5thRJyXwB58h2yHC_akJ7n", "eventCategory": "Management", "eventID": "fefcd55e-d6a1-4414-8de7-b2e4e5bfa6ab", "eventName": "DescribeInstanceAttribute", "eventSource": "ec2.amazonaws.com", "eventTime": "2025-06-11T02:03:26Z", "eventType": "AwsApiCall", "eventVersion": "1.10", "managementEvent": true, "readOnly": true, "recipientAccountId": "438465128930", "requestID": "9b4b9eac-cd91-4439-b1b8-e3efc983fd00", "requestParameters": { "attribute": "userData", "instanceId": "i-48900665" }, "requestParameters.attribute": "userData", "responseElements": null, "sourceIPAddress": "103.97.2.20", "tlsDetails": { "cipherSuite": "TLS_AES_128_GCM_SHA256", "clientProvidedHostHeader": "ec2.ap-southeast-2.amazonaws.com", "tlsVersion": "TLSv1.3" }, "userAgent": "stratus-red-team_f35bceb2-2907-4857-8757-81f2ff283526", "userIdentity": { "accessKeyId": "ASIAWMFUO5HRBA65NSAV", "accountId": "438465128930", "arn": "arn:aws:sts::438465128930:assumed-role/stratus-red-team-get-usr-data-role/aws-go-sdk-1749607398822003000", "principalId": "AROAWMFUO5HREQSALCNDJ:aws-go-sdk-1749607398822003000", "sessionContext": { "attributes": { "creationDate": "2025-06-11T02:03:25Z", "mfaAuthenticated": "false" }, "sessionIssuer": { "accountId": "438465128930", "arn": "arn:aws:iam::438465128930:role/stratus-red-team-get-usr-data-role", "principalId": "AROAWMFUO5HREQSALCNDJ", "type": "Role", "userName": "stratus-red-team-get-usr-data-role" } }, "type": "AssumedRole" }}
No fields found