Registry Persistence via AppInit DLL

AppInit DLLs are dynamic-link libraries (DLLs) that are loaded into every process that creates a user interface (loads user32.dll) on Microsoft Windows operating systems. The AppInit DLL mechanism is used to load custom code into user-mode processes, allowing for the customization of the user interface and the behavior of Windows-based applications. Attackers who add those DLLs to the registry locations can execute code with elevated privileges, similar to process injection, and provide a solid and constant persistence on the machine.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/11/18"
  3integration = ["endpoint", "windows", "m365_defender", "sentinel_one_cloud_funnel", "crowdstrike"]
  4maturity = "production"
  5updated_date = "2025/08/28"
  6
  7[transform]
  8[[transform.osquery]]
  9label = "Osquery - Retrieve AppInit Registry Value"
 10query = """
 11SELECT * FROM registry r where (r.key == 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows'
 12or r.key == 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows') and r.name ==
 13'AppInit_DLLs'
 14"""
 15
 16[[transform.osquery]]
 17label = "Osquery - Retrieve DNS Cache"
 18query = "SELECT * FROM dns_cache"
 19
 20[[transform.osquery]]
 21label = "Osquery - Retrieve All Services"
 22query = "SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services"
 23
 24[[transform.osquery]]
 25label = "Osquery - Retrieve Services Running on User Accounts"
 26query = """
 27SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services WHERE
 28NOT (user_account LIKE '%LocalSystem' OR user_account LIKE '%LocalService' OR user_account LIKE '%NetworkService' OR
 29user_account == null)
 30"""
 31
 32[[transform.osquery]]
 33label = "Osquery - Retrieve Service Unsigned Executables with Virustotal Link"
 34query = """
 35SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, name, description, start_type, status, pid,
 36services.path FROM services JOIN authenticode ON services.path = authenticode.path OR services.module_path =
 37authenticode.path JOIN hash ON services.path = hash.path WHERE authenticode.result != 'trusted'
 38"""
 39
 40
 41[rule]
 42author = ["Elastic"]
 43description = """
 44AppInit DLLs are dynamic-link libraries (DLLs) that are loaded into every process that creates a user interface (loads
 45user32.dll) on Microsoft Windows operating systems. The AppInit DLL mechanism is used to load custom code into user-mode
 46processes, allowing for the customization of the user interface and the behavior of Windows-based applications.
 47Attackers who add those DLLs to the registry locations can execute code with elevated privileges, similar to process
 48injection, and provide a solid and constant persistence on the machine.
 49"""
 50from = "now-9m"
 51index = [
 52    "winlogbeat-*",
 53    "logs-endpoint.events.registry-*",
 54    "logs-windows.sysmon_operational-*",
 55    "endgame-*",
 56    "logs-m365_defender.event-*",
 57    "logs-sentinel_one_cloud_funnel.*",
 58    "logs-crowdstrike.fdr*",
 59]
 60language = "eql"
 61license = "Elastic License v2"
 62name = "Registry Persistence via AppInit DLL"
 63note = """## Triage and analysis
 64
 65### Investigating Registry Persistence via AppInit DLL
 66
 67AppInit DLLs are dynamic-link libraries (DLLs) that are loaded into every process that creates a user interface (loads `user32.dll`) on Microsoft Windows operating systems. The AppInit DLL mechanism is used to load custom code into user-mode processes, allowing for the customization of the user interface and the behavior of Windows-based applications.
 68
 69Attackers who add those DLLs to the registry locations can execute code with elevated privileges, similar to process injection, and provide a solid and constant persistence on the machine.
 70
 71This rule identifies modifications on the AppInit registry keys.
 72
 73> **Note**:
 74> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/current/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
 75
 76#### Possible investigation steps
 77
 78- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
 79- Review the source process and related DLL file tied to the Windows Registry entry.
 80  - Check whether the DLL is signed, and tied to a authorized program used on your environment.
 81- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
 82- Retrieve all DLLs under the AppInit registry keys:
 83  - $osquery_0
 84- Examine the host for derived artifacts that indicate suspicious activities:
 85  - Analyze the process executable and the DLLs using a private sandboxed analysis system.
 86  - Observe and collect information about the following activities in both the sandbox and the alert subject host:
 87    - Attempts to contact external domains and addresses.
 88      - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
 89      - Examine the DNS cache for suspicious or anomalous entries.
 90        - $osquery_1
 91    - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
 92    - Examine the host services for suspicious or anomalous entries.
 93      - $osquery_2
 94      - $osquery_3
 95      - $osquery_4
 96  - Retrieve the files' SHA-256 hash values using the PowerShell `Get-FileHash` cmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
 97
 98### False positive analysis
 99
100- This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.
101
102### Response and remediation
103
104- Initiate the incident response process based on the outcome of the triage.
105- Isolate the involved host to prevent further post-compromise behavior.
106- If the triage identified malware, search the environment for additional compromised hosts.
107  - Implement temporary network rules, procedures, and segmentation to contain the malware.
108  - Stop suspicious processes.
109  - Immediately block the identified indicators of compromise (IoCs).
110  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
111- Remove and block malicious artifacts identified during triage.
112- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
113- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
114- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
115"""
116risk_score = 47
117rule_id = "d0e159cf-73e9-40d1-a9ed-077e3158a855"
118severity = "medium"
119tags = [
120    "Domain: Endpoint",
121    "OS: Windows",
122    "Use Case: Threat Detection",
123    "Tactic: Persistence",
124    "Tactic: Defense Evasion",
125    "Resources: Investigation Guide",
126    "Data Source: Elastic Endgame",
127    "Data Source: Elastic Defend",
128    "Data Source: Sysmon",
129    "Data Source: Microsoft Defender for Endpoint",
130    "Data Source: SentinelOne",
131    "Data Source: Crowdstrike",
132]
133timestamp_override = "event.ingested"
134type = "eql"
135
136query = '''
137registry where host.os.type == "windows" and event.type == "change" and
138  registry.value : "AppInit_Dlls" and
139  not process.executable : (
140     "?:\\Windows\\System32\\DriverStore\\FileRepository\\*\\Display.NvContainer\\NVDisplay.Container.exe",
141     "?:\\Windows\\System32\\msiexec.exe",
142     "?:\\Windows\\SysWOW64\\msiexec.exe",
143     "?:\\Program Files\\Commvault\\Base\\cvd.exe",
144     "?:\\Program Files\\Commvault\\ContentStore*\\Base\\cvd.exe",
145     "?:\\Program Files (x86)\\Commvault\\Base\\cvd.exe",
146     "?:\\Program Files (x86)\\Commvault\\ContentStore*\\Base\\cvd.exe",
147     "?:\\Program Files\\NVIDIA Corporation\\Display.NvContainer\\NVDisplay.Container.exe",
148
149     /* Crowdstrike specific condition as it uses NT Object paths */
150     "\\Device\\HarddiskVolume*\\Windows\\System32\\DriverStore\\FileRepository\\*\\Display.NvContainer\\NVDisplay.Container.exe",
151     "\\Device\\HarddiskVolume*\\Windows\\System32\\msiexec.exe",
152     "\\Device\\HarddiskVolume*\\Windows\\SysWOW64\\msiexec.exe",
153     "\\Device\\HarddiskVolume*\\Program Files\\Commvault\\Base\\cvd.exe",
154     "\\Device\\HarddiskVolume*\\Program Files\\Commvault\\ContentStore*\\Base\\cvd.exe",
155     "\\Device\\HarddiskVolume*\\Program Files (x86)\\Commvault\\Base\\cvd.exe",
156     "\\Device\\HarddiskVolume*\\Program Files (x86)\\Commvault\\ContentStore*\\Base\\cvd.exe",
157     "\\Device\\HarddiskVolume*\\Program Files\\NVIDIA Corporation\\Display.NvContainer\\NVDisplay.Container.exe"
158  )
159  /*
160    Full registry key path omitted due to data source variations:
161    "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls"
162    "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls"
163  */
164'''
165
166
167[[rule.threat]]
168framework = "MITRE ATT&CK"
169[[rule.threat.technique]]
170id = "T1546"
171name = "Event Triggered Execution"
172reference = "https://attack.mitre.org/techniques/T1546/"
173[[rule.threat.technique.subtechnique]]
174id = "T1546.010"
175name = "AppInit DLLs"
176reference = "https://attack.mitre.org/techniques/T1546/010/"
177
178
179
180[rule.threat.tactic]
181id = "TA0003"
182name = "Persistence"
183reference = "https://attack.mitre.org/tactics/TA0003/"
184[[rule.threat]]
185framework = "MITRE ATT&CK"
186[[rule.threat.technique]]
187id = "T1112"
188name = "Modify Registry"
189reference = "https://attack.mitre.org/techniques/T1112/"
190
191
192[rule.threat.tactic]
193id = "TA0005"
194name = "Defense Evasion"
195reference = "https://attack.mitre.org/tactics/TA0005/"

