Detection rules › Elastic

Windows API via a CallBack Function

Source
github.com/elastic/protections-artifacts

Identifies the call of Memory Windows APIs indirectly via a callback function. This may be the result of an evasion attempt to hide the origin of the API call from the call stack such as unbacked memory region.

MITRE ATT&CK coverage

TacticTechniques
Stealth

Rule body

[rule]
description = """
Identifies the call of Memory Windows APIs indirectly via a callback function. This may be the result of an evasion
attempt to hide the origin of the API call from the call stack such as unbacked memory region.
"""
id = "8a8daa15-eed0-4bf0-85b5-ada73b55ab05"
license = "Elastic License v2"
name = "Windows API via a CallBack Function"
os_list = ["windows"]
reference = ["https://www.elastic.co/security-labs/doubling-down-etw-callstacks"]
version = "1.0.24"

query = '''
api where process.executable != null and
 (
  (process.Ext.api.behaviors == "proxy_call" and
   process.Ext.api.name in ("VirtualAlloc", "VirtualProtect", "WriteProcessMemory", "VirtualProtectEx", "VirtualAllocEx",
                            "MapViewOfFile", "MapViewOfFile2", "SuspendThread", "ReadProcessMemory") and
   process.thread.Ext.call_stack_summary in ("ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll", "ntdll.dll|kernel32.dll|ntdll.dll") and
   process.thread.Ext.call_stack_final_user_module.name in ("ntdll.dll", "Undetermined") and
   _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info : ("*TpReleaseCleanupGroupMembers*", "*ntdll.dll!RtlDeregisterWaitEx*"))) or

  (process.Ext.api.name == "SetThreadContext" and process.thread.Ext.call_stack_summary in ("ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll", "ntdll.dll|kernel32.dll|ntdll.dll") and
   process.thread.Ext.call_stack_final_user_module.name in ("ntdll.dll", "Undetermined")) or

  (process.Ext.api.behaviors == "proxy_call" and
   process.Ext.api.name in ("VirtualProtect", "VirtualAlloc", "WriteProcessMemory", "VirtualProtectEx", "VirtualAllocEx", "SuspendThread") and
   process.thread.Ext.call_stack_summary == "ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll" and
   process.thread.Ext.call_stack_final_user_module.name == "Undetermined") and
   not _arraysearch(process.thread.Ext.call_stack, $entry,
                    $entry.symbol_info : ("c:\\windows\\system32\\ntdll.dll!KiUserApcDispatcher*",
                                          "c:\\windows\\system32\\ntdll.dll!LdrShutdownThread*",
                                          "c:\\windows\\system32\\kernelbase.dll!GetFinalPathNameByHandleW*",
                                          "c:\\windows\\system32\\kernelbase.dll!LoadLibrary*"))
 ) and
 not _arraysearch(process.thread.Ext.call_stack, $entry,
                  $entry.symbol_info : ("*\\jhooksatellite.dll!*",
                                        "*ntdll.dll!qsort*",
                                        "*kernelbase.dll!AppXLookupMoniker*",
                                        "*ntdll.dll!RtlCaptureStackContext*",
                                        "*ntdll.dll!LdrSystemDllInitBlock*",
                                        "*kernelbase.dll!CheckIsMSIXPackage*",
                                        "*rpcrt4.dll!NdrSendReceive*",
                                        "*ntdll.dll!RtlSetThreadWorkOnBehalfTicket*",
                                        "*ntdll.dll!RtlPcToFileHeader*",
                                        "?:\\program files*\\remote desktop\\rdclientax.dll!DllDeleteSavedCreds*",
                                        "c:\\windows\\system32\\ntdll.dll!NtUpdateWnfStateData+*",
                                        "*ntdll.dll!*RtlUnlockHeap*", "*ntdll.dll+0x*", "*kernelbase.dll!AppXUpdatePackageCapabilities*"))
'''

