Name:Inline PHP Code Execution id:312567b0-4e9b-4f3a-b842-a3ba17a89975 version:1 date:None author:Nasreddine Bencherchali, Onur Mustafa Erdogan, Raven Tait, Splunk status:production type:Anomaly Description:The following analytic detects PHP command-line interpreters executing code supplied directly on the command line with the CLI -r / --run options, or code supplied to PHPDBG through standard input.
It covers common CLI executable names on Linux and Windows, including php.exe, php-win.exe, the legacy php-cli.exe name, versioned Linux php binaries, phpdbg, and FrankenPHP's php-cli subcommand.
PHP-CGI and PHP-FPM are excluded because they do not support the PHP CLI inline -r option.
This behavior can be used legitimately for administration and automation, but unexpected or obfuscated inline PHP execution may indicate an attacker using an installed interpreter to run commands without dropping a script file.
Data_source:
-CrowdStrike ProcessRollup2
-Sysmon EventID 1
-Sysmon for Linux EventID 1
-Windows Event Log Security 4688
search:| tstats `security_content_summariesonly` count min(_time) as firstTime max(_time) as lastTime
FROM datamodel=Endpoint.Processes WHERE
( ( Processes.process_name IN ( "php-cli.exe", "php-win.exe", "php.exe", "php", "php5*", "php7*", "php8*", "php9*", ) Processes.process IN ("* -r *", "* --run *", "* --run=*") NOT Processes.process_name IN ("*cgi*", "*fpm*") ) OR ( Processes.process_name IN ("phpdbg", "phpdbg.exe") Processes.process IN ("* -s", "* -s ", "* -s=*") ) OR ( Processes.process_name IN ("frankenphp", "frankenphp.exe") Processes.process= "*php-cli*" Processes.process= "* -r *" ) )
how_to_implement:The detection is based on data that originates from Endpoint Detection and Response (EDR) agents. These agents are designed to provide security-related telemetry from the endpoints where the agent is installed. To implement this search, you must ingest logs that contain the process GUID, process name, and parent process. Additionally, you must ingest complete command-line executions. These logs must be processed using the appropriate Splunk Technology Add-ons that are specific to the EDR product. The logs must also be mapped to the `Processes` node of the `Endpoint` data model. Use the Splunk Common Information Model (CIM) to normalize the field names and speed up the data modeling process.
known_false_positives:Developers and administrators may use PHP CLI or PHPDBG for legitimate automation and troubleshooting. Review the command line, parent process, user, host, and execution context. Tune approved automation by host or parent process as needed.
References: -https://www.php.net/commandline.options -https://www.php.net/phpdbg -https://www.php2shell.com/ drilldown_searches:
: analytic_story:['PHP2Shell']