ctf-agent 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,522 +1,532 @@
1
- # CTF-Agent: Autonomous Security Intelligence & Competitive Exploitation Framework
2
-
3
- > **A High-Performance AI Agent Architecture for Live CTF Competitions, Lab Vulnerability Audits, and Security Research.**
4
- > Compatible with **Antigravity IDE**, **Cursor**, **Claude Code**, and **OpenAI Codex/Agent** ecosystems.
5
-
6
- ---
7
-
8
- ## Quick Navigation
9
-
10
- - [CRITICAL: Environment Backend Selection (WSL vs Docker)](#critical-environment-backend-selection-wsl-vs-docker)
11
- - [Operational Modes: Blitz vs Deep Analysis](#operational-modes-blitz-vs-deep-analysis)
12
- - [LLM Safety Guardrails & Policy Compliance](#llm-safety-guardrails--policy-compliance)
13
- - [Machine-Enforced Scope Guard](#machine-enforced-scope-guard-runtime-execution-boundary)
14
- - [Specialized Category Skills](#specialized-category-skills)
15
- - [Parallel Triage & High-Speed Reconnaissance](#parallel-triage--high-speed-reconnaissance-p0-engine)
16
- - [Quick Start & Workspace Installation](#quick-start--workspace-installation)
17
- - [References & Deep Knowledge Base](#references--deep-knowledge-base)
18
- - [Constitution & Architectural Governance](#constitution--architectural-governance)
19
-
20
- ---
21
-
22
- ## CRITICAL: Environment Backend Selection (WSL vs Docker)
23
-
24
- > [!CAUTION]
25
- > ### ANTI-DISK-OVERFLOW RULE (DO NOT INITIALIZE BOTH ENVIRONMENTS!)
26
- > **DO NOT build the Docker container AND install the full WSL toolchain at the same time.**
27
- > Installing full multi-tier CTF tools (compilers, SMT solvers, `sagemath`, `pwntools`, `angr`, `torch`, `volatility3`, `hashcat`) requires **15 to 25 GB of disk space per environment**.
28
- > Initializing **BOTH** will consume **30 to 50 GB+**, risking catastrophic host drive exhaustion and environment conflicts.
29
- >
30
- > **AI Agents & Players MUST detect and choose EXACTLY ONE backend:**
31
-
32
- ```
33
- ┌─────────────────────────────┐
34
- │ Choose ONE Backend Engine │
35
- └──────────────┬──────────────┘
36
-
37
- ┌──────────────────────────────┴──────────────────────────────┐
38
- ▼ ▼
39
- [OPTION A: WSL Kali Linux] [OPTION B: Docker Sandbox]
40
- Best for: Windows Host Development Best for: Linux, macOS, or CI/CD
41
- - Zero VM overhead, fast host I/O - 100% ephemeral and disposable
42
- - Direct file access via /mnt/c/Users/... - Clean host isolation
43
- - Direct GUI/GDB debugging support - Standardized container image
44
- ```
45
-
46
- ### Option A: WSL Kali Linux (Recommended on Windows)
47
- 1. **Verify WSL Kali Availability**:
48
- ```powershell
49
- wsl -d kali-linux uname -a
50
- ```
51
- 2. **Install CTF Toolchain Inside WSL (Select Profiles to Save Disk)**:
52
- ```bash
53
- # Inside WSL or wrapped from PowerShell:
54
- wsl -d kali-linux bash -c "bash scripts/install_ctf_tools.sh core"
55
- # To install specific profiles: pwn, rev, crypto, web, forensics
56
- wsl -d kali-linux bash -c "bash scripts/install_ctf_tools.sh pwn crypto web"
57
- ```
58
- 3. **Execution Wrapper**:
59
- ```powershell
60
- wsl -d kali-linux bash -c "source ~/.ctf-tools/venv/bin/activate && <command>"
61
- ```
62
-
63
- ### Option B: Docker Container Sandbox (Recommended on Linux / macOS / CI)
64
- 1. **Build Container Image**:
65
- ```bash
66
- docker compose build
67
- ```
68
- 2. **Execute Inside Container Sandbox**:
69
- ```bash
70
- docker compose run --rm ctf-agent <command>
71
- ```
72
- 3. **Interactive Shell**:
73
- ```bash
74
- docker compose run --rm ctf-agent /bin/bash
75
- ```
76
-
77
- ---
78
-
79
- ## Operational Profiles & Specialized Modes (Text Flags)
80
-
81
- > [!TIP]
82
- > ### HOW MODES WORK (PROMPT TEXT FLAGS)
83
- > Operational modes (`--fast`, `--blitz`, `--deep`, `--lab`) are **instructional text flags** recognized by the Agent through [AGENTS.md](AGENTS.md).
84
- > **How to use**: Simply write the flags as plain text in your chat prompt or combine them with slash commands (e.g. `/ctf-web --fast <url>` or `/solve-challenge --mode blitz <dir>`).
85
- > *(Note: In Antigravity IDE, typing `@` searches files/symbols in the workspace; modes are passed directly as text flags in your prompt text).*
86
-
87
- `CTF-Agent` provides 3 specialized agent personas designed to eliminate multi-agent refusal cascades and optimize for both speedrun competitions and deep lab audits:
88
-
89
- ```
90
- ┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
91
- │ CTF-AGENT PERSONA MATRIX │
92
- ├──────────────────────────┬───────────────────────────────┬──────────────────────────────────────┤
93
- │ MASTER ORCHESTRATOR │ BLITZ / SPEEDRUN SOLVER │ DEEP RESEARCH AUDITOR │
94
- │ @ctf-controller │ @ctf-speedrun (--blitz) │ @ctf-analyzer (--deep) │
95
- ├──────────────────────────┼───────────────────────────────┼──────────────────────────────────────┤
96
- Role: State Controller Role: First Blood Hunter │ Role: Security Auditor / RCA │
97
- │ Enforces: Shallow depth │ Stop Condition: On Flag HALT │ Stop Condition: Verified Writeup │
98
- Context: SCO & Envelope Documentation: ZERO overheadDocumentation: 5-Section writeup
99
- Refusal: 3-Tier Router Workspace: Auto-purge debris Workspace: Organize resources/
100
- │ Fallback: Deterministic │ Output: Verified Flag Banner │ Output: Authoritative RCA report │
101
- └──────────────────────────┴───────────────────────────────┴──────────────────────────────────────┘
102
- ```
103
-
104
- ### 1. Master Controller (`@ctf-controller` / `/solve-challenge`)
105
- Use as the primary entrypoint for complex multi-step labs or challenges.
106
- - **Prompt Examples**:
107
- - `/solve-challenge http://challenge.ctf.site:8000`
108
- - `/solve-challenge ./challenge_directory`
109
- - **Security Context & Task Envelope**: Wraps target endpoints or local lab files in machine-readable context objects (`security_context`, `task_envelope`) to prevent subagents from evaluating prompts with zero inherited context.
110
- - **Shallow Orchestration (Depth = 1)**: Dispatches directly to a single specialist skill or agent. Prohibits deep recursive agent chaining (`Agent A -> Agent B -> Agent C`).
111
- - **3-Tier Refusal Router**: Automatically classifies model refusals (Type A Wording, Type B Ambiguity, Type C Hard Policy) and shifts execution immediately to deterministic CLI tools without entering infinite paraphrasing loops.
112
-
113
- ### 2. Blitz / Speedrun Mode (`@ctf-speedrun` / `--blitz` / `--fast`)
114
- Use during active CTF competitions where time is points.
115
- - **Prompt Examples**:
116
- - `/ctf-web --fast http://challenge.ctf.site:8080`
117
- - `/solve-challenge --mode blitz ./pwn_challenge`
118
- - `--blitz Solve this crypto puzzle: c = 12345, e = 3, n = 99999`
119
- - **Stop-on-Flag (HALT immediately)**: The instant a valid flag matching target regex (`flag{...}`, `picoCTF{...}`) is confirmed, all tool invocations and probing **stop immediately**.
120
- - **High-Visibility Flag Banner**:
121
- ```text
122
- ============================================================
123
- [+] FLAG ACQUIRED: picoCTF{example_flag_value}
124
- Confidence: 100% | Source: HTTP 200 Response
125
- ============================================================
126
- ```
127
- - **Automated Workspace Cleanup**:
128
- ```bash
129
- python3 scripts/workspace_cleaner.py --fast
130
- ```
131
- Automatically removes temporary scratch files (`test*.py`, `fuzz*.py`, `tmp*`, `core.*`, `payload*.bin`), keeping only the original challenge files and the winning `solve.py`.
132
- - **Zero Overhead**: Does **not** invoke `ctf-writeup` and does **not** create `writeup.md`.
133
-
134
- ### 3. Deep Analysis / Lab Mode (`@ctf-analyzer` / `--deep` / `--lab`)
135
- Use when solving challenge labs (HackTheBox, PortSwigger, pwnable.tw), post-mortems, or security research.
136
- - **Prompt Examples**:
137
- - `/ctf-pwn --deep ./vulnerable_binary`
138
- - `/solve-challenge --mode deep ./web_lab`
139
- - `--lab Perform deep root cause analysis and generate writeup`
140
- - **Root Cause Analysis (RCA)**: Deep analysis of memory corruption layouts, AST flaws, or cryptographic mathematical proofs.
141
- - **Directory Standardization**:
142
- ```bash
143
- python3 scripts/workspace_cleaner.py --deep
144
- ```
145
- Enforces clean lab layout: only `writeup.md`, `solve.py`, and a `resources/` folder containing all challenge binaries, PCAPs, dumps, and source archives.
146
- - **Standardized Writeup**: Automatically invokes `ctf-writeup` to author a publication-ready 5-section `writeup.md`.
147
-
148
- ---
149
-
150
- ## LLM Safety Guardrails & Policy Compliance (Prompt Sanitization & Guardrail Navigation)
151
-
152
- When working on cybersecurity labs (HackTheBox, TryHackMe, PortSwigger) or participating in CTF competitions, user prompts and challenge descriptions often contain aggressive adversarial terminology (`exploit`, `attack`, `bypass policy`, `reverse shell`, `weaponize`...). Modern backend LLM safety classifiers (Gemini, Claude, GPT) can mistakenly flag these requests as unauthorized intrusions and **prematurely halt agent execution mid-lab**.
153
-
154
- `CTF-Agent` integrates an authorized educational framing standard and an automated **Prompt Policy Sanitizer** to eliminate false-positive policy blocks while preserving 100% technical solving capabilities:
155
-
156
- ### 1. How to Apply in Labs & CTF Competitions
157
-
158
- Before submitting complex prompts or challenge descriptions to the Agent, run the sanitizer utility to automatically rewrite the text into safe academic phrasing and attach the authorized educational context preamble:
159
-
160
- ```bash
161
- # Sanitize an input prompt with high-risk keywords:
162
- python scripts/prompt_policy_sanitizer.py "Write an exploit payload to bypass security policy and extract the flag"
163
-
164
- # Sanitize a prompt with specific language support:
165
- python scripts/prompt_policy_sanitizer.py "Write script to bypass filter and capture flag" --lang en
166
-
167
- # Scan and sanitize an entire challenge prompt file or writeup:
168
- python scripts/prompt_policy_sanitizer.py --file path/to/prompt.txt --check
169
- ```
170
-
171
- ### 2. Automated Sanitization Mechanism
172
-
173
- - **Risk Scoring**: Assesses policy risk from `SAFE` (0) to `CRITICAL` (100) across 5 high-risk trigger families (Evasion, Redteam, Exploit, Payload, Exfiltration).
174
- - **Academic Lexicon Standard**: Automatically replaces adversarial attack jargon with defensive and diagnostic testing equivalents:
175
- - *exploit vulnerability* -> *verify vulnerability with proof-of-concept (PoC)*
176
- - *bypass policy* -> *evaluate mitigation boundaries*
177
- - *steal credentials / exfiltrate* -> *retrieve challenge flag token*
178
- - *redteam attack* -> *diagnostic security assessment*
179
- - **Educational CTF Context Preamble**: Injects explicit authorized testing boundaries (`localhost`, Docker, designated CTF target) to satisfy upstream safety filters.
180
- - **Path & Link Preservation**: Automatically preserves markdown links `[text](target.md)` and URLs without unwanted corruption.
181
-
182
- For comprehensive guidelines and full replacement dictionaries, see [ctf-safety-framing-rules.md](rules/ctf-safety-framing-rules.md) and [llm-safety-and-policy-compliance.md](references/llm-safety-and-policy-compliance.md).
183
-
184
- ### 3. Machine-Enforced Scope Guard (Runtime Execution Boundary)
185
-
186
- While the Prompt Policy Sanitizer protects prompts from semantic upstream LLM filter rejections, the **Scope Guard** ([scripts/scope_guard.py](scripts/scope_guard.py)) converts the Security Context Object (SCO) and Task Envelope into an active, machine-enforced runtime execution fence.
187
-
188
- - **Network Boundary Validation**: Only authorized CTF targets are permitted:
189
- - Local loopback: `127.0.0.1`, `localhost`, `::1`
190
- - RFC1918 private subnets: `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`
191
- - Authorized CTF domains & competition platforms: `*.challs.io`, `*.picoctf.net`, `*.ctfd.io`, `*.tryhackme.com`, `*.hackthebox.com`, `*.flagyard.com`, and localhost ports.
192
- - Arbitrary external IP addresses and unauthorized internet endpoints are rejected with explicit policy violations.
193
- - **Prohibited Action Guard**: Automatically intercepts and blocks commands containing:
194
- - Destructive disk actions (`rm -rf /`, `mkfs`, `dd if=/dev/zero`)
195
- - Backdoor persistence mechanisms (`crontab`, systemd services, SSH key installation in `~/.ssh/authorized_keys`, root password modification)
196
- - Wide automated network sweeps (`nmap -iR`, masscan against external CIDR blocks)
197
- - **Runtime Execution**:
198
- ```bash
199
- # Validate a target endpoint before probing:
200
- python scripts/scope_guard.py http://127.0.0.1:8080
201
-
202
- # Validate a diagnostic CLI command before running:
203
- python scripts/scope_guard.py --command "checksec --file=chall"
204
-
205
- # Generate a formal Security Context Object (SCO):
206
- python scripts/scope_guard.py --target http://chall.ctf.site:9000 --json
207
- ```
208
-
209
- ---
210
-
211
- ## Specialized Category Skills
212
-
213
- `CTF-Agent` equips models with 11 domain-specific skills accessible via slash commands or subagent delegation:
214
-
215
- | Skill | Description | Key Capabilities |
216
- |:---|:---|:---|
217
- | [`solve-challenge`](skills/solve-challenge/SKILL.md) | **Master Dispatcher & Orchestrator** | Hint-First triage, category routing, mode branching (Blitz vs Deep). |
218
- | [`ctf-web`](skills/ctf-web/SKILL.md) | **Web Vulnerability Assessment** | SQLi, SSTI, JWT verification, prototype pollution, RSC Flight RCE, SSRF. |
219
- | [`ctf-pwn`](skills/ctf-pwn/SKILL.md) | **Binary Security Analysis** | Glibc heap (House of Apple 2, TLS dtors), ROP, ret2libc, boundary testing. |
220
- | [`ctf-crypto`](skills/ctf-crypto/SKILL.md) | **Cryptanalysis & Math** | RSA, ECC, LLL/BKZ lattice reduction, HNP/CVP, padding oracle, ZKP. |
221
- | [`ctf-reverse`](skills/ctf-reverse/SKILL.md) | **Reverse Engineering** | Anti-analysis, custom VMs, WASM, `.pyc` (`pycdc`), Ghidra/radare2/GDB. |
222
- | [`ctf-forensics`](skills/ctf-forensics/SKILL.md) | **Digital Forensics** | Memory dumps (Volatility 3), PCAP analysis, disk recovery, steganography. |
223
- | [`ctf-ai-ml`](skills/ctf-ai-ml/SKILL.md) | **AI & Machine Learning** | Adversarial ML, model robustness, extraction evaluation, AI puzzle triage. |
224
- | [`ctf-osint`](skills/ctf-osint/SKILL.md) | **Open Source Intelligence** | Geolocation, social media tracking, Tor relay tracing, DNS footprinting. |
225
- | [`ctf-misc`](skills/ctf-misc/SKILL.md) | **Miscellaneous & Jails** | PyJails, bash jails, esoteric encodings, RF/SDR signals, game reversing. |
226
- | [`ctf-malware`](skills/ctf-malware/SKILL.md) | **Malware Analysis** | C2 protocol decoding, PE/.NET unpackers, obfuscated script analysis. |
227
- | [`ctf-writeup`](skills/ctf-writeup/SKILL.md) | **Write-up Generator** | Standardized 5-section submission writeup and directory organizer. |
228
-
229
- ### Custom Skill Extension & Envelope Validation
230
-
231
- When adding external or custom CTF skills into `.agents/skills/`, run the built-in validator ([scripts/skill_validator.py](scripts/skill_validator.py)) to ensure prompt envelope compatibility and prevent model policy rejections:
232
-
233
- ```bash
234
- # Validate a specific custom skill:
235
- ctf-agent validate-skill .agents/skills/my-custom-skill
236
-
237
- # Audit all skills in the workspace:
238
- ctf-agent validate-skill --all
239
-
240
- # Via NPX:
241
- npx ctf-agent validate-skill .agents/skills/my-custom-skill
242
- ```
243
-
244
- **Compatibility Rules Checked**:
245
- - **Shallow Orchestration (Depth <= 1)**: Verifies the skill operates as a direct specialist without recursive subagent chaining.
246
- - **YAML Frontmatter Integrity**: Verifies `name`, `description` (>= 20 chars), and checks against collisions with reserved core skills.
247
- - **Operational Mode Handling**: Checks for Blitz Mode (Stop-on-Flag) and Deep Mode (RCA / writeup).
248
- - **LLM Safety Policy Lexicon**: Flags unshielded adversarial triggers (`evil_payload`, `jailbreak`, `weaponize`) and recommends academic diagnostic equivalents.
249
- - **Command Boundary Guard**: Intercepts destructive host commands (`rm -rf /`, `mkfs`) and backdoor persistence attempts (`crontab`, `authorized_keys`).
250
-
251
- ---
252
-
253
- ## Parallel Triage & High-Speed Reconnaissance (P0 Engine)
254
-
255
- To maximize Time-to-Flag during live CTF competitions, `CTF-Agent` integrates a high-speed parallel reconnaissance scheduler ([scripts/parallel_triage.py](scripts/parallel_triage.py)) that executes Tier 1 and Tier 2 diagnostics concurrently:
256
-
257
- ```
258
- ┌────────────────────────────────┐
259
- │ Target Challenge Diagnostic │
260
- └───────────────┬────────────────┘
261
-
262
- ┌───────────────────────────────┴───────────────────────────────┐
263
- ▼ ▼
264
- [Binary / ELF Target] [Web / HTTP Target]
265
- ThreadPoolExecutor Concurrency ThreadPoolExecutor Concurrency
266
- - Pure-Python ELF Parser (Arch, Endian, NX, PIE) - HTTP Server & Powered-By Headers
267
- - checksec security mitigations - /robots.txt & /sitemap.xml leaks
268
- - strings pattern match (flags, /bin/sh, libc) - Sensitive paths (.git/HEAD, .env)
269
- - readelf / symbol table analysis - Flag regex candidate pre-scan
270
- │ │
271
- └───────────────────────────────┬───────────────────────────────┘
272
-
273
- ┌────────────────────────────────┐
274
- │ Synthesized Triage Plan │
275
- - Discovered Vulnerabilities
276
- │ - Recommended Specialist │
277
- │ - Immediate Exploit Vector │
278
- └────────────────────────────────┘
279
- ```
280
-
281
- - **Zero-Dependency Native ELF Parser**: Reads ELF binary headers using pure Python standard library (`struct`), extracting machine architecture, bitness, endianness, entry point, section counts, NX stack protection, and PIE position independence without requiring external tools.
282
- - **Concurrent Execution Modes**:
283
- ```bash
284
- # Concurrent triage of a binary challenge:
285
- python scripts/parallel_triage.py ./chall.bin
286
-
287
- # Concurrent triage of a web challenge:
288
- python scripts/parallel_triage.py http://127.0.0.1:8080
289
-
290
- # Machine-readable output for automated agent pipelines:
291
- python scripts/parallel_triage.py ./chall.bin --json
292
- ```
293
-
294
- ---
295
-
296
- ## Quick Start & Workspace Installation
297
-
298
- ### Method 0: Intelligent Workspace Initialization (Triple-Engine Architecture)
299
-
300
- ```
301
- ┌─────────────────────────────────────────┐
302
- │ User Workspace Initialization │
303
- └────────────────────┬────────────────────┘
304
-
305
- ┌────────────────────────────────┼────────────────────────────────┐
306
- ▼ ▼ ▼
307
- [1. Web & JS Ecosystem] [2. Python Workstation] [3. Modern UV Toolchain]
308
- npx ctf-agent init python scripts/ctf_init.py uvx ctf-agent init
309
- │ │
310
- └────────────────────────────────┼────────────────────────────────┘
311
-
312
- ┌─────────────────────────────────────────┐
313
- │ Step 1: Preflight Detection │
314
- - OS, CPU, RAM & Disk Storage Free
315
- │ - WSL2 & Kali Linux Distro Status │
316
- │ - Docker CLI & Daemon Connectivity │
317
- │ - Check for Existing .agents/ Folder │
318
- └────────────────────┬────────────────────┘
319
-
320
-
321
- ┌─────────────────────────────────────────┐
322
- Step 2: Backend Capability Score
323
- │ WSL Kali Score vs Docker Daemon Score │
324
- (Objective transparent recommendation)│
325
- └────────────────────┬────────────────────┘
326
-
327
-
328
- ┌─────────────────────────────────────────┐
329
- Step 3: Workload Purpose Selection
330
- │ [1] Live CTF: core, pwn, web, crypto │
331
- [2] Security Lab: 10 deep profiles │
332
- │ [3] Rev & Binary: pwn, rev, kernel │
333
- │ [4] Full Workstation: all 15 profiles │
334
- └────────────────────┬────────────────────┘
335
-
336
-
337
- ┌─────────────────────────────────────────┐
338
- Step 4: Provision & Conflict Guard
339
- │ - If .agents exists: Prompt / Confirm │
340
- - Deploy .agents/ & AGENTS.md config │
341
- │ - Preserve solve.py & resources/ │
342
- │ - Provision Toolchain into Backend │
343
- └────────────────────┬────────────────────┘
344
-
345
-
346
- ┌─────────────────────────────────────────┐
347
- Step 5: Health Verification
348
- │ Verify subagents, venv & CLI tools │
349
- [OK] WORKSPACE READY TO SOLVE! │
350
- └─────────────────────────────────────────┘
351
- ```
352
-
353
- CTF-Agent provides three interchangeable execution engines tailored to different developer workflows:
354
-
355
- #### 1. Web & JavaScript Ecosystem (`npx`)
356
- Zero-clone setup for developers accustomed to npm and modern web toolchains:
357
- ```bash
358
- # Initialize via NPX directly from GitHub (zero-clone):
359
- npx github:nvtruongops/CTF-Agent init
360
-
361
- # Target a specific challenge workspace:
362
- npx github:nvtruongops/CTF-Agent init /path/to/ctf-workspace
363
-
364
- # Run preflight inspection in dry-run mode:
365
- npx github:nvtruongops/CTF-Agent init --dry-run
366
-
367
- # Or install locally for direct 'ctf-agent' command:
368
- npm link # run inside cloned repo once
369
- ctf-agent init
370
- ```
371
-
372
- #### 2. Native Python Security Workstation (`ctf-agent` / `ctf_agent_cli.py`)
373
- Pure standard library execution with zero external third-party dependencies:
374
- ```bash
375
- # Recommended: Install CLI entrypoint once (available everywhere):
376
- pip install -e . # run inside cloned repo once
377
- ctf-agent init /path/to/ctf-workspace
378
-
379
- # Or execute directly from cloned repository root:
380
- python ctf_agent_cli.py init /path/to/ctf-workspace
381
-
382
- # Automated unattended setup (auto-selects highest-scored backend and purpose):
383
- ctf-agent init /path/to/ctf-workspace --auto --purpose live-ctf
384
-
385
- # Preflight analysis and dry-run inspection (zero filesystem writes):
386
- ctf-agent init --dry-run
387
-
388
- # Health check verification on an existing workspace:
389
- ctf-agent init /path/to/ctf-workspace --check-only
390
- ```
391
-
392
- #### 3. Modern Python Toolchain (`uvx`)
393
- Ultra-fast ephemeral execution powered by the Rust-based `uv` package manager:
394
- ```bash
395
- # Execute directly from repository source without installation:
396
- uvx --from git+https://github.com/nvtruongops/CTF-Agent ctf-agent init
397
-
398
- # Target a specific workspace:
399
- uvx --from git+https://github.com/nvtruongops/CTF-Agent ctf-agent init /path/to/ctf-workspace
400
-
401
- # Automated speedrun profile:
402
- uvx --from git+https://github.com/nvtruongops/CTF-Agent ctf-agent init --auto --purpose live-ctf
403
- ```
404
-
405
- ---
406
-
407
- ### Workspace & Skill Updates (`ctf-agent update`)
408
-
409
- Keep deployed CTF workspaces up to date with new skills, agent personas, rules, and security references without losing custom modifications or challenge files:
410
-
411
- ```bash
412
- # Update current workspace via CLI (if installed):
413
- ctf-agent update
414
-
415
- # Or via NPX directly from GitHub:
416
- npx github:nvtruongops/CTF-Agent update /path/to/ctf-workspace
417
-
418
- # Modern toolchain (uvx):
419
- uvx --from git+https://github.com/nvtruongops/CTF-Agent ctf-agent update /path/to/ctf-workspace
420
-
421
- # Native Python from cloned repo root:
422
- python ctf_agent_cli.py update /path/to/ctf-workspace
423
-
424
- # Preview planned skill & rule updates without writing changes:
425
- npx ctf-agent update --dry-run
426
-
427
- # Only synchronize skills (preserve rules, agents, and scripts):
428
- npx ctf-agent update --skills-only
429
-
430
- # Update global configuration (~/.gemini/config/):
431
- python scripts/ctf_update.py --global
432
- ```
433
-
434
- **Zero Data Loss Guarantees**:
435
- - **Conflict Guard**: Inspects SHA-256 hashes against `skills-lock.json`. If you made local modifications to a skill, it creates a safe backup (`SKILL.md.bak`) before updating.
436
- - **Custom Skills & Non-Skill Directory Preservation**: Custom skills in `.agents/skills/`, custom subagents in `.agents/agents/`, custom rules in `.agents/rules/`, and custom scripts in `.agents/scripts/` that are not part of upstream CTF-Agent are preserved completely untouched without wholesale directory wipes.
437
- - **Automated Backups for Modified Support Files**: Any modified upstream files in `.agents/rules/`, `.agents/agents/`, `.agents/references/`, or `scripts/` receive `.bak` backup files prior to update.
438
- - **Challenge Assets Protected**: Exploit scripts (`solve.py`), challenge binaries (`resources/`), CTF notes (`notes/`), and credentials (`.env`) are never overwritten or deleted.
439
-
440
- ---
441
-
442
- ### Method 1: Deploy CTF-Agent into a CTF Challenge Project (`.agents/`)
443
- Deploy CTF-Agent as an `.agents` bundle into any target CTF directory:
444
- ```bash
445
- # Using symlinks/junctions (live synced with updates):
446
- python scripts/install_as_agent.py /path/to/ctf-workspace --symlink
447
-
448
- # Or standalone copy:
449
- python scripts/install_as_agent.py /path/to/ctf-workspace
450
- ```
451
-
452
- ### Method 2: Global Installation Across All Projects
453
- Install skills, rules, and subagents globally into `~/.gemini/config/`:
454
- ```bash
455
- python scripts/install_as_agent.py --global
456
- ```
457
-
458
- ### Method 3: Direct Usage Within This Workspace
459
- This workspace already has `.agents/` configured. You can start prompting directly using slash commands and text flags:
460
- - **Master Orchestrator**: `/solve-challenge <target-url-or-dir>`
461
- - **Speedrun / Blitz Mode (Fast Solve, Stop-on-Flag)**: `/solve-challenge --mode blitz <target>` or `/ctf-web --fast <target>` or `--blitz <prompt>`
462
- - **Deep Analysis Mode (RCA & Writeup)**: `/solve-challenge --mode deep <target>` or `/ctf-pwn --deep <target>` or `--lab <prompt>`
463
- - **Specific Category Skills**: `/ctf-web`, `/ctf-pwn`, `/ctf-crypto`, `/ctf-reverse`, `/ctf-forensics`, `/ctf-osint`, `/ctf-misc`, `/ctf-ai-ml`, `/ctf-malware`, `/ctf-writeup`
464
-
465
- ---
466
-
467
- ## Automated Automation Utilities
468
-
469
- Located in [scripts/](scripts/):
470
-
471
- - **`parallel_triage.py`**:
472
- - `python3 scripts/parallel_triage.py <target-binary-or-url>`: Executes high-speed concurrent Tier 1 & 2 diagnostics (pure Python ELF parsing, checksec, strings, headers, robots.txt, sitemap.xml, sensitive leak probes) via ThreadPoolExecutor.
473
- - `python3 scripts/parallel_triage.py <target> --json`: Emits machine-readable diagnostic synthesis with recommended specialist category skills.
474
- - **`scope_guard.py`**:
475
- - `python3 scripts/scope_guard.py <target-or-command>`: Machine-enforces authorized testing boundaries (RFC1918 subnets, loopback, CTF platform domains) and blocks destructive commands or root persistence attempts.
476
- - `python3 scripts/scope_guard.py --target <url> --json`: Generates a formal Security Context Object (SCO) for multi-agent dispatch.
477
- - **`skill_validator.py`**:
478
- - `python3 scripts/skill_validator.py <path-to-skill>`: Validates external custom skills against YAML frontmatter schemas, shallow orchestration constraints (depth <= 1), mode awareness, policy lexicon, and prohibited commands.
479
- - `python3 scripts/skill_validator.py --all --json`: Scans all skills across `.agents/skills/` and returns structured JSON reports for CI/CD or agent pipelines.
480
- - **`prompt_policy_sanitizer.py`**:
481
- - `python3 scripts/prompt_policy_sanitizer.py "<prompt>" --lang [vi|en]`: Scans, scores policy risk, and sanitizes prompts with academic terminology and educational CTF preambles.
482
- - `python3 scripts/prompt_policy_sanitizer.py --file <path> --check`: Verifies that challenge writeups, prompts, or scripts do not trigger modern LLM backend filters.
483
- - **`workspace_cleaner.py`**:
484
- - `python3 scripts/workspace_cleaner.py --fast`: Purges scratch files (`test*.py`, `fuzz*.py`, `tmp*`), keeping challenge assets and winning `solve.py`.
485
- - `python3 scripts/workspace_cleaner.py --deep`: Enforces `writeup.md`, `solve.py`, and `resources/` folder structure.
486
- - **`extract_flags.py`**:
487
- - `python3 scripts/extract_flags.py "<output>" --banner`: Prints high-visibility flag banner and verifies candidate regex.
488
- - `python3 scripts/extract_flags.py -f output.log --json`: Emits machine-readable JSON candidate rankings.
489
- - **`ctfd_client.py`**:
490
- - Python API client for automated challenge retrieval, attachment downloading, and flag submission.
491
- - **`cve_lookup.py`**:
492
- - Automated CVE advisory and exploit lookup utility via Sploitus and Exploit-DB.
493
-
494
- ---
495
-
496
- ## References & Deep Knowledge Base
497
-
498
- Detailed references offloaded to [references/](references/) to preserve maximum context window tokens during agent turns:
499
- - [multi-agent-orchestration-and-policy-routing.md](references/multi-agent-orchestration-and-policy-routing.md) — Comprehensive guide on Security Context Objects, Task Envelopes, shallow orchestration, and the 3-Tier Refusal Router.
500
- - [llm-safety-and-policy-compliance.md](references/llm-safety-and-policy-compliance.md) Comprehensive guide on modern LLM safety filter architecture, trigger dictionary (EN/VI), and safe prompt engineering.
501
- - [ctf-triage-ladder.md](references/ctf-triage-ladder.md) — Hierarchical 4-Tier progression (Tier 1 plaintext to Tier 4 in-meta).
502
- - [version-matrix.md](references/version-matrix.md) Glibc heap, PHP type juggling, and Python bytecode compatibility matrix.
503
- - [exploit-databases.md](references/exploit-databases.md) — Exploit databases, CVE search, and GitHub PoC repositories.
504
- - [security-events-and-intelligence.md](references/security-events-and-intelligence.md) — CTFtime intelligence and event key extraction techniques.
505
-
506
- ---
507
-
508
- ## Constitution & Architectural Governance
509
-
510
- The rules governing all CTF-Agent behavior are defined in [AGENTS.md](AGENTS.md):
511
- 1. **Hint-First Rule**: Analyze metadata and hints before touching code or tools.
512
- 2. **Operational Mode Compliance**: Strictly follow Blitz or Deep Analysis protocols.
513
- 3. **Execution Guard**: Never modify original challenge files; wrap Linux binaries through WSL/Docker; enforce 60s command timeouts.
514
- 4. **Flag Anti-Hallucination**: 100% verified flag strings directly from runtime output.
515
- 5. **LLM Safety & Policy Compliance**: Enforce authorized educational sandbox scope and use academic diagnostic terminology per [ctf-safety-framing-rules.md](rules/ctf-safety-framing-rules.md).
516
- 6. **Context Propagation & Task Envelopes**: Propagate machine-readable Security Context Objects and enforce shallow execution depth (max depth: 1).
517
- 7. **Refusal Router & Deterministic Tool Fallback**: Enforce 3-tier refusal classification; never enter infinite paraphrasing loops on hard refusals, falling back directly to deterministic CLI tools.
518
-
519
- ---
520
-
521
- ### License & Attribution
522
- Distributed under the MIT License. Designed for authorized security research, academic labs, and ethical CTF competitions.
1
+ # CTF-Agent: Autonomous Security Intelligence & Competitive Exploitation Framework
2
+
3
+ [![npm version](https://img.shields.io/npm/v/ctf-agent.svg)](https://www.npmjs.com/package/ctf-agent)
4
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
5
+ [![Docker Image](https://img.shields.io/badge/docker-ghcr.io%2Fnvtruongops%2Fctf--agent-blue.svg)](https://github.com/nvtruongops/CTF-Agent/pkgs/container/ctf-agent)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
7
+
8
+ > **A High-Performance AI Agent Architecture for Live CTF Competitions, Lab Vulnerability Audits, and Security Research.**
9
+ > Compatible with **Antigravity IDE**, **Cursor**, **Claude Code**, and **OpenAI Codex/Agent** ecosystems.
10
+
11
+ ---
12
+
13
+ ## Quick Navigation
14
+
15
+ - [CRITICAL: Environment Backend Selection (WSL vs Docker)](#critical-environment-backend-selection-wsl-vs-docker)
16
+ - [Operational Modes: Blitz vs Deep Analysis](#operational-modes-blitz-vs-deep-analysis)
17
+ - [LLM Safety Guardrails & Policy Compliance](#llm-safety-guardrails--policy-compliance)
18
+ - [Machine-Enforced Scope Guard](#machine-enforced-scope-guard-runtime-execution-boundary)
19
+ - [Specialized Category Skills](#specialized-category-skills)
20
+ - [Parallel Triage & High-Speed Reconnaissance](#parallel-triage--high-speed-reconnaissance-p0-engine)
21
+ - [Quick Start & Workspace Installation](#quick-start--workspace-installation)
22
+ - [References & Deep Knowledge Base](#references--deep-knowledge-base)
23
+ - [Constitution & Architectural Governance](#constitution--architectural-governance)
24
+
25
+ ---
26
+
27
+ ## CRITICAL: Environment Backend Selection (WSL vs Docker)
28
+
29
+ > [!CAUTION]
30
+ > ### ANTI-DISK-OVERFLOW RULE (DO NOT INITIALIZE BOTH ENVIRONMENTS!)
31
+ > **DO NOT build the Docker container AND install the full WSL toolchain at the same time.**
32
+ > Installing full multi-tier CTF tools (compilers, SMT solvers, `sagemath`, `pwntools`, `angr`, `torch`, `volatility3`, `hashcat`) requires **15 to 25 GB of disk space per environment**.
33
+ > Initializing **BOTH** will consume **30 to 50 GB+**, risking catastrophic host drive exhaustion and environment conflicts.
34
+ >
35
+ > **AI Agents & Players MUST detect and choose EXACTLY ONE backend:**
36
+
37
+ ```
38
+ ┌─────────────────────────────┐
39
+ │ Choose ONE Backend Engine │
40
+ └──────────────┬──────────────┘
41
+
42
+ ┌──────────────────────────────┴──────────────────────────────┐
43
+ ▼ ▼
44
+ [OPTION A: WSL Kali Linux] [OPTION B: Docker Sandbox]
45
+ Best for: Windows Host Development Best for: Linux, macOS, or CI/CD
46
+ - Zero VM overhead, fast host I/O - 100% ephemeral and disposable
47
+ - Direct file access via /mnt/c/Users/... - Clean host isolation
48
+ - Direct GUI/GDB debugging support - Standardized container image
49
+ ```
50
+
51
+ ### Option A: WSL Kali Linux (Recommended on Windows)
52
+ 1. **Verify WSL Kali Availability**:
53
+ ```powershell
54
+ wsl -d kali-linux uname -a
55
+ ```
56
+ 2. **Install CTF Toolchain Inside WSL (Select Profiles to Save Disk)**:
57
+ ```bash
58
+ # Inside WSL or wrapped from PowerShell:
59
+ wsl -d kali-linux bash -c "bash scripts/install_ctf_tools.sh core"
60
+ # To install specific profiles: pwn, rev, crypto, web, forensics
61
+ wsl -d kali-linux bash -c "bash scripts/install_ctf_tools.sh pwn crypto web"
62
+ ```
63
+ 3. **Execution Wrapper**:
64
+ ```powershell
65
+ wsl -d kali-linux bash -c "source ~/.ctf-tools/venv/bin/activate && <command>"
66
+ ```
67
+
68
+ ### Option B: Docker Container Sandbox (Recommended on Linux / macOS / CI)
69
+ 1. **Build Container Image**:
70
+ ```bash
71
+ docker compose build
72
+ ```
73
+ 2. **Execute Inside Container Sandbox**:
74
+ ```bash
75
+ docker compose run --rm ctf-agent <command>
76
+ ```
77
+ 3. **Interactive Shell**:
78
+ ```bash
79
+ docker compose run --rm ctf-agent /bin/bash
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Operational Profiles & Specialized Modes (Text Flags)
85
+
86
+ > [!TIP]
87
+ > ### HOW MODES WORK (PROMPT TEXT FLAGS)
88
+ > Operational modes (`--fast`, `--blitz`, `--deep`, `--lab`) are **instructional text flags** recognized by the Agent through [AGENTS.md](AGENTS.md).
89
+ > **How to use**: Simply write the flags as plain text in your chat prompt or combine them with slash commands (e.g. `/ctf-web --fast <url>` or `/solve-challenge --mode blitz <dir>`).
90
+ > *(Note: In Antigravity IDE, typing `@` searches files/symbols in the workspace; modes are passed directly as text flags in your prompt text).*
91
+
92
+ `CTF-Agent` provides 3 specialized agent personas designed to eliminate multi-agent refusal cascades and optimize for both speedrun competitions and deep lab audits:
93
+
94
+ ```
95
+ ┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
96
+ CTF-AGENT PERSONA MATRIX
97
+ ├──────────────────────────┬───────────────────────────────┬──────────────────────────────────────┤
98
+ MASTER ORCHESTRATOR BLITZ / SPEEDRUN SOLVER DEEP RESEARCH AUDITOR
99
+ @ctf-controller @ctf-speedrun (--blitz) @ctf-analyzer (--deep)
100
+ ├──────────────────────────┼───────────────────────────────┼──────────────────────────────────────┤
101
+ │ Role: State Controller │ Role: First Blood Hunter │ Role: Security Auditor / RCA │
102
+ │ Enforces: Shallow depth │ Stop Condition: On Flag HALT │ Stop Condition: Verified Writeup │
103
+ │ Context: SCO & Envelope │ Documentation: ZERO overhead │ Documentation: 5-Section writeup │
104
+ │ Refusal: 3-Tier Router │ Workspace: Auto-purge debris │ Workspace: Organize resources/
105
+ │ Fallback: Deterministic │ Output: Verified Flag Banner │ Output: Authoritative RCA report │
106
+ └──────────────────────────┴───────────────────────────────┴──────────────────────────────────────┘
107
+ ```
108
+
109
+ ### 1. Master Controller (`@ctf-controller` / `/solve-challenge`)
110
+ Use as the primary entrypoint for complex multi-step labs or challenges.
111
+ - **Prompt Examples**:
112
+ - `/solve-challenge http://challenge.ctf.site:8000`
113
+ - `/solve-challenge ./challenge_directory`
114
+ - **Security Context & Task Envelope**: Wraps target endpoints or local lab files in machine-readable context objects (`security_context`, `task_envelope`) to prevent subagents from evaluating prompts with zero inherited context.
115
+ - **Shallow Orchestration (Depth = 1)**: Dispatches directly to a single specialist skill or agent. Prohibits deep recursive agent chaining (`Agent A -> Agent B -> Agent C`).
116
+ - **3-Tier Refusal Router**: Automatically classifies model refusals (Type A Wording, Type B Ambiguity, Type C Hard Policy) and shifts execution immediately to deterministic CLI tools without entering infinite paraphrasing loops.
117
+
118
+ ### 2. Blitz / Speedrun Mode (`@ctf-speedrun` / `--blitz` / `--fast`)
119
+ Use during active CTF competitions where time is points.
120
+ - **Prompt Examples**:
121
+ - `/ctf-web --fast http://challenge.ctf.site:8080`
122
+ - `/solve-challenge --mode blitz ./pwn_challenge`
123
+ - `--blitz Solve this crypto puzzle: c = 12345, e = 3, n = 99999`
124
+ - **Stop-on-Flag (HALT immediately)**: The instant a valid flag matching target regex (`flag{...}`, `picoCTF{...}`) is confirmed, all tool invocations and probing **stop immediately**.
125
+ - **High-Visibility Flag Banner**:
126
+ ```text
127
+ ============================================================
128
+ [+] FLAG ACQUIRED: picoCTF{example_flag_value}
129
+ Confidence: 100% | Source: HTTP 200 Response
130
+ ============================================================
131
+ ```
132
+ - **Automated Workspace Cleanup**:
133
+ ```bash
134
+ python3 scripts/workspace_cleaner.py --fast
135
+ ```
136
+ Automatically removes temporary scratch files (`test*.py`, `fuzz*.py`, `tmp*`, `core.*`, `payload*.bin`), keeping only the original challenge files and the winning `solve.py`.
137
+ - **Zero Overhead**: Does **not** invoke `ctf-writeup` and does **not** create `writeup.md`.
138
+
139
+ ### 3. Deep Analysis / Lab Mode (`@ctf-analyzer` / `--deep` / `--lab`)
140
+ Use when solving challenge labs (HackTheBox, PortSwigger, pwnable.tw), post-mortems, or security research.
141
+ - **Prompt Examples**:
142
+ - `/ctf-pwn --deep ./vulnerable_binary`
143
+ - `/solve-challenge --mode deep ./web_lab`
144
+ - `--lab Perform deep root cause analysis and generate writeup`
145
+ - **Root Cause Analysis (RCA)**: Deep analysis of memory corruption layouts, AST flaws, or cryptographic mathematical proofs.
146
+ - **Directory Standardization**:
147
+ ```bash
148
+ python3 scripts/workspace_cleaner.py --deep
149
+ ```
150
+ Enforces clean lab layout: only `writeup.md`, `solve.py`, and a `resources/` folder containing all challenge binaries, PCAPs, dumps, and source archives.
151
+ - **Standardized Writeup**: Automatically invokes `ctf-writeup` to author a publication-ready 5-section `writeup.md`.
152
+
153
+ ---
154
+
155
+ ## LLM Safety Guardrails & Policy Compliance (Prompt Sanitization & Guardrail Navigation)
156
+
157
+ When working on cybersecurity labs (HackTheBox, TryHackMe, PortSwigger) or participating in CTF competitions, user prompts and challenge descriptions often contain aggressive adversarial terminology (`exploit`, `attack`, `bypass policy`, `reverse shell`, `weaponize`...). Modern backend LLM safety classifiers (Gemini, Claude, GPT) can mistakenly flag these requests as unauthorized intrusions and **prematurely halt agent execution mid-lab**.
158
+
159
+ `CTF-Agent` integrates an authorized educational framing standard and an automated **Prompt Policy Sanitizer** to eliminate false-positive policy blocks while preserving 100% technical solving capabilities:
160
+
161
+ ### 1. How to Apply in Labs & CTF Competitions
162
+
163
+ Before submitting complex prompts or challenge descriptions to the Agent, run the sanitizer utility to automatically rewrite the text into safe academic phrasing and attach the authorized educational context preamble:
164
+
165
+ ```bash
166
+ # Sanitize an input prompt with high-risk keywords:
167
+ python scripts/prompt_policy_sanitizer.py "Write an exploit payload to bypass security policy and extract the flag"
168
+
169
+ # Sanitize a prompt with specific language support:
170
+ python scripts/prompt_policy_sanitizer.py "Write script to bypass filter and capture flag" --lang en
171
+
172
+ # Scan and sanitize an entire challenge prompt file or writeup:
173
+ python scripts/prompt_policy_sanitizer.py --file path/to/prompt.txt --check
174
+ ```
175
+
176
+ ### 2. Automated Sanitization Mechanism
177
+
178
+ - **Risk Scoring**: Assesses policy risk from `SAFE` (0) to `CRITICAL` (100) across 5 high-risk trigger families (Evasion, Redteam, Exploit, Payload, Exfiltration).
179
+ - **Academic Lexicon Standard**: Automatically replaces adversarial attack jargon with defensive and diagnostic testing equivalents:
180
+ - *exploit vulnerability* -> *verify vulnerability with proof-of-concept (PoC)*
181
+ - *bypass policy* -> *evaluate mitigation boundaries*
182
+ - *steal credentials / exfiltrate* -> *retrieve challenge flag token*
183
+ - *redteam attack* -> *diagnostic security assessment*
184
+ - **Educational CTF Context Preamble**: Injects explicit authorized testing boundaries (`localhost`, Docker, designated CTF target) to satisfy upstream safety filters.
185
+ - **Path & Link Preservation**: Automatically preserves markdown links `[text](target.md)` and URLs without unwanted corruption.
186
+
187
+ For comprehensive guidelines and full replacement dictionaries, see [ctf-safety-framing-rules.md](rules/ctf-safety-framing-rules.md) and [llm-safety-and-policy-compliance.md](references/llm-safety-and-policy-compliance.md).
188
+
189
+ ### 3. Machine-Enforced Scope Guard (Runtime Execution Boundary)
190
+
191
+ While the Prompt Policy Sanitizer protects prompts from semantic upstream LLM filter rejections, the **Scope Guard** ([scripts/scope_guard.py](scripts/scope_guard.py)) converts the Security Context Object (SCO) and Task Envelope into an active, machine-enforced runtime execution fence.
192
+
193
+ - **Network Boundary Validation**: Only authorized CTF targets are permitted:
194
+ - Local loopback: `127.0.0.1`, `localhost`, `::1`
195
+ - RFC1918 private subnets: `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`
196
+ - Authorized CTF domains & competition platforms: `*.challs.io`, `*.picoctf.net`, `*.ctfd.io`, `*.tryhackme.com`, `*.hackthebox.com`, `*.flagyard.com`, and localhost ports.
197
+ - Arbitrary external IP addresses and unauthorized internet endpoints are rejected with explicit policy violations.
198
+ - **Prohibited Action Guard**: Automatically intercepts and blocks commands containing:
199
+ - Destructive disk actions (`rm -rf /`, `mkfs`, `dd if=/dev/zero`)
200
+ - Backdoor persistence mechanisms (`crontab`, systemd services, SSH key installation in `~/.ssh/authorized_keys`, root password modification)
201
+ - Wide automated network sweeps (`nmap -iR`, masscan against external CIDR blocks)
202
+ - **Runtime Execution**:
203
+ ```bash
204
+ # Validate a target endpoint before probing:
205
+ python scripts/scope_guard.py http://127.0.0.1:8080
206
+
207
+ # Validate a diagnostic CLI command before running:
208
+ python scripts/scope_guard.py --command "checksec --file=chall"
209
+
210
+ # Generate a formal Security Context Object (SCO):
211
+ python scripts/scope_guard.py --target http://chall.ctf.site:9000 --json
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Specialized Category Skills
217
+
218
+ `CTF-Agent` equips models with 11 domain-specific skills accessible via slash commands or subagent delegation:
219
+
220
+ | Skill | Description | Key Capabilities |
221
+ |:---|:---|:---|
222
+ | [`solve-challenge`](skills/solve-challenge/SKILL.md) | **Master Dispatcher & Orchestrator** | Hint-First triage, category routing, mode branching (Blitz vs Deep). |
223
+ | [`ctf-web`](skills/ctf-web/SKILL.md) | **Web Vulnerability Assessment** | SQLi, SSTI, JWT verification, prototype pollution, RSC Flight RCE, SSRF. |
224
+ | [`ctf-pwn`](skills/ctf-pwn/SKILL.md) | **Binary Security Analysis** | Glibc heap (House of Apple 2, TLS dtors), ROP, ret2libc, boundary testing. |
225
+ | [`ctf-crypto`](skills/ctf-crypto/SKILL.md) | **Cryptanalysis & Math** | RSA, ECC, LLL/BKZ lattice reduction, HNP/CVP, padding oracle, ZKP. |
226
+ | [`ctf-reverse`](skills/ctf-reverse/SKILL.md) | **Reverse Engineering** | Anti-analysis, custom VMs, WASM, `.pyc` (`pycdc`), Ghidra/radare2/GDB. |
227
+ | [`ctf-forensics`](skills/ctf-forensics/SKILL.md) | **Digital Forensics** | Memory dumps (Volatility 3), PCAP analysis, disk recovery, steganography. |
228
+ | [`ctf-ai-ml`](skills/ctf-ai-ml/SKILL.md) | **AI & Machine Learning** | Adversarial ML, model robustness, extraction evaluation, AI puzzle triage. |
229
+ | [`ctf-osint`](skills/ctf-osint/SKILL.md) | **Open Source Intelligence** | Geolocation, social media tracking, Tor relay tracing, DNS footprinting. |
230
+ | [`ctf-misc`](skills/ctf-misc/SKILL.md) | **Miscellaneous & Jails** | PyJails, bash jails, esoteric encodings, RF/SDR signals, game reversing. |
231
+ | [`ctf-malware`](skills/ctf-malware/SKILL.md) | **Malware Analysis** | C2 protocol decoding, PE/.NET unpackers, obfuscated script analysis. |
232
+ | [`ctf-writeup`](skills/ctf-writeup/SKILL.md) | **Write-up Generator** | Standardized 5-section submission writeup and directory organizer. |
233
+
234
+ ### Custom Skill Extension & Envelope Validation
235
+
236
+ When adding external or custom CTF skills into `.agents/skills/`, run the built-in validator ([scripts/skill_validator.py](scripts/skill_validator.py)) to ensure prompt envelope compatibility and prevent model policy rejections:
237
+
238
+ ```bash
239
+ # Validate a specific custom skill:
240
+ ctf-agent validate-skill .agents/skills/my-custom-skill
241
+
242
+ # Audit all skills in the workspace:
243
+ ctf-agent validate-skill --all
244
+
245
+ # Via NPX:
246
+ npx ctf-agent validate-skill .agents/skills/my-custom-skill
247
+ ```
248
+
249
+ **Compatibility Rules Checked**:
250
+ - **Shallow Orchestration (Depth <= 1)**: Verifies the skill operates as a direct specialist without recursive subagent chaining.
251
+ - **YAML Frontmatter Integrity**: Verifies `name`, `description` (>= 20 chars), and checks against collisions with reserved core skills.
252
+ - **Operational Mode Handling**: Checks for Blitz Mode (Stop-on-Flag) and Deep Mode (RCA / writeup).
253
+ - **LLM Safety Policy Lexicon**: Flags unshielded adversarial triggers (`evil_payload`, `jailbreak`, `weaponize`) and recommends academic diagnostic equivalents.
254
+ - **Command Boundary Guard**: Intercepts destructive host commands (`rm -rf /`, `mkfs`) and backdoor persistence attempts (`crontab`, `authorized_keys`).
255
+
256
+ ---
257
+
258
+ ## Parallel Triage & High-Speed Reconnaissance (P0 Engine)
259
+
260
+ To maximize Time-to-Flag during live CTF competitions, `CTF-Agent` integrates a high-speed parallel reconnaissance scheduler ([scripts/parallel_triage.py](scripts/parallel_triage.py)) that executes Tier 1 and Tier 2 diagnostics concurrently:
261
+
262
+ ```
263
+ ┌────────────────────────────────┐
264
+ Target Challenge Diagnostic │
265
+ └───────────────┬────────────────┘
266
+
267
+ ┌───────────────────────────────┴───────────────────────────────┐
268
+ ▼ ▼
269
+ [Binary / ELF Target] [Web / HTTP Target]
270
+ ThreadPoolExecutor Concurrency ThreadPoolExecutor Concurrency
271
+ - Pure-Python ELF Parser (Arch, Endian, NX, PIE) - HTTP Server & Powered-By Headers
272
+ - checksec security mitigations - /robots.txt & /sitemap.xml leaks
273
+ - strings pattern match (flags, /bin/sh, libc) - Sensitive paths (.git/HEAD, .env)
274
+ - readelf / symbol table analysis - Flag regex candidate pre-scan
275
+
276
+ └───────────────────────────────┬───────────────────────────────┘
277
+
278
+ ┌────────────────────────────────┐
279
+ │ Synthesized Triage Plan │
280
+ │ - Discovered Vulnerabilities │
281
+ - Recommended Specialist │
282
+ - Immediate Exploit Vector │
283
+ └────────────────────────────────┘
284
+ ```
285
+
286
+ - **Zero-Dependency Native ELF Parser**: Reads ELF binary headers using pure Python standard library (`struct`), extracting machine architecture, bitness, endianness, entry point, section counts, NX stack protection, and PIE position independence without requiring external tools.
287
+ - **Concurrent Execution Modes**:
288
+ ```bash
289
+ # Concurrent triage of a binary challenge:
290
+ python scripts/parallel_triage.py ./chall.bin
291
+
292
+ # Concurrent triage of a web challenge:
293
+ python scripts/parallel_triage.py http://127.0.0.1:8080
294
+
295
+ # Machine-readable output for automated agent pipelines:
296
+ python scripts/parallel_triage.py ./chall.bin --json
297
+ ```
298
+
299
+ ---
300
+
301
+ ## Quick Start & Workspace Installation
302
+
303
+ ### Method 0: Intelligent Workspace Initialization (Triple-Engine Architecture)
304
+
305
+ ```
306
+ ┌─────────────────────────────────────────┐
307
+ │ User Workspace Initialization
308
+ └────────────────────┬────────────────────┘
309
+
310
+ ┌────────────────────────────────┼────────────────────────────────┐
311
+ ▼ ▼
312
+ [1. Zero-Install NPX] [2. Python Workstation] [3. Modern UV Toolchain]
313
+ npx ctf-agent init ctf-agent init (pip) uvx --from git+... init
314
+
315
+ └────────────────────────────────┼────────────────────────────────┘
316
+
317
+ ┌─────────────────────────────────────────┐
318
+ │ Step 1: Preflight Detection │
319
+ - OS, CPU, RAM & Disk Storage Free │
320
+ │ - WSL2 & Kali Linux Distro Status │
321
+ │ - Docker CLI & Daemon Connectivity │
322
+ - Check for Existing .agents/ Folder
323
+ └────────────────────┬────────────────────┘
324
+
325
+
326
+ ┌─────────────────────────────────────────┐
327
+ │ Step 2: Backend Capability Score │
328
+ │ WSL Kali Score vs Docker Daemon Score │
329
+ (Objective transparent recommendation)
330
+ └────────────────────┬────────────────────┘
331
+
332
+
333
+ ┌─────────────────────────────────────────┐
334
+ │ Step 3: Workload Purpose Selection │
335
+ [1] Live CTF: core, pwn, web, crypto │
336
+ │ [2] Security Lab: 10 deep profiles │
337
+ │ [3] Rev & Binary: pwn, rev, kernel │
338
+ [4] Full Workstation: all 15 profiles
339
+ └────────────────────┬────────────────────┘
340
+
341
+
342
+ ┌─────────────────────────────────────────┐
343
+ │ Step 4: Provision & Conflict Guard │
344
+ - If .agents exists: Prompt / Confirm │
345
+ │ - Deploy .agents/ & AGENTS.md config │
346
+ │ - Preserve solve.py & resources/ │
347
+ - Provision Toolchain into Backend
348
+ └────────────────────┬────────────────────┘
349
+
350
+
351
+ ┌─────────────────────────────────────────┐
352
+ │ Step 5: Health Verification │
353
+ │ Verify subagents, venv & CLI tools │
354
+ │ [OK] WORKSPACE READY TO SOLVE! │
355
+ └─────────────────────────────────────────┘
356
+ ```
357
+
358
+ CTF-Agent provides three interchangeable execution engines tailored to different developer environments and host constraints:
359
+
360
+ #### 1. Zero-Install Global NPX (`npx ctf-agent init`) - Recommended Default
361
+ Zero-clone setup for developers accustomed to npm and modern command-line toolchains:
362
+ ```bash
363
+ # Initialize current workspace (Zero clone, zero manual install):
364
+ npx ctf-agent init
365
+
366
+ # Target a specific challenge workspace:
367
+ npx ctf-agent init /path/to/ctf-workspace
368
+
369
+ # Run preflight inspection in dry-run mode (zero filesystem writes):
370
+ npx ctf-agent init --dry-run
371
+
372
+ # Or run bleeding-edge unreleased commits directly from GitHub:
373
+ npx github:nvtruongops/CTF-Agent init /path/to/ctf-workspace
374
+ ```
375
+ > [!NOTE]
376
+ > **Prerequisites**: Node.js (v18+) and Python 3 (v3.10+). The `ctf-agent` npm package acts as a lightweight global launcher bridge that orchestrates the Python backend engine.
377
+
378
+ #### 2. Native Python Security Workstation (`ctf-agent` / `ctf_agent_cli.py`)
379
+ Pure standard library execution with zero third-party dependencies. Recommended for headless Linux boxes, Kali Linux, offline environments, or systems where Node.js is not installed:
380
+ ```bash
381
+ # Scenario A: Globally installed CLI command (available anywhere):
382
+ pip install -e . # run once inside cloned repository
383
+ ctf-agent init /path/to/ctf-workspace
384
+
385
+ # Scenario B: Run directly from cloned repository root:
386
+ python ctf_agent_cli.py init /path/to/ctf-workspace
387
+
388
+ # Automated unattended setup (auto-selects highest-scored backend and purpose):
389
+ ctf-agent init /path/to/ctf-workspace --auto --purpose live-ctf
390
+
391
+ # Preflight analysis and dry-run inspection:
392
+ ctf-agent init --dry-run
393
+
394
+ # Health check verification on an existing workspace:
395
+ ctf-agent init /path/to/ctf-workspace --check-only
396
+ ```
397
+ > [!IMPORTANT]
398
+ > **Prevent Relative Path Errors**: Do not execute `python scripts/ctf_init.py` from outside the cloned `CTF-Agent` directory. If you are in an arbitrary target folder without cloning, use `npx ctf-agent init`, the installed `ctf-agent` CLI, or the `uvx` toolchain below.
399
+
400
+ #### 3. Ephemeral Modern Python Toolchain (`uvx`)
401
+ Ultra-fast ephemeral execution powered by the Rust-based `uv` package manager without Node.js or local `venv` activation:
402
+ ```bash
403
+ # Execute directly from repository source without cloning or manual installation:
404
+ uvx --from git+https://github.com/nvtruongops/CTF-Agent ctf-agent init
405
+
406
+ # Target a specific workspace:
407
+ uvx --from git+https://github.com/nvtruongops/CTF-Agent ctf-agent init /path/to/ctf-workspace
408
+
409
+ # Automated speedrun profile:
410
+ uvx --from git+https://github.com/nvtruongops/CTF-Agent ctf-agent init --auto --purpose live-ctf
411
+ ```
412
+ > [!NOTE]
413
+ > **Why `--from git+...` is Required**: Because `ctf-agent` is hosted on GitHub and npm rather than PyPI, the `--from git+https://github.com/nvtruongops/CTF-Agent` flag directs `uvx` to build directly from the verified source repository.
414
+
415
+ ---
416
+
417
+ ### Workspace & Skill Updates (`ctf-agent update`)
418
+
419
+ Keep deployed CTF workspaces up to date with new skills, agent personas, rules, and security references without losing custom modifications or challenge files:
420
+
421
+ ```bash
422
+ # Method 1: Zero-install NPX:
423
+ npx ctf-agent update /path/to/ctf-workspace
424
+
425
+ # Method 2: Native CLI (if installed via pip or npm link):
426
+ ctf-agent update /path/to/ctf-workspace
427
+
428
+ # Method 3: Ephemeral modern toolchain (uvx):
429
+ uvx --from git+https://github.com/nvtruongops/CTF-Agent ctf-agent update /path/to/ctf-workspace
430
+
431
+ # Method 4: Native Python from cloned repository root:
432
+ python ctf_agent_cli.py update /path/to/ctf-workspace
433
+
434
+ # Preview planned skill & rule updates without writing changes:
435
+ npx ctf-agent update --dry-run
436
+
437
+ # Only synchronize skills (preserve rules, agents, and scripts):
438
+ npx ctf-agent update --skills-only
439
+
440
+ # Update global configuration (~/.gemini/config/):
441
+ python scripts/ctf_update.py --global
442
+ ```
443
+
444
+ **Zero Data Loss Guarantees**:
445
+ - **Conflict Guard**: Inspects SHA-256 hashes against `skills-lock.json`. If you made local modifications to a skill, it creates a safe backup (`SKILL.md.bak`) before updating.
446
+ - **Custom Skills & Non-Skill Directory Preservation**: Custom skills in `.agents/skills/`, custom subagents in `.agents/agents/`, custom rules in `.agents/rules/`, and custom scripts in `.agents/scripts/` that are not part of upstream CTF-Agent are preserved completely untouched without wholesale directory wipes.
447
+ - **Automated Backups for Modified Support Files**: Any modified upstream files in `.agents/rules/`, `.agents/agents/`, `.agents/references/`, or `scripts/` receive `.bak` backup files prior to update.
448
+ - **Challenge Assets Protected**: Exploit scripts (`solve.py`), challenge binaries (`resources/`), CTF notes (`notes/`), and credentials (`.env`) are never overwritten or deleted.
449
+
450
+ ---
451
+
452
+ ### Method 1: Deploy CTF-Agent into a CTF Challenge Project (`.agents/`)
453
+ Deploy CTF-Agent as an `.agents` bundle into any target CTF directory:
454
+ ```bash
455
+ # Using symlinks/junctions (live synced with updates):
456
+ python scripts/install_as_agent.py /path/to/ctf-workspace --symlink
457
+
458
+ # Or standalone copy:
459
+ python scripts/install_as_agent.py /path/to/ctf-workspace
460
+ ```
461
+
462
+ ### Method 2: Global Installation Across All Projects
463
+ Install skills, rules, and subagents globally into `~/.gemini/config/`:
464
+ ```bash
465
+ python scripts/install_as_agent.py --global
466
+ ```
467
+
468
+ ### Method 3: Direct Usage Within This Workspace
469
+ This workspace already has `.agents/` configured. You can start prompting directly using slash commands and text flags:
470
+ - **Master Orchestrator**: `/solve-challenge <target-url-or-dir>`
471
+ - **Speedrun / Blitz Mode (Fast Solve, Stop-on-Flag)**: `/solve-challenge --mode blitz <target>` or `/ctf-web --fast <target>` or `--blitz <prompt>`
472
+ - **Deep Analysis Mode (RCA & Writeup)**: `/solve-challenge --mode deep <target>` or `/ctf-pwn --deep <target>` or `--lab <prompt>`
473
+ - **Specific Category Skills**: `/ctf-web`, `/ctf-pwn`, `/ctf-crypto`, `/ctf-reverse`, `/ctf-forensics`, `/ctf-osint`, `/ctf-misc`, `/ctf-ai-ml`, `/ctf-malware`, `/ctf-writeup`
474
+
475
+ ---
476
+
477
+ ## Automated Automation Utilities
478
+
479
+ Located in [scripts/](scripts/):
480
+
481
+ - **`parallel_triage.py`**:
482
+ - `python3 scripts/parallel_triage.py <target-binary-or-url>`: Executes high-speed concurrent Tier 1 & 2 diagnostics (pure Python ELF parsing, checksec, strings, headers, robots.txt, sitemap.xml, sensitive leak probes) via ThreadPoolExecutor.
483
+ - `python3 scripts/parallel_triage.py <target> --json`: Emits machine-readable diagnostic synthesis with recommended specialist category skills.
484
+ - **`scope_guard.py`**:
485
+ - `python3 scripts/scope_guard.py <target-or-command>`: Machine-enforces authorized testing boundaries (RFC1918 subnets, loopback, CTF platform domains) and blocks destructive commands or root persistence attempts.
486
+ - `python3 scripts/scope_guard.py --target <url> --json`: Generates a formal Security Context Object (SCO) for multi-agent dispatch.
487
+ - **`skill_validator.py`**:
488
+ - `python3 scripts/skill_validator.py <path-to-skill>`: Validates external custom skills against YAML frontmatter schemas, shallow orchestration constraints (depth <= 1), mode awareness, policy lexicon, and prohibited commands.
489
+ - `python3 scripts/skill_validator.py --all --json`: Scans all skills across `.agents/skills/` and returns structured JSON reports for CI/CD or agent pipelines.
490
+ - **`prompt_policy_sanitizer.py`**:
491
+ - `python3 scripts/prompt_policy_sanitizer.py "<prompt>" --lang [vi|en]`: Scans, scores policy risk, and sanitizes prompts with academic terminology and educational CTF preambles.
492
+ - `python3 scripts/prompt_policy_sanitizer.py --file <path> --check`: Verifies that challenge writeups, prompts, or scripts do not trigger modern LLM backend filters.
493
+ - **`workspace_cleaner.py`**:
494
+ - `python3 scripts/workspace_cleaner.py --fast`: Purges scratch files (`test*.py`, `fuzz*.py`, `tmp*`), keeping challenge assets and winning `solve.py`.
495
+ - `python3 scripts/workspace_cleaner.py --deep`: Enforces `writeup.md`, `solve.py`, and `resources/` folder structure.
496
+ - **`extract_flags.py`**:
497
+ - `python3 scripts/extract_flags.py "<output>" --banner`: Prints high-visibility flag banner and verifies candidate regex.
498
+ - `python3 scripts/extract_flags.py -f output.log --json`: Emits machine-readable JSON candidate rankings.
499
+ - **`ctfd_client.py`**:
500
+ - Python API client for automated challenge retrieval, attachment downloading, and flag submission.
501
+ - **`cve_lookup.py`**:
502
+ - Automated CVE advisory and exploit lookup utility via Sploitus and Exploit-DB.
503
+
504
+ ---
505
+
506
+ ## References & Deep Knowledge Base
507
+
508
+ Detailed references offloaded to [references/](references/) to preserve maximum context window tokens during agent turns:
509
+ - [multi-agent-orchestration-and-policy-routing.md](references/multi-agent-orchestration-and-policy-routing.md) — Comprehensive guide on Security Context Objects, Task Envelopes, shallow orchestration, and the 3-Tier Refusal Router.
510
+ - [llm-safety-and-policy-compliance.md](references/llm-safety-and-policy-compliance.md) Comprehensive guide on modern LLM safety filter architecture, trigger dictionary (EN/VI), and safe prompt engineering.
511
+ - [ctf-triage-ladder.md](references/ctf-triage-ladder.md) Hierarchical 4-Tier progression (Tier 1 plaintext to Tier 4 in-meta).
512
+ - [version-matrix.md](references/version-matrix.md) Glibc heap, PHP type juggling, and Python bytecode compatibility matrix.
513
+ - [exploit-databases.md](references/exploit-databases.md) Exploit databases, CVE search, and GitHub PoC repositories.
514
+ - [security-events-and-intelligence.md](references/security-events-and-intelligence.md) CTFtime intelligence and event key extraction techniques.
515
+
516
+ ---
517
+
518
+ ## Constitution & Architectural Governance
519
+
520
+ The rules governing all CTF-Agent behavior are defined in [AGENTS.md](AGENTS.md):
521
+ 1. **Hint-First Rule**: Analyze metadata and hints before touching code or tools.
522
+ 2. **Operational Mode Compliance**: Strictly follow Blitz or Deep Analysis protocols.
523
+ 3. **Execution Guard**: Never modify original challenge files; wrap Linux binaries through WSL/Docker; enforce 60s command timeouts.
524
+ 4. **Flag Anti-Hallucination**: 100% verified flag strings directly from runtime output.
525
+ 5. **LLM Safety & Policy Compliance**: Enforce authorized educational sandbox scope and use academic diagnostic terminology per [ctf-safety-framing-rules.md](rules/ctf-safety-framing-rules.md).
526
+ 6. **Context Propagation & Task Envelopes**: Propagate machine-readable Security Context Objects and enforce shallow execution depth (max depth: 1).
527
+ 7. **Refusal Router & Deterministic Tool Fallback**: Enforce 3-tier refusal classification; never enter infinite paraphrasing loops on hard refusals, falling back directly to deterministic CLI tools.
528
+
529
+ ---
530
+
531
+ ### License & Attribution
532
+ Distributed under the MIT License. Designed for authorized security research, academic labs, and ethical CTF competitions.