Inline PHP Code Execution
The following analytic detects PHP command-line interpreters executing code supplied directly on the command line with the CLI -r / --run options, per-line execution flags, non-empty auto-prepend or auto-append settings, 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.
Detection Query
| 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-cli",
"php-win.exe",
"php.exe",
"php",
"php5*",
"php7*",
"php8*",
"php9*"
)
NOT Processes.process_name IN ("*cgi*", "*fpm*")
Processes.process IN (
"* -r *", "* --run *", "* --run=*", "* -r\"*", "* -r'*", "* -r$*",
"* -B *", "* -R *", "* -E *", "* -F *",
"* --process-begin *", "* --process-code *", "* --process-file *", "* --process-end *",
"*auto_prepend_file=*", "*auto_append_file=*", "*allow_url_include=*"
)
)
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 IN ("* -r *", "* -r\"*", "* -r'*", "* -r$*")
)
)
BY Processes.action Processes.dest Processes.original_file_name
Processes.parent_process Processes.parent_process_exec Processes.parent_process_guid
Processes.parent_process_id Processes.parent_process_name Processes.parent_process_path
Processes.process Processes.process_exec Processes.process_guid
Processes.process_hash Processes.process_id Processes.process_integrity_level
Processes.process_name Processes.process_path Processes.user
Processes.user_id Processes.vendor_product
| `drop_dm_object_name(Processes)`
| eval php_inline_r=if(match(process, "(^|\s)(-r|--run)(\s|=|\"|'|\$)"), 1, 0)
| eval php_per_line=if(match(process, "(^|\s)(-[BREF]|--process-(begin|code|file|end))(\s|$)"), 1, 0)
| eval php_ini_inject=if(match(process, "(?i)-d\s*\"?(auto_prepend_file|auto_append_file)\s*=\s*\"?[^\s\"']"), 1, 0)
| eval php_allow_url_include=if(match(process, "(?i)-d\s*\"?allow_url_include\s*=\s*\"?(?:1|on|true|yes)(?=\s|\"|'|$)"), 1, 0)
| eval phpdbg_or_franken=if(match(process_name, "(?i)^(phpdbg|frankenphp)"), 1, 0)
| where (
php_inline_r=1
OR php_per_line=1
OR php_ini_inject=1
OR php_allow_url_include=1
OR phpdbg_or_franken=1
)
| where NOT (
lower(parent_process_name)="cmd.exe"
AND like(lower(process), "%\\.config\\herd\\bin\\php8%\\php.exe%")
AND like(lower(process), "% -r \"define('laravel_start'%")
AND like(lower(process), "%vendor/autoload.php%")
AND like(lower(process), "%bootstrap/app.php%")
)
| `security_content_ctime(firstTime)`
| `security_content_ctime(lastTime)`
| `inline_php_code_execution_filter`
Author
Nasreddine Bencherchali, Onur Mustafa Erdogan, Raven Tait, Splunk
Created
2026-10-22
Data Sources
References
Tags
Raw Content
name: Inline PHP Code Execution
id: 312567b0-4e9b-4f3a-b842-a3ba17a89975
version: 2
creation_date: '2026-10-22'
modification_date: '2026-10-28'
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, per-line execution flags, non-empty auto-prepend or auto-append settings, 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-cli",
"php-win.exe",
"php.exe",
"php",
"php5*",
"php7*",
"php8*",
"php9*"
)
NOT Processes.process_name IN ("*cgi*", "*fpm*")
Processes.process IN (
"* -r *", "* --run *", "* --run=*", "* -r\"*", "* -r'*", "* -r$*",
"* -B *", "* -R *", "* -E *", "* -F *",
"* --process-begin *", "* --process-code *", "* --process-file *", "* --process-end *",
"*auto_prepend_file=*", "*auto_append_file=*", "*allow_url_include=*"
)
)
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 IN ("* -r *", "* -r\"*", "* -r'*", "* -r$*")
)
)
BY Processes.action Processes.dest Processes.original_file_name
Processes.parent_process Processes.parent_process_exec Processes.parent_process_guid
Processes.parent_process_id Processes.parent_process_name Processes.parent_process_path
Processes.process Processes.process_exec Processes.process_guid
Processes.process_hash Processes.process_id Processes.process_integrity_level
Processes.process_name Processes.process_path Processes.user
Processes.user_id Processes.vendor_product
| `drop_dm_object_name(Processes)`
| eval php_inline_r=if(match(process, "(^|\s)(-r|--run)(\s|=|\"|'|\$)"), 1, 0)
| eval php_per_line=if(match(process, "(^|\s)(-[BREF]|--process-(begin|code|file|end))(\s|$)"), 1, 0)
| eval php_ini_inject=if(match(process, "(?i)-d\s*\"?(auto_prepend_file|auto_append_file)\s*=\s*\"?[^\s\"']"), 1, 0)
| eval php_allow_url_include=if(match(process, "(?i)-d\s*\"?allow_url_include\s*=\s*\"?(?:1|on|true|yes)(?=\s|\"|'|$)"), 1, 0)
| eval phpdbg_or_franken=if(match(process_name, "(?i)^(phpdbg|frankenphp)"), 1, 0)
| where (
php_inline_r=1
OR php_per_line=1
OR php_ini_inject=1
OR php_allow_url_include=1
OR phpdbg_or_franken=1
)
| where NOT (
lower(parent_process_name)="cmd.exe"
AND like(lower(process), "%\\.config\\herd\\bin\\php8%\\php.exe%")
AND like(lower(process), "% -r \"define('laravel_start'%")
AND like(lower(process), "%vendor/autoload.php%")
AND like(lower(process), "%bootstrap/app.php%")
)
| `security_content_ctime(firstTime)`
| `security_content_ctime(lastTime)`
| `inline_php_code_execution_filter`
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/
intermediate_findings:
entities:
- field: dest
type: system
score: 20
message: PHP inline code execution using [$process_name$] was observed on endpoint [$dest$] by user [$user$] with command line [$process$].
threat_objects:
- field: process_name
type: process_name
- field: process
type: process
analytic_story:
- PHP2Shell
asset_type: Endpoint
mitre_attack_id:
- T1059
product:
- Splunk Enterprise
- Splunk Enterprise Security
- Splunk Cloud
category: endpoint
security_domain: endpoint
tests:
- name: True Positive Test - Windows
attack_data:
- data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/emerging_threats/php2shell/inline_php_exec_windows.log
source: XmlWinEventLog:Microsoft-Windows-Sysmon/Operational
sourcetype: XmlWinEventLog
test_type: unit
- name: True Positive Test - Linux
attack_data:
- data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/emerging_threats/php2shell/inline_php_exec_linux.log
source: Syslog:Linux-Sysmon/Operational
sourcetype: sysmon:linux
test_type: unit