NTFS Alternate Data Streams (ADS) are a feature of the NTFS file system that allow multiple data streams to be associated with a single file. While intended for legitimate purposes, such as storing file metadata, attackers can exploit ADS to conceal malicious code, making detection challenging.
1. Concealing Malware Using ADS
Attackers can embed malware within ADS to hide their presence:
echo MaliciousCode > legitimate.txt:malware.exe
In this scenario, malware.exe is hidden within the ADS of legitimate.txt.
- Evasion of Standard Detection: Since standard file listing commands and many antivirus programs do not inspect ADS by default, malware stored in ADS can evade detection. This stealth technique allows malicious code to persist on a system unnoticed.
2. Listing and Analyzing ADS on a Windows System
To detect and analyze ADS, you can use built-in Windows tools and PowerShell commands:
dir /R
This command lists all files in the directory, including their alternate data streams.
3. Detection and Mitigation of ADS-Based Attacks
Security tools and practices can help detect and prevent ADS-based malware:
-
Antivirus and Anti-Malware Solutions:
Modern security software often includes features to scan for and detect malicious ADS. Ensure your antivirus definitions are up-to-date and that your security software is configured to scan all data streams.
-
Specialized Tools:
Utilities like Sysinternals' Streams can enumerate ADS on a system:
streams.exe -s C:\
This command recursively scans the C: drive for files containing ADS.
4. Practical Example: Creating and Detecting ADS with PowerShell
Here's how you can create and detect an ADS using PowerShell:
# Create a new file
Set-Content -Path "C:\path\to\example.txt" -Value "This is the main file content."
# Add an alternate data stream
Set-Content -Path "C:\path\to\example.txt" -Stream "hiddenStream" -Value "This is hidden malicious content."
# List all streams associated with the file
Get-Item -Path "C:\path\to\example.txt" -Stream *
# Output:
# FileName: C:\path\to\example.txt
# Stream: :$DATA
# Length: 31
# FileName: C:\path\to\example.txt
# Stream: hiddenStream
# Length: 30
This output shows the default data stream (:$DATA) and the hidden stream (hiddenStream).
# Read the content of the hidden stream
Get-Content -Path "C:\path\to\example.txt" -Stream "hiddenStream"
# Output:
# This is hidden malicious content.
By understanding and monitoring ADS, you can enhance your system's security posture against threats that utilize this feature for malicious purposes.