SSRF_METADATA_BYPASS security network_error ai_generated true

SSRF bypasses cloud metadata endpoint block via redirect or alternative IP representation

ID: security/ssrf-cloud-metadata-bypass

Also available as: JSON · Markdown · 中文
85%Fix Rate
89%Confidence
1Evidence
2025-02-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
AWS IMDSv1 active
GCP Metadata Server 2023 active
Azure IMDS 2024-02-01 active

Root Cause

The application blocks direct requests to 169.254.169.254 but does not handle redirects to that IP or alternative representations such as decimal IP (2852039166), IPv6 mapped IPv4 (::ffff:169.254.169.254), or DNS rebinding, allowing SSRF to access cloud metadata.

generic

中文

应用程序阻止直接请求169.254.169.254,但未处理重定向到该IP或替代表示形式(如十进制IP 2852039166、IPv6映射IPv4 ::ffff:169.254.169.254或DNS重绑定),使SSRF可以访问云元数据。

Official Documentation

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html

Workarounds

  1. 90% success Use a DNS resolver that resolves all hostnames and validate that the resolved IP is not in the private or link-local range (169.254.0.0/16, 10.0.0.0/8, etc.) before making the request. Example in Python: import socket; ip = socket.gethostbyname(hostname); if ipaddress.ip_address(ip).is_private: raise Exception('Blocked SSRF')
    Use a DNS resolver that resolves all hostnames and validate that the resolved IP is not in the private or link-local range (169.254.0.0/16, 10.0.0.0/8, etc.) before making the request. Example in Python: import socket; ip = socket.gethostbyname(hostname); if ipaddress.ip_address(ip).is_private: raise Exception('Blocked SSRF')
  2. 85% success Disable redirect following in HTTP clients (e.g., requests.get(url, allow_redirects=False)) to prevent redirect-based SSRF
    Disable redirect following in HTTP clients (e.g., requests.get(url, allow_redirects=False)) to prevent redirect-based SSRF
  3. 80% success Use IMDSv2 with a session token that requires a PUT request, making it harder for SSRF to access metadata even if the IP is reached
    Use IMDSv2 with a session token that requires a PUT request, making it harder for SSRF to access metadata even if the IP is reached

中文步骤

  1. Use a DNS resolver that resolves all hostnames and validate that the resolved IP is not in the private or link-local range (169.254.0.0/16, 10.0.0.0/8, etc.) before making the request. Example in Python: import socket; ip = socket.gethostbyname(hostname); if ipaddress.ip_address(ip).is_private: raise Exception('Blocked SSRF')
  2. Disable redirect following in HTTP clients (e.g., requests.get(url, allow_redirects=False)) to prevent redirect-based SSRF
  3. Use IMDSv2 with a session token that requires a PUT request, making it harder for SSRF to access metadata even if the IP is reached

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Attackers can use decimal IP (2852039166), hex (0xA9FEA9FE), or DNS names that resolve to that IP.

  2. 70% fail

    Does not block alternative ports (e.g., 443) or redirects that come from other IPs.

  3. 65% fail

    Attackers can use IPv6 mapped addresses or DNS rebinding to bypass the deny list.