Potential Proxy Execution via PHP


Description

This rule detects the execution of a command or binary through the PHP interpreter. Attackers may use this technique to execute commands while attempting to evade detection.

Query · eql

process where event.type == "start" and event.action == "exec" and
process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and

// Check if the parent process is a PHP interpreter with an optional version number

process.parent.name regex~ """php?[0-9]?\.?[0-9]{0,2}""" and process.parent.args == "-r" and

// Check if -r is used right after the PHP process or process path

process.parent.command_line regex~ """(\/.*\/)?php[0-9]?\.?[0-9]{0,2} \-r .*"""

and not (
  process.command_line in (
    "sh -c mysql --version 2>/dev/null", "sh -c locale -a", "locale -a", "stty -a", "datadog-ipc-helper",
    "sh -c whereis -b traceroute", "sh -c git describe --always --tags --abbrev=0", "sh -c git rev-parse --short HEAD",
    "/usr/sbin/sendmail -t -i", "sh -c /usr/sbin/sendmail -t -i", "sh -c stty -a | grep columns", "whereis -b traceroute",
    "sh -c /usr/sbin/sendmail -t -i ", "sh -c exec rpm -q --queryformat '%{VERSION}.%{RELEASE}' SecurityCenter",
    "sh -c /usr/bin/convert -version 2>&1", "sh -c /usr/bin/convert -list delegate 2>&1"
  ) or
  process.args like ("/var/lib/asterisk/bin/backup.php*", "/usr/sbin/sendmail*") or
  process.executable in ("/usr/bin/newrelic-daemon", "/usr/bin/git") or 
  process.command_line like "*git*" or
  process.parent.command_line == "php get_monatsdaten.php -v -s1 -r"
)
Raw source Potential Proxy Execution via PHP · Elastic TOML
Esc
Published by elastic/protections-artifacts ↗, licensed under Elastic License 2.0 ↗. Reproduced here unmodified.
[rule]
description = """
This rule detects the execution of a command or binary through the PHP interpreter. Attackers may use this technique to
execute commands while attempting to evade detection.
"""
id = "dd914805-e99b-4ff6-b445-775c53d44e10"
license = "Elastic License v2"
name = "Potential Proxy Execution via PHP"
os_list = ["linux"]
reference = ["https://gtfobins.github.io/gtfobins/php/"]
version = "1.0.8"

query = '''
process where event.type == "start" and event.action == "exec" and
process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and

// Check if the parent process is a PHP interpreter with an optional version number

process.parent.name regex~ """php?[0-9]?\.?[0-9]{0,2}""" and process.parent.args == "-r" and

// Check if -r is used right after the PHP process or process path

process.parent.command_line regex~ """(\/.*\/)?php[0-9]?\.?[0-9]{0,2} \-r .*"""

and not (
  process.command_line in (
    "sh -c mysql --version 2>/dev/null", "sh -c locale -a", "locale -a", "stty -a", "datadog-ipc-helper",
    "sh -c whereis -b traceroute", "sh -c git describe --always --tags --abbrev=0", "sh -c git rev-parse --short HEAD",
    "/usr/sbin/sendmail -t -i", "sh -c /usr/sbin/sendmail -t -i", "sh -c stty -a | grep columns", "whereis -b traceroute",
    "sh -c /usr/sbin/sendmail -t -i ", "sh -c exec rpm -q --queryformat '%{VERSION}.%{RELEASE}' SecurityCenter",
    "sh -c /usr/bin/convert -version 2>&1", "sh -c /usr/bin/convert -list delegate 2>&1"
  ) or
  process.args like ("/var/lib/asterisk/bin/backup.php*", "/usr/sbin/sendmail*") or
  process.executable in ("/usr/bin/newrelic-daemon", "/usr/bin/git") or 
  process.command_line like "*git*" or
  process.parent.command_line == "php get_monatsdaten.php -v -s1 -r"
)
'''

min_endpoint_version = "7.15.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0

[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"



[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1218"
name = "System Binary Proxy Execution"
reference = "https://attack.mitre.org/techniques/T1218/"


[threat.tactic]
id = "TA0005"
name = "Defense Evasion"
reference = "https://attack.mitre.org/tactics/TA0005/"

[internal]
min_endpoint_version = "7.15.0"

Detection rules belong to the projects that publish them and remain under their own licenses. This site indexes and links to them; it claims no rights in them.