Leanpub Header

Skip to main content

Adversarial Bash

Build Your Own Pentest Arsenal — In Bash

Adversarial Bash
This book is 100% completeLast updated on 2026-11-17

Most offensive-security books hand you a framework and a flag. This one hands you a terminal prompt 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 Bash.

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 port scanners with `/dev/tcp`, web crawlers with `curl`, SQL-injection extractors with pipes and string manipulation, a prompt-injection fuzzer with `jq`, a cron-persisted reverse-shell implant, Kerberoasting wrappers, a covert DNS exfiltration channel with `dig`, and a report generator that pulls every finding into a finished deliverable. Every tool is a script you can paste into any Linux terminal with zero dependencies beyond a standard installation.

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 Bash?

Python dominates offensive tooling for good reason — it is powerful, readable, and everywhere. Rust compiles to fast, dependency-free binaries. But Bash offers something neither can:

- It is already on the target. Every Linux host, every container, every cloud instance ships with a POSIX shell. There is nothing to install, nothing to upload, nothing to compile. Your tool is the terminal.

- No forensic footprint. A Bash script leaves no binary on disk, no interpreter to flag, no package manager log. When you pipe commands through a reverse shell, the tool exists only in memory and in process lists.

- Living off the land. `curl`, `dig`, `awk`, `grep`, `find`, `openssl`, `base64`, `xxd`, `sqlite3` — standard utilities that defenders expect to see in log files. Using them for offense is indistinguishable from normal administration.

- Instant iteration. No compile step, no dependency resolution, no virtual environment. Edit, run, observe. The feedback loop is measured in keystrokes.

- Universal skill transfer. Every sysadmin writes Bash. Learning to weaponize it teaches you to defend against the same techniques — because the attacker at the keyboard looks exactly like the admin.

This book does not replace your Python toolkit or your compiled Rust binaries. It extends your capabilities into the space where those tools cannot go — the compromised host where you have a shell and nothing else.

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 a terminal prompt 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 Bash.

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 port scanners with `/dev/tcp`, web crawlers with `curl`, SQL-injection extractors with pipes and string manipulation, a prompt-injection fuzzer with `jq`, a cron-persisted reverse-shell implant, Kerberoasting wrappers, a covert DNS exfiltration channel with `dig`, and a report generator that pulls every finding into a finished deliverable. Every tool is a script you can paste into any Linux terminal with zero dependencies beyond a standard installation.

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 Bash?

Python dominates offensive tooling for good reason — it is powerful, readable, and everywhere. Rust compiles to fast, dependency-free binaries. But Bash offers something neither can:

- It is already on the target. Every Linux host, every container, every cloud instance ships with a POSIX shell. There is nothing to install, nothing to upload, nothing to compile. Your tool *is* the terminal.

- No forensic footprint. A Bash script leaves no binary on disk, no interpreter to flag, no package manager log. When you pipe commands through a reverse shell, the tool exists only in memory and in process lists.

- Living off the land. `curl`, `dig`, `awk`, `grep`, `find`, `openssl`, `base64`, `xxd`, `sqlite3` — standard utilities that defenders expect to see in log files. Using them for offense is indistinguishable from normal administration.

- Instant iteration. No compile step, no dependency resolution, no virtual environment. Edit, run, observe. The feedback loop is measured in keystrokes.

- Universal skill transfer. Every sysadmin writes Bash. Learning to weaponize it teaches you to defend against the same techniques — because the attacker at the keyboard looks exactly like the admin.

This book does not replace your Python toolkit or your compiled Rust binaries. It extends your capabilities into the space where those tools cannot go — the compromised host where you have a shell and nothing else.

Who This Book Is For

You should be comfortable with:

- Bash fundamentals. You know variables, loops, conditionals, functions, pipes, and redirection. You have written at least a few scripts that automate real tasks. This book will not teach the shell — 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, `cron`. 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 Bash, utility by utility, 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="bash"}

```

#!/usr/bin/env bash

echo "You are reading a Bash code block."

```

Shell output appears as:

{lang="text"}

```

[+] Target: apex-web.foundry.local

[+] Open ports: 22, 80, 443, 5432

```

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.sh`) | 1 |

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

| 3 | Active Reconnaissance & Scanning | Bash 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 | Cron-persisted reverse-shell implant and task runner | 1 |

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

| 10 | Active Directory & Lateral Movement | Kerberoasting wrapper, SSH 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 |

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 shell scripts.

Adversarial Bash is his third book, following Adversarial Python and Adversarial Rust. You can find him collecting badges on cybersecurity training platforms and, occasionally, arguing with `set -euo pipefail`.

Contents

Table of Contents

Adversarial Bash

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

Chapter 0: Rules of Engagement

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

Chapter 1: Building the Range

  1. Briefing
  2. Objective
  3. Concepts
  4. Build
  5. Capture
  6. 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
  5. Capture
  6. Debrief

Chapter 4 — Mapping the Web Attack Surface

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

Chapter 5 — Vulnerability Discovery

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

Chapter 6 — Exploitation: The Web Foothold

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

Chapter 7: Exploiting the AI Layer

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

Chapter 8: Post-Exploitation

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

Chapter 9: Privilege Escalation

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

Chapter 10 — Active Directory & Lateral Movement

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

Chapter 11 — Actions on Objectives

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

Chapter 12: Reporting

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

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