Leanpub Header

Skip to main content

Adversarial Nim

Custom Offensive Tooling for the Modern Red Team

Adversarial Nim
This book is 100% completeLast updated on 2026-11-20

Nim compiles to C. That single fact changes everything for a red teamer. While defenders build detection signatures for Python scripts, PowerShell commands, and .NET assemblies, a Nim binary lands on disk looking like any other native executable — small, fast, and unfamiliar to most EDR heuristics. The language gives you Python-like syntax with C-level performance, direct Windows API access without P/Invoke wrappers, cross-compilation from Linux to Windows with one flag, and compile-time metaprogramming that can encrypt strings, encode payloads, and generate polymorphic code before the binary is even built.

Minimum price

$10.99

$14.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

Nim compiles to C. That single fact changes everything for a red teamer. While defenders build detection signatures for Python scripts, PowerShell commands, and .NET assemblies, a Nim binary lands on disk looking like any other native executable — small, fast, and unfamiliar to most EDR heuristics. The language gives you Python-like syntax with C-level performance, direct Windows API access without P/Invoke wrappers, cross-compilation from Linux to Windows with one flag, and compile-time metaprogramming that can encrypt strings, encode payloads, and generate polymorphic code before the binary is even built.

This book teaches offensive tool development through one continuous red team engagement against Nexus Foundry, a fictional defense-adjacent advanced materials research firm. You will build a complete custom toolkit from scratch — reconnaissance utilities, shellcode loaders, process injectors, a C2 implant, defense evasion modules, privilege escalation exploits, lateral movement tools, and covert exfiltration channels. Every tool compiles. Every technique is demonstrated against a realistic lab environment with Active Directory, Windows Defender, Sysmon, and network monitoring. Every finding maps to a professional red team report.

This book assumes you are comfortable with at least one programming language and have a working understanding of Windows internals (processes, threads, memory, the PE format). You do not need prior Nim experience — the book teaches offensive Nim from the ground up.

The Engagement

Client: Nexus Foundry

Type: Red Team Assessment — Full Adversary Simulation

Scope: All Windows and Linux systems within the Nexus Foundry corporate network, including Active Directory, workstations, file servers, and development infrastructure

Methodology: Reconnaissance → Initial Access → Execution → Persistence → Privilege Escalation → Defense Evasion → Lateral Movement → Exfiltration → Reporting

Conventions

Code blocks with `{lang="nim"}` contain Nim source — the core offensive craft. Code blocks with `{lang="bash"}` contain shell commands for compilation, deployment, and lab management. Code blocks with `{lang="python"}` contain supporting Python scripts. Code blocks with `{lang="text"}` contain tool output and log excerpts.

Flags follow the format `NEXUS{...}` and prove each objective was completed. Collect them all.

Disclaimer

The techniques in this book are for authorized red team engagements and educational purposes only. Deploy the included lab environment and practice there. Never test against systems without explicit written authorization. Building offensive tools carries responsibility — use them ethically.

Bundle

Bundles that include this book

Author

About the Author

Andrew Ingram

Andrew Ingram is a cybersecurity professional with years of experience in banking and financial services security. His career has spanned threat analysis, security operations, phishing simulation, and security awareness — the kind of work where you see real attacks hit real infrastructure every day and have to decide, fast, what to do about them.

That day-job exposure to adversary tradecraft is what drives this book. Andrew built every tool in these pages because he wanted to understand exactly what the frameworks were doing under the hood — and because the best way to defend a network is to know how it breaks. When he is not dissecting BEC campaigns or writing detection rules at work, he is standing up lab ranges, chasing flags, and turning offensive techniques into clean, reusable code.

Adversarial Nim is his eighth book. You can find him collecting badges on cybersecurity training platforms and, occasionally, losing arguments with his homelab's DNS.

Contents

Table of Contents

Adversarial Nim

  1. Custom Offensive Tooling for the Modern Red Team
  2. About This Book
  3. The Engagement
  4. Conventions
  5. Disclaimer

