一个用于自动化红队常见持久性任务的 BOF

作者:Sec-Labs | 发布时间:

项目地址

https://github.com/Crypt0s/PersistBOF

PersistBOF

一个帮助自动化常见持久性机制的工具。目前支持打印监视器(SYSTEM)、时间提供程序(Network Service)、启动文件夹快捷方式劫持(User)、Junction 文件夹(User)和 Xll Add-In(User)。

使用方法

克隆项目,运行 make,将 .cna 文件添加到 Cobalt Strike 客户端。

在 Cobalt Strike 控制台中运行:help persist-ice

语法:

  • persist-ice [PrintMon, TimeProv, Shortcut, Junction, Xll] [persist or clean] [arg1] [arg2];

技术概述

所有这些技术都依赖于将 Dll 文件单独放置在磁盘上。它故意不是 BOF 的一部分。

Xll Add-in

创建一个带有导出函数 xlAutoOpen() 的 Dll。将 .dll 文件重命名为 .xll,并放置在 %appdata%\Microsoft\Addins 目录下。无需通知,每次打开 Excel 时都会加载该插件。在 HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\{版本号}\Excel\Options 写入一个注册表键值,请提供正确的版本号,因为可能存在多个版本。

示例:

  • persist-ice Xll persist XllName.xll 16
  • persist-ice Xll clean XllName.xll 16 > 将删除注册表键值,并尝试删除 Dll。

必须将 Dll 文件放置在磁盘上,并位于 PATH(Dll 搜索顺序)中的某个位置,在运行 BOF 之前。否则将失败。该 Dll 将立即由 spoolsv.exe 以 SYSTEM 身份加载。这可用于从管理员权限提升到 SYSTEM,以及用于持久化。将在系统启动时执行。必须提升权限才能运行。

  • 项目中演示了 Print Monitor Dll

示例:

  1. 将 NotMalware.dll 上传到 C:\Windows\NotMalware.dll
  2. persist-ice PrintMon persist TotesLegitMonitor NotMalware.dll
  3. 以 SYSTEM 身份立即执行
  4. 将在启动时执行,直到被删除
  5. persist-ice PrintMon clean TotesLegitMonitor C:\Windows\NotMalware.dll > 将删除注册表键值并卸载 Dll,然后尝试删除提供的正确路径下的 Dll。应该成功。

Time Provider

在运行 BOF 后,由 svchost.exe 以 NETWORK SERVICE 身份加载,准备好你的土豆!必须提升权限才能运行。

  • 项目中演示了 Time Provider Dll

示例:

  • persist-ice TimeProv persist TotesLegitTimeProvider C:\anywhere\NotMalware.dll
  • persist-ice TimeProv clean TotesLegitTimeProvider C:\anywhere\NotMalware.dll > 将删除注册表键值,并尝试删除提供的正确路径下的 Dll。可能会失败,因为进程没有卸载 Dll。

Junction Folder

与 Vault 7 泄露中演示的技术相同。在用户登录时执行。非提升权限。Dll 将加载到 explorer.exe 中。

注意:这必须是一个 COM 服务器 Dll 才能正常运行。你可以在 DllRegisterServer、DllMain 或 DllGetClassObject 中执行代码,具体取决于你要做什么。确保实现其他所需的导出函数。

示例:

  • persist-ice Juction persist TotesLegitFolder C:\user-writable-folder\NotMalware.dll 保存 CLSID
  • persist-ice Juction clean TotesLegitFolder C:\user-writable-folder\NotMalware.dll 6be5e092-90cc-452d-be83-208029e259e0 > 将删除注册表键值、Junction 文件夹,并尝试删除 Dll。

Start Folder Hijack

创建一个新的、可由用户写入的文件夹,将一个可劫持的 Windows 二进制文件复制到该文件夹中,然后在启动文件夹中创建一个快捷方式。在用户登录时执行。非提升权限。

示例:

  • persist-ice Shortcut persist C:\TotesLegitFolder C:\Windows\System32\Dism.exe > 将你的 Dll 作为代理 Dll 上传到 C:\TotesLegitFolder 中的 dismcore.dll
  • persist-ice Shortcut clean C:\TotesLegitFolder C:\Windows\System32\Dism.exe > 将尝试删除新文件夹中的所有文件,然后删除文件夹本身。如果 Dll 仍然加载在进程中,这将失败。

参考资料

https://stmxcsr.com/persistence/print-monitor.html

https://stmxcsr.com/persistence/time-provider.html

https://pentestlab.blog/2019/10/28/persistence-port-monitors/

https://blog.f-secure.com/hunting-for-junction-folder-persistence/

https://attack.mitre.org/techniques/T1547/010/

https://attack.mitre.org/techniques/T1547/003/

https://attack.mitre.org/techniques/T1547/009/

标签:工具分享, cobaltstrike系列