Leanpub Header

Skip to main content

Adversarial Rust

Build Your Own Pentest Arsenal — In Rust

Adversarial Rust

Most offensive-security books hand you a framework and a flag. This one hands you `cargo new` and a target.

Apex Foundry is a precision-manufacturing company that builds industrial control interfaces, runs a customer-facing web application backed by Postgres, operates an Active Directory domain for its corporate workforce, and recently bolted an AI assistant onto its support portal. It also happens to be running entirely inside your homelab — Docker containers, a virtual AD forest, and a vulnerable web stack you control end to end.

Your job is to break it. Your constraint is that every tool you use must be one you wrote yourself, in Rust.

Over thirteen chapters you will work through a single, continuous penetration test — from passive reconnaissance through data exfiltration and final reporting. Each chapter adds a link to the attack chain: you will build async port scanners, web crawlers, exploit frameworks, a prompt-injection fuzzer, an encrypted implant, Kerberoasting tooling, a covert DNS exfiltration channel, and a report generator that pulls every finding into a finished deliverable. Every tool compiles to a single, dependency-free binary you can drop on a target without a runtime.

Along the way you will capture twenty flags (format: `APEX{...}`) and document **twenty-two findings**, building a portfolio that doubles as a real-world pentest report.

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

Most offensive-security books hand you a framework and a flag. This one hands you `cargo new` and a target.

**Apex Foundry** is a precision-manufacturing company that builds industrial control interfaces, runs a customer-facing web application backed by Postgres, operates an Active Directory domain for its corporate workforce, and recently bolted an AI assistant onto its support portal. It also happens to be running entirely inside your homelab — Docker containers, a virtual AD forest, and a vulnerable web stack you control end to end.

Your job is to break it. Your constraint is that every tool you use must be one you wrote yourself, in Rust.

Over thirteen chapters you will work through a single, continuous penetration test — from passive reconnaissance through data exfiltration and final reporting. Each chapter adds a link to the attack chain: you will build async port scanners, web crawlers, exploit frameworks, a prompt-injection fuzzer, an encrypted implant, Kerberoasting tooling, a covert DNS exfiltration channel, and a report generator that pulls every finding into a finished deliverable. Every tool compiles to a single, dependency-free binary you can drop on a target without a runtime.

Along the way you will capture **twenty flags** (format: `APEX{...}`) and document **twenty-two findings**, building a portfolio that doubles as a real-world pentest report.

### Why Rust?

Python dominates offensive tooling for good reason — it is fast to write, easy to read, and ubiquitous on target machines. But Rust offers something Python cannot:

- **No runtime dependency.** A Rust binary is a single static executable. No interpreter to install, no virtualenv to configure, no `pip install` on a compromised host.

- **Memory safety without garbage collection.** Implants that manage their own memory without a GC pause are harder to fingerprint and more reliable under constrained resources.

- **Performance.** An async port scanner built on Tokio saturates a gigabit link. A fuzzer built on Rust's zero-cost abstractions runs at native speed.

- **Cross-compilation.** `cargo build --target x86_64-unknown-linux-musl` produces a fully static Linux binary from macOS or Windows. `cargo build --target x86_64-pc-windows-gnu` produces a Windows `.exe` from Linux.

- **Growing real-world adoption.** Red teams and malware authors alike are moving to Rust. Understanding Rust-based tooling is no longer optional for defenders — and building it is the fastest way to understand it.

This book does not replace your Python toolkit. It extends it with a language that excels where Python struggles: on-target execution, raw performance, and operational security.

## Who This Book Is For

You should be comfortable with:

- **Rust fundamentals.** You know `struct`, `enum`, `impl`, `trait`, ownership, borrowing, and lifetimes. You have written at least a few programs with `cargo`. This book will not teach the language — it will teach you what to build with it.

- **Networking basics.** TCP/IP, DNS, HTTP, and TLS at a conceptual level. You know what a SYN packet is and what a `301` means.

