AMSI Bypass via PowerShell Reflection
Detection of AMSI (Antimalware Scan Interface) tampering via PowerShell reflection, utilizing PowerShell Script Block Logging (EventCode=4104) to identify commands manipulating `system.management.automation.amsi`, potentially leading to undetected malicious code execution and system compromise.
This brief focuses on detecting attempts to bypass the Antimalware Scan Interface (AMSI) by using PowerShell reflection. AMSI is a crucial security feature in Windows that allows applications and services to request malware scans of potentially malicious scripts and code. Attackers often attempt to disable or bypass AMSI to execute malicious payloads without being detected by security solutions. This particular technique leverages PowerShell’s ability to interact with .NET objects via reflection to manipulate the AMSI provider and effectively disable it. The use of system.management.automation.amsi within PowerShell scripts is a strong indicator of this behavior. Detecting this activity is critical as it allows malicious scripts to run undetected, potentially leading to system compromise, data exfiltration, or other malicious activities.
Attack Chain
- Attacker gains initial access to the system (e.g., via phishing or exploiting a vulnerability).
- The attacker executes a PowerShell script.
- The PowerShell script uses reflection to access the
system.management.automation.amsiobject. - The script modifies the AMSI provider to disable scanning or return false negatives.
- The attacker executes malicious code (e.g., malware, ransomware) via PowerShell.
- Because AMSI is disabled, the malicious code is not scanned or detected.
- The attacker performs further actions, such as privilege escalation, lateral movement, or data exfiltration.
- The attacker achieves their objective, such as deploying ransomware or stealing sensitive data.
Impact
Successful exploitation of this technique can lead to complete system compromise, as AMSI is a critical defense against script-based attacks. Depending on the attacker’s objectives, impacts can range from data theft and ransomware deployment to persistent backdoor installation and disruption of services. Organizations using vulnerable PowerShell configurations may experience widespread malware infections and significant data loss. If left undetected, this technique can allow attackers to operate undetected for extended periods, increasing the potential for severe damage.
Recommendation
- Enable PowerShell Script Block Logging (EventCode 4104) to capture and analyze PowerShell commands. See the provided references for configuration details.
- Deploy the provided Sigma rule
Detect AMSI Unloading via PowerShell Reflectionto your SIEM to detect the use ofsystem.management.automation.amsiin PowerShell scripts. - Filter out known false positives from third-party applications as needed, based on your environment.
- Monitor for unexpected PowerShell processes spawning from unusual parent processes, as this may indicate malicious activity.
- Implement application control policies to restrict the execution of unsigned or untrusted PowerShell scripts.
Detection coverage 2
Detect AMSI Unloading via PowerShell Reflection
highDetects attempts to bypass AMSI by using PowerShell reflection to access and modify the `system.management.automation.amsi` object.
Detect AMSI Unloading via PowerShell Script Block Logging
highDetects attempts to unload AMSI via PowerShell reflection based on script block logging (EventCode=4104).
Detection queries are kept inside the platform. Get full rules →