greydgl--pentestgpt
ab5fbb4d90
* first refactor
* feat: dockerized tool with persistent Claude+Codex login + multi-model benchmark
Run the autonomous CTF/pentest tool in Docker with a one-time, persistent login for
BOTH Claude Code and Codex, and add a multi-model benchmark harness.
Backend (multi-model):
- Add `--backend {claude,codex}` to the CTF pipeline. CodexBackend (pentestgpt/core/
backend.py) wraps unified_agent's Codex backend and translates its events into
AgentMessages, so the same pipeline runs on Claude (opus/sonnet) or Codex
(gpt-5.5/gpt-5.4-mini). Wired through config.backend, pipeline stage construction,
and the CLI (+ PENTESTGPT_CODEX_EFFORT; greppable [CODEX_USAGE] under PENTESTGPT_BENCH=1).
Docker tool (tool-only image; the benchmark stays OUTSIDE the image):
- Extend Dockerfile: Codex CLI (@openai/codex) + openai_codex SDK + unified_agent/
pentestgpt_agent/pentestgpt_legacy packages + gobuster/dirb + socat. Add .dockerignore
(keeps creds/benchmark/workspace out of the build context).
- Persistent dual login (the hard part) — asymmetric by token model:
* Claude: `setup-token` -> token stored in the pentestgpt-claude volume; entrypoint
exports CLAUDE_CODE_OAUTH_TOKEN (setup-token does not write .credentials.json; macOS
host creds live in the Keychain and can't be copied).
* Codex: the container does its OWN `codex login` (NOT seeding -- ChatGPT refresh tokens
are single-use, so a shared/copied login 401s on first refresh). The 127.0.0.1:1455
OAuth callback is forwarded into the container via a socat hop (-p 1455:8455).
* scripts/docker-login.sh is idempotent: checks logins live, logs in only the missing one(s).
- docker-compose codex-config volume (+ pinned names); entrypoint token-export + non-blocking
preflight; scripts/docker-auth-status.sh; Make targets (docker-build/login/auth-status/
run/shell/down/nuke).
- Verified end-to-end: one `make docker-login` -> a fresh container reports claude+codex
logged in with live round-trips; the CTF pipeline (Codex) captured a flag against an
isolated fixture and the pentest pipeline ran cleanly; persists across recreation, no re-login.
Benchmark (multi-model, host-side):
- benchmark/pilot/ harness (run_pilot.py + report.py): builds each xbow challenge, discovers
the loopback port, runs the pipeline across the 4 model combos, judges by the baked
FLAG{sha256(UPPER-dir)}, and renders REPORT.md (infra failures excluded from solve rates).
Includes the partial pilot's results (results.jsonl + REPORT.md).
Docs: docs/docker-dev-plan.md (full plan + implementation status); CLAUDE.md and README
docker quickstart; benchmark/pilot/README.md; design-doc roadmap (docs/redesign).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix: fail controller on backend error messages
* fix: allow listing sessions without target
* docs: add docker xbow benchmark report
* fix: infer concrete backend constructor type
* docs: refresh docker benchmark documentation
* feat(benchmark): add pure single-agent baseline + pipeline comparison
Add a "pure single agent" benchmark variant -- one bare `claude -p` /
`codex exec` call per target (no pipeline) -- to quantify what the 3-stage
PentestGPT pipeline buys over an un-orchestrated agent on the xbow targets.
- pentestgpt/prompts/stages.py: ctf_single_agent_{system,task}_prompt -- the
pipeline's shared fragments collapsed into ONE turn, so prompt content is
held constant and the only variable is the multi-stage decomposition.
- benchmark/pilot/run_docker_bench.py: docker-network runner
(--variant single|pipeline). Brings the target up, discovers the container's
internal IP+network (skips DB side-cars/ports), docker-runs the tool image on
that network, and scores the ground-truth flag against the agent's *assistant
text* only (parity with the pipeline's raw streaming). Reads stdout in chunks
to handle >64KB JSON lines. Resumable; --dry-run supported.
- benchmark/pilot/report_comparison.py -> DOCKER_COMPARISON.md: head-to-head
pipeline-vs-single per model on the common non-infra set.
- tests/unit/test_single_agent_prompt.py: prompt-builder coverage.
- docs: README, CLAUDE.md, benchmark README, DOCKER_REPORT updated.
Recorded result (10 medium/hard targets x 4 models, container-to-container,
same baseline image digest 0c4c0f3e..., commit dca0019 image):
Model Pipeline Single
Claude Opus 5/10 7/10 (single +2)
Claude Sonnet 6/10 4/10 (pipeline +2)
Codex gpt-5.5 7/10 7/10 (tie)
Codex gpt-5.4-mini 3/10 4/10 (single +1)
TOTAL 21/40 22/40
Single agent matches the pipeline on solve rate (55% vs 52%) while using
~40% fewer Codex tokens (13.0M vs 21.8M) and solving faster. The pipeline
only clearly helps Claude Sonnet (which times out solo); Opus is better solo.
Full per-challenge grid in DOCKER_COMPARISON.md; raw records in
docker_single_results.jsonl.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* feat(benchmark): add pentestgpt_agent docker harness
* bench: refresh pentestgpt_agent smoke result
* fix(benchmark): make repeat rows variant-aware
* fix(agent): fall back for semantic executor labels
* fix(agent): tolerate executor prose evidence
* fix(benchmark): score accepted framework findings
* bench: append partial framework repeat results
* bench: complete framework repeat sweep
* bench: expose framework executor concurrency
* bench: add extended parallel framework sweep
* checkpoint: preserve working agent and benchmark state
* feat: harden durable agent loop and xbow qualification
* fix: reserve an exploit result turn
* docs: record clean xbow qualification
* build: consume unified-agent from the git wrapper repo
Repoint pentestgpt_agent_new's unified-agent dependency from the local
editable path (../../UnifiedAgentPoC, now renamed and gone) to the pinned
git source PentestGPT-Project/UnifedAgentWrapper@d05d21f. Regenerate uv.lock
and update test_dependency.py to assert the external package is installed
from that VCS URL (not the repo-root vendored copy) at version 0.2.0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* refactor: make pentestgpt_agent_new the sole framework
Remove the retired ledger-based pentestgpt_agent package (instructor/executor/
judge) and its orphaned unit + smoke tests. The nested pentestgpt_agent_new
project (Supervisor/Executor over a durable SQLite loop, consuming unified-agent
from the git wrapper) is now the single maintained framework.
Repoint the top-level tooling to it:
- pyproject: drop the pentestgpt-agent console script and pentestgpt_agent from
the wheel packages.
- Makefile: lint/format target parent code only; typecheck/check/ci now run the
nested framework's own gate (ruff, format, mypy, pytest) via test-agent-new /
check-agent-new, so `make check` finally covers it; `make run` delegates to the
pentestgpt-agent-new CLI.
- Dockerfile: stop copying the removed package (kept the build working); note the
framework is not baked into the image yet.
- docker container-health test: import the substrate packages that actually ship.
- CLAUDE.md / AGENT.md: describe the new framework, the git-sourced wrapper, and
the deprioritized benchmark/Docker rewire.
The XBOW `--variant framework` path and docker-bench Makefile targets still point
at the old in-image framework and are left as a pending rewire (benchmarks
deprioritized); the naive `--variant single` path is unaffected.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* refactor: rename pentestgpt_agent_new -> pentestgpt_agent
The framework reclaims the clean name now that the old ledger-based package is
gone. Rename the nested project folder, its src package, the distribution
(pentestgpt-agent-new -> pentestgpt-agent) and CLI, and every import/reference in
the package, the umbrella Makefile, the Dockerfile, the docker health test, and
CLAUDE.md / AGENT.md. Regenerate uv.lock. The audit CLI stays pentestgpt-agent-audit;
the git-sourced unified-agent dependency is unchanged. `make check` is green
(108 nested tests). The two historical *_REPORT.md files keep the old name as
dated records.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* chore: extract benchmark harness to sibling xbow-benchmark repo
Move PentestGPT/benchmark/ out to ../xbow-benchmark (its own repo) to keep this
project clean. The harness was decoupled from the framework code (it scores
container output, never imports pentestgpt_agent/unified_agent), so only
operational ties remain and they now live in the sibling repo.
- Remove benchmark/ and the 4 harness unit tests (relocated + repointed there).
- Strip the docker-bench-*/bench-* targets and their config vars from the
Makefile; keep the tool-image lifecycle (docker-build/login/run/...) and add a
help pointer to `make -C ../xbow-benchmark help`.
The sibling repo mounts this checkout read-only (--source-root ../PentestGPT) and
runs the pentestgpt:latest image built here.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* feat: harden autonomous framework and runtime integration
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
146 行
4.8 KiB
Python
146 行
4.8 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from unified_agent.skills import (
|
|
discover_skills,
|
|
install_skills,
|
|
lint_skill,
|
|
load_skill,
|
|
make_skill,
|
|
)
|
|
from unified_agent.types import SkillError
|
|
|
|
|
|
def write_skill(root: Path, dirname: str, frontmatter: str, body: str = "Do the thing.") -> Path:
|
|
d = root / dirname
|
|
d.mkdir(parents=True)
|
|
(d / "SKILL.md").write_text(f"---\n{frontmatter}\n---\n\n{body}")
|
|
return d
|
|
|
|
|
|
def test_load_valid_skill(tmp_path):
|
|
d = write_skill(
|
|
tmp_path,
|
|
"word-count",
|
|
"name: word-count\ndescription: Count words in files. Use when asked for word counts.",
|
|
)
|
|
s = load_skill(d)
|
|
assert s.name == "word-count"
|
|
assert s.description.startswith("Count words")
|
|
assert "Do the thing." in s.body
|
|
assert s.path == d
|
|
|
|
|
|
def test_name_must_match_directory(tmp_path):
|
|
d = write_skill(tmp_path, "other-dir", "name: word-count\ndescription: x")
|
|
with pytest.raises(SkillError, match="directory"):
|
|
load_skill(d)
|
|
|
|
|
|
@pytest.mark.parametrize("bad", ["Deploy", "a--b", "-x", "x-", "a" * 65, "has_underscore"])
|
|
def test_invalid_names_rejected(tmp_path, bad):
|
|
d = write_skill(tmp_path, "okdir", f"name: '{bad}'\ndescription: x")
|
|
with pytest.raises(SkillError):
|
|
load_skill(d)
|
|
|
|
|
|
def test_description_required_and_capped(tmp_path):
|
|
d1 = write_skill(tmp_path, "s-one", "name: s-one\ndescription: ''")
|
|
with pytest.raises(SkillError, match="description"):
|
|
load_skill(d1)
|
|
d2 = write_skill(tmp_path, "s-two", f"name: s-two\ndescription: {'y' * 1025}")
|
|
with pytest.raises(SkillError, match="1024"):
|
|
load_skill(d2)
|
|
|
|
|
|
def test_missing_frontmatter_rejected(tmp_path):
|
|
d = tmp_path / "s-three"
|
|
d.mkdir()
|
|
(d / "SKILL.md").write_text("no frontmatter here")
|
|
with pytest.raises(SkillError, match="frontmatter"):
|
|
load_skill(d)
|
|
|
|
|
|
def test_lint_warns_on_claude_only_syntax(tmp_path):
|
|
d = write_skill(
|
|
tmp_path,
|
|
"porta",
|
|
"name: porta\ndescription: x",
|
|
body="Run with $ARGUMENTS and !`git diff` and ${CLAUDE_SKILL_DIR}/x",
|
|
)
|
|
s = load_skill(d)
|
|
warnings = lint_skill(s)
|
|
joined = " ".join(warnings)
|
|
assert "$ARGUMENTS" in joined
|
|
assert "!`" in joined or "injection" in joined
|
|
assert "${CLAUDE_" in joined
|
|
|
|
|
|
def test_make_and_discover(tmp_path):
|
|
make_skill(tmp_path, "alpha-skill", "Does alpha. Use for alpha tasks.", "Body A")
|
|
make_skill(tmp_path, "beta-skill", "Does beta. Use for beta tasks.", "Body B")
|
|
(tmp_path / "not-a-skill").mkdir()
|
|
names = [s.name for s in discover_skills(tmp_path)]
|
|
assert names == ["alpha-skill", "beta-skill"]
|
|
|
|
|
|
def test_install_symlinks_into_both_discovery_dirs(tmp_path):
|
|
src = tmp_path / "skills"
|
|
make_skill(src, "alpha-skill", "Does alpha.", "Body A")
|
|
ws = tmp_path / "ws"
|
|
installed = install_skills(ws, src)
|
|
assert [s.name for s in installed] == ["alpha-skill"]
|
|
for root in [ws / ".claude" / "skills", ws / ".agents" / "skills"]:
|
|
link = root / "alpha-skill"
|
|
assert link.is_symlink()
|
|
assert (link / "SKILL.md").read_text().find("Does alpha.") != -1
|
|
assert link.resolve() == (src / "alpha-skill").resolve()
|
|
|
|
|
|
def test_install_idempotent_and_replaces_stale_symlink(tmp_path):
|
|
src = tmp_path / "skills"
|
|
make_skill(src, "alpha-skill", "Does alpha.", "Body A")
|
|
ws = tmp_path / "ws"
|
|
install_skills(ws, src)
|
|
install_skills(ws, src) # no error
|
|
# point the link somewhere stale, then reinstall
|
|
link = ws / ".claude" / "skills" / "alpha-skill"
|
|
link.unlink()
|
|
other = tmp_path / "elsewhere"
|
|
other.mkdir()
|
|
link.symlink_to(other)
|
|
install_skills(ws, src)
|
|
assert link.resolve() == (src / "alpha-skill").resolve()
|
|
|
|
|
|
def test_install_refuses_real_dir_without_force(tmp_path):
|
|
src = tmp_path / "skills"
|
|
make_skill(src, "alpha-skill", "Does alpha.", "Body A")
|
|
ws = tmp_path / "ws"
|
|
real = ws / ".agents" / "skills" / "alpha-skill"
|
|
real.mkdir(parents=True)
|
|
(real / "SKILL.md").write_text("preexisting")
|
|
with pytest.raises(SkillError, match="force"):
|
|
install_skills(ws, src)
|
|
install_skills(ws, src, force=True)
|
|
assert (ws / ".agents" / "skills" / "alpha-skill").is_symlink()
|
|
|
|
|
|
def test_install_copy_mode(tmp_path):
|
|
src = tmp_path / "skills"
|
|
make_skill(src, "alpha-skill", "Does alpha.", "Body A")
|
|
ws = tmp_path / "ws"
|
|
install_skills(ws, src, mode="copy")
|
|
target = ws / ".claude" / "skills" / "alpha-skill"
|
|
assert target.is_dir() and not target.is_symlink()
|
|
assert "Does alpha." in (target / "SKILL.md").read_text()
|
|
install_skills(ws, src, mode="copy") # idempotent re-copy
|
|
|
|
|
|
def test_install_empty_source_errors(tmp_path):
|
|
empty = tmp_path / "skills"
|
|
empty.mkdir()
|
|
with pytest.raises(SkillError, match=r"[Nn]o skills"):
|
|
install_skills(tmp_path / "ws", empty)
|