17 - AMSI Bypass
Topics
Introduction to the Windows Shells
Windows Permissions
Reverse Shells in Windows
SeImpersonatePrivilege Exploitation
On Cross Compilation
Windows Services
Weak Service Permissions
Unquoted Service Path
DLL Hijacking
Always Install Elevated
Files with Sensitive Data
Windows Hashes
Stored Credentials and the Windows Vault
Scheduled Task
Critical Registry Paths
Useful Tools
AMSI Bypass
What is an Antivirus?
An antivirus is software designed to detect, prevent, and remove malicious software (malware). Its purpose is to protect systems from threats such as viruses, worms, trojans, spyware, and ransomware.
Modern antivirus software employs various detection techniques:
Signature-Based Detection Matches files against a database of known malware signatures (e.g., MD5 hash).
Static Analysis Examines file properties and code structure for suspicious patterns.
Dynamic Analysis Observes program behavior in real-time or in isolated environments like sandboxes to identify malicious actions.
Machine Learning Models Uses predictive algorithms to detect unknown threats based on behavioral patterns.
Related Technologies
Antivirus software often works in tandem with other security solutions:
Firewalls: Block unauthorized network traffic.
Endpoint Detection and Response (EDR): Provides advanced threat hunting and endpoint protection.
Intrusion Detection/Prevention Systems (IDPS): Monitor networks for malicious activity.
Web Application Firewalls (WAF): Protect web applications from common attacks like SQL injection and cross-site scripting (XSS).
Antivirus in Windows
Windows includes several built-in security technologies to safeguard users:
Windows Defender Antivirus: Real-time protection against malware and viruses.
Firewall & Network Protection: Blocks unauthorized traffic.
Secure Boot: Prevents unauthorized software from running during startup.
BitLocker: Encrypts disks to protect sensitive data.
Windows Hello: Password-free authentication using biometrics.
Windows Antimalware Scan Interface (AMSI)
Introduced in 2015, AMSI is a standard interface for integrating security tools with Windows applications. AMSI scans memory, files, and script content for malicious behavior before execution.
Key Features of AMSI:
Supported by PowerShell, WMI, and Office macros.
Integrates with antivirus solutions for dynamic scans.
Useful for analyzing script-based attacks, such as those using PowerShell or JavaScript.
Workflow:
The application requests a scan.
AMSI sends the request to an antivirus provider.
The antivirus scans the data and provides results.
Examples of AMSI Scanning:
PowerShell scripts
Office macros (e.g., VBA)
.NET assemblies
AMSI Bypass
Despite AMSI's robust design, attackers have developed techniques to bypass its protections. These bypasses typically exploit PowerShell or manipulate AMSI-related memory structures.
Modifying amsiContext
amsiContext
The System.Management.Automation.AmsiUtils
class handles AMSI interactions in PowerShell. By modifying the amsiContext
pointer to disable AMSI scans:
Setting amsiInitFailed
amsiInitFailed
This bypass involves setting the amsiInitFailed
flag to true
:
Demonstration of AMSI Blocking a Malicious Script
Attempting to load a malicious script like Invoke-PowerShellTcp.ps1 results in an AMSI warning:
Error:
With the bypass, AMSI is disabled, allowing the script to execute.
Other Resources
AMSI Bypass Techniques Overview: AMSI Bypass
GitHub Repository with AMSI Bypass Examples: S3cur3Th1sSh1t - AMSI Bypass
Microsoft AMSI Documentation: AMSI Developer Guide
Disclaimer
❗ Never use tools and techniques on real IP addresses, hosts or networks without proper authorization!❗
Last updated