Detection rules › Elastic

Memory Protection from Read to Execute

Source
github.com/elastic/protections-artifacts

Identifies attempts to modify the memory protection from read only to read and execute, malware may use this approach to avoid leaving suspicious allocation properties.

MITRE ATT&CK coverage

TacticTechniques
Stealth

Rule body

[rule]
description = """
Identifies attempts to modify the memory protection from read only to read and execute, malware may use this approach to
avoid leaving suspicious allocation properties.
"""
id = "647e485d-4850-43da-9407-7618c9b23843"
license = "Elastic License v2"
name = "Memory Protection from Read to Execute"
os_list = ["windows"]
reference = ["https://www.elastic.co/security-labs/doubling-down-etw-callstacks"]
version = "1.0.5"

query = '''
api where process.Ext.api.name == "VirtualProtect" and
  process.Ext.api.parameters.protection == "R-X" and process.Ext.api.parameters.protection_old == "R--" and
  process.thread.Ext.call_stack_final_user_module.protection_provenance != "Kernel" and
  process.Ext.api.metadata.target_address_name != "Unknown" and process.Ext.api.parameters.size != 64 and
  process.thread.Ext.call_stack_final_user_module.name != "Unknown" and
  process.thread.Ext.call_stack_summary != null and process.thread.Ext.call_stack_final_user_module.name != null and
  process.thread.Ext.call_stack_final_user_module.protection_provenance != "Unknown" and
  not (process.thread.Ext.call_stack_summary == "ntdll.dll|Unbacked" and process.thread.Ext.call_stack_final_user_module.name == "Unbacked") and 
  not (process.thread.Ext.call_stack_final_user_module.name == "Unbacked" and process.thread.Ext.call_stack_final_user_module.protection_provenance == "Unbacked") and 
  not (process.thread.Ext.call_stack_final_user_module.name == "Undetermined" and process.Ext.api.behaviors == "truncated_stack") and 
  not (process.Ext.api.parameters.size == 4096 and
       process.thread.Ext.call_stack_final_user_module.path like "c:\\windows\\winsxs\\temp\\pendingdeletes\\$$deleteme*") and
  not (process.thread.Ext.call_stack_final_user_module.path in ("c:\\program files\\bold\\agent\\bold.exe", "c:\\program files\\bold\\agent\\boldengine.exe") and user.id == "S-1-5-18") and 
  not process.thread.Ext.call_stack_final_user_module.path == "c:\\windows\\syswow64\\cyinjct.dll" and
  process.Ext.api.summary in ("VirtualProtect( cryptsp.dll, 0x108, R-X, R-- )", "VirtualProtect( crypt32.dll, 0x108, R-X, R-- )") and
  process.thread.Ext.call_stack_final_user_module.hash.sha256 in
                                        ("6722b52ed34bbf1c1cbb2215130b725b66fd9bb2abc7ac7b9281ba9643b17498",
                                         "87628b8c8fba57a55383999de84a4f1a4ae6e37d735bb785bc29abba4d9ba701",
                                         "be636d9eb262f8db59bf793c35ba0b7fe25091f5351ca25f9fe5a90493b151a1",
                                         "bb6c1bae7516b2d61e7cbf94c10ec9287fcaab34550dec268d99cd605c24f0d3",
                                         "edd811ce347d68ebde7565a618cf93494f8b57e94d875c1717046a55c6865e1c", 
                                         "2ab9a610db6fba4d41c6b9e971588fec0fbb47e19f1590bc04696cb2a80fc447", 
                                         "0db3072535e19bb206277c726497f0dae6066b620a39c4502d8c0060032feaa6", 
                                         "8d328590dc4cadfb45e04fc1476e0989e98fffd6b97dc47f91b6a105a53dd221", 
                                         "466970a44c0998f43b350d850615ec01bb9ad0ad1d0991883f69c31d61563f8c",
                                         "1e8b5406e30074784409cf2d8d65dca376d7c51cea2458a99a635b087a8f96a5") and
  not _arraysearch(process.thread.Ext.call_stack_final_user_module.code_signature, $entry, $entry.trusted == true) and
  not process.thread.Ext.call_stack_final_user_module.protection_provenance_path like
                                     ("c:\\program files (x86)\\common files\\microsoft shared\\office??\\mso*.dll",
                                      "c:\\windows\\assembly\\nativeimages*.ni.dll",
                                      "c:\\windows\\system32\\spool\\drivers\\x64\\3\\ricoh_drv\\*.dll") and
  not _arraysearch(process.thread.Ext.call_stack, $entry,
                   $entry.symbol_info like ("c:\\windows\\sys?????\\cyinjct.dll*", 
                                            "c:\\windows\\sys?????\\user32.dll!DispatchMessage*",
                                            "c:\\windows\\sys?????\\ntdll.dll!LdrResolveDelayLoadedAPI*",
                                            "c:\\windows\\sys?????\\ntdll.dll!LdrLoadDll*",
                                            "c:\\windows\\sys?????\\ntdll.dll!LdrShutdownThread*")) and
  not _arraysearch(process.thread.Ext.call_stack, $entry,
                   $entry.callsite_trailing_bytes == "85c00f85fc000000448b4df0488d45f04c8d45e84889442420488d55e04883c9ff41ffd685c00f85d8000000813e504500000f85cc0000008b462885c00f84c1")
'''

