Suspicious DLL Loaded for Persistence or Privilege Escalation

Identifies the loading of a non Microsoft signed DLL that is missing on a default Windows install (phantom DLL) or one that can be loaded from a different location by a native Windows process. This may be abused to persist or elevate privileges via privileged file write vulnerabilities.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/01/07"
  3integration = ["endpoint", "windows"]
  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[rule]
 10author = ["Elastic"]
 11description = """
 12Identifies the loading of a non Microsoft signed DLL that is missing on a default Windows install (phantom DLL) or one
 13that can be loaded from a different location by a native Windows process. This may be abused to persist or elevate
 14privileges via privileged file write vulnerabilities.
 15"""
 16from = "now-9m"
 17index = ["winlogbeat-*", "logs-endpoint.events.library*", "logs-windows.sysmon_operational-*", "endgame-*"]
 18language = "eql"
 19license = "Elastic License v2"
 20name = "Suspicious DLL Loaded for Persistence or Privilege Escalation"
 21note = """## Triage and analysis
 22
 23### Investigating Suspicious DLL Loaded for Persistence or Privilege Escalation
 24
 25Attackers can execute malicious code by abusing missing modules that processes try to load, enabling them to escalate privileges or gain persistence. This rule identifies the loading of a non-Microsoft-signed DLL that is missing on a default Windows installation or one that can be loaded from a different location by a native Windows process.
 26
 27#### Possible investigation steps
 28
 29- Examine the DLL signature and identify the process that created it.
 30  - Investigate any abnormal behaviors by the process such as network connections, registry or file modifications, and any spawned child processes.
 31- Investigate other alerts associated with the user/host during the past 48 hours.
 32- Retrieve the DLL and determine if it is malicious:
 33  - Use a private sandboxed malware analysis system to perform analysis.
 34    - Observe and collect information about the following activities:
 35      - Attempts to contact external domains and addresses.
 36      - File and registry access, modification, and creation activities.
 37      - Service creation and launch activities.
 38      - Scheduled task creation.
 39  - Use the PowerShell Get-FileHash cmdlet to get the files' SHA-256 hash values.
 40    - Search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
 41
 42### False positive analysis
 43
 44- This activity is unlikely to happen legitimately. Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.
 45
 46### Response and remediation
 47
 48- Initiate the incident response process based on the outcome of the triage.
 49- Isolate the involved host to prevent further post-compromise behavior.
 50- If the triage identified malware, search the environment for additional compromised hosts.
 51  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 52  - Stop suspicious processes.
 53  - Immediately block the identified indicators of compromise (IoCs).
 54  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 55- Remove and block malicious artifacts identified during triage.
 56- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 57- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
 58- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 59- 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).
 60"""
 61references = [
 62    "https://itm4n.github.io/windows-dll-hijacking-clarified/",
 63    "http://remoteawesomethoughts.blogspot.com/2019/05/windows-10-task-schedulerservice.html",
 64    "https://googleprojectzero.blogspot.com/2018/04/windows-exploitation-tricks-exploiting.html",
 65    "https://shellz.club/2020/10/16/edgegdi-dll-for-persistence-and-lateral-movement.html",
 66    "https://windows-internals.com/faxing-your-way-to-system/",
 67    "http://waleedassar.blogspot.com/2013/01/wow64logdll.html",
 68]
 69risk_score = 73
 70rule_id = "bfeaf89b-a2a7-48a3-817f-e41829dc61ee"
 71setup = """## Setup
 72
 73If enabling an EQL rule on a non-elastic-agent index (such as beats) for versions <8.2,
 74events will not define `event.ingested` and default fallback for EQL rules was not added until version 8.2.
 75Hence for this rule to work effectively, users will need to add a custom ingest pipeline to populate
 76`event.ingested` to @timestamp.
 77For more details on adding a custom ingest pipeline refer - https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html
 78"""
 79severity = "high"
 80tags = [
 81    "Domain: Endpoint",
 82    "OS: Windows",
 83    "Use Case: Threat Detection",
 84    "Tactic: Persistence",
 85    "Tactic: Privilege Escalation",
 86    "Tactic: Defense Evasion",
 87    "Resources: Investigation Guide",
 88    "Data Source: Elastic Endgame",
 89    "Data Source: Elastic Defend",
 90    "Data Source: Sysmon",
 91]
 92timestamp_override = "event.ingested"
 93type = "eql"
 94
 95query = '''
 96any where host.os.type == "windows" and
 97(event.category : ("driver", "library") or (event.category == "process" and event.action : "Image loaded*")) and
 98(
 99  /* compatible with Elastic Endpoint Library Events */
100  (
101    ?dll.name : (
102        "wlbsctrl.dll", "wbemcomn.dll", "WptsExtensions.dll", "Tsmsisrv.dll", "TSVIPSrv.dll", "Msfte.dll",
103        "wow64log.dll", "WindowsCoreDeviceInfo.dll", "Ualapi.dll", "wlanhlp.dll", "phoneinfo.dll", "EdgeGdi.dll",
104        "cdpsgshims.dll", "windowsperformancerecordercontrol.dll", "diagtrack_win.dll", "TPPCOIPW32.dll", 
105        "tpgenlic.dll", "thinmon.dll", "fxsst.dll", "msTracer.dll"
106    )
107    and (
108      ?dll.code_signature.trusted != true or
109      ?dll.code_signature.exists != true or
110      (
111        dll.code_signature.trusted == true and
112          not dll.code_signature.subject_name : ("Microsoft Windows", "Microsoft Corporation", "Microsoft Windows Publisher")
113      )
114  ) or
115   /* oci.dll is too noisy due to unsigned Oracle related DLL loaded from random dirs */
116  (
117   (?dll.path : "?:\\Windows\\*\\oci.dll" and process.executable : "?:\\Windows\\*.exe" and 
118    (?dll.code_signature.trusted != true or ?dll.code_signature.exists != true)) or 
119    
120   (file.path : "?:\\Windows\\*\\oci.dll" and not file.code_signature.status == "Valid" and process.executable : "?:\\Windows\\*.exe")
121   ) or 
122
123  /* compatible with Sysmon EventID 7 - Image Load */
124  (file.name : ("wlbsctrl.dll", "wbemcomn.dll", "WptsExtensions.dll", "Tsmsisrv.dll", "TSVIPSrv.dll", "Msfte.dll",
125               "wow64log.dll", "WindowsCoreDeviceInfo.dll", "Ualapi.dll", "wlanhlp.dll", "phoneinfo.dll", "EdgeGdi.dll",
126               "cdpsgshims.dll", "windowsperformancerecordercontrol.dll", "diagtrack_win.dll", "TPPCOIPW32.dll", 
127               "tpgenlic.dll", "thinmon.dll", "fxsst.dll", "msTracer.dll") and 
128   not file.hash.sha256 : 
129            ("6e837794fc282446906c36d681958f2f6212043fc117c716936920be166a700f", 
130             "b14e4954e8cca060ffeb57f2458b6a3a39c7d2f27e94391cbcea5387652f21a4", 
131             "c258d90acd006fa109dc6b748008edbb196d6168bc75ace0de0de54a4db46662") and 
132   not file.code_signature.status == "Valid")
133  ) and
134  not
135  (
136    ?dll.path : (
137      "?:\\Windows\\System32\\wbemcomn.dll",
138      "?:\\Windows\\SysWOW64\\wbemcomn.dll",
139      "?:\\Windows\\System32\\windowsperformancerecordercontrol.dll",
140      "?:\\Windows\\System32\\wlanhlp.dll", 
141      "\\Device\\HarddiskVolume?\\Windows\\SysWOW64\\wbemcomn.dll", 
142      "\\Device\\HarddiskVolume?\\Windows\\System32\\wbemcomn.dll", 
143      "\\Device\\HarddiskVolume?\\Windows\\SysWOW64\\wlanhlp.dll", 
144      "\\Device\\HarddiskVolume?\\Windows\\System32\\wlanhlp.dll", 
145      "\\Device\\HarddiskVolume?\\Windows\\SysWOW64\\windowsperformancerecordercontrol.dll", 
146      "\\Device\\HarddiskVolume?\\Windows\\System32\\windowsperformancerecordercontrol.dll", 
147      "C:\\ProgramData\\docker\\windowsfilter\\*\\Files\\Windows\\System32\\windowsperformancerecordercontrol.dll", 
148      "C:\\ProgramData\\docker\\windowsfilter\\*\\Files\\Windows\\System32\\windowsperformancerecordercontrol.dll", 
149      "\\Device\\vmsmb\\VSMB-{*}\\os\\windows\\system32\\*.dll"
150    ) or
151    file.path : (
152      "?:\\Windows\\System32\\wbemcomn.dll",
153      "?:\\Windows\\SysWOW64\\wbemcomn.dll",
154      "?:\\Windows\\System32\\windowsperformancerecordercontrol.dll",
155      "?:\\Windows\\System32\\wlanhlp.dll", 
156      "C:\\ProgramData\\docker\\windowsfilter\\*\\Files\\Windows\\System32\\windowsperformancerecordercontrol.dll", 
157      "C:\\ProgramData\\docker\\windowsfilter\\*\\Files\\Windows\\System32\\wbemcomn.dll", 
158      "\\Device\\vmsmb\\VSMB-{*}\\os\\windows\\system32\\*.dll"
159    )
160  )
161)
162'''
163
164
165[[rule.threat]]
166framework = "MITRE ATT&CK"
167[[rule.threat.technique]]
168id = "T1574"
169name = "Hijack Execution Flow"
170reference = "https://attack.mitre.org/techniques/T1574/"
171[[rule.threat.technique.subtechnique]]
172id = "T1574.002"
173name = "DLL Side-Loading"
174reference = "https://attack.mitre.org/techniques/T1574/002/"
175
176
177
178[rule.threat.tactic]
179id = "TA0004"
180name = "Privilege Escalation"
181reference = "https://attack.mitre.org/tactics/TA0004/"
182[[rule.threat]]
183framework = "MITRE ATT&CK"
184[[rule.threat.technique]]
185id = "T1574"
186name = "Hijack Execution Flow"
187reference = "https://attack.mitre.org/techniques/T1574/"
188[[rule.threat.technique.subtechnique]]
189id = "T1574.001"
190name = "DLL Search Order Hijacking"
191reference = "https://attack.mitre.org/techniques/T1574/001/"
192
193
194
195[rule.threat.tactic]
196id = "TA0003"
197name = "Persistence"
198reference = "https://attack.mitre.org/tactics/TA0003/"
199[[rule.threat]]
200framework = "MITRE ATT&CK"
201[[rule.threat.technique]]
202id = "T1036"
203name = "Masquerading"
204reference = "https://attack.mitre.org/techniques/T1036/"
205[[rule.threat.technique.subtechnique]]
206id = "T1036.001"
207name = "Invalid Code Signature"
208reference = "https://attack.mitre.org/techniques/T1036/001/"
209
210
211
212[rule.threat.tactic]
213id = "TA0005"
214name = "Defense Evasion"
215reference = "https://attack.mitre.org/tactics/TA0005/"

Triage and analysis

Investigating Suspicious DLL Loaded for Persistence or Privilege Escalation

Attackers can execute malicious code by abusing missing modules that processes try to load, enabling them to escalate privileges or gain persistence. This rule identifies the loading of a non-Microsoft-signed DLL that is missing on a default Windows installation or one that can be loaded from a different location by a native Windows process.

Possible investigation steps

  • Examine the DLL signature and identify the process that created it.
    • Investigate any abnormal behaviors by the process such as network connections, registry or file modifications, and any spawned child processes.
  • Investigate other alerts associated with the user/host during the past 48 hours.
  • Retrieve the DLL and determine if it is malicious:
    • Use a private sandboxed malware analysis system to perform analysis.
      • Observe and collect information about the following activities:
        • Attempts to contact external domains and addresses.
        • File and registry access, modification, and creation activities.
        • Service creation and launch activities.
        • Scheduled task creation.
    • Use the PowerShell Get-FileHash cmdlet to get the files' SHA-256 hash values.
      • 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. Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.

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.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
  • 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).

References

Related rules

to-top