Detection rules › Elastic

Module Stomping from a Copied Library

Time window
3m
Sequence by
user.id
Source
github.com/elastic/protections-artifacts

Identifies the load of a library that was recently copied and with a unusual memory allocation properties. This may be the result of a code injection using module stomping or DLL hollowing via overwriting the content of legit DLL with malicious code.

MITRE ATT&CK coverage

TacticTechniques
Stealth

Rule body

[rule]
description = """
Identifies the load of a library that was recently copied and with a unusual memory allocation properties. This may be
the result of a code injection using module stomping or DLL hollowing via overwriting the content of legit DLL with
malicious code.
"""
id = "c3758f2c-66d5-4cbe-820f-1c6207c6e341"
license = "Elastic License v2"
name = "Module Stomping from a Copied Library"
os_list = ["windows"]
version = "1.0.22"

query = '''
sequence by user.id with maxspan=3m

[file where event.action != "deletion" and
 not user.id : ("S-1-5-18", "S-1-5-19", "S-1-5-20") and

  /* PE file dropped via CopyFile API calls  */
  file.Ext.header_bytes : "4d5a*" and
 _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info: ("*CopyFileEx*", "*MoveFileExW*")) and

 not process.executable : ("?:\\Program Files (x86)\\Citrix\\ICA Client\\concentr.exe",  
                           "?:\\Program Files (x86)\\InstallShield Installation Information\\*\\setup.exe") and
 not file.path : ("?:\\Program Files (x86)\\Web Components\\NetStream.dll", "C:\\WINDOWS\\system32\\myah0.cpl")] as event0

[library where

  /* common networing and recon system modules */
  dll.name : ("ws2_32.dll", "dnsapi.dll", "wininet.dll", "psapi.dll", "vaultcli.dll") and

  /* stack starts from the recently dropped PE */
  endswith~(process.thread.Ext.call_stack_summary, event0.file.name) and

  /* Process name is different from the dropped PE */
  process.name != event0.file.name and

  /* Abnormal private bytes allocation for the dropped PE when loaded in memory */
 _arraysearch(process.thread.Ext.call_stack, $entry,
              $entry.allocation_private_bytes >= 100000 and startswith~($entry.symbol_info, event0.file.path))]
'''

min_endpoint_version = "8.7.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.tactic]
id = "TA0005"
name = "Defense Evasion"
reference = "https://attack.mitre.org/tactics/TA0005/"

[internal]
min_endpoint_version = "8.7.0"

Stages and Predicates

Ordered sequence: each step below must occur in order within 3m, correlated by user.id.

Stage 1: file

[file where event.action != "deletion" and
 not user.id : ("S-1-5-18", "S-1-5-19", "S-1-5-20") and
  file.Ext.header_bytes : "4d5a*" and
 _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info: ("*CopyFileEx*", "*MoveFileExW*")) and
 not process.executable : ("?:\\Program Files (x86)\\Citrix\\ICA Client\\concentr.exe",
                           "?:\\Program Files (x86)\\InstallShield Installation Information\\*\\setup.exe") and
 not file.path : ("?:\\Program Files (x86)\\Web Components\\NetStream.dll", "C:\\WINDOWS\\system32\\myah0.cpl")] as event0

Stage 2: library

[library where
  dll.name : ("ws2_32.dll", "dnsapi.dll", "wininet.dll", "psapi.dll", "vaultcli.dll") and
  endswith~(process.thread.Ext.call_stack_summary, event0.file.name) and
  process.name != event0.file.name and
 _arraysearch(process.thread.Ext.call_stack, $entry,
              $entry.allocation_private_bytes >= 100000 and startswith~($entry.symbol_info, event0.file.path))]

Exclusions

The rule actively suppresses these predicates.

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
dll.namewildcard
  • dnsapi.dll corpus 7 (elastic 7)
  • psapi.dll corpus 7 (elastic 7)
  • vaultcli.dll corpus 8 (elastic 8)
  • wininet.dll corpus 18 (elastic 18)
  • ws2_32.dll corpus 20 (elastic 20)
field:"dll.name" kind:wildcard
event.actionne
  • deletion corpus 86 (elastic 86)
field:"EventType" kind:ne value:"deletion"
file.Ext.header_byteswildcard
  • 4d5a* corpus 46 (elastic 46)
field:"file.Ext.header_bytes" kind:wildcard value:"4d5a*"
process.namene
  • event0.file.name (field reference)
field:"process_name" kind:ne value:"event0.file.name"
process.thread.Ext.call_stack_summaryends_with
  • event0.file.name (field reference)
field:"process.thread.Ext.call_stack_summary" kind:ends_with value:"event0.file.name"