Detection rules › Elastic

Remote Process Injection via Python

Source
github.com/elastic/protections-artifacts

Identifies attempt to perform remote process code injection from a python program.

MITRE ATT&CK coverage

TacticTechniques
Stealth

Rule body

[rule]
description = "Identifies attempt to perform remote process code injection from a python program."
id = "634dcd98-0656-48a8-bd41-5fa025b6c812"
license = "Elastic License v2"
name = "Remote Process Injection via Python"
os_list = ["windows"]
version = "1.0.8"

query = '''
api where process.Ext.api.behaviors == "cross-process" and process.Ext.api.metadata.target_address_name like "?*" and
 process.thread.Ext.call_stack_final_user_module.name : ("libffi*.dll", "python*.dll") and
 not process.Ext.api.metadata.target_address_name in ("PEB", "PEB32", "ProcessStartupInfo") and
 not process.Ext.api.summary like ("* PEB*", "* PEB32*", "*ProcessStartupInfo*", "*Data*", "*python??.dll*", "NtQueueApcThread( cmd.exe, Unbacked, NULL, NULL, NULL )") and
 not process.executable : ("?:\\Program Files\\*", "?:\\Program Files (x86)\\*.exe") and
 not (process.Ext.api.name == "WriteProcessMemory" and process.Ext.api.parameters.size == 4) and
 not process.thread.Ext.call_stack_final_user_module.path like
                                  ("c:\\program files\\*.dll",
                                   "c:\\program files (x86)\\*.dll",
                                   "c:\\programdata\\anaconda3\\python??.dll",
                                   "c:\\windows\\systemtemp\\chrome_unpacker_*\\python*.dll")
'''

min_endpoint_version = "8.10.0"
[[actions]]
action = "kill_process"
field = "Target.process.entity_id"
state = 0

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

[[optional_actions]]
action = "rollback"
field = "process.entity_id"
state = 0

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1055"
name = "Process Injection"
reference = "https://attack.mitre.org/techniques/T1055/"


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

[internal]
min_endpoint_version = "8.10.0"

Stages and Predicates

Stage 1: api

api where process.Ext.api.behaviors == "cross-process" and process.Ext.api.metadata.target_address_name like "?*" and
 process.thread.Ext.call_stack_final_user_module.name : ("libffi*.dll", "python*.dll") and
 not process.Ext.api.metadata.target_address_name in ("PEB", "PEB32", "ProcessStartupInfo") and
 not process.Ext.api.summary like ("* PEB*", "* PEB32*", "*ProcessStartupInfo*", "*Data*", "*python??.dll*", "NtQueueApcThread( cmd.exe, Unbacked, NULL, NULL, NULL )") and
 not process.executable : ("?:\\Program Files\\*", "?:\\Program Files (x86)\\*.exe") and
 not (process.Ext.api.name == "WriteProcessMemory" and process.Ext.api.parameters.size == 4) and
 not process.thread.Ext.call_stack_final_user_module.path like
                                  ("c:\\program files\\*.dll",
                                   "c:\\program files (x86)\\*.dll",
                                   "c:\\programdata\\anaconda3\\python??.dll",
                                   "c:\\windows\\systemtemp\\chrome_unpacker_*\\python*.dll")

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.Ext.api.nameeqWriteProcessMemoryexcludes:process.Ext.api.name field:"process.Ext.api.name" value:"WriteProcessMemory"
process.Ext.api.parameters.sizeeq4excludes:process.Ext.api.parameters.size field:"process.Ext.api.parameters.size" value:"4"
process.Ext.api.metadata.target_address_nameinPEB, PEB32, ProcessStartupInfoexcludes:process.Ext.api.metadata.target_address_name field:"process.Ext.api.metadata.target_address_name" value:"PEB" field:"process.Ext.api.metadata.target_address_name" value:"PEB32" field:"process.Ext.api.metadata.target_address_name" value:"ProcessStartupInfo"
process.Ext.api.summarywildcard* PEB*, * PEB32*, *ProcessStartupInfo*, *Data*, *python??.dll*, NtQueueApcThread( cmd.exe, Unbacked, NULL, NULL, NULL )excludes:process.Ext.api.summary
process.executablewildcard?:\Program Files\*, ?:\Program Files (x86)\*.exeexcludes:process.executable field:"process.executable" value:"?:\Program Files\*" field:"process.executable" value:"?:\Program Files (x86)\*.exe"
process.thread.Ext.call_stack_final_user_module.pathwildcardc:\program files\*.dll, c:\program files (x86)\*.dll, c:\programdata\anaconda3\python??.dll, c:\windows\systemtemp\chrome_unpacker_*\python*.dllexcludes:process.thread.Ext.call_stack_final_user_module.path

Indicators

These rows show field, operator, and value matches.