【问题标题】:What does creating a file as "file.ext:file.ext" really do? [closed]将文件创建为“file.ext:file.ext”的真正作用是什么? [关闭]
【发布时间】:2019-09-01 13:09:20
【问题描述】:

我最近开始研究隐写术,并且我在网上找到了一个教程,为了在另一个文件中隐藏一个新的文本文件,教程提供者使用了类似于以下命令的内容:

    notepad.exe file.ext:textfile.txt

我发现命令行中的: 相当奇怪:记事本将此识别为文件的有效索引,并且原始文件(file.ext)现在在磁盘上增加了空间以包含新文本中的数据文件。由于我知之甚少,并且在我的学术生活中很少使用 cmd,我想知道这里发生了什么。这是什么功能?它的预期用途是什么?这是 windows cmd 独有的还是 UNIX 上的等价物?

【问题讨论】:

  • 这是一个文件流。它特定于 NTFS(主要是 Windows)。有关它们是什么以及它们如何工作的详细信息,请参阅docs.microsoft.com/en-us/windows/desktop/fileio/file-streams。这不会将文件隐藏在另一个文件中。它将备用文件流附加到同一文件,但它作为附加文件存储在外部,而不是原始文件中。
  • 键入 Dir /r 以列出流。 15/01/2016 08:07 AM 2,910,631 script56.chm 和第二行 29 script56.chm:Zone.Identifier:$DATA。 Windows Explorer 使用这个实际的流来表示这个文件来自 Internet。
  • 一次,但不再是,cmets 可以将文件作为流存储。但是没有人使用它。记事本也是针对不同 Windows 功能的测试程序。在记事本的文件打开对话框中输入https://www.microsoft.com(你必须正确)。这是记事本测试的文件打开对话框的一项功能。

标签: windows cmd steganography


【解决方案1】:

TL;DR:

您正在查看的是 NTFS 文件系统 (FS) 中文件的备用数据流 (ADS)。

详情:

在较旧的操作系统 (OS) 中,文件系统 (FS) 中的一个条目代表一组数据,这意味着文件只是一个文件。较新的操作系统具有现代 FS,它允许一个条目表示一组或多组数据。在 NTFS 中,这些称为流,而在其他操作系统中,这些通常称为分叉。对于这种解释,这两个术语是同义词。

在今天的 FS 中,每个文件都至少有 1 个流。第一个流没有名称,类型为$DATA。第一个流有时被称为主要的、默认的或匿名的流。除第一个 ADS 之外的所有 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 威胁。

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.

补充阅读:

Miocrosoft - Windows protocols

Winitor - NTFS Alternate Data Streams

Enigma0x3 - Using alternate date streams to persist on a compormised machine

【讨论】:

    猜你喜欢
    • 2011-12-17
    • 2012-11-19
    • 2021-12-26
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    相关资源
    最近更新 更多