Detection rules › Elastic

Shellcode Heap Allocation from Unbacked Memory

Source
github.com/elastic/protections-artifacts

Identifies attempt to allocate shellcode via heap memory allocation and from an unsigned final user module. This may indicate an attempt to prepare for shellcode injection evading security monitoring for suspicious VirtualAlloc API calls.

MITRE ATT&CK coverage

TacticTechniques
Stealth

Rule body

[rule]
description = """
Identifies attempt to allocate shellcode via heap memory allocation and from an unsigned final user module. This may
indicate an attempt to prepare for shellcode injection evading security monitoring for suspicious VirtualAlloc API
calls.
"""
id = "ef671d7c-0bb2-46c9-9a6f-9f44e30d037f"
license = "Elastic License v2"
name = "Shellcode Heap Allocation from Unbacked Memory"
os_list = ["windows"]
reference = ["https://learn.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heapcreate"]
version = "1.0.3"

query = '''
api where process.Ext.api.name == "VirtualAlloc" and
  process.Ext.api.behaviors == "allocate_shellcode" and process.Ext.api.parameters.size > 4096 and
  process.thread.Ext.call_stack_summary in
                             ("ntdll.dll|Unbacked",
                              "ntdll.dll|Unbacked|kernel32.dll|ntdll.dll",
                              "ntdll.dll|kernelbase.dll|Unbacked",
                              "ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll",
                              "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|Unbacked",
                              "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|Unbacked|kernel32.dll|ntdll.dll",                           
                              "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked",
                              "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll") and
  _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info: ("*kernelbase.dll!HeapCreate*", "*ntdll.dll!RtlCreateHeap*")) and
 process.thread.Ext.call_stack_final_user_module.hash.sha256 != null and
 process.thread.Ext.call_stack_final_user_module.code_signature != null and
 not _arraysearch(process.thread.Ext.call_stack_final_user_module.code_signature, $entry, $entry.trusted == true and
                  $entry.subject_name : ("Hewlett-Packard Company", "Microsoft Windows Hardware Compatibility Publisher", "Microsoft Windows Software Compatibility Publisher")) and
 not process.thread.Ext.call_stack_final_user_module.hash.sha256 in
                                                 ("c4cf159dd3796298eced1d69336d6c39f6066ce407ecd9b0c2147a64e897d28f",
                                                  "cd6ddc67c9866a42d61f4989bf7716f2e445c3c1e6d6bddce877511ad003ced4",
                                                  "9becd39f90077a5ab064681c0a1be139d15be9ce434bacd48cd1dc894d3911cb",
                                                  "c5265f4825f6787ece500c20c10c8cefc32b452be8f0aa3f1a71ccc650439b2f")
'''

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

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1620"
name = "Reflective Code Loading"
reference = "https://attack.mitre.org/techniques/T1620/"


[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.name == "VirtualAlloc" and
  process.Ext.api.behaviors == "allocate_shellcode" and process.Ext.api.parameters.size > 4096 and
  process.thread.Ext.call_stack_summary in
                             ("ntdll.dll|Unbacked",
                              "ntdll.dll|Unbacked|kernel32.dll|ntdll.dll",
                              "ntdll.dll|kernelbase.dll|Unbacked",
                              "ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll",
                              "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|Unbacked",
                              "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|Unbacked|kernel32.dll|ntdll.dll",                           
                              "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked",
                              "ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll") and
  _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info: ("*kernelbase.dll!HeapCreate*", "*ntdll.dll!RtlCreateHeap*")) and
 process.thread.Ext.call_stack_final_user_module.hash.sha256 != null and
 process.thread.Ext.call_stack_final_user_module.code_signature != null and
 not _arraysearch(process.thread.Ext.call_stack_final_user_module.code_signature, $entry, $entry.trusted == true and
                  $entry.subject_name : ("Hewlett-Packard Company", "Microsoft Windows Hardware Compatibility Publisher", "Microsoft Windows Software Compatibility Publisher")) and
 not process.thread.Ext.call_stack_final_user_module.hash.sha256 in
                                                 ("c4cf159dd3796298eced1d69336d6c39f6066ce407ecd9b0c2147a64e897d28f",
                                                  "cd6ddc67c9866a42d61f4989bf7716f2e445c3c1e6d6bddce877511ad003ced4",
                                                  "9becd39f90077a5ab064681c0a1be139d15be9ce434bacd48cd1dc894d3911cb",
                                                  "c5265f4825f6787ece500c20c10c8cefc32b452be8f0aa3f1a71ccc650439b2f")

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.thread.Ext.call_stack_final_user_module.code_signaturearray_any(no value, null check)excludes:process.thread.Ext.call_stack_final_user_module.code_signature
process.thread.Ext.call_stack_final_user_module.hash.sha256in9becd39f90077a5ab064681c0a1be139d15be9ce434bacd48cd1dc894d3911cb, c4cf159dd3796298eced1d69336d6c39f6066ce407ecd9b0c2147a64e897d28f, c5265f4825f6787ece500c20c10c8cefc32b452be8f0aa3f1a71ccc650439b2f, cd6ddc67c9866a42d61f4989bf7716f2e445c3c1e6d6bddce877511ad003ced4excludes:process.thread.Ext.call_stack_final_user_module.hash.sha256

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
process.Ext.api.behaviorseq
  • allocate_shellcode corpus 9 (elastic 9)
field:"process.Ext.api.behaviors" kind:eq value:"allocate_shellcode"
process.Ext.api.nameeq
  • VirtualAlloc corpus 4 (elastic 4)
field:"process.Ext.api.name" kind:eq value:"VirtualAlloc"
process.Ext.api.parameters.sizegt
  • 4096 transforms: number corpus 5 (elastic 5)
field:"process.Ext.api.parameters.size" kind:gt value:"4096"
process.thread.Ext.call_stack_final_user_module.code_signatureis_not_null
  • (no value, null check)
field:"process.thread.Ext.call_stack_final_user_module.code_signature" kind:is_not_null
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_summaryin
  • ntdll.dll|Unbacked
  • ntdll.dll|Unbacked|kernel32.dll|ntdll.dll
  • ntdll.dll|kernelbase.dll|Unbacked corpus 3 (elastic 3)
  • ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll
  • ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|Unbacked
  • ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|Unbacked|kernel32.dll|ntdll.dll
  • ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked
  • ntdll.dll|wow64.dll|wow64cpu.dll|wow64.dll|ntdll.dll|kernelbase.dll|Unbacked|kernel32.dll|ntdll.dll
field:"process.thread.Ext.call_stack_summary" kind:in