> For the complete documentation index, see [llms.txt](https://legacy.thehacker.recipes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://legacy.thehacker.recipes/web/inputs/null-byte-injection.md).

# Null-byte injection

## Theory

Null byte is a bypass technique for sending data that would be filtered otherwise. It relies on injecting the null byte characters (`%00`, `\x00`) in the supplied data. Its role is to terminate a string.

## Practice

### File access restriction by extension

Accessing a file in an application that appends an extension.

Example:

1. An attacker wants to retrieve the file`/etc/passwd` but an extension `.php` is appended automatically such as `/etc/passwd.php`.
2. The attacker uses the null byte to terminate the string and throw away the `.php` extension: `/etc/passwd%00`

### File upload restriction by extension

Uploading a file that is filtered by its extension.

Example:

1. An attacker wants to upload a `malicious.php`, but the only extension allowed is `.pdf`.
2. The attacker constructs the file name such as `malicious.php%00.pdf` and uploads the file.
3. The application reads the `.pdf` extension, validate the upload, and later throws the end of the string due to the null byte.
4. The file `malicious.php` is then put in the server.


---

# 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://legacy.thehacker.recipes/web/inputs/null-byte-injection.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.
