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

# 通过空字节和扩展名验证绕过

### 文件路径遍历，通过空字节绕过文件扩展名验证

这个实验展示了在显示产品图片时存在的路径遍历漏洞。/ 应用程序会检查所提供的文件名是否以预期的扩展名正确结尾。

目标是读取……的内容 **/etc/passwd** 文件中的用户进行测试。

#### **分析**

如果直接提供路径

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

应用程序会返回错误，因为它要求文件具有扩展名 **.jpg**.

在较早版本的 PHP 中（早于 **5.3.4**），可以使用零 **字节（%00）** 来绕过此验证：/ PHP 引擎在空字节处停止读取文件名，而应用程序仍然认为该扩展名是有效的。

<figure><img src="/files/90da337028e6c6271e9073196a9bf654474bf335" alt=""><figcaption></figcaption></figure>

#### **载荷**

在扩展名前添加一个空字节：

```bash
%00.jpg
```

浏览器仍然会解析 ".jpg"，但 PHP 会在“ /etc/passwd”处停止，因此你可以读取敏感文件。

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

<figure><img src="/files/abf0e00dbcb9a24d79570959509b029edad210a4" 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/zh/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.
