> 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/path-traversal/path-traversal-bypass-with-null-byte-and-extension-validation.md).

# Contournement de traversée de répertoires avec byte nul et validation d'extension

### Parcours de chemin de fichier, validation de l’extension de fichier avec contournement par octet nul

Ce laboratoire présente une vulnérabilité de parcours de répertoires lors de l’affichage des images des produits. / L’application vérifie que le nom de fichier fourni se termine bien par l’extension attendue.

L'objectif est de lire le contenu du **/etc/passwd** .

#### **Analyse**

Si le chemin est fourni directement

```bash
../../../../etc/passwd
```

L’application renvoie une erreur car elle exige que le fichier ait l’extension **.jpg**.

Dans les anciennes versions de PHP (avant **5.3.4**), il était possible d’utiliser un zéro **octet (%00)** pour contourner cette validation : / le moteur PHP cessait de lire le nom du fichier au niveau de l’octet nul, tandis que l’application continuait à voir une extension valide.

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

#### **Charge utile**

Ajoutez un octet nul avant l’extension :

```bash
%00.jpg
```

Le navigateur interprète toujours ".jpg", mais PHP s’arrête à " /etc/passwd", ce qui vous permet de lire le fichier sensible.

```bash
../../../../etc/passwd%00.jpg
```

<figure><img src="/files/6acd7ba8f3caab91e5219edc20b4f82d8c48ccf2" 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/path-traversal/path-traversal-bypass-with-null-byte-and-extension-validation.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.
