Curl-url-http-3a-2f-2f169.254.169.254-2flatest-2fapi-2ftoken _hot_
The command curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"
Replace YOUR_TOKEN_HERE with the actual token received from the /latest/api/token endpoint. curl-url-http-3A-2F-2F169.254.169.254-2Flatest-2Fapi-2Ftoken
The command curl -X PUT "http://169.254.169" is essential for generating a Session Token required to access Amazon Web Services (AWS) Instance Metadata Service Version 2 (IMDSv2). This method secures EC2 instance metadata access by mitigating Server-Side Request Forgery (SSRF) vulnerabilities, requiring a token rather than allowing direct, unauthenticated access. The command curl -X PUT "http://169
How IMDSv2 Works
- Token retrieval: The instance first makes a
PUTrequest tohttp://169.254.169.254/latest/api/tokenwith aX-aws-ec2-metadata-token-ttl-secondsheader (e.g., 21600 for 6 hours). - Token usage: The returned token is then included in subsequent metadata requests using the
X-aws-ec2-metadata-tokenheader. - Metadata access: With the token, the instance can access paths like
/latest/meta-data/iam/security-credentials/role-name.
The server makes a request from its internal IP to the metadata service, retrieves the token, and potentially returns it in an error message or redirect. Token retrieval : The instance first makes a
-X PUT: IMDSv2 requires a PUT request to ensure that simple GET-based SSRF vulnerabilities cannot trigger a token generation.