如果你想了解有关此框架中使用的技术的更多信息,请查看第 1部分和第 2 部分
ScareCrow 是一个有效载荷创建框架,用于侧加载(而不是注入)到合法的 Windows 进程(绕过应用程序白名单控件)。一旦 DLL 加载器加载到内存中,它就会利用一种技术将 EDR 的挂钩从进程内存中运行的系统 DLL 中清除。这是有效的,因为我们知道 EDR 的钩子是在进程生成时放置的。ScareCrow 可以通过使用 API 函数 VirtualProtect 来定位这些 DLL 并在内存中操作它们,该函数将进程的一部分内存权限更改为不同的值,特别是从 Execute-Read 到 Read-Write-Execute。
执行时,ScareCrow 会将存储在磁盘上的系统 DLL 的字节复制到
C:\Windows\System32\. 这些 DLL 存储在磁盘“干净”的 EDR 钩子上,因为系统使用它们在新进程产生时将未更改的副本加载到新进程中。由于 EDR 仅在内存中挂钩这些进程,因此它们保持不变。ScareCrow 不会复制整个 DLL 文件,而是只关注 DLL 的 .text 部分。DLL 的这一部分包含可执行程序集,通过这样做,ScareCrow 有助于降低被检测到的可能性,因为重新读取整个文件可能会导致 EDR 检测到对系统资源进行了修改。然后使用每个函数的偏移量将数据复制到正确的内存区域。每个函数都有一个偏移量,它表示从它们所在的基地址开始的确切字节数,提供函数在堆栈中的位置。为此,ScareCrow 更改了 . 使用 VirtualProtect 的内存文本区域。即使这是一个系统 DLL,因为它已加载到我们的进程中(由我们控制),我们可以更改内存权限而无需提升权限。
一旦这些钩子被移除,ScareCrow 就会利用自定义系统调用在内存中加载和运行 shellcode。即使在 EDR 挂钩被移除后,ScareCrow 也会这样做,以帮助避免被非用户空间、基于挂钩的遥测收集工具(如 Windows 事件跟踪 (ETW) 或其他事件记录机制)检测到。这些自定义系统调用还用于执行 VirtualProtect 调用,以移除 EDR 放置的挂钩,如上所述,以避免被任何 EDR 的防篡改控件检测到。这是通过调用 VirtualProtect 系统调用的自定义版本 NtProtectVirtualMemory 来完成的。ScareCrow 利用 Golang 生成这些加载器,然后为这些自定义系统调用函数进行组装。
ScareCrow 通过首先解密 shellcode 将 shellcode 加载到内存中,shellcode 默认使用带有解密和初始化向量密钥的 AES 加密进行加密。一旦解密并加载,shellcode就会被执行。根据指定的加载器选项,ScareCrow 将为 DLL 设置不同的导出函数。加载的 DLL 也不包含所有 DLL 通常需要操作的标准 DLLmain 函数。DLL 仍然可以毫无问题地执行,因为我们加载到的进程会寻找那些导出函数,而不用担心 DLLMain 是否存在。
在加载器的创建过程中,ScareCrow 利用一个库在信标呼叫回家后混合到背景中。这个库做了两件事:
limelighter创建 pfx12 文件来创建这些证书。该包采用用户指定的输入域名来为该域创建代码签名证书。如果需要,你也可以使用自己的代码签名证书(如果有),使用有效的命令行选项。
有了这些文件和 go 代码,ScareCrow 将使用 c 共享库选项将它们交叉编译成 DLL。一旦 DLL 被编译,它就会被混淆成一个损坏的 base64 字符串,该字符串将被嵌入到一个文件中。这允许远程拉取、访问和以编程方式执行文件。
与往常一样,第一步是克隆 repo。在编译 ScareCrow 之前,你需要安装依赖项。
要安装它们,请运行以下命令:
go get github.com/fatih/color go get github.com/yeka/zip go get github.com/josephspurrier/goversioninfo
确保你的操作系统上安装了以下内容:
openssl osslsigncode mingw-w64
然后构建它
go build ScareCrow.go
./ScareCrow -h _________ _________ / _____/ ____ _____ _______ ____ \_ ___ \_______ ______ _ __ \_____ \_/ ___\\__ \\_ __ \_/ __ \/ \ \/\_ __ \/ _ \ \/ \/ / / \ \___ / __ \| | \/\ ___/\ \____| | \( <_> ) / /_______ /\___ >____ /__| \___ >\______ /|__| \____/ \/\_/ \/ \/ \/ \/ \/ (@Tyl0us) “Fear, you must understand is more than a mere obstacle. Fear is a TEACHER. the first one you ever had.” Usage of ./ScareCrow: -I string Path to the raw 64-bit shellcode. -Loader string Sets the type of process that will sideload the malicious payload: [*] binary - Generates a binary based payload. (This type does not benefit from any sideloading) [*] control - Loads a hidden control applet - the process name would be rundll32 if -O is specified. A JScript loader will be generated. [*] dll - Generates just a DLL file. Can be executed with commands such as rundll32 or regsvr32 with DllRegisterServer, DllGetClassObject as export functions. [*] excel - Loads into a hidden Excel process using a JScript loader. [*] msiexec - Loads into MSIexec process using a JScript loader. [*] wscript - Loads into WScript process using a JScript loader. (default "binary") -O string Name of output file (e.g. loader.js or loader.hta). If Loader is set to dll or binary this option is not required. -configfile string The path to a json based configuration file to generate custom file attributes. This will not use the default ones. -console Only for Binary Payloads - Generates verbose console information when the payload is executed. This will disable the hidden window feature. -delivery string Generates a one-liner command to download and execute the payload remotely: [*] bits - Generates a Bitsadmin one liner command to download, execute and remove the loader (Compatible with Binary, Control, Excel and Wscript Loaders). [*] hta - Generates a blank hta file containing the loader along with a MSHTA command to execute the loader remotely in the background (Compatible with Control and Excel Loaders). [*] macro - Generates an office macro that will download and execute the loader remotely (Compatible with Control, Excel and Wscript Loaders) -domain string The domain name to use for creating a fake code signing cert. (e.g. www.acme.com) -etw Enables ETW patching to prevent ETW events from being generated -injection string Enables Process Injection Mode and specifies the path to the process to create/inject into (use \ for the path). -password string The password for the code signing cert. Required when -valid is used. -sandbox Enables sandbox evasion using IsDomainedJoined calls. -unmodified When enabled will generate a DLL loader that WILL NOT remove the EDR hooks in system DLLs and only use custom syscalls (set to false by default) -url string URL associated with the Delivery option to retrieve the payload. (e.g. https://acme.com/) -valid string The path to a valid code signing cert. Used instead of -domain if a valid code signing cert is desired.
加载器确定将 shellcode 加载到目标系统的技术类型。如果没有选择 Loader 选项,ScareCrow 将只编译标准 DLL 文件,rundll32、regsvr32 或其他利用 DLL 的技术可以使用该文件。ScareCrow 使用三种不同类型的加载器将 shellcode 加载到内存中:
如果需要,ScareCrow 还可以使用
-loader命令行选项生成基于二进制的有效负载。这些二进制文件不会从任何并行加载技术中受益,而是作为根据情况执行 shellcode 的附加技术。
ScareCrow 利用一种技术首先创建流程,然后将其移至后台。这有两件事,首先它有助于保持进程隐藏,其次,避免被任何 EDR 产品检测到。在后台立即生成一个进程可能非常可疑,并且是恶意的指标。ScareCrow 通过在创建进程并加载 EDR 的钩子后调用“GetConsoleWindow”和“ShowWindow”Windows 函数来完成此操作,然后将窗口属性更改为隐藏。ScareCrow 使用这些 API 而不是使用传统 API,
-ldflags -H=windowsgui因为这是高度签名的,并且在大多数安全产品中被归类为妥协指标。
如果选择了
-console命令行选项,ScareCrow 不会在后台隐藏进程。相反,ScareCrow 将添加几个调试消息,显示加载程序正在做什么。
ScareCrow 包含进行进程注入攻击的能力。为了避免在加载程序进程或注入进程本身中发生任何挂钩或检测,ScareCrow 首先像往常一样解除加载程序进程的挂钩,以确保进程中没有挂钩。完成后,加载器将生成创建命令中指定的进程。生成后,加载器将创建进程的句柄以检索加载的 DLL 列表。一旦找到 DLL,它将枚举远程进程中每个 DLL 的基地址。使用函数 WriteProcessMemory,加载程序将写入存储在磁盘上的系统 DLL 的字节(因为它们是“清除”EDR 钩子的),而无需先更改内存权限。ScareCrow 使用 WriteProcessMemory 是因为该函数包含一个主要用于调试的功能,即使一段内存是只读的,如果在调用 WriteProcessMemory 中一切正确,它会暂时更改读写权限,更新内存段然后恢复原来的权限。一旦完成,加载器就可以毫无问题地将 shellcode 注入到生成的进程中,因为在这两个进程中都没有 EDR 钩子。
此选项可与任何加载程序选项一起使用。要启用进程注入,请使用
-injection命令行选项以及要用于注入的进程的完整路径。将路径作为参数放入时,重要的是对路径中的每个目录
""使用 double 或 double包围完整
\路径。
ScareCrow 包含修补 ETW 函数的能力,防止进程生成任何事件。ETW 利用内置的系统调用来生成这种遥测。由于 ETW 是 Windows 内置的本机功能,因此安全产品不需要“挂钩”ETW 系统调用来获取信息。因此,为了防止 ETW,ScareCrow 修补了大量 ETW 系统调用,刷新寄存器并将执行流程返回到下一条指令。使用
-etw命令行选项在你的加载程序中启用它。
交付命令行参数允许你生成命令或代码字符串(在宏情况下)以将文件从远程源远程拉取到受害者主机。这些交付方式包括:
虽然 ScareCrow 有大量的文件属性列表,但在某些情况下需要自定义(可能是特定于环境的)属性集。为了适应这一点,ScareCrow 允许输入包含属性的 JSON 文件。使用
-configfile命令行选项,ScareCrow 将使用这些属性和文件名,而不是 ScareCrow 中预先存在的属性和文件名。该文件
main.json包含 JSON 结构正常工作所需的示例模板。请注意,你用作“内部名称”的任何内容都将是文件名。