> For the complete documentation index, see [llms.txt](https://x7331.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://x7331.gitbook.io/notes/htb/api-attacks/ssrf.md).

# SSRF

> [CWE-918: Server-Side Request Forgery (SSRF)](https://cwe.mitre.org/data/definitions/918.html)

* When an API fetches a remote resource without validating the user-supplied URL.
* The attacker can force the app to send a request to an unexpected destination, such as localhost, bypassing firewalls or VPNs.

The web API stores the path of the files using the `file` URI scheme, which is used to represent local file paths (Figure 1).&#x20;

<figure><img src="/files/fL8GQGfQ14xoOUqojCu2" alt=""><figcaption><p>Figure 1: Finding a potential vulnerable-to-SSRF endpoint.</p></figcaption></figure>

This path is stored under the `/supplier-companies/current-user` endpoint (Figure 2).

<figure><img src="/files/VHr3kZTB4D2tro13iVJb" alt=""><figcaption><p>Figure 2: The URI path is now stored in the application.</p></figcaption></figure>

The `/api/v1/supplier-companies` `PATCH` endpoint allows the user to modify the URI path (Figure 3); this should not be the case as it should be dynamically set only by the value defined by the `/api/v1/supplier-companies/certificates-of-incorporation` `POST` endpoint.

<figure><img src="/files/9Kq2ZCEIgBTGsEQHYqwB" alt=""><figcaption><p>Figure 3: The URI path can be manually modified by the user.</p></figcaption></figure>

An attacker could leverage this flaw and read a local file, such as `/etc/passwd` (Figure 4).

<figure><img src="/files/2cTfhC8P5Lz7LuimJOUz" alt=""><figcaption><p>Figure 4: Leveraging SSRF to read a local file.</p></figcaption></figure>

## Exercise

<figure><img src="/files/KW2HlrNrXaPXPcEtMAmB" alt=""><figcaption><p>Figure 5: Exploiting another SSRF vulnerability.</p></figcaption></figure>
