Detection rules › Elastic

Suspicious PHP Script Execution

Time window
5m
Source
github.com/elastic/protections-artifacts

Identifies the execution a PHP script utility that was recently dropped followed by an egress network activity or spawning a suspicious child process.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Identifies the execution a PHP script utility that was recently dropped followed by an egress network activity or
spawning a suspicious child process.
"""
id = "fb54419b-1284-4e85-abfd-aac59db82c8b"
license = "Elastic License v2"
name = "Suspicious PHP Script Execution"
os_list = ["windows"]
version = "1.0.4"

query = '''
sequence with maxspan=5m
 [any where
  (
   (event.category == "process" and event.type == "start" and process.pe.original_file_name == "php.exe" and
    (process.Ext.relative_file_creation_time <= 300 or process.Ext.relative_file_name_modify_time <= 300) and
    process.executable : "C:\\*") or

   (event.category == "library" and event.action == "load" and dll.pe.original_file_name : ("php?.dll", "php.dll") and
    (dll.Ext.relative_file_creation_time <= 300 or dll.Ext.relative_file_name_modify_time <= 300) and
    process.executable : "C:\\*")
   ) and
  process.executable : ("C:\\Users\\*.exe", "C:\\ProgramData\\*.exe", "C:\\Windows\\*")
 ] as event0
[any where
   /* spawn a child process */
   (event.category == "process" and event.action == "start" and process.name : ("cmd.exe", "powershell.exe") and
    process.parent.entity_id == event0.process.entity_id and
    not process.command_line : ("* /V:ON /E:ON /D*", "cmd.exe /c \"echo '%os%'\"",
                                "cmd.exe /s /c \"echo '%os%'\"", "cmd.exe /s /c \"mode CON\"",
                                "cmd.exe /s /c \"stty 2>&1\"", "cmd.exe /c \"stty 2> NUL\"", "cmd.exe /c mode CON")) or
   /* DNS lookup */
   (event.category == "dns" and process.entity_id == event0.process.entity_id and dns.question.name != null) or
   /* perform an egress conn to the internet */
   (event.category == "network" and event.action in ("disconnect_received", "connection_attempted") and
    process.entity_id == event0.process.entity_id and
    not cidrmatch(destination.ip, "10.0.0.0/8", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24",
       "192.0.0.0/29", "192.0.0.8/32", "192.0.0.9/32", "192.0.0.10/32", "192.0.0.170/32", "192.0.0.171/32",
       "192.0.2.0/24", "192.31.196.0/24", "192.52.193.0/24", "192.88.99.0/24", "224.0.0.0/4",
       "100.64.0.0/10", "192.175.48.0/24","198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "240.0.0.0/4", "::1",
       "FE80::/10", "FF00::/8"))]
'''

min_endpoint_version = "8.4.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.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.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1071"
name = "Application Layer Protocol"
reference = "https://attack.mitre.org/techniques/T1071/"


[threat.tactic]
id = "TA0011"
name = "Command and Control"
reference = "https://attack.mitre.org/tactics/TA0011/"

[internal]
min_endpoint_version = "8.4.0"

Stages and Predicates

Stage 1: any

[any where
  (
   (event.category == "process" and event.type == "start" and process.pe.original_file_name == "php.exe" and
    (process.Ext.relative_file_creation_time <= 300 or process.Ext.relative_file_name_modify_time <= 300) and
    process.executable : "C:\\*") or

   (event.category == "library" and event.action == "load" and dll.pe.original_file_name : ("php?.dll", "php.dll") and
    (dll.Ext.relative_file_creation_time <= 300 or dll.Ext.relative_file_name_modify_time <= 300) and
    process.executable : "C:\\*")
   ) and
  process.executable : ("C:\\Users\\*.exe", "C:\\ProgramData\\*.exe", "C:\\Windows\\*")
 ] as event0

Stage 2: any

[any where
   (event.category == "process" and event.action == "start" and process.name : ("cmd.exe", "powershell.exe") and
    process.parent.entity_id == event0.process.entity_id and
    not process.command_line : ("* /V:ON /E:ON /D*", "cmd.exe /c \"echo '%os%'\"",
                                "cmd.exe /s /c \"echo '%os%'\"", "cmd.exe /s /c \"mode CON\"",
                                "cmd.exe /s /c \"stty 2>&1\"", "cmd.exe /c \"stty 2> NUL\"", "cmd.exe /c mode CON")) or
   (event.category == "dns" and process.entity_id == event0.process.entity_id and dns.question.name != null) or
   (event.category == "network" and event.action in ("disconnect_received", "connection_attempted") and
    process.entity_id == event0.process.entity_id and
    not cidrmatch(destination.ip, "10.0.0.0/8", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24",
       "192.0.0.0/29", "192.0.0.8/32", "192.0.0.9/32", "192.0.0.10/32", "192.0.0.170/32", "192.0.0.171/32",
       "192.0.2.0/24", "192.31.196.0/24", "192.52.193.0/24", "192.88.99.0/24", "224.0.0.0/4",
       "100.64.0.0/10", "192.175.48.0/24","198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "240.0.0.0/4", "::1",
       "FE80::/10", "FF00::/8"))]

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
dll.Ext.relative_file_creation_timele
  • 300 transforms: number corpus 7 (elastic 7)
field:"dll.Ext.relative_file_creation_time" kind:le value:"300"
dll.Ext.relative_file_name_modify_timele
  • 300 transforms: number corpus 2 (elastic 2)
field:"dll.Ext.relative_file_name_modify_time" kind:le value:"300"
dll.pe.original_file_namewildcard
  • php.dll
  • php?.dll
field:"dll.pe.original_file_name" kind:wildcard
dns.question.nameis_not_null
  • (no value, null check)
field:"QueryName" kind:is_not_null
event.actioneq
  • load corpus 24 (elastic 24)
  • start corpus 391 (elastic 391)
field:"EventType" kind:eq
event.actionin
  • connection_attempted corpus 73 (elastic 73)
  • disconnect_received corpus 2 (elastic 2)
field:"EventType" kind:in
event.categoryeq
  • dns corpus 3 (elastic 3)
  • library corpus 22 (elastic 22)
  • network corpus 19 (elastic 19)
  • process corpus 142 (elastic 142)
field:"event.category" kind:eq
event.typeeq
  • start corpus 1078 (elastic 1078)
field:"event.type" kind:eq value:"start"
process.Ext.relative_file_creation_timele
  • 300 transforms: number corpus 11 (elastic 11)
field:"process.Ext.relative_file_creation_time" kind:le value:"300"
process.Ext.relative_file_name_modify_timele
  • 300 transforms: number corpus 9 (elastic 9)
field:"process.Ext.relative_file_name_modify_time" kind:le value:"300"
process.entity_ideq
  • event0.process.entity_id (field reference) corpus 4 (elastic 4)
field:"process_guid" kind:eq value:"event0.process.entity_id"
process.executablewildcard
  • C:\* corpus 16 (elastic 16)
  • C:\ProgramData\*.exe corpus 3 (elastic 3)
  • C:\Users\*.exe corpus 3 (elastic 3)
  • C:\Windows\* corpus 2 (sigma 1, elastic 1)
field:"Image" kind:wildcard
process.namewildcard
  • cmd.exe corpus 121 (elastic 92, splunk 29)
  • powershell.exe corpus 184 (elastic 140, splunk 44)
field:"process_name" kind:wildcard
process.parent.entity_ideq
  • event0.process.entity_id (field reference) corpus 2 (elastic 2)
field:"parent_process_guid" kind:eq value:"event0.process.entity_id"
process.pe.original_file_nameeq
  • php.exe corpus 2 (sigma 1, elastic 1)
field:"OriginalFileName" kind:eq value:"php.exe"