EC2 Instance Metadata Service Version 1 Enabled

EC2 instances still accept Instance Metadata Service version 1 requests, so a request forgery flaw in a hosted application can be used to steal the instance's IAM role credentials.

SeverityMedium
CVSS 3.16.8 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:N/A:N Open in the calculator
CVSS 4.08.9 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:N/VA:N/SC:H/SI:N/SA:N Open in the calculator
CWECWE-306: Missing Authentication for Critical Function
OWASP Top 10A07:2025 Authentication Failures
MITRE ATT&CKT1552.005 Cloud Instance Metadata API, T1078.004 Cloud Accounts
CategorySecurity Misconfiguration

Description

The EC2 Instance Metadata Service (IMDS), reachable from an instance at http://169.254.169.254, provides information about the instance, including temporary credentials for its IAM role. Version 1 (IMDSv1) answers simple GET requests. Version 2 (IMDSv2) requires a session token, obtained with a PUT request carrying the X-aws-ec2-metadata-token-ttl-seconds header and then sent with each request in an X-aws-ec2-metadata-token header. The token response is limited by a network hop limit, and token requests carrying an X-Forwarded-For header are refused.

When an instance's HttpTokens metadata option is optional, both versions are accepted. IMDSv1 is not exploitable on its own, but it turns another flaw into credential theft: an application on the instance that can be made to fetch a URL chosen by an attacker, through server-side request forgery (SSRF), an open proxy or a misconfigured reverse proxy, can then be used to read /latest/meta-data/iam/security-credentials/ and the role's credentials, because such flaws can usually send a plain GET but not the PUT with a custom header that IMDSv2 needs.

An unauthenticated attacker who exploits such a flaw can use those temporary credentials from anywhere to call AWS APIs with the role's permissions, which are often broad: reading S3 buckets, secrets and parameters, or changing infrastructure. The credentials remain valid for hours and can be refreshed by repeating the request. The impact depends on the role's permissions, and is greatest on internet-facing instances whose applications fetch URLs or proxy requests.

Whether a new instance accepts IMDSv1 depends on the AMI's ImdsSupport value, the account-level default for the Region and the launch parameters, so instances launched from older AMIs or by older templates often still allow it. The setting is reviewed with aws ec2 describe-instances (MetadataOptions.HttpTokens) and reported by Prowler, ScoutSuite and Security Hub. The CloudWatch metric MetadataNoToken shows whether IMDSv1 is still being used.

Remediation

Require IMDSv2 on every instance, after confirming that the software on it supports it:

aws ec2 modify-instance-metadata-options --instance-id "$INSTANCE_ID" --http-tokens required --http-endpoint enabled
  • Use the MetadataNoToken CloudWatch metric to find instances still making IMDSv1 calls, and update old AWS SDKs, CLI versions and agents that do not support IMDSv2 before enforcing it.
  • Set the account-level default for new launches in each Region (aws ec2 modify-instance-metadata-defaults --http-tokens required), set ImdsSupport to v2.0 on custom AMIs, and set HttpTokens to required in launch templates and infrastructure code.
  • Keep the PUT response hop limit (HttpPutResponseHopLimit) at 1 unless containers on the instance need the metadata service, in which case 2 is normally sufficient.
  • Disable the metadata endpoint (--http-endpoint disabled) on instances that do not use it, and stop IMDSv1 returning with service control policies that deny ec2:RunInstances unless ec2:MetadataHttpTokens is required, and deny ec2:ModifyInstanceMetadataOptions to everyone but administrators.
  • Fix any SSRF or proxy flaws found in the applications, and limit each instance role to the permissions it needs.

Confirm the fix with aws ec2 describe-instances showing HttpTokens as required for every instance, and by checking from the instance that a metadata request without a token is refused with HTTP 401.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More AWS Findings

Every AWS finding