HunterX v7 — Offensive Tool Orchestration & Full Mission Execution

Status: Ratified (Sprint 020) Version: 1.0.0 Owner: HunterX Architecture Council


1. Purpose / Scope

This document defines the Offensive Tool Orchestration Engine — the mission-execution half of HunterX v7. Sprint 012–019 built Target Intelligence, Vulnerability Intelligence and Safe Validation; Sprint 020 connects them into complete authorized security missions through a controlled execution graph.

The engine transforms:

MISSION OBJECTIVE
→ SCOPE
→ TARGET DISCOVERY
→ ASSET ENUMERATION
→ TECHNOLOGY IDENTIFICATION
→ ATTACK-SURFACE ENUMERATION
→ VULNERABILITY INTELLIGENCE
→ HYPOTHESIS GENERATION
→ SAFE VALIDATION
→ EVIDENCE COLLECTION
→ CORRELATION
→ RISK PRIORITIZATION
→ REPORTING

as an adaptive graph: OBSERVE → DECIDE → PLAN → EXECUTE → LEARN → REPLAN → VERIFY. HunterX never behaves like “run every tool against every target”.

Hard constraints:

Scope: src/hunterx/domain/orchestration/, src/hunterx/domain/ports/orchestration.py, src/hunterx/engines/orchestration/, src/hunterx/application/orchestration.py, src/hunterx/domain/entities/tidb/orchestration.py and the c7d3e9f1a4b8_offensive_orchestration_tables Alembic migration.


2. Design Goals

  1. Capability-driven, not tool-count-driven. Tools are selected because they provide a required capability, never because they exist.
  2. Adaptive planning. Only the phases and steps relevant to the observed attack surface are planned; irrelevant capabilities are never executed.
  3. Scope/safety fail-closed. Every task passes the scope guard, safety enforcer and rate limiter before execution; out-of-scope discovery is blocked and recorded.
  4. Reusable lifecycle. The mission lifecycle state machine is explicit and every transition is validated.
  5. Resumable. Checkpoints persist mission state; pause/resume/crash recovery never repeat completed destructive or expensive operations.
  6. Explainable. Coverage and quality metrics carry explanations; every gate decision, selection and failure is recorded.

3. Package Overview

src/hunterx/
├── domain/
│   ├── orchestration/                 # orchestration domain models
│   │   ├── enums.py                   # MissionType, MissionState, phases, failure classes, ...
│   │   ├── models.py                  # OffensiveMission, MissionScope, Policies, ExecutionPlan, ...
│   │   └── selection.py               # CapabilityNeed, ToolSelection, ToolSelectionResult
│   ├── ports/orchestration.py         # OffensiveMissionRepository, ExecutionPlanRepository, ...
│   ├── exceptions/orchestration.py    # OffensiveOrchestrationError hierarchy
│   └── entities/tidb/orchestration.py # persisted orchestration entities
└── engines/
    └── orchestration/
        ├── lifecycle.py               # MissionLifecycle state machine
        ├── scope.py                   # MissionScopeGuard (fail-closed)
        ├── safety.py                  # MissionSafetyEnforcer
        ├── selector.py                # MissionToolSelector (TIP + registry)
        ├── planner.py                 # MissionPlanner (adaptive phases)
        ├── graph.py                   # MissionDependencyGraph
        ├── executor.py                # MissionExecutor (runs steps via SDK)
        ├── retry.py                   # FailureClassifier + RetryEngine
        ├── fallback.py                # FallbackEngine (capability-equivalent)
        ├── dedup.py                   # ExecutionDeduplicator (input-hash + freshness)
        ├── ratelimit.py               # RateLimiter (multi-key token bucket)
        ├── checkpoints.py             # MissionCheckpointManager
        ├── memory.py                  # MissionMemoryStore (per-target)
        ├── replan.py                  # ReplanningEngine (never expands scope)
        ├── coverage.py                # CoverageModel
        ├── quality.py                 # MissionQualityScorer
        ├── events.py                  # MissionEventEmitter
        ├── engine.py                  # OffensiveOrchestrationEngine (composition root)
        └── api.py                     # OffensiveOrchestrationAPI (facade)
flowchart TD
    API[OffensiveOrchestrationAPI] --> ENG[OffensiveOrchestrationEngine]
    ENG --> LC[MissionLifecycle]
    ENG --> PL[MissionPlanner]
    ENG --> EX[MissionExecutor]
    ENG --> CK[MissionCheckpointManager]
    ENG --> MEM[MissionMemoryStore]
    ENG --> RP[ReplanningEngine]
    ENG --> COV[CoverageModel]
    ENG --> QL[MissionQualityScorer]
    ENG --> EM[MissionEventEmitter]
    EX --> GR[MissionDependencyGraph]
    EX --> SCOPE[MissionScopeGuard]
    EX --> SAFE[MissionSafetyEnforcer]
    EX --> SEL[MissionToolSelector]
    EX --> RETRY[RetryEngine]
    EX --> FB[FallbackEngine]
    EX --> DEDUP[ExecutionDeduplicator]
    EX --> RL[RateLimiter]
    EX --> SDK[Tool Integration SDK ExecutionEngine]
    ENG --> TIP[Tool Intelligence Platform]
    ENG --> TIDB[TIDB / Knowledge Graph / Event Bus]

4. Mission Model

4.1 MissionType

bug-bounty, web-pentest, api-pentest, external-assessment, internal-assessment, red-team-recon, cloud-assessment, continuous-attack-surface-monitoring, vulnerability-assessment.

4.2 MissionState

