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