min_endpoint_version = "8.14.2"
optional_actions = []
[[actions]]
action = "kill_process"
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.14.2"

Stages and Predicates

Stage 1: api

api where process.Ext.api.name == "VirtualProtect" and
  process.Ext.api.parameters.protection == "R-X" and process.Ext.api.parameters.protection_old == "R--" and
  process.thread.Ext.call_stack_final_user_module.protection_provenance != "Kernel" and
  process.Ext.api.metadata.target_address_name != "Unknown" and process.Ext.api.parameters.size != 64 and
  process.thread.Ext.call_stack_final_user_module.name != "Unknown" and
  process.thread.Ext.call_stack_summary != null and process.thread.Ext.call_stack_final_user_module.name != null and
  process.thread.Ext.call_stack_final_user_module.protection_provenance != "Unknown" and
  not (process.thread.Ext.call_stack_summary == "ntdll.dll|Unbacked" and process.thread.Ext.call_stack_final_user_module.name == "Unbacked") and 
  not (process.thread.Ext.call_stack_final_user_module.name == "Unbacked" and process.thread.Ext.call_stack_final_user_module.protection_provenance == "Unbacked") and 
  not (process.thread.Ext.call_stack_final_user_module.name == "Undetermined" and process.Ext.api.behaviors == "truncated_stack") and 
  not (process.Ext.api.parameters.size == 4096 and
       process.thread.Ext.call_stack_final_user_module.path like "c:\\windows\\winsxs\\temp\\pendingdeletes\\$$deleteme*") and
  not (process.thread.Ext.call_stack_final_user_module.path in ("c:\\program files\\bold\\agent\\bold.exe", "c:\\program files\\bold\\agent\\boldengine.exe") and user.id == "S-1-5-18") and 
  not process.thread.Ext.call_stack_final_user_module.path == "c:\\windows\\syswow64\\cyinjct.dll" and
  process.Ext.api.summary in ("VirtualProtect( cryptsp.dll, 0x108, R-X, R-- )", "VirtualProtect( crypt32.dll, 0x108, R-X, R-- )") and
  process.thread.Ext.call_stack_final_user_module.hash.sha256 in
                                        ("6722b52ed34bbf1c1cbb2215130b725b66fd9bb2abc7ac7b9281ba9643b17498",
                                         "87628b8c8fba57a55383999de84a4f1a4ae6e37d735bb785bc29abba4d9ba701",
                                         "be636d9eb262f8db59bf793c35ba0b7fe25091f5351ca25f9fe5a90493b151a1",
                                         "bb6c1bae7516b2d61e7cbf94c10ec9287fcaab34550dec268d99cd605c24f0d3",
                                         "edd811ce347d68ebde7565a618cf93494f8b57e94d875c1717046a55c6865e1c", 
                                         "2ab9a610db6fba4d41c6b9e971588fec0fbb47e19f1590bc04696cb2a80fc447", 
                                         "0db3072535e19bb206277c726497f0dae6066b620a39c4502d8c0060032feaa6", 
                                         "8d328590dc4cadfb45e04fc1476e0989e98fffd6b97dc47f91b6a105a53dd221", 
                                         "466970a44c0998f43b350d850615ec01bb9ad0ad1d0991883f69c31d61563f8c",
                                         "1e8b5406e30074784409cf2d8d65dca376d7c51cea2458a99a635b087a8f96a5") and
  not _arraysearch(process.thread.Ext.call_stack_final_user_module.code_signature, $entry, $entry.trusted == true) and
  not process.thread.Ext.call_stack_final_user_module.protection_provenance_path like
                                     ("c:\\program files (x86)\\common files\\microsoft shared\\office??\\mso*.dll",
                                      "c:\\windows\\assembly\\nativeimages*.ni.dll",
                                      "c:\\windows\\system32\\spool\\drivers\\x64\\3\\ricoh_drv\\*.dll") and
  not _arraysearch(process.thread.Ext.call_stack, $entry,
                   $entry.symbol_info like ("c:\\windows\\sys?????\\cyinjct.dll*", 
                                            "c:\\windows\\sys?????\\user32.dll!DispatchMessage*",
                                            "c:\\windows\\sys?????\\ntdll.dll!LdrResolveDelayLoadedAPI*",
                                            "c:\\windows\\sys?????\\ntdll.dll!LdrLoadDll*",
                                            "c:\\windows\\sys?????\\ntdll.dll!LdrShutdownThread*")) and
  not _arraysearch(process.thread.Ext.call_stack, $entry,
                   $entry.callsite_trailing_bytes == "85c00f85fc000000448b4df0488d45f04c8d45e84889442420488d55e04883c9ff41ffd685c00f85d8000000813e504500000f85cc0000008b462885c00f84c1")

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.Ext.api.behaviorseqtruncated_stackexcludes:process.Ext.api.behaviors field:"process.Ext.api.behaviors" value:"truncated_stack"
process.thread.Ext.call_stack_final_user_module.nameeqUndeterminedexcludes:process.thread.Ext.call_stack_final_user_module.name field:"process.thread.Ext.call_stack_final_user_module.name" value:"Undetermined"
process.Ext.api.parameters.sizeeq4096excludes:process.Ext.api.parameters.size field:"process.Ext.api.parameters.size" value:"4096"
process.thread.Ext.call_stack_final_user_module.pathstarts_withc:\windows\winsxs\temp\pendingdeletes\$$deletemeexcludes:process.thread.Ext.call_stack_final_user_module.path field:"process.thread.Ext.call_stack_final_user_module.path" value:"c:\windows\winsxs\temp\pendingdeletes\$$deleteme"
process.thread.Ext.call_stackarray_any(no value, null check)excludes:process.thread.Ext.call_stack
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.nameeqUnbackedexcludes:process.thread.Ext.call_stack_final_user_module.name field:"process.thread.Ext.call_stack_final_user_module.name" value:"Unbacked"
process.thread.Ext.call_stack_final_user_module.protection_provenanceeqUnbackedexcludes:process.thread.Ext.call_stack_final_user_module.protection_provenance field:"process.thread.Ext.call_stack_final_user_module.protection_provenance" value:"Unbacked"
process.thread.Ext.call_stack_summaryeqntdll.dll|Unbackedexcludes:process.thread.Ext.call_stack_summary field:"process.thread.Ext.call_stack_summary" value:"ntdll.dll|Unbacked"
process.thread.Ext.call_stack_final_user_module.pathinc:\program files\bold\agent\bold.exe, c:\program files\bold\agent\boldengine.exeexcludes:process.thread.Ext.call_stack_final_user_module.path field:"process.thread.Ext.call_stack_final_user_module.path" value:"c:\program files\bold\agent\bold.exe" field:"process.thread.Ext.call_stack_final_user_module.path" value:"c:\program files\bold\agent\boldengine.exe"
user.ideqS-1-5-18excludes:user.id field:"user.id" value:"S-1-5-18"
process.thread.Ext.call_stack_final_user_module.patheqc:\windows\syswow64\cyinjct.dllexcludes:process.thread.Ext.call_stack_final_user_module.path field:"process.thread.Ext.call_stack_final_user_module.path" value:"c:\windows\syswow64\cyinjct.dll"
process.thread.Ext.call_stack_final_user_module.protection_provenance_pathwildcardc:\program files (x86)\common files\microsoft shared\office??\mso*.dll, c:\windows\assembly\nativeimages*.ni.dll, c:\windows\system32\spool\drivers\x64\3\ricoh_drv\*.dllexcludes:process.thread.Ext.call_stack_final_user_module.protection_provenance_path field:"process.thread.Ext.call_stack_final_user_module.protection_provenance_path" value:"c:\program files (x86)\common files\microsoft shared\office??\mso*.dll" field:"process.thread.Ext.call_stack_final_user_module.protection_provenance_path" value:"c:\windows\assembly\nativeimages*.ni.dll" field:"process.thread.Ext.call_stack_final_user_module.protection_provenance_path" value:"c:\windows\system32\spool\drivers\x64\3\ricoh_drv\*.dll"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
process.Ext.api.metadata.target_address_namene
  • Unknown
