S3cur3Th1sSh1t/NimSyscallPacker
GitHub: S3cur3Th1sSh1t/NimSyscallPacker
一个已弃用的红队 payload 打包工具,可将 C#、PE 或 Shellcode 加密封装为 Nim 二进制文件,提供丰富的注入与规避技术。
Stars: 162 | Forks: 29
# NimSyscallPacker / Loader
This tool was made public after a talk at [x33fcon](https://x33fcon.com/#!s/FabianMosch.md). It was my private main coding project from 2021 - 2024 and is now considered deprecated and is not maintained anymore. Dont expect bug fixes or feature updates here from my side. Instead, [RustPack](https://msecops.de/products) is maintained now as a commercial and controlled version for vetted Red Teams and Pentesters which is even more feature rich but also much more OPSec save.
This Packer can be used to pack any C# Assembly, PE-File or Shellcode into a Nim binary. It will encrypt the target payload, build the corresponding Nim source code according to the given arguments and compiles it to an Nim binary.
### Setup
A Video - if you prefer that - can be found here:
[https://youtu.be/0PwIn3Nxmgo](https://youtu.be/0PwIn3Nxmgo)
#### Windows
Git needs to be installed for Nim/Nimble to work properly.
Tested with **Nim 2.2.10** and the **MinGW-w64 GCC 11.1.0** bundle linked from the Nim Windows download page. Newer Nim releases default to a high PE image base on Windows, which breaks `-static` links with `relocation truncated to fit: R_X86_64_32S against .bss`; the packer now forces `-Wl,--image-base=0x10000` to keep static builds working, so any MinGW-w64 11.x build should be fine. Only **x64** is supported here — x86/`--x86`/`--wow64` is not maintained.
1. Download Nim and MinGW (x86_64):
- [`nim-2.2.10_x64.zip`](https://nim-lang.org/download/nim-2.2.10_x64.zip)
- [`mingw64.7z`](https://nim-lang.org/download/mingw64.7z) (linked from the Nim Windows install page)
2. Extract Nim with **7-Zip** (not Windows' built-in `Expand-Archive` — it silently drops `lib\system.nim` because of the case-collision with the `lib\system\` directory). The Nim zip ships `bin\7zG.exe` which you can use to extract MinGW.
3. Add `
\bin` and `\bin` to your `%PATH%`. Logoff/logon (or restart your shell) for the change to take effect.
4. Install nimble dependencies:
nimble install nimcrypto@0.6.0 docopt ptr_math winim https://github.com/S3cur3Th1sSh1t/nim-strenc/
Versions known to work (as of Nim 2.2.10): `nimcrypto 0.6.0`, `docopt 0.7.1`, `ptr_math 0.3.0`, `winim 3.9.4`, `nim-strenc` (HEAD — the repo has no tagged releases).
5. Disable Windows Defender Sample Submission (the Packer refuses to run otherwise):
Set-MpPreference -SubmitSamplesConsent 2
6. Compile the Packer:
nim c NimSyscallLoader.nim
If you want to use the LLVM obfuscator on Windows, use the embedded modified denim version from [denim](https://github.com/S3cur3Th1sSh1t/denim). Install it via `denim\denim.exe setup`.
#### Linux
E.g. on Kali / Debian. The packer historically required `nim 1.6.8` + `mingw-64 8.0.0-1`; with the static-link `--image-base=0x10000` workaround now baked in, newer toolchains should work too. The Windows build is what's actively tested — Linux is best-effort.
apt-get install nim mingw-w64
nimble install nimcrypto@0.6.0 docopt ptr_math winim https://github.com/S3cur3Th1sSh1t/nim-strenc/
If `--hellsgate` fails to assemble on a newer mingw-w64, downgrade to `mingw-64=8.0.0-1`.
Install donut via `pip3 install donut-shellcode`. `denim` cannot be used from Unix so obfuscation via LLVM is not possible here. Same for Callobfuscator.
Compile the Packer via `nim c -d:noRES NimSyscallLoader.nim`. Ready to go. If you don't use -d:noRES you might get the following error:
/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 Setup
Needs to be built once (takes some time the first time, subsequent builds will be cached).
`sudo docker build . -t nimsyscallloader`
Then run the packer with:
`sudo docker run -v $(pwd):/shared nimsyscallloader --output=/shared/packed.exe`
where `$(pwd)` is the directory on the host system that is shared with the container, i.e. the directory where the files to encrypt should be and where the output will be saved to.
#### Third party deps
If you want to make use of Code Signing certificates via LimeLighter you'll also need the following things installed and in your %PATH%:
openssl - (for Windows) for example from [here](https://slproweb.com/products/Win32OpenSSL.html)
osslsigncode - for example from [here](https://github.com/mtrojnar/osslsigncode/releases/tag/2.3)
##### Third party tool support
I will not give Support for issues in the third party tools which are used here. So please open up an issue in the corresponsing repositories if you're facing problems with them. Third party tools in use:
- [Donut](https://github.com/S4ntiagoP/donut/tree/syscalls)
- [Denim](https://github.com/S3cur3Th1sSh1t/denim)
- [LimeLighter](https://github.com/Tylous/Limelighter)
- [Callobfuscator](https://github.com/d35ha/CallObfuscator)
- [NimlineWhispers3](https://github.com/klezVirus/NimlineWhispers3)
- [Koppeling](https://github.com/monoxgas/Koppeling/)
You can either use my precompiled binaries or of course compile them your own from the above links.
### Usage
A Video - if you prefer that - can be found here:
[https://youtu.be/UHaIgdzqHDA](https://youtu.be/UHaIgdzqHDA)
I also added short videos for some features as this was requested:
**Caro-Kann:**
https://youtu.be/etAFZrIyb44
**ThreadlessInject Feature:**
https://youtu.be/eRS-4AywrHI
**Module Stomping Feature:**
https://youtu.be/l-TmqqQ49UI
**shellcodeURL Feature:**
https://youtu.be/OYxcL4D7K0c
**stegoFile Feature:**
https://youtu.be/Vr58_R4rYDA
**shellcodeFile Feature:**
https://youtu.be/Oj55uilxEF4
**Ruy Lopez for local processes**
https://youtu.be/8fBkRo1zlIM
**Shellcode output format**
https://youtu.be/ZTiZA2fg3WM
**Assembly output feature**
https://youtu.be/TDEJ-U18UIk
**And I made a public Video showcasing how to customize ThreadlessInject technique to other processes than the default one:**
https://youtu.be/BYuAUYQcI-E
NimSyscall_Loader v 2.2
Usage:
NimSyscall_Loader [--file=file_to_encrypt --key= --keyfile= --dnsKey --dnsdomain= --environmentalKey= --output=标签:DNS 反向解析, Nim, PE加载器, 知识库安全, 请求拦截, 载荷加密, 逆向工具, 高危端口监控