Triage and analysis

Investigating Registry Persistence via AppInit DLL

AppInit DLLs are dynamic-link libraries (DLLs) that are loaded into every process that creates a user interface (loads user32.dll) on Microsoft Windows operating systems. The AppInit DLL mechanism is used to load custom code into user-mode processes, allowing for the customization of the user interface and the behavior of Windows-based applications.

Attackers who add those DLLs to the registry locations can execute code with elevated privileges, similar to process injection, and provide a solid and constant persistence on the machine.

This rule identifies modifications on the AppInit registry keys.

Note: This investigation guide uses the Osquery Markdown Plugin introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.

Possible investigation steps

  • Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
  • Review the source process and related DLL file tied to the Windows Registry entry.
    • Check whether the DLL is signed, and tied to a authorized program used on your environment.
  • Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
  • Retrieve all DLLs under the AppInit registry keys:
    • $osquery_0
  • Examine the host for derived artifacts that indicate suspicious activities:
    • Analyze the process executable and the DLLs using a private sandboxed analysis system.
    • Observe and collect information about the following activities in both the sandbox and the alert subject host:
      • Attempts to contact external domains and addresses.
        • Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' process.entity_id.
        • Examine the DNS cache for suspicious or anomalous entries.
          • $osquery_1
      • Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
      • Examine the host services for suspicious or anomalous entries.
        • $osquery_2
        • $osquery_3
        • $osquery_4
    • Retrieve the files' SHA-256 hash values using the PowerShell Get-FileHash cmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.

False positive analysis

  • This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Isolate the involved host to prevent further post-compromise behavior.
  • If the triage identified malware, search the environment for additional compromised hosts.
    • Implement temporary network rules, procedures, and segmentation to contain the malware.
    • Stop suspicious processes.
    • Immediately block the identified indicators of compromise (IoCs).
    • Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
  • Remove and block malicious artifacts identified during triage.
  • Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
  • Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

Related rules

to-top