> For the complete documentation index, see [llms.txt](https://hacktricks.xsx.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacktricks.xsx.tw/pentesting-web/file-inclusion/via-php_session_upload_progress.md).

# LFI2RCE via PHP\_SESSION\_UPLOAD\_PROGRESS

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想看到您的**公司在 HackTricks 中做广告**或**下载 PDF 版的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)\*\* 上\*\*关注我们。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>

## 基本信息

如果您发现了一个**本地文件包含**漏洞，即使您**没有会话**且 `session.auto_start` 为 `Off`。如果 **`session.upload_progress.enabled`** 为 **`On`**，并且您在**多部分 POST** 数据中提供了 **`PHP_SESSION_UPLOAD_PROGRESS`**，PHP 将**为您启用会话**。

```bash
$ curl http://127.0.0.1/ -H 'Cookie: PHPSESSID=iamorange'
$ ls -a /var/lib/php/sessions/
. ..
$ curl http://127.0.0.1/ -H 'Cookie: PHPSESSID=iamorange' -d 'PHP_SESSION_UPLOAD_PROGRESS=blahblahblah'
$ ls -a /var/lib/php/sessions/
. ..
$ curl http://127.0.0.1/ -H 'Cookie: PHPSESSID=iamorange' -F 'PHP_SESSION_UPLOAD_PROGRESS=blahblahblah'  -F 'file=@/etc/passwd'
$ ls -a /var/lib/php/sessions/
. .. sess_iamorange

In the last example the session will contain the string blahblahblah
```

请注意，使用 **`PHP_SESSION_UPLOAD_PROGRESS`** 您可以**控制会话内的数据**，因此，如果包含您的会话文件，您可以包含您控制的部分（例如一个 PHP shellcode）。

{% hint style="info" %}
尽管互联网上的大多数教程建议您将 `session.upload_progress.cleanup` 设置为 `Off` 以进行调试。但 PHP 中默认的 `session.upload_progress.cleanup` 仍然是 `On`。这意味着您的会话中的上传进度将尽快清除。因此，这将是**竞争条件**。
{% endhint %}

### 夺旗赛

在[**原始夺旗赛**](https://blog.orange.tw/2018/10/)中，评论了这种技术，利用竞争条件是不够的，加载的内容还需要以字符串 `@<?php` 开头。

由于 `session.upload_progress.prefix` 的默认设置，我们的**会话文件将以烦人的前缀** `upload_progress_` 开头，例如：`upload_progress_controlledcontentbyattacker`

**去除初始前缀**的技巧是**将有效载荷进行三次 base64 编码**，然后通过 `convert.base64-decode` 过滤器解码，这是因为**在 base64 解码时 PHP 会删除奇怪的字符**，所以经过 3 次后，只有**攻击者发送的有效载荷**会**保留**（然后攻击者可以控制初始部分）。

更多信息请查看原始写作 <https://blog.orange.tw/2018/10/> 和最终利用 <https://github.com/orangetw/My-CTF-Web-Challenges/blob/master/hitcon-ctf-2018/one-line-php-challenge/exp_for_php.py>\
另一篇写作在 <https://spyclub.tech/2018/12/21/one-line-and-return-of-one-line-php-writeup/>