Chapter 0: Engagement Brief — Nexus Foundry

  1. Why Nim
  2. Engagement Scope
  3. Network Architecture
  4. Kill Chain Overview
  5. What You Will Build

Chapter 1: Range Deployment

  1. Lab Architecture
  2. Attacker Machine Setup
  3. Domain Controller Setup
  4. Workstation Configuration
  5. Development Server (Docker)
  6. C2 Infrastructure
  7. Network Validation

Chapter 2: Nim for Red Teamers

  1. Language Essentials
  2. Memory Management
  3. Windows API with winim
  4. Compile-Time Metaprogramming
  5. Networking in Nim
  6. Cross-Compilation Recipes
  7. Putting It Together

Chapter 3: Reconnaissance

  1. nexus-scan: Port Scanner
  2. nexus-recon: Active Directory Enumeration
  3. Web Application Reconnaissance
  4. Findings Log

Chapter 4: Payload Crafting

  1. PE Format Fundamentals
  2. Compile-Time Payload Encryption
  3. nexus-craft: The Payload Generator
  4. Building Initial Access Payloads
  5. Compile-Time String Obfuscation in Practice
  6. Polymorphic Stub Generation
  7. Findings Log

Chapter 5: Shellcode Loaders

  1. Loader Architecture
  2. Method 1: VirtualAlloc + CreateThread
  3. Method 2: NtCreateSection + NtMapViewOfSection
  4. Method 3: Callback-Based Execution
  5. Method 4: Fiber-Based Execution
  6. Method 5: APC Injection (Self-Injection)
  7. Method 6: Early Bird APC Injection
  8. Encrypted Shellcode Loader
  9. Loader Method Comparison
  10. Findings Log

Chapter 6: Process Injection

  1. Process Injection Fundamentals
  2. Method 1: Classic Remote Injection
  3. Method 2: DLL Injection
  4. Method 3: Process Hollowing
  5. Method 4: Remote APC Injection
  6. Command-Line Interface
  7. Testing Against the Lab
  8. Injection Method Comparison
  9. Findings Log

Chapter 7: Implant Development

  1. C2 Architecture
  2. Check-In Protocol
  3. Command Execution
  4. Screenshot Capture
  5. Keylogger Module
  6. Sleep Obfuscation
  7. Task Dispatcher
  8. Main Beacon Loop
  9. C2 Server (Listener)
  10. Deploying Against Nexus Foundry
  11. Findings Log

Chapter 8: Defense Evasion

  1. Understanding the Defense Stack
  2. AMSI Bypass
  3. ETW Patching
  4. API Unhooking — Fresh ntdll from Disk
  5. Direct Syscalls
  6. Compile-Time String Encryption Revisited
  7. The nexus-cloak Unified Module
  8. Compilation and Testing
  9. Findings Log

Chapter 9: Privilege Escalation

  1. Token Manipulation
  2. Named Pipe Impersonation
  3. UAC Bypass via fodhelper.exe
  4. Credential Harvesting
  5. nexus-escalate CLI
  6. Deployment Against Nexus Foundry
  7. Findings Log

Chapter 10: Lateral Movement

  1. WMI Remote Execution
  2. SMB Execution (PsExec-style)
  3. WinRM Execution
  4. Pass-the-Hash
  5. nexus-pivot CLI
  6. Attack Execution Against Nexus Foundry
  7. Findings Log

Chapter 11: Persistence and Exfiltration

  1. Registry Run Key Persistence
  2. Scheduled Task Persistence
  3. DLL Search Order Hijacking
  4. DNS Exfiltration
  5. HTTPS Exfiltration
  6. nexus-persist and nexus-exfil CLI
  7. Deployment Against Nexus Foundry
  8. Findings Log

Chapter 12: Reporting — From Shell to Boardroom

  1. Report Structure
  2. Executive Summary
  3. CVSS Scoring
  4. Consolidated Findings Table
  5. Severity Distribution
  6. Attack Narrative
  7. CTF Flag Summary
  8. Remediation Roadmap
  9. Report Generation Script
  10. Closing Notes

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub