NTFS Alternate Data Streams
On NTFS a file is not one stream of data, it is several. The content everybody sees lives in the unnamed $DATA stream, but the filesystem lets you hang as many named streams off the same file as you like. The syntax is file:stream, and what sits inside does not show in a dir, does not count towards the file size and is not read by a plain type.
It is a documented NTFS feature, not a bug: Windows uses it for Zone.Identifier, the mark behind the "this file came from the internet" warning. For an attacker it is a hiding place, and for anyone solving a box it is where a flag can sit while dir swears the file is empty.
There are two ways to list them, and the second one needs nothing uploaded:
Get-Item -Path <file> -Stream *
dir /Rdir /R lists every file's streams on their own line under the name, with the stream's size. That is where a 34-byte root.txt:root.txt:$DATA shows up under a 0-byte root.txt.
To read them, type does not take stream paths on many versions; more does, and PowerShell has its own parameter:
more < <file>:<stream>
Get-Content -Path <file> -Stream <stream>And to write one, which is the offensive side:
Set-Content -Path <file> -Stream <stream> -Value '<payload>'An executable hidden in a stream could be launched directly on older Windows versions (start file:stream.exe); on current ones it takes wmic process call create with the full path, or an interpreter willing to read from there.
Requirements. An NTFS filesystem: alternate streams are a feature of it and are lost when copying to FAT32, exFAT or a network share that does not support them. Copying a file with a plain copy takes only the unnamed stream, so a simple move destroys the evidence without anyone noticing.
How to detect it. Sysmon Event ID 15 (FileCreateStreamHash) logs exactly the creation of an alternate stream, and it is the event worth having switched on. In a manual review, a recursive dir /R or Get-ChildItem -Recurse | Get-Item -Stream * over the usual writable directories (%TEMP%, %APPDATA%, user profiles) surfaces what does not belong. A stream named anything other than Zone.Identifier on a document or an executable is anomalous on its own.
Defence. Watch Event ID 15, and on file servers consider fsutil to audit them. Modern antivirus scans alternate streams, but hand-written rules based on the main file's size or hash do not see them, which is precisely what the technique trades on.
It goes hand in hand with credential hunting, because it is one of the places to look when what you are after is on disk and does not show up.
Machines where it's used
- JeevesHackTheBox