created → scoping → planning → ready → running
                                     ├→ paused → running
                                     ├→ waiting → running
                                     ├→ replanning → running
                                     ├→ blocked → running
                                     ├→ completed
                                     ├→ partial
                                     ├→ failed
                                     └→ cancelled

Terminal states: completed, partial, failed, cancelled. Every transition is validated by MissionLifecycle; illegal transitions raise InvalidStateTransitionError.

4.3 OffensiveMission

The canonical mission aggregate:

Field Meaning
mission_id stable mission identifier
mission_type MissionType
objective mission objective statement
scope MissionScope (roots/includes/excludes, follow subdomains/redirects)
exclusions explicit out-of-scope identifiers
authorization Authorization (reference, holder, status, validity)
priority low/medium/high/critical
policies Policies (execution/safety/tool/retry/rate-limit)
target_set TargetSet (targets + stable ids + criticality)
workflow workflow reference
state current MissionState
plan_id id of the current execution plan
analysis_version analysis version

4.4 Policies


5. Execution Plan

ExecutionPlan decomposes a mission into Phases and MissionSteps:

The planner selects phases adaptively (see §7) and the graph/executor drive the steps.


6. Mission Lifecycle

MissionLifecycle owns the state machine; MissionLifecycleOperator provides named operations (scope, plan, ready, start, pause, resume, wait, replan, block, complete, partial, cancel, fail).

The engine persists every transition and emits the canonical mission.* events (mission.scoping.started, mission.plan.created, mission.step.started, mission.tool.selected, mission.replanned, mission.checkpoint.created, mission.blocked, mission.partial, mission.quality.computed, mission.coverage.computed, …).


7. Mission Planner

MissionPlanner consumes an IntelligenceSummary:

and produces an ExecutionPlan. Phase selection is adaptive:

Phases are topologically ordered (PHASE 0…12) and wired with dependencies. The planner never executes anything.


8. Tool Selection

MissionToolSelector selects tools for a step’s CapabilityNeed (capability + target type + safety class). Selection is capability-driven:

  1. Build a ToolSelectionCriteria from the need + mission type + tool policy.
  2. Query TIP for ranked candidates providing the capability.
  3. Filter by the mission tool policy (allow/deny) and registered execution adapters.
  4. Rank by TIP selection score; preferences add a bonus.

FallbackEngine selects a capability-equivalent alternative when the primary tool is unavailable or failed, preserving the input/output contracts and the mission tool policy. Tool chaining uses canonical schemas only — one tool’s normalized output becomes the next tool’s canonical input; raw stdout is never parsed inside another adapter.


9. Scope Guard

MissionScopeGuard executes before every tool task and classifies the target identifier:

Identifiers are classified IN_SCOPE, OUT_OF_SCOPE, REQUIRES_AUTHORIZATION or UNKNOWN. Only IN_SCOPE identifiers are acted upon. Every decision is recorded (ExecutionPolicyDecision) and emitted as a mission.step.blocked event when refused.

10. Safety Enforcer

MissionSafetyEnforcer executes before every tool task and checks:

A refusal produces a SafetyDecision that is recorded and emitted.

11. Execution

MissionExecutor walks the MissionDependencyGraph:

Parallelism: independent steps in the same ready wave may be executed concurrently by the SDK’s ParallelExecutionManager, respecting global/target/ tool concurrency and rate limits.

12. Retry / Fallback / Dedup / Rate Limit

13. Checkpoints & Resume

MissionCheckpointManager persists a checkpoint containing the mission state, plan version, completed/pending/failed/blocked steps and the gate records. resume_state reconstructs the resume context so an executor can continue without repeating completed work (crash recovery, worker restart, network interruption).

14. Mission Memory

MissionMemoryStore keeps per-target TargetMemory: discovered assets, technologies, tools used, previous results, vulnerabilities, false positives, validations, risk, tool reliability, evidence history and first/last-seen. Memory is scoped per target so cross-target and cross-mission isolation is guaranteed.

15. Replanning

ReplanningEngine evaluates a ReplanRequest (new assets, technologies, endpoints, providers, capability changes) and classifies every discovered asset. Only IN_SCOPE assets continue automatically; OUT_OF_SCOPE and REQUIRES_AUTHORIZATION assets are blocked. Replanning never expands scope.

16. Coverage & Quality

17. Persistence

TIDB entities (migration c7d3e9f1a4b8):

MissionPlanRecord, MissionPhaseRecord, MissionStepRecord, ExecutionDependency, ExecutionCheckpoint, ExecutionPolicyDecision, ToolSelectionRecord, ToolFallback, MissionReplan, MissionCoverage, MissionQuality, MissionFailure, MissionTaskHistory.

The generic TidbRepositoryFactory.repository_for(Entity) persists them; the repository ports (OffensiveMissionRepository, ExecutionPlanRepository, ToolSelectionRepository) have in-memory implementations (infrastructure/memory/orchestration.py) used as the default backend.

18. Events & Observability

The engine emits the canonical mission.* orchestration events (see §6). Every recorded gate decision, selection, fallback and failure is available via MissionExecutor.records() and persisted to TIDB. Observability ids (mission/plan/step/execution/tool/correlation) flow through every record.

19. Testing

20. Error Reference

Exception Meaning
OffensiveOrchestrationError base orchestration error
OffensiveMissionNotFoundError unknown mission
ExecutionPlanNotFoundError unknown plan
InvalidMissionStateError operation requires a different mission state
ScopeViolationError out-of-scope identifier
SafetyViolationError safety-policy refusal
ToolSelectionUnavailableError no tool satisfies a capability need
RateLimitExceededError rate-limit refusal
MissionCancelledError operation on a cancelled mission