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"]
  4maturity = "production"
  5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
  6min_stack_version = "8.3.0"
  7updated_date = "2024/03/28"
  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-*"]
 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"
112setup = """## Setup
113
114If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2,
115events will not define `event.ingested` and default fallback for EQL rules was not added until version 8.2.
116Hence for this rule to work effectively, users will need to add a custom ingest pipeline to populate
117`event.ingested` to @timestamp.
118For more details on adding a custom ingest pipeline refer - https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html
119"""
120severity = "medium"
121tags = ["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"]
122timestamp_override = "event.ingested"
123type = "eql"
124
125query = '''
126registry where host.os.type == "windows" and
127  registry.path : (
128     "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls",
129     "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls",
130     "\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls",
131     "\\REGISTRY\\MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_Dlls"
132  ) and
133  not process.executable : (
134     "?:\\Windows\\System32\\DriverStore\\FileRepository\\*\\Display.NvContainer\\NVDisplay.Container.exe",
135     "?:\\Windows\\System32\\msiexec.exe",
136     "?:\\Windows\\SysWOW64\\msiexec.exe",
137     "?:\\Program Files\\Commvault\\Base\\cvd.exe",
138     "?:\\Program Files\\Commvault\\ContentStore*\\Base\\cvd.exe",
139     "?:\\Program Files (x86)\\Commvault\\Base\\cvd.exe",
140     "?:\\Program Files (x86)\\Commvault\\ContentStore*\\Base\\cvd.exe",
141     "?:\\Program Files\\NVIDIA Corporation\\Display.NvContainer\\NVDisplay.Container.exe"
142  )
143'''
144
145
146[[rule.threat]]
147framework = "MITRE ATT&CK"
148[[rule.threat.technique]]
149id = "T1546"
150name = "Event Triggered Execution"
151reference = "https://attack.mitre.org/techniques/T1546/"
152[[rule.threat.technique.subtechnique]]
153id = "T1546.010"
154name = "AppInit DLLs"
155reference = "https://attack.mitre.org/techniques/T1546/010/"
156
157
158
159[rule.threat.tactic]
160id = "TA0003"
161name = "Persistence"
162reference = "https://attack.mitre.org/tactics/TA0003/"
163
164
165
166[[rule.threat]]
167framework = "MITRE ATT&CK"
168[[rule.threat.technique]]
169id = "T1112"
170name = "Modify Registry"
171reference = "https://attack.mitre.org/techniques/T1112/"
172
173[rule.threat.tactic]
174id = "TA0005"
175name = "Defense Evasion"
176reference = "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