我最近开始研究隐写术,并且在网上找到了一个教程,在该教程中,为了给另一个文件中隐藏新的文本文件,教程提供者使用了类似于以下命令的内容:
notepad.exe file.ext:textfile.txt
我在命令行中发现:
很奇怪:记事本将其识别为文件的有效索引,并且原始文件(file.ext)现在在磁盘上具有增加的空间来容纳来自文件的数据。新的文本文件。就我所知甚少,在我的学术生活中使用cmd非常吓人,我想知道这里发生了什么。这是什么功能?它的预期用途是什么?这是Windows cmd独有的,还是在UNIX上等效?
答案 0 :(得分:0)
您正在查看的是NTFS文件系统(FS)中文件的备用数据流(ADS)。
在较旧的操作系统(OS)中,文件系统(FS)中的一个条目代表一组数据,这意味着文件只是一个文件。较新的OS具有现代的FS,它允许一个条目代表一组或多组数据。在NTFS中,这些称为流,在其他OS中,这些通常称为fork。为了便于说明,这两个术语是同义词。
在当今的FS中,每个文件将至少具有1个流。第一个流将没有名称,并且将具有$DATA
类型。第一个流有时称为主要流,默认流或匿名流。除第一个以外的所有ADS都将具有名称和类型。默认且最常见的流类型为$DATA
。
流的全名格式为:
<filename>:<stream name>:<stream type>
在Windows中(自您提到notepad.exe
以来一直集中在此),ADS有许多用途。人们与之交互(甚至没有意识到)的最常见的ADS是Zone.Identifier
,它被添加到Internet Explorer和某些其他浏览器下载的文件中。操作系统将这些额外的数据流用作“潜在不安全运行”的标志。同样,MS Office应用程序在打开可能包含恶意宏的文档时将使用相同的流来警告用户。在所有这些情况下,都会警告用户,但不会阻止用户打开危险文件。
dir /r
来自cmd.exe
Streams.exe
来自SysInternals
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声誉不佳。即使到了今天,与ADS相比,许多现代病毒扫描程序仍能够检测来自主流的威胁。 Microsoft Defender,高级威胁防护和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