Detection: Inline PHP Code Execution

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.

 1
 2| tstats `security_content_summariesonly`
 3  count min(_time) as firstTime
 4        max(_time) as lastTime
 5
 6FROM datamodel=Endpoint.Processes WHERE
 7
 8(
 9    (
10        Processes.process_name IN (
11            "php-cli.exe",
12            "php-win.exe",
13            "php.exe",
14            "php",
15            "php5*",
16            "php7*",
17            "php8*",
18            "php9*",
19        )
20        Processes.process IN ("* -r *", "* --run *", "* --run=*")
21        NOT Processes.process_name IN ("*cgi*", "*fpm*")
22    )
23    OR
24    (
25        Processes.process_name IN ("phpdbg", "phpdbg.exe")
26        Processes.process IN ("* -s", "* -s ", "* -s=*")
27    )
28    OR
29    (
30        Processes.process_name IN ("frankenphp", "frankenphp.exe")
31        Processes.process= "*php-cli*"
32        Processes.process= "* -r *"
33    )
34)
35
36by Processes.action Processes.dest Processes.original_file_name
37   Processes.parent_process Processes.parent_process_exec Processes.parent_process_guid
38   Processes.parent_process_id Processes.parent_process_name Processes.parent_process_path
39   Processes.process Processes.process_exec Processes.process_guid
40   Processes.process_hash Processes.process_id Processes.process_integrity_level
41   Processes.process_name Processes.process_path Processes.user
42   Processes.user_id Processes.vendor_product
43
44
45| `drop_dm_object_name(Processes)`
46
47| `security_content_ctime(firstTime)`
48
49| `security_content_ctime(lastTime)`
50
51| `inline_php_code_execution_filter`

Data Source

Name Platform Sourcetype Source
Windows Event Log Security 4688 Windows icon Windows 'XmlWinEventLog' 'XmlWinEventLog:Security'
CrowdStrike ProcessRollup2 Other 'crowdstrike:events:sensor' 'crowdstrike'
Sysmon EventID 1 Windows icon Windows 'XmlWinEventLog' 'XmlWinEventLog:Microsoft-Windows-Sysmon/Operational'
Sysmon for Linux EventID 1 Linux icon Linux 'sysmon:linux' 'Syslog:Linux-Sysmon/Operational'

Macros Used

Name Value
security_content_ctime convert timeformat="%Y-%m-%dT%H:%M:%S" ctime($field$)
inline_php_code_execution_filter search *
inline_php_code_execution_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.

Annotations

- MITRE ATT&CK
+ Kill Chain Phases
+ NIST
+ CIS
- Threat Actors
ID Technique Tactic
T1059 Command and Scripting Interpreter Execution
Installation
DE.AE
CIS 10

Default Configuration

This detection is configured by default in Splunk Enterprise Security to run with the following settings:

Setting Value
Disabled true
Cron Schedule 0 * * * *
Earliest Time -70m@m
Latest Time -10m@m
Schedule Window auto
Creates Finding (Notable) No
Creates Intermediate Finding (Risk Event) Yes
Anomaly detections generate Intermediate Findings (Risk Events). They do not generate a Finding (Notable) directly.

Implementation

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.

Associated Analytic Story

Intermediate Findings

Message Entity Field Entity Type Risk Score
PHP inline code execution using [$process_name$] was observed on endpoint [$dest$] by user [$user$] with command line [$process$]. dest system 20

Threat Objects

Field Type
process_name process_name
process process

References

Detection Testing

Test Type Status Dataset Source Sourcetype
Validation ✅ Passing N/A N/A N/A
Unit ✅ Passing Dataset XmlWinEventLog:Microsoft-Windows-Sysmon/Operational XmlWinEventLog
Integration ✅ Passing Dataset XmlWinEventLog:Microsoft-Windows-Sysmon/Operational XmlWinEventLog

Replay any dataset to Splunk Enterprise by using our replay.py tool or the UI. Alternatively you can replay a dataset into a Splunk Attack Range


Source: GitHub |

Version: 1