field:"process.Ext.api.metadata.target_address_name" kind:ne value:"Unknown"
process.Ext.api.nameeq
  • VirtualProtect corpus 19 (elastic 19)
field:"process.Ext.api.name" kind:eq value:"VirtualProtect"
process.Ext.api.parameters.protectioneq
  • R-X corpus 3 (elastic 3)
field:"process.Ext.api.parameters.protection" kind:eq value:"R-X"
process.Ext.api.parameters.protection_oldeq
  • R--
field:"process.Ext.api.parameters.protection_old" kind:eq value:"R--"
process.Ext.api.parameters.sizene
  • 64 transforms: number
field:"process.Ext.api.parameters.size" kind:ne value:"64"
process.Ext.api.summaryin
  • VirtualProtect( crypt32.dll, 0x108, R-X, R-- )
  • VirtualProtect( cryptsp.dll, 0x108, R-X, R-- )
field:"process.Ext.api.summary" kind:in
process.thread.Ext.call_stack_final_user_module.hash.sha256in
  • 0db3072535e19bb206277c726497f0dae6066b620a39c4502d8c0060032feaa6
  • 1e8b5406e30074784409cf2d8d65dca376d7c51cea2458a99a635b087a8f96a5
  • 2ab9a610db6fba4d41c6b9e971588fec0fbb47e19f1590bc04696cb2a80fc447
  • 466970a44c0998f43b350d850615ec01bb9ad0ad1d0991883f69c31d61563f8c
  • 6722b52ed34bbf1c1cbb2215130b725b66fd9bb2abc7ac7b9281ba9643b17498
  • 87628b8c8fba57a55383999de84a4f1a4ae6e37d735bb785bc29abba4d9ba701
  • 8d328590dc4cadfb45e04fc1476e0989e98fffd6b97dc47f91b6a105a53dd221
  • bb6c1bae7516b2d61e7cbf94c10ec9287fcaab34550dec268d99cd605c24f0d3
  • be636d9eb262f8db59bf793c35ba0b7fe25091f5351ca25f9fe5a90493b151a1
  • edd811ce347d68ebde7565a618cf93494f8b57e94d875c1717046a55c6865e1c
field:"process.thread.Ext.call_stack_final_user_module.hash.sha256" kind:in
process.thread.Ext.call_stack_final_user_module.nameis_not_null
  • (no value, null check)
field:"process.thread.Ext.call_stack_final_user_module.name" kind:is_not_null
process.thread.Ext.call_stack_final_user_module.namene
  • Unknown
field:"process.thread.Ext.call_stack_final_user_module.name" kind:ne value:"Unknown"
process.thread.Ext.call_stack_final_user_module.protection_provenancene
  • Kernel corpus 3 (elastic 3)
  • Unknown
field:"process.thread.Ext.call_stack_final_user_module.protection_provenance" kind:ne
process.thread.Ext.call_stack_summaryis_not_null
  • (no value, null check)
field:"process.thread.Ext.call_stack_summary" kind:is_not_null