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