How 0xsteph/pentest-ai works
Purpose and entry points
pentest-ai (ptai) is a Python 3.10+ local-first, AI-coordinated penetration-testing system. Its central contract is that candidate findings must be reproducible by deterministic machine oracles before being reported as verified. Primary entry points are the standalone CLI in cli/main.py, REST/dashboard server in api/server.py, and MCP server in mcp_server/server.py. Packaging, console command, and runtime dependencies are defined in pyproject.toml.
Engagement orchestration and safety boundary
An engagement begins with target/scope confirmation, consent, execution context, rate/scope controls, and orchestration. The orchestrator sequences specialist phases and persists engagement state; target expansion and tool/probe activity must pass scope enforcement. Human-in-the-loop pause/takeover and compliance behavior are engine-level concerns.
• engine/orchestrator.py
• engine/scope.py
• engine/exec_context.py
• engine/aup_consent.py
Specialist-agent phase layer
Specialist agents encapsulate recon, authenticated web/API/browser testing, AD/cloud/credential/privesc work, vulnerability aggregation, chaining, validation, detection, and reporting. They share the base-agent contract and are selected/ordered by orchestration rather than being independent applications. The web path is architecturally central because it combines crawling, authentication, scanners, and curated probes.
• agents/base.py
• agents/web/web_agent.py
• agents/recon/recon_agent.py
• agents/poc_validator/poc_agent.py
Deterministic detection and proof pipeline
The probe registry exposes curated test implementations; probes receive scoped context, use reusable HTTP/payload primitives, and emit candidate observations/evidence. Candidate findings are normalized, deduplicated, triaged, and passed to a verifier/oracle gate. Verification—not scanner or LLM output—is the boundary that promotes a result to a reportable finding. Out-of-band classes use the OOB subsystem for callback-based evidence.
• engine/probes/registry.py
• engine/probes/context.py
• engine/verifier.py
• engine/oracles.py
• engine/oob/client.py
State, evidence, and portable outputs
The findings database is the system-of-record boundary between execution phases: it stores findings, evidence artifacts, verdict visibility, and lifecycle state. Verified findings can become replayable capsules and attack chains, then flow to report/export formats including SARIF and JUnit. This separates raw tool/probe observations from durable, consumable security results.
• engine/findings_db.py
• engine/evidence.py
• engine/capsule.py
• engine/chain_capsule.py
• engine/exporters/contract.py
LLM and external integration boundary
LLMs coordinate agent loops and reason over results but are not authoritative detectors. The LLM factory supports Anthropic, OpenAI-compatible endpoints, LiteLLM, and local Ollama, with cost tracking for standalone runs. MCP exposes tools/probes/engagement APIs to external AI clients; REST/WebSocket serves dashboards and integrations. External security binaries are discovered/installed and invoked through the tool registry; scanner output still enters the verification pipeline.
• engine/agent_loop.py
• engine/llm/factory.py
• mcp_server/security_tools.py
• tools/registry.py
• api/server.py
Authentication, infrastructure, and deployment
Authenticated scanning maintains reusable sessions and resolves credential references from environment variables, 1Password, Vault, or AWS Secrets Manager rather than embedding secret values. Default execution is local with local persistence; optional cloud workspace authentication/sync is exposed through CLI auth. OAST defaults to an external collaborator but can use a local server/self-hosted endpoint. Docker supports containerized operation, while GitHub Action and CI mode support pipeline gating.
• engine/authenticated_scan.py
• engine/auth_session.py
• cli/credential_resolvers/aws_sm.py
• engine/oob/local_server.py
• Dockerfile
Main entry points: findings_db.py Findings Database · orchestrator.py Orchestrator · registry.py Probe Registry · context.py Scoped Probe Context
Components 20
Entry Points
- CLI · Standalone engagement and authentication command surface.
cli/main.py - REST Dashboard · REST and WebSocket interface for dashboards and integrations.
api/server.py - MCP Server · Exposes engagement, tool, and probe APIs to AI clients.
mcp_server/server.py
Engagement Control
- Orchestrator · Sequences phases and persists engagement execution state.
engine/orchestrator.py - Scope & Consent · Enforces target, consent, rate, and execution constraints.
engine/scope.py - Agent Loop · Runs LLM-guided specialist-agent loops without authorizing findings.
engine/agent_loop.py - LLM Factory · Selects local and hosted LLM providers.
engine/llm/factory.py
Specialist Agents
- Specialist Agents · Shared contract for recon, web, validation, and other phases.
agents/base.py - Web Testing Agent · Combines crawling, authentication, scanners, and curated web probes.
agents/web/web_agent.py - Recon Agent
agents/recon/recon_agent.py - Authenticated Scanning · Maintains reusable authenticated sessions and credential references.
engine/authenticated_scan.py
Detection & Proof
- Probe Registry · Selects deterministic tests for scoped execution.
engine/probes/registry.py - Scoped Probe Context · Supplies probes with controlled target and runtime context.
engine/probes/context.py - OOB Evidence · Collects callback evidence for out-of-band vulnerability classes.
engine/oob/client.py - Verifier · Promotes candidates only when deterministic oracle checks succeed.
engine/verifier.py - Machine Oracles · Reproducible authority for verified findings.
engine/oracles.py
Results & Integrations
- Findings Database · Stores findings, evidence, verdicts, and lifecycle state.
engine/findings_db.py - Replay & Chain Capsules · Packages verified findings and attack chains for replay.
engine/capsule.py - Report Exporters · Produces consumable outputs including SARIF and JUnit.
engine/exporters/contract.py - Tool Registry · Discovers and invokes security binaries.
tools/registry.py
Connections 25
- CLI → Orchestrator: starts engagement
- REST Dashboard → Orchestrator: controls
- MCP Server → Orchestrator: engagement API
- MCP Server → Probe Registry: probe tools
- Orchestrator → Scope & Consent: enforces before activity
- Orchestrator → Agent Loop: coordinates
- Agent Loop → LLM Factory: uses models
- Orchestrator → Specialist Agents: selects phases
- Specialist Agents → Recon Agent: specializes
- Specialist Agents → Web Testing Agent: specializes
- Web Testing Agent → Authenticated Scanning: reuses sessions
- Web Testing Agent → Probe Registry: runs probes
- Recon Agent → Scoped Probe Context: expands scoped targets
- Scope & Consent → Scoped Probe Context: constrains
- Probe Registry → Scoped Probe Context: executes with
- Probe Registry → Tool Registry: invokes binaries
- Probe Registry → OOB Evidence: requests callbacks
- Scoped Probe Context → Findings Database: candidate observations
- OOB Evidence → Findings Database: callback evidence
- Findings Database → Verifier: candidates and evidence
- Verifier → Machine Oracles: evaluates via
- Verifier → Findings Database: persists verdict
- Findings Database → Replay & Chain Capsules: verified findings
- Findings Database → Report Exporters: verified results
- REST Dashboard → Findings Database: dashboard visibility