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.
Once you have the $TOKEN , you can use it to fetch information (e.g., IAM role credentials, instance ID).
Based on the specific encoded format in your request ( http%3A%2F%2F169.254.169.254... ), this is often used in scenarios or security challenges like the Wiz Cloud Security Championship . If you are accessing it through a proxy endpoint, the command looks like this:
get_cached_token() local now=$(date +%s) if [ $now -ge $TOKEN_EXPIRY ]; then TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 3600") TOKEN_EXPIRY=$((now + 3600 - 60)) # refresh 1 minute early fi echo "$TOKEN"
: The specific endpoint responsible for evaluating your request and generating the session token. curl-url-http-3A-2F-2F169.254.169.254-2Flatest-2Fapi-2Ftoken
: A mandatory header defining how long the token remains valid (in this case, 6 hours).
Understanding the AWS IMDSv2 Token Fetch Command: curl 169.254.169
http://169.254.169.254/latest/api/token
The AWS metadata service is a RESTful API that provides information about an instance. The service is accessible only from within the instance and is used to retrieve metadata about the instance, such as its ID, type, and IP address. The service is typically used by applications running on the instance to access other AWS resources. The command curl -X PUT "http://169
Once the token is securely stored in the $TOKEN variable, it is used to retrieve the actual metadata:
(what our keyword does):
To successfully execute this request, you must use the PUT method and include a header specifying the token's Time-to-Live (TTL). If you are running this directly on an EC2 instance:
: Even if an attacker can execute a GET request through your app, they cannot easily perform the PUT handshake required to get a token. Conclusion Based on the specific encoded format in your
Writing a script to automate via IMDSv2 Share public link
: IMDSv2 requires a PUT request to ensure that simple GET-based SSRF vulnerabilities cannot trigger a token generation.
Originally, cloud metadata services were simple and dangerous.