Detection rules › Elastic

Potential Proxy Execution via PHP

Source
github.com/elastic/protections-artifacts

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.

MITRE ATT&CK coverage

Rule body

[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"

Stages and Predicates

Stage 1: process

process where event.type == "start" and event.action == "exec" and
process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and
process.parent.name regex~ """php?[0-9]?\.?[0-9]{0,2}""" and process.parent.args == "-r" and
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"
)

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.argsstarts_with/var/lib/asterisk/bin/backup.php, /usr/sbin/sendmailexcludes:process.args field:"process.args" value:"/var/lib/asterisk/bin/backup.php" field:"process.args" value:"/usr/sbin/sendmail"
process.command_linein/usr/sbin/sendmail -t -i, datadog-ipc-helper, locale -a, sh -c /usr/bin/convert -list delegate 2>&1, sh -c /usr/bin/convert -version 2>&1, sh -c /usr/sbin/sendmail -t -i, sh -c /usr/sbin/sendmail -t -i , sh -c exec rpm -q --queryformat '%{VERSION}.%{RELEASE}' SecurityCenter, sh -c git describe --always --tags --abbrev=0, sh -c git rev-parse --short HEAD, sh -c locale -a, sh -c mysql --version 2>/dev/null, sh -c stty -a | grep columns, sh -c whereis -b traceroute, stty -a, whereis -b tracerouteexcludes:process.command_line
process.command_linematchgitexcludes:process.command_line field:"process.command_line" value:"git"
process.executablein/usr/bin/git, /usr/bin/newrelic-daemonexcludes:process.executable field:"process.executable" value:"/usr/bin/git" field:"process.executable" value:"/usr/bin/newrelic-daemon"
process.parent.command_lineeqphp get_monatsdaten.php -v -s1 -rexcludes:process.parent.command_line field:"process.parent.command_line" value:"php get_monatsdaten.php -v -s1 -r"

Indicators

These rows show field, operator, and value matches.