med0x2e/ExecuteAssembly
GitHub: med0x2e/ExecuteAssembly
ExecuteAssembly 是一款用 C/C++ 编写的 .NET 程序集内存加载与注入工具,通过 CLR 托管复用和多种 EDR 规避技术实现隐蔽执行。
Stars: 599 | Forks: 113
## 描述:
ExecuteAssembly 是 CS execute-assembly 的替代工具,使用 C/C++ 构建,可用于加载/注入 .NET assemblies;通过重用宿主 (spawnto) 进程加载的 CLR Modules/AppDomainManager,覆写 Loader/.NET assembly PE DOS 头,解除 .NET 相关模块的链接,绕过 ETW+AMSI,通过 NT static syscalls (x64) 避免 EDR hooks,并通过 superfasthash 哈希算法动态解析 API 来隐藏导入表。
## TLDR (功能):
- 从 PEB 数据结构中解除 CLR 相关模块的链接。(使用 MS 的 "ListDLLs" 实用程序而不是 PH 来进行确认)
- .NET Aseembly 和 Reflective DLL 头覆写(MZ bytes, e_lfanew, DOS Header, Rich Text, PE Header)。
- 使用静态硬编码的 syscalls 来绕过 EDR Hooks。(目前仅支持 x64,从 WinXP 到 Win10 19042)
- CLR "AppDomain/AppDomainManager" 枚举和重用 (ICLRMetaHost->EnumerateLoadedRuntimes),只需将 spawnto/宿主进程设置为已知的 Windows .NET 进程即可。
- 使用 API 对应的哈希 通过动态解析 WIN32 APIs (PEB)。
- 在加载 .NET assemblies 之前修补 AMSI 和 ETW。
- .NET assembly 字节解析和扫描,以确定要加载/使用的 CLR 版本。
- 绕过 ETW 时不使用 GetProcAddress/LoadLibrary/GetModuleHandle。
- 使用 v4 COM API 进行 CLR Hosting 和 Reflective DLL 注入
## 用法:
* x64(syscalls): 此版本主要依赖于使用 static syscalls 来绕过 EDR hooks,你可以使用此版本仅构建 DLL 的 x64 版本(目前仅支持 x64)。
* x86|x64(PEB): 在运行时通过遍历 PEB 模块 EAP 表并通过 superfasthash 哈希解析 API 来动态获取所需的 API 地址。但是,它不考虑放置在 kernel32.dll 或 ntdll.dll 上的 EDR hooks,你可以使用此版本同时构建 x86 和 x64 DLL,或者仅构建 x86 DLL 并使用 x64(syscalls) 版本来构建 x64 DLL 以应对常见的 EDR hooks。
* 使用 VS2017 和/或 Windows SDK 10.0.17134.0(或兼容的 SDK 版本)构建所需的 DLL。
* 确保 gzip 已安装,并且将以下文件放置在同一文件夹中,然后只需加载 aggressor 脚本 "ExecuteAssembly.cna":
* ExecuteAssembly.cna
* ExecuteAssembly-x64.dll
* ExecuteAssembly-x86.dll
* CLI 选项:
``--dotnetassembly: 要加载/注入的 .NET Assembly。``
``--assemblyargs: .NET assembly 参数。``
``--unlink-modules: 从 PEB 数据结构中解除 CLR/MsCoree 相关 DLL 等 .NET 相关模块的链接。``
``--stomp-headers: 覆写 .NET assembly 和 reflective DLL PE DOS 头。``
``--etw: 绕过 windows 事件跟踪。``
``--amsi: 绕过 AMSI。``
``--spawnto: 选择 spawnto 进程,执行时默认加载 CLR 的 .NET 二进制文件列表如下:``
``- PresentationHost.exe``
``- stordiag.exe``
``- ScriptRunner.exe``
``- caitstatic.exe``
``- Microsoft.Uev.SyncController.exe``
``- TsWpfWrp.exe``
``- UevAgentPolicyGenerator.exe``
``- UevAppMonitor.exe``
``- FileHistory.exe``
``- UevTemplateBaselineGenerator.exe``
``- UevTemplateConfigItemGenerator.exe``
* 查看 spawnto-list.txt 获取默认加载 CLR 且适合作为 spawnto 设置的额外 MS 二进制文件。(除非是开发者的机器,否则应避免使用已知的 LOLBins) ## 示例: - ``ExecuteAssembly --dotnetassembly /tmp/Seatbelt.exe --assemblyargs LogonSessions --unlink-modules --stomp-headers --amsi --etw --spawnto PresentationHost.exe``
- ``ExecuteAssembly --amsi --etw --unlink-modules --stomp-headers --dotnetassembly /tmp/ghostpack/SharPersist.exe --assemblyargs -t reg -c "C:\Windows\SysWow64\mshta.exe C:\Users\admin\Downloads\Test2.hta" -k logonscript -m add --spawnto FileHistory.exe``
- ``ExecuteAssembly --unlink-modules --stomp-headers --dotnetassembly /tmp/ghostpack/SharPersist.exe --assemblyargs -t reg -k "logonscript" -v "C:\Windows\SysWow64\mshta.exe C:\Users\admin\Downloads\Test.hta" -m remove --spawnto FileHistory.exe``
- ``ExecuteAssembly --unlink-modules --amsi --dotnetassembly /tmp/ghostpack/SharpWMI.exe --assemblyargs action=query computername=localhost query="select * from win32_service" --spawnto FileHistory.exe``
- ``ExecuteAssembly --amsi --etw --dotnetassembly /tmp/ghostpack/SharpWMI.exe --assemblyargs action=query query="select * from win32_process" --spawnto PresentationHost.exe`` ## C2 支持: 主要是在 cobalt strike 上创建和测试的,但是它也可以与其他 C2 框架一起使用 (MSF 等),只需注意 reflective DLL 的 DLLMAIN 需要单行 payload 作为参数,格式如下(不带 "."); * `AMSI_FLAG|ETW_FLAG|STOMPHEADERS_FLAG|UNLINKMODULES_FLAG|LL_FLAG.LENGTH_FLAG.B64_ENCODED_COMPRESSED_PAYLOAD [空格分隔的参数]` * `AMSI_FLAG`: 0|1 (0 或 1) * `ETW_FLAG`: 0|1 * `STOMPHEADERS_FLAG`: 0|1 * `UNLINKMODULES_FLAG`: 0|1 * `LENGTH_FLAG`: 以字节为单位的 .NET assembly 大小 * `LL_FLAG`: length_of(LENGTH_FLAG) (这里请多包涵,或者假装没看到这句) * `B64_ENCODED_COMPRESSED_PAYLOAD`: Gzip 压缩并经过 base64 编码的 .NET assembly。 * `[空格分隔的参数]`: .NET assembly 参数 ## 测试说明: * 使用没有 malleable profiles 的 cobalt strike 4.x 进行了测试。 * 使用以下 malleable profile 的 cobalt strike 4.x 进行了测试(设置了多个内存规避选项 等等); * https://github.com/threatexpress/malleable-c2/blob/master/jquery-c2.4.0.profile ## 待办事项: - RFLL 的替代方案,可能是 BOF + Named Pipes(对于长时间运行的任务不太确定) - static syscalls 的 x86 支持。 - 修复 Bug 并清理我遗漏的任何悬空指针或 mem-leaks :p ## 已知问题: - 对 SharpHound v2 和 v3 的支持(v2 曾经运行得很好,需要弄清楚发生了什么变化)。 - .NET assembly 大小限制 (< 1MB) ## 致谢/参考: * https://github.com/stephenfewer/ReflectiveDLLInjection * https://github.com/jthuraisamy/SysWhispers * https://github.com/etormadiv/HostingCLR * https://github.com/outflanknl/TamperETW/ * https://github.com/LloydLabs/Windows-API-Hashing * http://www.rohitab.com/discuss/topic/42077-module-pebldr-hiding-all-4-methods-x64/ * https://gist.github.com/christophetd/37141ba273b447ff885c323c0a7aff93
``- PresentationHost.exe``
``- stordiag.exe``
``- ScriptRunner.exe``
``- caitstatic.exe``
``- Microsoft.Uev.SyncController.exe``
``- TsWpfWrp.exe``
``- UevAgentPolicyGenerator.exe``
``- UevAppMonitor.exe``
``- FileHistory.exe``
``- UevTemplateBaselineGenerator.exe``
``- UevTemplateConfigItemGenerator.exe``
* 查看 spawnto-list.txt 获取默认加载 CLR 且适合作为 spawnto 设置的额外 MS 二进制文件。(除非是开发者的机器,否则应避免使用已知的 LOLBins) ## 示例: - ``ExecuteAssembly --dotnetassembly /tmp/Seatbelt.exe --assemblyargs LogonSessions --unlink-modules --stomp-headers --amsi --etw --spawnto PresentationHost.exe``
- ``ExecuteAssembly --amsi --etw --unlink-modules --stomp-headers --dotnetassembly /tmp/ghostpack/SharPersist.exe --assemblyargs -t reg -c "C:\Windows\SysWow64\mshta.exe C:\Users\admin\Downloads\Test2.hta" -k logonscript -m add --spawnto FileHistory.exe``
- ``ExecuteAssembly --unlink-modules --stomp-headers --dotnetassembly /tmp/ghostpack/SharPersist.exe --assemblyargs -t reg -k "logonscript" -v "C:\Windows\SysWow64\mshta.exe C:\Users\admin\Downloads\Test.hta" -m remove --spawnto FileHistory.exe``
- ``ExecuteAssembly --unlink-modules --amsi --dotnetassembly /tmp/ghostpack/SharpWMI.exe --assemblyargs action=query computername=localhost query="select * from win32_service" --spawnto FileHistory.exe``
- ``ExecuteAssembly --amsi --etw --dotnetassembly /tmp/ghostpack/SharpWMI.exe --assemblyargs action=query query="select * from win32_process" --spawnto PresentationHost.exe`` ## C2 支持: 主要是在 cobalt strike 上创建和测试的,但是它也可以与其他 C2 框架一起使用 (MSF 等),只需注意 reflective DLL 的 DLLMAIN 需要单行 payload 作为参数,格式如下(不带 "."); * `AMSI_FLAG|ETW_FLAG|STOMPHEADERS_FLAG|UNLINKMODULES_FLAG|LL_FLAG.LENGTH_FLAG.B64_ENCODED_COMPRESSED_PAYLOAD [空格分隔的参数]` * `AMSI_FLAG`: 0|1 (0 或 1) * `ETW_FLAG`: 0|1 * `STOMPHEADERS_FLAG`: 0|1 * `UNLINKMODULES_FLAG`: 0|1 * `LENGTH_FLAG`: 以字节为单位的 .NET assembly 大小 * `LL_FLAG`: length_of(LENGTH_FLAG) (这里请多包涵,或者假装没看到这句) * `B64_ENCODED_COMPRESSED_PAYLOAD`: Gzip 压缩并经过 base64 编码的 .NET assembly。 * `[空格分隔的参数]`: .NET assembly 参数 ## 测试说明: * 使用没有 malleable profiles 的 cobalt strike 4.x 进行了测试。 * 使用以下 malleable profile 的 cobalt strike 4.x 进行了测试(设置了多个内存规避选项 等等); * https://github.com/threatexpress/malleable-c2/blob/master/jquery-c2.4.0.profile ## 待办事项: - RFLL 的替代方案,可能是 BOF + Named Pipes(对于长时间运行的任务不太确定) - static syscalls 的 x86 支持。 - 修复 Bug 并清理我遗漏的任何悬空指针或 mem-leaks :p ## 已知问题: - 对 SharpHound v2 和 v3 的支持(v2 曾经运行得很好,需要弄清楚发生了什么变化)。 - .NET assembly 大小限制 (< 1MB) ## 致谢/参考: * https://github.com/stephenfewer/ReflectiveDLLInjection * https://github.com/jthuraisamy/SysWhispers * https://github.com/etormadiv/HostingCLR * https://github.com/outflanknl/TamperETW/ * https://github.com/LloydLabs/Windows-API-Hashing * http://www.rohitab.com/discuss/topic/42077-module-pebldr-hiding-all-4-methods-x64/ * https://gist.github.com/christophetd/37141ba273b447ff885c323c0a7aff93
标签:C++, SSH蜜罐, UML, 数据擦除, 私有化部署, 端点可见性, 进程注入, 防御规避