Detection rules › Elastic

Memory Allocation from a High Entropy Module

Source
github.com/elastic/protections-artifacts

Identifies the load of a signed DLL followed by calling VirtualAlloc API to allocate writable and executable memory. This may indicate an attempt to perform code injection from a signed library.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Identifies the load of a signed DLL followed by calling VirtualAlloc API to allocate writable and executable memory.
This may indicate an attempt to perform code injection from a signed library.
"""
id = "8f9a6523-fa8f-46d1-b2de-72ef18e85f52"
license = "Elastic License v2"
name = "Memory Allocation from a High Entropy Module"
os_list = ["windows"]
version = "1.0.6"

query = '''
sequence
[file where event.type in ("creation", "change") and user.id != "S-1-5-18" and process.pid != 4 and
 file.Ext.header_bytes : "4d5a*" and file.Ext.entropy >= 6 and
 not file.path : ("?:\\Windows\\Installer\\*",
                  "?:\\Windows\\System32\\DriverStore\\FileRepository\\*",
                  "?:\\Windows\\SysWOW64\\DriverStore\\FileRepository\\*",
                  "?:\\Windows\\assembly\\*",
                  "?:\\Program Files\\*",
                  "?:\\Program Files (x86)\\*")] as event0
[api where
  process.Ext.api.name : ("VirtualAlloc*", "MapViewOfFile*") and process.Ext.api.parameters.protection == "RWX" and
  process.Ext.api.metadata.target_address_name == "Unbacked" and
  process.Ext.token.integrity_level_name in ("medium", "high") and
  process.thread.Ext.call_stack_final_user_module.hash.sha256 != null and
  _arraysearch(process.thread.Ext.call_stack_final_user_module.code_signature, $entry, $entry.trusted == true and 
               not $entry.subject_name : ("College Board", "SEIKO EPSON CORPORATION", "EPADLINK", "Flexera Software, Inc. ", "Acresso Software Inc.", "Realtek Semiconductor Corp")) and
  stringcontains~(process.thread.Ext.call_stack_final_user_module.path, event0.file.path) and
  (
   endswith~(process.thread.Ext.call_stack_summary, concat("ntdll.dll|kernelbase.dll|", event0.file.name)) or
   endswith~(process.thread.Ext.call_stack_summary, concat("ntdll.dll|", event0.file.name))
   ) and
   not process.executable : ("?:\\Program Files\\*", "?:\\Program Files (x86)\\*") and
   not startswith~(process.thread.Ext.call_stack_final_user_module.name, process.name) and
   not (process.thread.Ext.call_stack_final_user_module.name in ("isrt.dll", "issetup.dll", "_isres.dll", "wow64.lmd") and
        process.thread.Ext.call_stack_summary in
                               ("ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|isrt.dll",
                                "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|issetup.dll",
                                "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|_isres.dll",
                                "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|wow64.lmd")) and
   not (process.executable : "?:\\Windows\\SysWOW64\\msiexec.exe" and
        process.thread.Ext.call_stack_final_user_module.name like "msi*.tmp" and
        process.thread.Ext.call_stack_summary like "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|msi*.tmp") and
   process.thread.Ext.call_stack_final_user_module.hash.sha256 != "b35e38071d8f32e1cfc51f7aa4c7f406461eb062123fd25ef746b3c75416c01a"
   ]
until [process where event.action == "end"]
'''

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

[[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.technique]]
id = "T1574"
name = "Hijack Execution Flow"
reference = "https://attack.mitre.org/techniques/T1574/"
[[threat.technique.subtechnique]]
id = "T1574.001"
name = "DLL"
reference = "https://attack.mitre.org/techniques/T1574/001/"



[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: file

[file where event.type in ("creation", "change") and user.id != "S-1-5-18" and process.pid != 4 and
 file.Ext.header_bytes : "4d5a*" and file.Ext.entropy >= 6 and
 not file.path : ("?:\\Windows\\Installer\\*",
                  "?:\\Windows\\System32\\DriverStore\\FileRepository\\*",
                  "?:\\Windows\\SysWOW64\\DriverStore\\FileRepository\\*",
                  "?:\\Windows\\assembly\\*",
                  "?:\\Program Files\\*",
                  "?:\\Program Files (x86)\\*")] as event0

Stage 2: api

[api where
  process.Ext.api.name : ("VirtualAlloc*", "MapViewOfFile*") and process.Ext.api.parameters.protection == "RWX" and
  process.Ext.api.metadata.target_address_name == "Unbacked" and
  process.Ext.token.integrity_level_name in ("medium", "high") and
  process.thread.Ext.call_stack_final_user_module.hash.sha256 != null and
  _arraysearch(process.thread.Ext.call_stack_final_user_module.code_signature, $entry, $entry.trusted == true and 
               not $entry.subject_name : ("College Board", "SEIKO EPSON CORPORATION", "EPADLINK", "Flexera Software, Inc. ", "Acresso Software Inc.", "Realtek Semiconductor Corp")) and
  stringcontains~(process.thread.Ext.call_stack_final_user_module.path, event0.file.path) and
  (
   endswith~(process.thread.Ext.call_stack_summary, concat("ntdll.dll|kernelbase.dll|", event0.file.name)) or
   endswith~(process.thread.Ext.call_stack_summary, concat("ntdll.dll|", event0.file.name))
   ) and
   not process.executable : ("?:\\Program Files\\*", "?:\\Program Files (x86)\\*") and
   not startswith~(process.thread.Ext.call_stack_final_user_module.name, process.name) and
   not (process.thread.Ext.call_stack_final_user_module.name in ("isrt.dll", "issetup.dll", "_isres.dll", "wow64.lmd") and
        process.thread.Ext.call_stack_summary in
                               ("ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|isrt.dll",
                                "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|issetup.dll",
                                "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|_isres.dll",
                                "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|wow64.lmd")) and
   not (process.executable : "?:\\Windows\\SysWOW64\\msiexec.exe" and
        process.thread.Ext.call_stack_final_user_module.name like "msi*.tmp" and
        process.thread.Ext.call_stack_summary like "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|msi*.tmp") and
   process.thread.Ext.call_stack_final_user_module.hash.sha256 != "b35e38071d8f32e1cfc51f7aa4c7f406461eb062123fd25ef746b3c75416c01a"
   ]

Until: process

until [process where event.action == "end"]

Ends the sequence: the steps above must complete before an event matching this clause occurs.

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
file.pathstarts_with?:\Windows\Installer\, ?:\Windows\System32\DriverStore\FileRepository\, ?:\Windows\SysWOW64\DriverStore\FileRepository\, ?:\Windows\assembly\, ?:\Program Files\, ?:\Program Files (x86)\excludes:file.path
process.executableeq?:\Windows\SysWOW64\msiexec.exeexcludes:process.executable field:"process.executable" value:"?:\Windows\SysWOW64\msiexec.exe"
process.thread.Ext.call_stack_final_user_module.namewildcardmsi*.tmpexcludes:process.thread.Ext.call_stack_final_user_module.name field:"process.thread.Ext.call_stack_final_user_module.name" value:"msi*.tmp"
process.thread.Ext.call_stack_summarywildcardntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|msi*.tmpexcludes:process.thread.Ext.call_stack_summary field:"process.thread.Ext.call_stack_summary" value:"ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|msi*.tmp"
process.thread.Ext.call_stack_final_user_module.namein_isres.dll, isrt.dll, issetup.dll, wow64.lmdexcludes:process.thread.Ext.call_stack_final_user_module.name
process.thread.Ext.call_stack_summaryinntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|_isres.dll, ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|isrt.dll, ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|issetup.dll, ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|wow64.lmdexcludes:process.thread.Ext.call_stack_summary
process.executablestarts_with?:\Program Files\, ?:\Program Files (x86)\excludes:process.executable field:"process.executable" value:"?:\Program Files\" field:"process.executable" value:"?:\Program Files (x86)\"
process.thread.Ext.call_stack_final_user_module.namestarts_withprocess.nameexcludes:process.thread.Ext.call_stack_final_user_module.name field:"process.thread.Ext.call_stack_final_user_module.name" value:"process.name"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • end corpus 18 (elastic 18)
field:"EventType" kind:eq value:"end"
event.typein
  • change corpus 94 (elastic 94)
  • creation corpus 53 (elastic 53)
field:"event.type" kind:in
file.Ext.entropyge
  • 6 transforms: number corpus 4 (elastic 4)
field:"file.Ext.entropy" kind:ge value:"6"
file.Ext.header_byteswildcard
  • 4d5a* corpus 46 (elastic 46)
field:"file.Ext.header_bytes" kind:wildcard value:"4d5a*"
process.Ext.api.metadata.target_address_nameeq
  • Unbacked corpus 8 (elastic 8)
field:"process.Ext.api.metadata.target_address_name" kind:eq value:"Unbacked"
process.Ext.api.namewildcard
  • MapViewOfFile* corpus 5 (elastic 5)
  • VirtualAlloc* corpus 4 (elastic 4)
field:"process.Ext.api.name" kind:wildcard
process.Ext.api.parameters.protectioneq
  • RWX corpus 8 (elastic 8)
field:"process.Ext.api.parameters.protection" kind:eq value:"RWX"
process.Ext.token.integrity_level_namein
  • high corpus 22 (elastic 22)
  • medium corpus 3 (elastic 3)
field:"process.Ext.token.integrity_level_name" kind:in
process.pidne
  • 4 transforms: number corpus 44 (elastic 44)
field:"process_id" kind:ne value:"4"
process.thread.Ext.call_stack_final_user_module.hash.sha256is_not_null
  • (no value, null check)
field:"process.thread.Ext.call_stack_final_user_module.hash.sha256" kind:is_not_null
process.thread.Ext.call_stack_final_user_module.hash.sha256ne
  • b35e38071d8f32e1cfc51f7aa4c7f406461eb062123fd25ef746b3c75416c01a
field:"process.thread.Ext.call_stack_final_user_module.hash.sha256" kind:ne value:"b35e38071d8f32e1cfc51f7aa4c7f406461eb062123fd25ef746b3c75416c01a"
process.thread.Ext.call_stack_final_user_module.pathcontains
  • event0.file.path (field reference)
field:"process.thread.Ext.call_stack_final_user_module.path" kind:contains value:"event0.file.path"
process.thread.Ext.call_stack_summaryends_with
  • concat("ntdll.dll|", event0.file.name) (expression)
  • concat("ntdll.dll|kernelbase.dll|", event0.file.name) (expression)
field:"process.thread.Ext.call_stack_summary" kind:ends_with
user.idne
  • S-1-5-18 corpus 36 (elastic 36)
field:"user.id" kind:ne value:"S-1-5-18"