Suspicious Usage of Unblock-File PowerShell Cmdlet
The abuse of the Unblock-File cmdlet is used by attackers to bypass Mark-of-the-Web (MotW) protections on downloaded files, facilitating the execution of malicious payloads.
The Unblock-File PowerShell cmdlet is a legitimate administrative tool used to remove the Zone.Identifier alternate data stream (ADS) from files downloaded from the internet. When a file is downloaded on Windows, the operating system attaches this stream to flag the file as potentially untrusted, which subsequently triggers security prompts or blocks execution of macros and scripts. Attackers frequently abuse this cmdlet to programmatically remove these protections from malicious payloads, such as droppers or scripts, to ensure they execute without user intervention or security warnings. Defenders should monitor for the use of this command in scripts, as its execution on non-standard files or in suspicious contexts is a common indicator of defense evasion.
Attack Chain
- Attacker delivers a malicious payload (e.g., LNK file or script) to the target host via phishing or web drive-by.
- The file is saved to the disk and receives a 'Zone.Identifier' alternate data stream identifying it as untrusted.
- The attacker executes a secondary script or payload wrapper on the host.
- The script identifies the downloaded file path.
- The attacker invokes the Unblock-File cmdlet targeting the malicious file.
- The PowerShell engine removes the Zone.Identifier ADS from the file system.
- The operating system no longer treats the file as originating from the internet.
- The attacker executes the now-trusted payload to achieve persistent access or secondary stage download.
Impact
Successful abuse of this cmdlet allows attackers to bypass Windows security features designed to prevent the execution of untrusted code. This leads to the silent execution of malware, increased probability of successful macro-based attacks, and the evasion of host-based security warnings, potentially resulting in full system compromise.
Recommendation
- Enable PowerShell Script Block Logging (Event ID 4104) across the environment to capture full command execution strings.
- Deploy the provided Sigma rule to detect the execution of Unblock-File.
- Baseline the usage of Unblock-File in your environment to identify legitimate automated deployment scripts and suppress them in the detection logic.
- Implement strict AppLocker or Windows Defender Application Control (WDAC) policies to restrict the execution of scripts that have been unblocked in unauthorized locations.
Immediate actions
Enable PowerShell Script Block Logging (Event ID 4104) on all workstations.
Threat Hunt
Search for instances of Unblock-File in historic Script Block logs.
Data: ScriptBlockText from Event ID 4104
Detection coverage 1
Detect Suspicious Unblock-File Usage
mediumDetects the use of the Unblock-File cmdlet to remove the Zone.Identifier alternate data stream from files.
Detection queries are available on the platform. Get full rules →