我最近开始研究隐写术,我在网上找到了一个教程,为了在另一个文件中隐藏一个新的文本文件,教程提供者使用类似于以下命令的东西:
notepad.exe file.ext:textfile.txt
我发现命令行中的:
相当奇怪:Notepad认为这是文件的有效索引,原始文件(file.ext)现在在磁盘上有更大的空间来包含新文本文件中的数据。据我所知,在我的学术生涯中我很少使用cmd,我想知道这里发生了什么。这有什么特点?它的用途是什么?这是Windows cmd独有的还是在UNIX上有等价的?
您正在查看的是NTFS文件系统(FS)中文件的备用数据流(ADS)。
在较旧的操作系统(OS)中,文件系统(FS)中的一个条目表示一组数据,这意味着文件只是一个文件。较新的操作系统具有现代FS,允许一个条目表示一组或多组数据。在NTFS中,这些被称为流,而在其他操作系统中,这些通常称为分支。对于这个解释,这两个术语是同义词。
在今天的FS中,每个文件至少有一个流。第一个流没有名称,并且将具有$DATA
类型。第一个流有时称为主要,默认或匿名流。超出第一个的所有ADS都将具有名称和类型。默认和最常见的流类型是$DATA
。
流的全名是以下形式:
<filename>:<stream name>:<stream type>
在Windows中(自从你提到notepad.exe
以来一直关注),ADS有很多用途。最常见的ADS人员(甚至没有意识到)进行交互的是Zone.Identifier
,它被添加到Internet Explorer和其他一些浏览器下载的文件中。另外,这个额外的数据流被OS用作“可能不安全运行”的标志。同样,MS Office应用程序将在打开可能包含恶意宏的文档时使用相同的流来提醒用户。在所有这些情况下,都会警告用户,但不会阻止用户打开危险文件。
来自dir /r
的cmd.exe
来自SysInternals的Streams.exe
来自Get-Item
的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。虽然目录没有默认数据流,但它们可以具有命名数据流。
近年来,ADS遭受了一些不良声誉,因为它们被不良行为者使用和滥用来编写隐藏数据,存储病毒并保持持久性。即便在今天,与ADS相比,许多现代病毒扫描程序更能够从主流中检测威胁。 Microsoft Defender,Advanced Threat Protection和SmartScreen可以像从主流一样有效地检测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.
Miocrosoft - Windows protocols
Winitor - NTFS Alternate Data Streams
Enigma0x3 - Using alternate date streams to persist on a compormised machine