PHP RCE in a Restricted Environment Using pcntl_fork and pcntl_ex
The PHP functions exec, shell_exec, system, and others were disabled, but pcntl_exec and pcntl_fork remained enabled. An attacker who can upload a PHP shell could use these functions to execute arbitrary commands and achieve remote code execution.
⚠️ Disclaimer: This content is for educational purposes only. Do not use in unauthorized environments
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could execute arbitrary commands on the server, leading to full system compromise.
What the attacker needed
Ability to upload a PHP file; pcntl_exec and pcntl_fork enabled
The fix
The fix should be to disable pcntl_exec and pcntl_fork in php.ini, or remove the pcntl extension if not needed.
How it was found
- Upload a PHP shell to the target.
- Open the shell in a browser and try to run a command, which fails because shell_exec is disabled.
- Run a function checker script to see which functions are enabled.
- Find that pcntl_exec and pcntl_fork are enabled.
- Create a new shell that uses pcntl_fork and pcntl_exec to run commands.
- Upload the new shell and execute commands successfully.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
In PHP, some functions let you run system commands. Defenders often disable the common ones to stop attackers. But if a less common function like pcntl_exec is left enabled, an attacker who can run PHP code can still execute commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.