Detection rules › Elastic

VirtualProtect Call via NtTestAlert

Source
github.com/elastic/protections-artifacts

Detects calls to the VirtualProtect Windows API to change memory permissions and the call is originating from a thread pointing to the API NtTestAlert. This may indicate that this call is coming from a pending APC or a sleeping thread.

MITRE ATT&CK coverage

Rule body

[rule]
description = """
Detects calls to the VirtualProtect Windows API to change memory permissions and the call is originating from a thread
pointing to the API NtTestAlert. This may indicate that this call is coming from a pending APC or a sleeping thread.
"""
id = "9906a386-771f-4003-b426-fbe75bdd6e73"
license = "Elastic License v2"
name = "VirtualProtect Call via NtTestAlert"
os_list = ["windows"]
reference = ["https://www.elastic.co/security-labs/doubling-down-etw-callstacks"]
version = "1.0.7"

query = '''
api where 
 process.Ext.api.name : "VirtualProtect" and 
 process.thread.Ext.call_stack_summary : "ntdll.dll*" and 
 _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info : ("*NtTestAlert*", "*ZwTestAlert*")) and 
 _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info : "*ProtectVirtualMemory*") and 
 process.thread.Ext.call_stack_summary : ("ntdll.dll", "ntdll.dll|kernelbase.dll|ntdll.dll|Unknown", "ntdll.dll|Unbacked", "ntdll.dll|Unknown") and
 not _arraysearch(process.thread.Ext.call_stack, $entry, $entry.protection_provenance : ("Kernel", "Kernel|*"))
'''

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

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

[[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.8.0"

Stages and Predicates

Stage 1: api

api where 
 process.Ext.api.name : "VirtualProtect" and 
 process.thread.Ext.call_stack_summary : "ntdll.dll*" and 
 _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info : ("*NtTestAlert*", "*ZwTestAlert*")) and 
 _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info : "*ProtectVirtualMemory*") and 
 process.thread.Ext.call_stack_summary : ("ntdll.dll", "ntdll.dll|kernelbase.dll|ntdll.dll|Unknown", "ntdll.dll|Unbacked", "ntdll.dll|Unknown") and
 not _arraysearch(process.thread.Ext.call_stack, $entry, $entry.protection_provenance : ("Kernel", "Kernel|*"))

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.namewildcard
  • VirtualProtect corpus 5 (elastic 5)
field:"process.Ext.api.name" kind:wildcard value:"VirtualProtect"
process.thread.Ext.call_stack_summarywildcard
  • ntdll.dll corpus 3 (elastic 3)
  • ntdll.dll* corpus 4 (elastic 4)
  • ntdll.dll|Unbacked corpus 6 (elastic 6)
  • ntdll.dll|Unknown
  • ntdll.dll|kernelbase.dll|ntdll.dll|Unknown
field:"process.thread.Ext.call_stack_summary" kind:wildcard