- **Linux command-line work.** Shell navigation, process management, file permissions. You will live in a terminal.

- **Docker.** You can pull images, run containers, and read a `docker-compose.yml`. The entire lab runs in containers.

Prior penetration-testing experience helps but is not required. Each chapter explains the *why* before the *how*.

## Conventions Used in This Book

Each chapter follows a consistent structure:

| Section | Purpose |

| --- | --- |

| **Briefing** | Sets the operational context — where you are in the engagement and what intelligence you have so far. |

| **Objective** | States the chapter's concrete goal: what you will build and what flag(s) you will capture. |

| **Concepts** | Explains the underlying vulnerability class, protocol, or technique before you write a line of code. |

| **Build** | Walks through the tool's design and implementation in Rust, crate by crate, function by function. |

| **Capture** | Runs the finished tool against the lab range and captures one or more flags. |

| **Debrief** | Reviews what the tool revealed, documents findings, and previews the next chapter's attack vector. |

Code blocks use Markua's language-annotated fences:

{lang="rust"}

```

fn main() {

println!("You are reading a Rust code block.");

}

```

Shell commands appear as:

{lang="bash"}

```

cargo build --release --target x86_64-unknown-linux-musl

```

Flags appear inline when captured and follow the format `APEX{lower_case_l33t}`.

## Engagement Roadmap

| Ch. | Title | Tool Built | Flags |

| --- | --- | --- | --- |

| 0 | Rules of Engagement | Workstation preflight checker | 1 |

| 1 | Building the Range | Range orchestrator (`apex-range`) | 1 |

| 2 | Passive Reconnaissance | DNS enumerator and OSINT dossier builder | 1 |

| 3 | Active Reconnaissance & Scanning | Async TCP scanner and service fingerprinter | 1 |

| 4 | Mapping the Web Attack Surface | Web crawler, content discovery, parameter miner | 3 |

| 5 | Vulnerability Discovery | IDOR/SSRF scanner with triage engine | 2 |

| 6 | Exploitation: The Web Foothold | SQL-injection extractor and foothold shell | 2 |

| 7 | Exploiting the AI Layer | Prompt-injection fuzzer and agent-abuse toolkit | 3 |

| 8 | Post-Exploitation | Encrypted reverse-shell implant and async tasker | 1 |

| 9 | Privilege Escalation | Linux enumerator, SUID exploit, container escape | 2 |

| 10 | Active Directory & Lateral Movement | Kerberoasting client, SMB lateral-movement tool | 2 |

| 11 | Actions on Objectives | Data hunter and DNS exfiltration channel | 1 |

| 12 | Reporting | Findings database, CVSS scorer, report generator | — |

| | | **Total** | **20** |

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 Rust.

*Adversarial Rust* is his second book, following *Adversarial Python*. You can find him collecting badges on cybersecurity training platforms and, occasionally, arguing with the borrow checker.

Contents

Table of Contents

Chapter 0 — Rules of Engagement

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

Static Linux binary (no glibc dependency)

Windows executable from Linux/macOS

Debian/Ubuntu

Fedora

Static Linux binary

Windows binary (from Linux or macOS)

  1. Capture
  2. Debrief

# Chapter 1 — Building the Range

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

range/dns/Corefile

From the project root (where docker-compose.yml lives)

Run the orchestrator

  1. Capture
  2. Debrief

# Chapter 2 — Passive Reconnaissance

  1. Briefing
  2. Objective
  3. Concepts
  4. Build
  5. Capture
  6. Debrief

# Chapter 3 — Active Reconnaissance & Scanning

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

Increase file descriptor limit for aggressive scanning

Full port scan with aggressive settings

  1. Capture
  2. Debrief

# Chapter 4 — Mapping the Web Attack Surface

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

Apex Foundry Application Configuration

  1. Capture

Crawl — catches the HTML comment flag

Content discovery — catches the .env flag

Parameter mining on the API gateway — catches the debug param flag

  1. Debrief

