Back to Blog

Analyzing NTFS Alternate Data Streams for Malware Persistence

Analyzing NTFS Alternate Data Streams for Malware Persistence

In the landscape of digital forensics and incident response (DFIR), the most dangerous threats are often those that exploit the fundamental architecture of the operating system rather than simple software vulnerabilities. One such architectural feature is the Alternate Data Stream (ADS) within the New Technology File System (NTFS). While designed for legitimate metadata purposes, ADS provides a sophisticated mechanism for attackers to hide malicious payloads, configuration data, and even entire executables in plain sight, bypassing traditional file-based detection methods.

The Architecture of NTFS Streams

To understand how ADS can be weaponized, one must first understand the structure of the NTFS Master File Table (MFT). In NTFS, a file is not merely a blob of data; it is a collection of attributes. The most prominent attribute is `$DATA`, which contains the actual content of the file.

Under normal circumstances, when you create a file, the OS creates an unnamed `$DATA` attribute. This is what you see when you open a file in a text editor. However, NTFS allows for named `$DATA` attributes. These are the Alternate Data Streams. An attacker can attach a named stream to an existing, benign file. Crucially, the primary file size, as reported by standard Windows Explorer or the basic `dir` command, does not change when a named stream is added. The "size" reported is only the size of the unnamed `$DATA` stream.

This discrepancy between the logical file size and the actual disk space consumed is the primary indicator of ADS presence, but it is an indicator that is frequently overlooked by entry-level monitoring tools.

The Malware Lifecycle: Storage and Execution

Malware authors utilize ADS primarily for two purposes: obfuscated storage and indirect execution.

1. Obfuscated Storage

An attacker can "tuck" a malicious payload inside a ubiquitous system file or a user-created document. For example, a large, encrypted ransomware payload can be hidden within a `readme.txt` file.

```powershell

Creating a hidden payload in a text file

echo "Malicious Payload Content" > benign.txt:payload.exe

```

To a casual observer or a basic integrity checker, `benign.txt` appears unchanged in size and content. The malicious data exists in a parallel stream that is invisible to standard file-read operations targeting the default stream.

2. Indirect Execution

The true danger lies in the ability to trigger the execution of these hidden streams. While you cannot directly "double-click" an ADS, Windows provides several legitimate utilities that can be coerced into executing the hidden code.

  • WMIC (Windows Management Instrumentation Command-line): An attacker can use `wmic` to call the hidden stream.

```cmd

sytemprocess call create "C:\path\to\benign.txt:payload.exe"

```

  • Rundll32/Regsvr32: If the hidden stream contains a DLL, these utilities can be used to load the library from the stream.
  • Bitsadmin: The Background Intelligent Transfer Service (BITS) can be leveraged to interact with streams during file transfers.

By combining ADS with common persistence mechanisms-such as a Registry `Run` key or a Scheduled Task-an attacker achieves a highly resilient persistence posture that survives basic file deletions and standard antivirus scans that only inspect the primary `$DATA` stream.

Detection and Forensic Analysis

Detecting ADS requires moving beyond the abstraction layer provided by the Windows API's standard file-reading functions and instead querying the filesystem for all associated streams.

Command-Line Identification

The simplest way to identify streams in a Windows environment is via the `dir /r` command in the Command Prompt. The `/r` flag instructs the OS to display all alternate data streams associated with the files in the directory.

```cmd

C:\Users\Admin> dir /r

...

05/22/2023 10:00 PM 150 benign.txt

05/22/2023 10:00 PM 5420 benign.txt:payload.exe

```

In PowerShell, the `Get-Item` cmdlet provides more granular control. Using the `-Stream` parameter allows an investigator to enumerate every stream attached to a file object.

```powershell

Get-Item -Path .\benign.txt -Stream *

```

Forensic Indicators of Compromise (IoCs)

When performing deep-dive forensics, look for the following:

  1. MFT Discrepancies: Use forensic tools (like Sleuth Kit or EnCase) to examine the MFT entries. Look for `$DATA` attributes with names other than the null string.
  2. Entropy Analysis: Large, high-entropy streams attached to small, low-entropy files (like `.txt` or `.ini`) are a significant red flag, suggesting encrypted or compressed payloads.
  3. Zone.Identifier Anomalies: While the `Zone.Identifier` stream (the "Mark of the Web") is a legitimate ADS used by browsers, an abundance of unexpected named streams in system directories (`C:\Windows\System32`) should trigger immediate investigation.

Operational Considerations and Implementation

For security practitioners, implementing a detection strategy involves a trade-off between performance and visibility.

Implementation Strategies

  • Endpoint Detection and Response (EDR): Modern EDR solutions should be configured to monitor for `CreateFile` operations that utilize the `:` syntax. Monitoring for process creation where the command line contains a colon following a file path is a high-fidelity signal.
  • Automated Scanning: Deploying Sysinternals `Streams.exe` via a central management tool can help identify known malicious patterns across the fleet.
  • File Integrity Monitoring (FIM): FIM solutions must be configured to monitor not just the file itself, but the entire MFT attribute list

Conclusion

As shown across "The Architecture of NTFS Streams", "The Malware Lifecycle: Storage and Execution", "Detection and Forensic Analysis", a secure implementation for analyzing ntfs alternate data streams for malware persistence depends on execution discipline as much as design.

The practical hardening path is to enforce host hardening baselines with tamper-resistant telemetry, behavior-chain detection across process, memory, identity, and network telemetry, and continuous control validation against adversarial test cases. This combination reduces both exploitability and attacker dwell time by forcing failures across multiple independent control layers.

Operational confidence should be measured, not assumed: track time from suspicious execution chain to host containment and mean time to detect, triage, and contain high-risk events, then use those results to tune preventive policy, detection fidelity, and response runbooks on a fixed review cadence.

Related Articles

Explore related cybersecurity topics:

Recommended Next Steps

If this topic is relevant to your organisation, use one of these paths: