TL;DR:
您看到的是 NTFS 文件系统 (FS) 中文件的备用数据流 (ADS)。
Details:
在较旧的操作系统 (OS) 中,文件系统 (FS) 中的一个条目代表一组数据,这意味着文件只是一个文件。较新的操作系统具有现代文件系统,允许一个条目代表一组或多组数据。在 NTFS 中,这些称为流,而在其他操作系统中,这些通常称为分叉。对于这种解释,这两个术语是同义词。
在今天的 FS 中,每个文件至少有 1 个流。第一个流没有名称,并且类型为$DATA
。第一个流有时称为主流、默认流或匿名流。除第一个之外的所有 ADS 都将具有名称和类型。默认且最常见的流类型是$DATA
.
流的全名的形式为:
<filename>:<stream name>:<stream type>
Usage:
在Windows中(自从你提到以来就集中在那里notepad.exe
),ADS 有很多用途。人们最常见的 ADS 交互(甚至没有意识到)是Zone.Identifier
,它会添加到 Internet Explorer 和其他一些浏览器下载的文件中。操作系统使用这个额外的数据流作为“运行可能不安全”的标志。同样,MS Office 应用程序在打开可能包含恶意宏的文档时将使用相同的流来警告用户。在所有这些情况下,用户都会收到警告,但不会阻止他们打开危险文件。
枚举工具(示例,并非详尽无遗):
dir /r
from cmd.exe
Streams.exe
来自系统内部
Get-Item
from powershell.exe
演示:创建、查看、读取、删除
c:\temp> dir /r ads_test*
File Not Found
c:\temp> echo this is normal text>ads_test.txt
c:\temp> dir /r ads_test*
04/11/2019 01:11 AM 21 ads_test.txt
c:\temp> echo this is text for an ADS>ads_test.txt:myHiddenAds
c:\temp> dir /r ads_test*
04/11/2019 01:12 AM 21 ads_test.txt
25 ads_test.txt:myHiddenAds:$DATA
c:\temp> dir ads_test*
04/11/2019 01:12 AM 21 ads_test.txt
c:\temp> more < ads_test.txt
this is normal text
c:\temp> more < ads_test.txt:myHiddenAds
this is text for an ADS
c:\temp> type nul 2>ads_test.txt:myHiddenAds
c:\temp> dir /r ads_test*
04/11/2019 01:20 AM 21 ads_test.txt
0 ads_test.txt:myHiddenAds:$DATA
c:\temp> echo this is yet another ADS>ads_test.txt:CashMeOutside
c:\temp> dir /r ads_test*
04/11/2019 01:24 AM 21 ads_test.txt
25 ads_test.txt:CashMeOutside:$DATA
0 ads_test.txt:myHiddenAds:$DATA
c:\temp> powershell.exe -c "& {get-item -path 'c:\temp\ads_test.txt' -stream * | ft -property FileName,Stream,Length}"
FileName Stream Length
-------- ------ ------
C:\temp\ads_test.txt :$DATA 21
C:\temp\ads_test.txt CashMeOutside 25
C:\temp\ads_test.txt myHiddenAds 0
c:\temp> powershell.exe -c "& {remove-item -path 'c:\temp\ads_test.txt' -stream myHiddenAds}"
c:\temp> powershell.exe -c "& {get-item -path 'c:\temp\ads_test.txt' -stream * | ft -property FileName,Stream,Length}"
FileName Stream Length
-------- ------ ------
C:\temp\ads_test.txt :$DATA 21
C:\temp\ads_test.txt CashMeOutside 25
其他用途:
虽然不常见,但目录也可以有 ADS。对于目录,没有默认的数据流,但有默认的目录流。目录是流类型 $INDEX_ALLOCATION。 $INDEX_ALLOCATION 类型(目录流)的默认流名称是 $I30。尽管目录没有默认数据流,但它们可以具有命名数据流。
Issues:
近年来,ADS 因被不良行为者使用和滥用来写入隐藏数据、存储病毒和保持持久性而名声不佳。即使在今天,与 ADS 相比,许多现代病毒扫描程序也更有能力检测来自主流的威胁。 Microsoft Defender、高级威胁防护和 SmartScreen 可以像检测主流威胁一样高效地检测 ADS 威胁。
Demo2 - 不良行为者如何使用 ADS 的无害示例
C:\temp> echo asdf > \\?\c:\temp\COM1.txt
C:\temp> type c:\windows\system32\calc.exe> \\?\c:\temp\COM1.txt:TotallyNotMalware.exe
C:\temp> wmic process call create "\\?\c:\temp\COM1.txt:TotallyNotMalware.exe"
C:\temp> dir /r
04/11/2019 01:30 AM 21 ads_test.txt
25 ads_test.txt:CashMeOutside:$DATA
04/11/2019 02:45 AM 7 COM1.txt
C:\temp> rem Notice above that the ADS doesn't show - This is because "COM1" is a system reserved name, and many internal and 3rd party programs deal with it wrong.
附加读物:
Microsoft - Windows 协议 https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/b134f29a-6278-4f3f-904f-5e58a713d2c5
Winitor - NTFS 备用数据流 https://winitor.com/pdf/NtfsAlternateDataStreams.pdf
Enigma0x3 - 使用备用数据流在受感染的计算机上保留 https://enigma0x3.net/2015/03/05/using-alternate-data-streams-to-persist-on-a-compromised-machine/