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

# lab-7

## Exploiting XInclude to Retrieve Files

**Difficulty:** Practitioner

### Lab Description

This lab has a "Check stock" feature that embeds user input inside a server-side XML document, which is subsequently parsed. Because the full XML document isn't user-controlled, a classic XXE attack (which requires defining a `DOCTYPE`/DTD) isn't possible here.

**Objective:** Inject an XInclude statement to retrieve the contents of the `/etc/passwd` file.

### Solution

**Step 1 — Identify the constraint**

In this lab there's no visible, fully-controllable XML structure to manipulate directly — the input goes into a single parameter (`productId`) that the backend embeds into a larger, server-controlled SOAP/XML document. Since the `DOCTYPE` declaration must appear before the root element and the attacker doesn't control the full document, a standard external entity injection won't work.

**Step 2 — Use XInclude instead of a DTD**

XInclude is a separate XML feature that lets a single element pull in external content without requiring a `DOCTYPE` declaration — making it usable even when only a single parameter value is controlled.

**Step 3 — Inject the XInclude payload**

In the `productId` parameter (or any other vulnerable input field embedded into server-side XML), submit:

```xml
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include parse="text" href="file:///etc/passwd"/>
</foo>
```

This tells the parser to process the `xi:include` directive and pull in the contents of `/etc/passwd` as plain text at that location in the document.

**Step 4 — Confirm the result**

Send the request. The response reflects the contents of `/etc/passwd` in place of the original parameter value, confirming the file read.

### Conclusion

XInclude attacks expand the XXE attack surface beyond places where a full XML document — and therefore a `DOCTYPE`/DTD — is directly controllable. Any input that ends up embedded inside a server-side XML document is a potential injection point, even without DTD-based payloads.


---

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