Skip to main content

Pen Test Agent Design

Design blueprint for a custom autonomous penetration testing agent targeting a Next.js + ECS Fargate + ALB + Neon stack. Synthesized from AWS Security Agent patterns and PentAGI architecture. Implemented in repo: ~/repos/pentest-agent.

Target Stack

Notable gap: no CloudFront/WAF — highest-priority finding before agent runs.

Agent Architecture

Loop: Plan → Probe → Report Supervisor + Specialists:
Per Agent Harness: state lives in shared filesystem (reports/), not agent memory. Each specialist writes findings to reports/findings-<phase>.json. Supervisor synthesizes.

Domain Scope Model (from AWS Security Agent)

Three categories — never conflate: This is a hard constraint in config/config.yaml. Any tool call targeting outside the target allowlist is rejected before execution.

Safety Constraints (Always-On)

  1. Scope lock: allowlist enforced per tool call
  2. Rate cap: 10 rps default; agent cannot override
  3. Read-only by default: POST/PUT/DELETE to data-mutating endpoints requires explicit destructive: true flag in tool schema
  4. Test account only: dedicated TEST_USERNAME + TEST_PASSWORD env vars; real account never used

Two Phases

Phase 1 — Black-Box (HTTP surface)

No AWS credentials required. Simulates external attacker. Tools:
  • nmap: port/service scan of ALB
  • testssl.sh: TLS config, cipher suite, HSTS
  • nuclei: template-based web vuln scan (CVEs, misconfigs, exposures)
  • Custom HTTP probes: security headers, Next.js-specific paths (/_next/static, /api/* enumeration), CORS config
  • sqlmap: SQL injection against discovered form/API endpoints

Phase 2 — Gray-Box (AWS config inspection)

Requires read-only AWS credentials. Inspects infrastructure layer. Tools:
  • Prowler: IAM misconfig, security group open ports, CloudTrail gaps, S3 public access
  • Trivy: ECR image CVE scan
  • boto3: ECS task definition env vars (secrets in plaintext?), security group rules

Auth Flow

Agent authenticates with test account at session start:
  1. POST to login endpoint with TEST_USERNAME / TEST_PASSWORD
  2. Extract session cookie or JWT from response
  3. Inject into all subsequent requests via Authorization / Cookie header
  4. Test account has real-user permissions, isolated data
Multiple credential sets for role-based testing (user vs. admin if applicable).

Tool Implementation Pattern

Each CLI wrapper follows this interface:
Error messages written as agent recovery instructions (what failed, correct usage, retry guidance). Per Tool Design for Agents.

Output

  • reports/findings.json: structured {vuln, severity, endpoint, evidence, remediation}
  • reports/report.md: human-readable, generated from findings.json
  • report.md ingested into wiki as wiki/summaries/pentest-YYYY-MM-DD.md
  • Diff against previous findings.json on subsequent runs

Progressive Deployment

Key Patterns Borrowed

  • Scope split (target/accessible/out-of-scope): from Aws Security Agent
  • Flow → Task → SubTask hierarchy: from PentAGI
  • Chain summarization for long scans: from PentAGI — implement if web-agent context fills during nuclei scan
  • Shared filesystem state: from Agent Harness