Suspicious Antimalware Scan Interface DLL

Identifies the creation of the Antimalware Scan Interface (AMSI) DLL in an unusual location. This may indicate an attempt to bypass AMSI by loading a rogue AMSI module instead of the legit one.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/01/17"
  3integration = ["windows", "endpoint", "sentinel_one_cloud_funnel", "m365_defender"]
  4maturity = "production"
  5min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
  6min_stack_version = "8.14.0"
  7updated_date = "2024/10/15"
  8
  9[transform]
 10[[transform.osquery]]
 11label = "Osquery - Retrieve DNS Cache"
 12query = "SELECT * FROM dns_cache"
 13
 14[[transform.osquery]]
 15label = "Osquery - Retrieve All Services"
 16query = "SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services"
 17
 18[[transform.osquery]]
 19label = "Osquery - Retrieve Services Running on User Accounts"
 20query = """
 21SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services WHERE
 22NOT (user_account LIKE '%LocalSystem' OR user_account LIKE '%LocalService' OR user_account LIKE '%NetworkService' OR
 23user_account == null)
 24"""
 25
 26[[transform.osquery]]
 27label = "Osquery - Retrieve Service Unsigned Executables with Virustotal Link"
 28query = """
 29SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, name, description, start_type, status, pid,
 30services.path FROM services JOIN authenticode ON services.path = authenticode.path OR services.module_path =
 31authenticode.path JOIN hash ON services.path = hash.path WHERE authenticode.result != 'trusted'
 32"""
 33
 34
 35[rule]
 36author = ["Elastic"]
 37description = """
 38Identifies the creation of the Antimalware Scan Interface (AMSI) DLL in an unusual location. This may indicate an
 39attempt to bypass AMSI by loading a rogue AMSI module instead of the legit one.
 40"""
 41from = "now-9m"
 42index = ["winlogbeat-*", "logs-endpoint.events.file-*", "logs-windows.sysmon_operational-*", "endgame-*", "logs-sentinel_one_cloud_funnel.*", "logs-m365_defender.event-*"]
 43language = "eql"
 44license = "Elastic License v2"
 45name = "Suspicious Antimalware Scan Interface DLL"
 46note = """## Triage and analysis
 47
 48### Investigating Suspicious Antimalware Scan Interface DLL
 49
 50The Windows Antimalware Scan Interface (AMSI) is a versatile interface standard that allows your applications and services to integrate with any antimalware product on a machine. AMSI integrates with multiple Windows components, ranging from User Account Control (UAC) to VBA macros and PowerShell.
 51
 52Attackers might copy a rogue AMSI DLL to an unusual location to prevent the process from loading the legitimate module, achieving a bypass to execute malicious code.
 53
 54> **Note**:
 55> 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.
 56
 57#### Possible investigation steps
 58
 59- Identify the process that created the DLL and which account was used.
 60- 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.
 61- Investigate other alerts associated with the user/host during the past 48 hours.
 62- Investigate the execution of scripts and macros after the registry modification.
 63- Investigate other processes launched from the directory that the DLL was created.
 64- Inspect the host for suspicious or abnormal behavior in the alert timeframe:
 65  - Observe and collect information about the following activities in the alert subject host:
 66    - Attempts to contact external domains and addresses.
 67      - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
 68      - Examine the DNS cache for suspicious or anomalous entries.
 69        - $osquery_0
 70    - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
 71    - Examine the host services for suspicious or anomalous entries.
 72      - $osquery_1
 73      - $osquery_2
 74      - $osquery_3
 75
 76### False positive analysis
 77
 78- This modification should not happen legitimately. Any potential benign true positive (B-TP) should be mapped and monitored by the security team as these modifications expose the host to malware infections.
 79
 80### Response and remediation
 81
 82- Initiate the incident response process based on the outcome of the triage.
 83- Isolate the involved hosts to prevent further post-compromise behavior.
 84- If the triage identified malware, search the environment for additional compromised hosts.
 85  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 86  - Stop suspicious processes.
 87  - Immediately block the identified indicators of compromise (IoCs).
 88  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 89- Remove and block malicious artifacts identified during triage.
 90- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 91- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 92- 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).
 93"""
 94references = ["https://github.com/S3cur3Th1sSh1t/Amsi-Bypass-Powershell"]
 95risk_score = 73
 96rule_id = "fa488440-04cc-41d7-9279-539387bf2a17"
 97severity = "high"
 98tags = [
 99    "Domain: Endpoint",
100    "OS: Windows",
101    "Use Case: Threat Detection",
102    "Tactic: Defense Evasion",
103    "Data Source: Elastic Endgame",
104    "Resources: Investigation Guide",
105    "Data Source: Elastic Defend",
106    "Data Source: Sysmon",
107    "Data Source: SentinelOne",
108    "Data Source: Microsoft Defender for Endpoint"
109]
110timestamp_override = "event.ingested"
111type = "eql"
112
113query = '''
114file where host.os.type == "windows" and event.type != "deletion" and file.path != null and
115  file.name : ("amsi.dll", "amsi") and
116  not file.path : (
117    "?:\\Windows\\system32\\amsi.dll",
118    "?:\\Windows\\Syswow64\\amsi.dll",
119    "?:\\$WINDOWS.~BT\\DUImageSandbox\\*",
120    "?:\\$WINDOWS.~BT\\NewOS\\Windows\\WinSXS\\*",
121    "?:\\$WINDOWS.~BT\\NewOS\\Windows\\servicing\\LCU\\*",
122    "?:\\$WINDOWS.~BT\\Work\\*\\*",
123    "?:\\Windows\\SoftwareDistribution\\Download\\*",
124    "?:\\Windows\\WinSxS\\amd64_microsoft-antimalware-scan-interface_*\\amsi.dll"
125  ) and
126  not
127  (
128    process.executable : "C:\\Windows\\System32\\wbengine.exe" and
129    file.path : (
130      "\\Device\\HarddiskVolume??\\Windows\\system32\\amsi.dll",
131      "\\Device\\HarddiskVolume??\\Windows\\syswow64\\amsi.dll",
132      "\\Device\\HarddiskVolume??\\Windows\\WinSxS\\*\\amsi.dll"
133    )
134  )
135'''
136
137
138[[rule.threat]]
139framework = "MITRE ATT&CK"
140[[rule.threat.technique]]
141id = "T1562"
142name = "Impair Defenses"
143reference = "https://attack.mitre.org/techniques/T1562/"
144[[rule.threat.technique.subtechnique]]
145id = "T1562.001"
146name = "Disable or Modify Tools"
147reference = "https://attack.mitre.org/techniques/T1562/001/"
148
149
150[[rule.threat.technique]]
151id = "T1574"
152name = "Hijack Execution Flow"
153reference = "https://attack.mitre.org/techniques/T1574/"
154[[rule.threat.technique.subtechnique]]
155id = "T1574.001"
156name = "DLL Search Order Hijacking"
157reference = "https://attack.mitre.org/techniques/T1574/001/"
158
159
160
161[rule.threat.tactic]
162id = "TA0005"
163name = "Defense Evasion"
164reference = "https://attack.mitre.org/tactics/TA0005/"

Triage and analysis

Investigating Suspicious Antimalware Scan Interface DLL

The Windows Antimalware Scan Interface (AMSI) is a versatile interface standard that allows your applications and services to integrate with any antimalware product on a machine. AMSI integrates with multiple Windows components, ranging from User Account Control (UAC) to VBA macros and PowerShell.

Attackers might copy a rogue AMSI DLL to an unusual location to prevent the process from loading the legitimate module, achieving a bypass to execute malicious code.

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

  • Identify the process that created the DLL and which account was used.
  • 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.
  • Investigate other alerts associated with the user/host during the past 48 hours.
  • Investigate the execution of scripts and macros after the registry modification.
  • Investigate other processes launched from the directory that the DLL was created.
  • Inspect the host for suspicious or abnormal behavior in the alert timeframe:
    • Observe and collect information about the following activities in 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_0
      • 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_1
        • $osquery_2
        • $osquery_3

False positive analysis

  • This modification should not happen legitimately. Any potential benign true positive (B-TP) should be mapped and monitored by the security team as these modifications expose the host to malware infections.

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Isolate the involved hosts 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).

References

Related rules

to-top