# Chapter 5 — Vulnerability Discovery

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

Simulated user database

  1. Capture

IDOR — enumerate user profiles

SSRF — probe internal services

Or run everything at once

  1. Debrief

# Chapter 6 — Exploitation

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

Add to server.py — vulnerable product search endpoint

  1. Capture

Copy into the target container

Execute it

APEX{f1rst_sh3ll_4p3x}

  1. Debrief

# Chapter 7 — The AI Layer

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

Apex Foundry CNC Maintenance Schedule

  1. Weekly Checks
  2. Monthly Checks
  3. Quarterly Checks

Simulated RAG document store

  1. Capture

Prompt injection — extracts the system prompt

RAG poisoning — injects and triggers malicious document

Agent abuse — tricks the agent into unauthorized actions

Or run everything

  1. Debrief

# Chapter 8 — Post-Exploitation

  1. Briefing
  2. Objective
  3. Concepts
  4. Build
  5. Capture

Terminal 1: Generate key and start the server

Copy the output key

Terminal 2: Cross-compile the implant

Deploy into the target container

Execute on target

  1. Debrief

# Chapter 9 — Privilege Escalation

  1. Briefing
  2. Objective
  3. Concepts
  4. Build
  5. Capture

Deploy into the container

Enumerate

Output (excerpt):

[!] /usr/local/bin/backup-tool (EXPLOITABLE)

Exploitable findings:

[CRITICAL] SUID — Exploitable SUID binary:

/usr/local/bin/backup-tool

Exploit the SUID binary

Output:

[+] /usr/local/bin/backup-tool has SUID bit set

Strategy: PATH hijack for relative commands

uid=0(root) gid=0(root)

[FLAG] APEX{su1d_r00t_pwn3d}

root:$6$…:…

—- Root shell achieved —-

Check for escape vectors

Output:

[*] Container check:

In container: YES

Docker socket: FOUND

[1] Verifying Docker API access…

Docker API accessible

[3] Creating privileged container with host mount…

[5] Waiting for execution…

Escape container output:

apex-host

APEX{c0nt41n3r_3sc4p3}

—- Container escape successful —-

[FLAG] APEX{c0nt41n3r_3sc4p3}

  1. Debrief

# Chapter 10 — Active Directory & Lateral Movement

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

Simulated AD users

  1. Capture

Output:

[+] Bound to ldap://172.28.0.4:389 as CN=j.martinez,…

[!] Kerberoastable: svc_sql (MSSQLSvc/apex-db.apex.local:1433)

[!!] Account has adminCount=1!

[!] Kerberoastable: svc_web (HTTP/apex-web.apex.local)

[*] Requesting TGS for: MSSQLSvc/apex-db.apex.local:1433

[+] Got TGS ticket

[*] Cracking: svc_sql (MSSQLSvc/apex-db.apex.local:1433)

[+] Cracked! svc_sql : Password1

[FLAG] APEX{k3rb3r04st_cr4ck3d}

Output:

[*] Reading \\172.28.0.4\IT-Internal\flag.txt

APEX{l4t3r4l_smb_pwn}

Lateral movement confirmed.

You now have access to the IT-Internal share.

[FLAG] APEX{l4t3r4l_smb_pwn}

  1. Debrief

# Chapter 11 — Actions on Objectives

  1. Briefing
  2. Objective
  3. Concepts
  4. Build

In server.py — add to imports and registration

Apex Foundry Production Configuration

  1. Capture

Apex Foundry Production Configuration

  1. Debrief

# Chapter 12 — Reporting

  1. Briefing
  2. Objective
  3. Concepts
  4. Build
  5. Capture
  6. Debrief

{frontmatter}

Adversarial Rust

  1. Build Your Own Pentest Arsenal — In Rust
  2. About This Book
  3. Who This Book Is For
  4. Conventions Used in This Book
  5. Engagement Roadmap
  6. About the Author

frontmatter.md

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