Potential Antimalware Scan Interface Bypass via PowerShell
Identifies the execution of PowerShell script with keywords related to different Antimalware Scan Interface (AMSI) bypasses. An adversary may attempt first to disable AMSI before executing further malicious powershell scripts to evade detection.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/01/17"
3integration = ["windows"]
4maturity = "production"
5updated_date = "2024/10/28"
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 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 execution of PowerShell script with keywords related to different Antimalware Scan Interface (AMSI)
39bypasses. An adversary may attempt first to disable AMSI before executing further malicious powershell scripts to evade
40detection.
41"""
42from = "now-9m"
43index = ["winlogbeat-*", "logs-windows.powershell*"]
44language = "kuery"
45license = "Elastic License v2"
46name = "Potential Antimalware Scan Interface Bypass via PowerShell"
47note = """## Triage and analysis
48
49### Investigating Potential Antimalware Scan Interface Bypass via PowerShell
50
51PowerShell is one of the main tools system administrators use for automation, report routines, and other tasks. This makes it available for use in various environments, and creates an attractive way for attackers to execute code.
52
53The 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.
54
55This rule identifies scripts that contain methods and classes that can be abused to bypass AMSI.
56
57> **Note**:
58> 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.
59
60#### Possible investigation steps
61
62- Examine the script content that triggered the detection; look for suspicious DLL imports, collection or exfiltration capabilities, suspicious functions, encoded or compressed data, and other potentially malicious characteristics.
63- Investigate the script 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.
64- Determine whether the script was executed and capture relevant information, such as arguments that reveal intent or are indicators of compromise (IoCs).
65- Investigate other alerts associated with the user/host during the past 48 hours.
66- Investigate commands and scripts executed after this activity was observed.
67- Inspect the host for suspicious or abnormal behavior in the alert timeframe:
68 - Observe and collect information about the following activities in the alert subject host:
69 - Attempts to contact external domains and addresses.
70 - Use the Elastic Defend network events to determine domains and addresses contacted by the subject process by filtering by the process' `process.entity_id`.
71 - Examine the DNS cache for suspicious or anomalous entries.
72 - $osquery_0
73 - Use the Elastic Defend registry events to examine registry keys accessed, modified, or created by the related processes in the process tree.
74 - Examine the host services for suspicious or anomalous entries.
75 - $osquery_1
76 - $osquery_2
77 - $osquery_3
78
79### False positive analysis
80
81- This activity is unlikely to happen legitimately. Benign true positives (B-TPs) can be added as exceptions if necessary.
82
83### Response and remediation
84
85- Initiate the incident response process based on the outcome of the triage.
86- Isolate the involved hosts to prevent further post-compromise behavior.
87- If the triage identified malware, search the environment for additional compromised hosts.
88 - Implement temporary network rules, procedures, and segmentation to contain the malware.
89 - Stop suspicious processes.
90 - Immediately block the identified indicators of compromise (IoCs).
91 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
92- Remove and block malicious artifacts identified during triage.
93- Restrict PowerShell usage outside of IT and engineering business units using GPOs, AppLocker, Intune, or similar software.
94- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
95- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
96- 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).
97"""
98references = ["https://github.com/S3cur3Th1sSh1t/Amsi-Bypass-Powershell"]
99risk_score = 73
100rule_id = "1f0a69c0-3392-4adf-b7d5-6012fd292da8"
101severity = "high"
102tags = [
103 "Domain: Endpoint",
104 "OS: Windows",
105 "Use Case: Threat Detection",
106 "Tactic: Defense Evasion",
107 "Data Source: PowerShell Logs",
108 "Resources: Investigation Guide",
109]
110timestamp_override = "event.ingested"
111type = "query"
112
113query = '''
114event.category:"process" and host.os.type:windows and
115 (
116 powershell.file.script_block_text : (
117 "System.Management.Automation.AmsiUtils" or
118 amsiInitFailed or
119 "Invoke-AmsiBypass" or
120 "Bypass.AMSI" or
121 "amsi.dll" or
122 AntimalwareProvider or
123 amsiSession or
124 amsiContext or
125 AmsiInitialize or
126 unloadobfuscated or
127 unloadsilent or
128 AmsiX64 or
129 AmsiX32 or
130 FindAmsiFun
131 ) or
132 powershell.file.script_block_text:("[System.Runtime.InteropServices.Marshal]::Copy" and "VirtualProtect") or
133 powershell.file.script_block_text:("[Ref].Assembly.GetType(('System.Management.Automation" and ".SetValue(")
134 ) and
135 not powershell.file.script_block_text : (
136 "sentinelbreakpoints" and "Set-PSBreakpoint"
137 )
138'''
139
140
141[[rule.threat]]
142framework = "MITRE ATT&CK"
143[[rule.threat.technique]]
144id = "T1562"
145name = "Impair Defenses"
146reference = "https://attack.mitre.org/techniques/T1562/"
147[[rule.threat.technique.subtechnique]]
148id = "T1562.001"
149name = "Disable or Modify Tools"
150reference = "https://attack.mitre.org/techniques/T1562/001/"
151
152
153
154[rule.threat.tactic]
155id = "TA0005"
156name = "Defense Evasion"
157reference = "https://attack.mitre.org/tactics/TA0005/"
158[[rule.threat]]
159framework = "MITRE ATT&CK"
160[[rule.threat.technique]]
161id = "T1059"
162name = "Command and Scripting Interpreter"
163reference = "https://attack.mitre.org/techniques/T1059/"
164[[rule.threat.technique.subtechnique]]
165id = "T1059.001"
166name = "PowerShell"
167reference = "https://attack.mitre.org/techniques/T1059/001/"
168
169
170
171[rule.threat.tactic]
172id = "TA0002"
173name = "Execution"
174reference = "https://attack.mitre.org/tactics/TA0002/"
Triage and analysis
Investigating Potential Antimalware Scan Interface Bypass via PowerShell
PowerShell is one of the main tools system administrators use for automation, report routines, and other tasks. This makes it available for use in various environments, and creates an attractive way for attackers to execute code.
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.
This rule identifies scripts that contain methods and classes that can be abused to bypass AMSI.
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
- Examine the script content that triggered the detection; look for suspicious DLL imports, collection or exfiltration capabilities, suspicious functions, encoded or compressed data, and other potentially malicious characteristics.
- Investigate the script 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.
- Determine whether the script was executed and capture relevant information, such as arguments that reveal intent or are indicators of compromise (IoCs).
- Investigate other alerts associated with the user/host during the past 48 hours.
- Investigate commands and scripts executed after this activity was observed.
- 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 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_1
- $osquery_2
- $osquery_3
- Attempts to contact external domains and addresses.
- Observe and collect information about the following activities in the alert subject host:
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 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.
- Restrict PowerShell usage outside of IT and engineering business units using GPOs, AppLocker, Intune, or similar software.
- 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
- Potential Process Injection via PowerShell
- PowerShell Script with Encryption/Decryption Capabilities
- PowerShell Suspicious Payload Encoded and Compressed
- Suspicious .NET Reflection via PowerShell
- Suspicious Portable Executable Encoded in Powershell Script