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

# Обход с помощью null byte и проверки расширения

### Переход по пути к файлу, проверка расширения файла с обходом через нулевой байт

Этот лабораторный стенд демонстрирует уязвимость перехода по пути при отображении изображений товаров. / Приложение проверяет, что указанное имя файла корректно оканчивается ожидаемым расширением.

Цель — прочитать содержимое **/etc/passwd** файле.

#### **Анализ**

Если путь указан напрямую

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

Приложение возвращает ошибку, потому что требуется, чтобы файл имел расширение **.jpg**.

В более старых версиях PHP (до **5.3.4**), можно было использовать нулевой **байт (%00)** для обхода этой проверки: / движок PHP переставал читать имя файла на нулевом байте, в то время как приложение продолжало видеть допустимое расширение.

<figure><img src="/files/54d23b48ef25b4ea4530e09b7916f80f691b37e5" alt=""><figcaption></figcaption></figure>

#### **Полезная нагрузка**

Добавьте нулевой байт перед расширением:

```bash
%00.jpg
```

Браузер по-прежнему интерпретирует ".jpg", но PHP останавливается на " /etc/passwd", что позволяет прочитать конфиденциальный файл.

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

<figure><img src="/files/9e587169ac9a3ac217eb4d1406ce6685180cc5d2" 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/ru/web/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.
