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"]
4maturity = "production"
5updated_date = "2025/03/20"
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]
59language = "eql"
60license = "Elastic License v2"
61name = "Registry Persistence via AppInit DLL"
62note = """## Triage and analysis
63
64### Investigating Registry Persistence via AppInit DLL
65
66AppInit 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.
67
68Attackers 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.
69
70This rule identifies modifications on the AppInit registry keys.
71
72> **Note**:
73> 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.
74
75#### Possible investigation steps
76
77- 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.
78- Review the source process and related DLL file tied to the Windows Registry entry.
79 - Check whether the DLL is signed, and tied to a authorized program used on your environment.
80- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
81- Retrieve all DLLs under the AppInit registry keys:
82 - $osquery_0
83- Examine the host for derived artifacts that indicate suspicious activities:
84 - Analyze the process executable and the DLLs using a private sandboxed analysis system.
85 - Observe and collect information about the following activities in both the sandbox and the alert subject host:
86 - Attempts to contact external domains and addresses.
87 - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
88 - Examine the DNS cache for suspicious or anomalous entries.
89 - $osquery_1
90 - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
91 - Examine the host services for suspicious or anomalous entries.
92 - $osquery_2
93 - $osquery_3
94 - $osquery_4
95 - 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.
96
97### False positive analysis
98
99- This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.
100
101### Response and remediation
102
103- Initiate the incident response process based on the outcome of the triage.
104- Isolate the involved host to prevent further post-compromise behavior.
105- If the triage identified malware, search the environment for additional compromised hosts.
106 - Implement temporary network rules, procedures, and segmentation to contain the malware.
107 - Stop suspicious processes.
108 - Immediately block the identified indicators of compromise (IoCs).
109 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
110- Remove and block malicious artifacts identified during triage.
111- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
112- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
113- 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).
114"""
115risk_score = 47
116rule_id = "d0e159cf-73e9-40d1-a9ed-077e3158a855"
117severity = "medium"
118tags = [
119 "Domain: Endpoint",
120 "OS: Windows",
121 "Use Case: Threat Detection",
122 "Tactic: Persistence",
123 "Tactic: Defense Evasion",
124 "Resources: Investigation Guide",
125 "Data Source: Elastic Endgame",
126 "Data Source: Elastic Defend",
127 "Data Source: Sysmon",
128 "Data Source: Microsoft Defender for Endpoint",
129 "Data Source: SentinelOne",
130]
131timestamp_override = "event.ingested"
132type = "eql"
133
134query = '''
135registry where host.os.type == "windows" and event.type == "change" and
136 registry.path : (
137 "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls",
138 "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls",
139 "\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls",
140 "\\REGISTRY\\MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls",
141 "MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls",
142 "MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls"
143 ) and
144 not process.executable : (
145 "?:\\Windows\\System32\\DriverStore\\FileRepository\\*\\Display.NvContainer\\NVDisplay.Container.exe",
146 "?:\\Windows\\System32\\msiexec.exe",
147 "?:\\Windows\\SysWOW64\\msiexec.exe",
148 "?:\\Program Files\\Commvault\\Base\\cvd.exe",
149 "?:\\Program Files\\Commvault\\ContentStore*\\Base\\cvd.exe",
150 "?:\\Program Files (x86)\\Commvault\\Base\\cvd.exe",
151 "?:\\Program Files (x86)\\Commvault\\ContentStore*\\Base\\cvd.exe",
152 "?:\\Program Files\\NVIDIA Corporation\\Display.NvContainer\\NVDisplay.Container.exe"
153 )
154'''
155
156
157[[rule.threat]]
158framework = "MITRE ATT&CK"
159[[rule.threat.technique]]
160id = "T1546"
161name = "Event Triggered Execution"
162reference = "https://attack.mitre.org/techniques/T1546/"
163[[rule.threat.technique.subtechnique]]
164id = "T1546.010"
165name = "AppInit DLLs"
166reference = "https://attack.mitre.org/techniques/T1546/010/"
167
168
169
170[rule.threat.tactic]
171id = "TA0003"
172name = "Persistence"
173reference = "https://attack.mitre.org/tactics/TA0003/"
174[[rule.threat]]
175framework = "MITRE ATT&CK"
176[[rule.threat.technique]]
177id = "T1112"
178name = "Modify Registry"
179reference = "https://attack.mitre.org/techniques/T1112/"
180
181
182[rule.threat.tactic]
183id = "TA0005"
184name = "Defense Evasion"
185reference = "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 network events to determine domains and addresses contacted by the subject process by filtering by the process'
- 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
- Attempts to contact external domains and addresses.
- 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
- Adding Hidden File Attribute via Attrib
- Image File Execution Options Injection
- Installation of Security Support Provider
- Suspicious ImagePath Service Creation
- Suspicious Startup Shell Folder Modification