Writing Custom Playbooks¶
For CTF challenges and highly structured engagements, relying on the LLM's "intuition" is often insufficient. Playbooks force the AI to follow a rigid, step-by-step methodology.
[!NOTE] The Problem: In a complex Pwn challenge, an AI might try to write a ROP chain before even determining the binary's architecture or checking for stack canaries.
The Solution: Playbooks (
core/ctf/playbooks.py) dictate the exact sequence of analytical steps the AI must take before writing or executing exploits.
1. Anatomy of a Playbook¶
A playbook is a simple Python dictionary mapping a category to a list of sequential instructions.
Open core/ctf/playbooks.py to see the structure:
PLAYBOOKS = {
"pwn": [
"Step 1: Run `file` and `checksec` on the provided binary. Do NOT write any exploit code yet. Wait for Reviewer approval.",
"Step 2: Open the binary in Ghidra and identify the vulnerable function (e.g., gets, strcpy).",
"Step 3: Calculate the exact offset to the instruction pointer.",
"Step 4: Draft the exploit using `pwntools`. Use `run_ctf_solver_command` to test it locally."
],
"forensics": [
"Step 1: Extract the file type using `binwalk` or `exiftool`.",
"Step 2: If it is a PCAP, isolate the HTTP and TCP streams."
]
}
2. Creating a New Playbook¶
If you are participating in a CTF with a unique category (e.g., blockchain or hardware), simply add a new key to the PLAYBOOKS dictionary.
"blockchain": [
"Step 1: Analyze the provided Solidity smart contract for Reentrancy or Integer Overflow.",
"Step 2: Map the state variables and check for improper access control on the `withdraw` function.",
"Step 3: Draft an attacker contract to exploit the vulnerability."
]
3. How the AI Uses Playbooks¶
When you submit a challenge via the CTF Manager:
1. The prompt_engine reads the assigned playbook.
2. It injects "Step 1" into the ctf_specialist prompt.
3. The AI executes Step 1, and the reviewer verifies it.
4. The prompt_engine then feeds the output of Step 1 back to the AI, along with "Step 2".
This State Machine approach guarantees methodical, professional execution.