min_endpoint_version = "8.10.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.executable != null and
 (
  (process.Ext.api.behaviors == "proxy_call" and
   process.Ext.api.name in ("VirtualAlloc", "VirtualProtect", "WriteProcessMemory", "VirtualProtectEx", "VirtualAllocEx",
                            "MapViewOfFile", "MapViewOfFile2", "SuspendThread", "ReadProcessMemory") and
   process.thread.Ext.call_stack_summary in ("ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll", "ntdll.dll|kernel32.dll|ntdll.dll") and
   process.thread.Ext.call_stack_final_user_module.name in ("ntdll.dll", "Undetermined") and
   _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info : ("*TpReleaseCleanupGroupMembers*", "*ntdll.dll!RtlDeregisterWaitEx*"))) or

  (process.Ext.api.name == "SetThreadContext" and process.thread.Ext.call_stack_summary in ("ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll", "ntdll.dll|kernel32.dll|ntdll.dll") and
   process.thread.Ext.call_stack_final_user_module.name in ("ntdll.dll", "Undetermined")) or

  (process.Ext.api.behaviors == "proxy_call" and
   process.Ext.api.name in ("VirtualProtect", "VirtualAlloc", "WriteProcessMemory", "VirtualProtectEx", "VirtualAllocEx", "SuspendThread") and
   process.thread.Ext.call_stack_summary == "ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll" and
   process.thread.Ext.call_stack_final_user_module.name == "Undetermined") and
   not _arraysearch(process.thread.Ext.call_stack, $entry,
                    $entry.symbol_info : ("c:\\windows\\system32\\ntdll.dll!KiUserApcDispatcher*",
                                          "c:\\windows\\system32\\ntdll.dll!LdrShutdownThread*",
                                          "c:\\windows\\system32\\kernelbase.dll!GetFinalPathNameByHandleW*",
                                          "c:\\windows\\system32\\kernelbase.dll!LoadLibrary*"))
 ) and
 not _arraysearch(process.thread.Ext.call_stack, $entry,
                  $entry.symbol_info : ("*\\jhooksatellite.dll!*",
                                        "*ntdll.dll!qsort*",
                                        "*kernelbase.dll!AppXLookupMoniker*",
                                        "*ntdll.dll!RtlCaptureStackContext*",
                                        "*ntdll.dll!LdrSystemDllInitBlock*",
                                        "*kernelbase.dll!CheckIsMSIXPackage*",
                                        "*rpcrt4.dll!NdrSendReceive*",
                                        "*ntdll.dll!RtlSetThreadWorkOnBehalfTicket*",
                                        "*ntdll.dll!RtlPcToFileHeader*",
                                        "?:\\program files*\\remote desktop\\rdclientax.dll!DllDeleteSavedCreds*",
                                        "c:\\windows\\system32\\ntdll.dll!NtUpdateWnfStateData+*",
                                        "*ntdll.dll!*RtlUnlockHeap*", "*ntdll.dll+0x*", "*kernelbase.dll!AppXUpdatePackageCapabilities*"))

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.thread.Ext.call_stackarray_any(no value, null check)excludes:process.thread.Ext.call_stack

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
process.Ext.api.behaviorseq
  • proxy_call corpus 4 (elastic 4)
field:"process.Ext.api.behaviors" kind:eq value:"proxy_call"
process.Ext.api.nameeq
  • SetThreadContext corpus 4 (elastic 4)
field:"process.Ext.api.name" kind:eq value:"SetThreadContext"
process.Ext.api.namein
  • MapViewOfFile
  • MapViewOfFile2
  • ReadProcessMemory
  • SuspendThread
  • VirtualAlloc corpus 4 (elastic 4)
  • VirtualAllocEx
  • VirtualProtect corpus 19 (elastic 19)
  • VirtualProtectEx
  • WriteProcessMemory corpus 14 (elastic 14)
field:"process.Ext.api.name" kind:in
process.executableis_not_null
  • (no value, null check)
field:"Image" kind:is_not_null
process.thread.Ext.call_stack_final_user_module.nameeq
  • Undetermined corpus 4 (elastic 4)
field:"process.thread.Ext.call_stack_final_user_module.name" kind:eq value:"Undetermined"
process.thread.Ext.call_stack_final_user_module.namein
  • Undetermined corpus 4 (elastic 4)
  • ntdll.dll
field:"process.thread.Ext.call_stack_final_user_module.name" kind:in
process.thread.Ext.call_stack_summaryeq
  • ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll
field:"process.thread.Ext.call_stack_summary" kind:eq value:"ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll"
process.thread.Ext.call_stack_summaryin
  • ntdll.dll|kernel32.dll|ntdll.dll corpus 4 (elastic 4)
  • ntdll.dll|kernelbase.dll|ntdll.dll|kernel32.dll|ntdll.dll
field:"process.thread.Ext.call_stack_summary" kind:in