SSRF通过重定向或替代IP表示绕过云元数据端点封锁
SSRF bypasses cloud metadata endpoint block via redirect or alternative IP representation
ID: security/ssrf-cloud-metadata-bypass
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| AWS IMDSv1 | active | — | — | — |
| GCP Metadata Server 2023 | active | — | — | — |
| Azure IMDS 2024-02-01 | active | — | — | — |
根因分析
应用程序阻止直接请求169.254.169.254,但未处理重定向到该IP或替代表示形式(如十进制IP 2852039166、IPv6映射IPv4 ::ffff:169.254.169.254或DNS重绑定),使SSRF可以访问云元数据。
English
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.
官方文档
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html解决方案
-
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') -
Disable redirect following in HTTP clients (e.g., requests.get(url, allow_redirects=False)) to prevent redirect-based SSRF
-
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
无效尝试
常见但无效的做法:
-
90% 失败
Attackers can use decimal IP (2852039166), hex (0xA9FEA9FE), or DNS names that resolve to that IP.
-
70% 失败
Does not block alternative ports (e.g., 443) or redirects that come from other IPs.
-
65% 失败
Attackers can use IPv6 mapped addresses or DNS rebinding to bypass the deny list.