PowerShell Script Execution from Alternate Data Streams
Detection of attackers using NTFS Alternate Data Streams (ADS) to hide and execute malicious PowerShell scripts, effectively bypassing simple file-based scanning.
This threat brief focuses on the technique of executing PowerShell scripts stored within NTFS Alternate Data Streams (ADS). Adversaries leverage ADS to hide malicious code within seemingly benign files, complicating traditional security auditing and static analysis. By attaching scripts to legitimate files, attackers can persist on a system or stage their payloads in a way that is not immediately visible to users or basic file browsers. When the PowerShell interpreter is called to read the content of these streams, the script is executed in memory. This technique is specifically identified as a method for stealth and persistent execution, often utilized during the post-exploitation phase to execute secondary stages of a compromise.
Attack Chain
- The attacker gains initial access to the target host through a separate vector.
- The attacker uses standard Windows utilities to create a hidden stream attached to an existing file (e.g.,
echo [payload] > legitimate.txt:malicious.ps1). - The attacker hides the presence of the ADS by modifying file timestamps or attributes to avoid manual inspection.
- The attacker triggers execution of the hidden script by spawning a PowerShell process.
- The PowerShell interpreter executes the
Get-Contentcmdlet with the-Streamparameter to read the contents of the hidden ADS. - The retrieved content is piped directly into the PowerShell runtime for immediate execution without writing a standalone file to disk.
- The process executes the malicious payload, such as a reverse shell or information stealer, in the context of the running PowerShell process.
Impact
Successful execution of scripts from ADS enables attackers to maintain stealthy persistence and execute malicious payloads that evade conventional file-integrity monitoring and signature-based detection. This technique allows for the execution of arbitrary code in memory, facilitating lateral movement, data exfiltration, or the deployment of further ransomware components within an enterprise environment.
Recommendation
Prioritized actions for detection engineering and security operations:
- Deploy the provided Sigma rule to monitor for suspicious use of
Get-Contentwith the-Streamparameter in PowerShell command lines. - Enable PowerShell script block logging to inspect the actual contents of the executed scripts regardless of their storage location.
- Review environments for unusual file metadata patterns or processes interacting with non-standard NTFS streams.
- Focus on monitoring child processes spawned by PowerShell that demonstrate unexpected network or file system activity.
Immediate actions
Deploy Sigma detection rule to SIEM environment
Threat Hunt
Search for Get-Content -Stream in historical command line logs
Data: Process creation command line telemetry
Mitigations
Enable PowerShell Script Block Logging (Event ID 4104)
Hidden PowerShell execution
Detection coverage 1
Detect PowerShell Script Execution from ADS
highDetects PowerShell execution where the script content is retrieved from an NTFS Alternate Data Stream (ADS)
Detection queries are available on the platform. Get full rules →