Medium Severity
Published: Nov 17, 2026

[GitHub] php2shell-poc

Other
Type
N/A
CVSS Score
10
Views
Anonymous
Author

Description

# php2shell — PHP 8.4.26 Session Vulnerability Reproduction

[中文](#中文) | [English](#english)

---

## 中文

在"完全远程、只用 HTTP、目标页面无 `session_start()`、不写任何目标侧 PHP"的约束下,用**一个 `exploit.py`** 打通 PHP 8.4.26 + Apache prefork + mod_php 的 RCE。目标页面只有 `<?php echo "OK\n"; ?>`。

### 支持范围(先读)

> **唯一支持的运行环境是官方 `php:8.4.26-apache` 镜像**(PHP 8.4.26 / Debian 12 / Apache prefork + mod_php)配合本仓库 [docker/](docker/) 下的配置。

这不是一个通用的 ASLR bypass,也没有关闭 ASLR:

- 利用过程只通过两次越界读泄漏 **Zend MM chunk base** 和 **libphp base**,不泄漏 libc、栈或完整内存映射。
- 地址空间仍然由 ASLR 随机化。宿主机内核 ASLR(kASLR)、容器运行时、内核 `mmap` 行为、分配器以及 PHP/Apache 的具体构建都会影响堆布局和泄漏结果。
- 链中的堆几何、标定值和 libphp 偏移是针对官方镜像实测的,不包含地址扫描或暴力枚举。换镜像、换 PHP 构建或换发行版后,即使地址仍能泄漏,后续伪造对象的布局也不一定成立。

Apache 侧也有硬性前提:

- 必须是 **prefork MPM + 单 worker + mod_php**。子进程 abort 后,父进程直接 `fork` 出新 worker,不重新 `exec`,因此 libphp 映射和各阶段依赖的地址空间得以保留。
- `docker/apache.conf` 固定 `StartServers/MinSpareServers/MaxSpareServers/MaxRequestWorkers/ServerLimit = 1`,`MaxConnectionsPerChild = 0`,并关闭 KeepAlive。
- 多 worker、event/worker MPM、Apache 重启/优雅重启、worker 重新 `exec`、容器重建或父进程退出,都可能重新随机化地址或让请求落到不同进程,整条链会失效。
- 如果任一阶段泄漏失败,ASLR 仍然有效;重试只是换一个 worker,并不会"击败"ASLR。

当前 RCE 还要求:`display_errors=1`、`memory_limit=8M`、`max_input_vars=1000`、`session.use_cookies=1`、`session.use_strict_mode=0`、`session.upload_progress.enabled=1`。

### 一键复现

本仓库不编译 PHP/Apache,也没有 `docker build`:环境就是官方 `php:8.4.26-apache` 镜像加 `docker/` 下的配置挂载。

```bash
# 依赖:Docker Engine/Desktop + Docker Compose v2 + Python 3.9+
git clone https://github.com/9bie/php2shell-bypass-aslr-exp.git
cd php2shell-bypass-aslr-exp

# 1) 拉官方镜像(PHP 8.4.26 / Debian 12 / Apache prefork)
docker compose -f docker/docker-compose.yml pull

# 2) 起目标:单 worker、display_errors=On、memory_limit=8M
docker compose -f docker/docker-compose.yml up -d

# 3) 等 Apache 就绪并确认普通页面
for i in $(seq 1 20); do
curl -fsS http://127.0.0.1:8088/index.php >/dev/null 2>&1 && break
sleep 0.5
done
curl -s http://127.0.0.1:8088/index.php # OK

# 4) 一条命令完成整个利用;首次运行会自动读取 libphp 偏移
python3 exploit.py -u http://127.0.0.1:8088
```

---

## English

Under the constraints of "fully remote, HTTP only, target page has no `session_start()`, no target-side PHP written," use **a single `exploit.py`** to achieve RCE on PHP 8.4.26 + Apache prefork + mod_php. The target page contains only `<?php echo "OK\n"; ?>`.

### Supported Scope (Read First)

> **The only supported runtime environment is the official `php:8.4.26-apache` image** (PHP 8.4.26 / Debian 12 / Apache prefork + mod_php) with configuration mounts from [docker/](docker/) in this repository.

This is not a generic ASLR bypass, nor is ASLR disabled:

- The exploitation process only leaks **Zend MM chunk base** and **libphp base** through two out-of-bounds reads; it does not leak libc, stack, or complete memory maps.
- The address space remains randomized by ASLR. Host kernel ASLR (kASLR), container runtime, kernel `mmap` behavior, allocator, and the specific builds of PHP/Apache all affect heap layout and leak results.
- The heap geometry, calibration values, and libphp offsets in the chain are measured against the official image; they do not include address scanning or brute-force enumeration. Changing the image, PHP build, or distribution may render the exploit ineffective even if addresses can still be leaked, as the subsequent object forgery layout may not hold.

There are also hard requirements on the Apache side:

- Must use **prefork MPM + single worker + mod_php**. After a child process aborts, the parent process directly `fork`s a new worker without re-`exec`ing, thus preserving libphp mappings and address space dependencies across stages.
- `docker/apache.conf` fixes `StartServers/MinSpareServers/MaxSpareServers/MaxRequestWorkers/ServerLimit = 1`, `MaxConnectionsPerChild = 0`, and disables KeepAlive.
- Multiple workers, event/worker MPM, Apache restarts/graceful restarts, worker re-`exec`, container rebuilds, or parent process exit may re-randomize addresses or route requests to different processes, breaking the entire chain.
- If any stage fails to leak, ASLR remains effective; retrying just switches to a different worker and does not "defeat" ASLR.

The current RCE also requires: `display_errors=1`, `memory_limit=8M`, `max_input_vars=1000`, `session.use_cookies=1`, `session.use_strict_mode=0`, `session.upload_progress.enabled=1`.

### One-Command Reproduction

This repository does not compile PHP/Apache and has no `docker build`: the environment is simply the official `php:8.4.26-apache` image plus mounted configuration from `docker/`.

```bash
# Dependencies: Docker Engine/Desktop + Docker Compose v2 + Python 3.9+
git clone https://github.com/9bie/php2shell-bypass-aslr-exp.git
cd php2shell-bypass-aslr-exp

# 1) Pull the official image (PHP 8.4.26 / Debian 12 / Apache prefork)
docker compose

Translated to English from Chinese. Show original · see the source links.
Community Rating
0

Login to rate this exploit

Quick Actions