Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xSteph Pentest ai build chain capsule

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Verification
Last Updated 2026-10-23 12:00 GMT

Overview

Concrete function that assembles a tamper-evident multi-hop chain proof capsule bundling every step of a verified attack chain, and a function to re-prove all hops in order against a live target.

Description

build_chain_capsule bundles one verified attack chain into a portable capsule. Each hop carries a finding, its receipt, and the step action that ties hops together. The integrity SHA reuses engine.capsule.capsule_integrity so any post-build edit to any hop is detectable.

replay_chain_capsule re-proves every hop in order against the live session. Before ANY oracle is built, the gate checks EVERY hop's request host(s) against allowed_hosts. If any hop host is off the allowlist, it raises CapsuleScopeError and builds nothing.

Returns a dict with per-hop verdicts and an `all_verified` flag.

Usage

Import this when you need to:

  • Bundle a multi-step attack chain into a portable, replayable artifact
  • Re-prove every step of a chain against a live target
  • Share composed attack proofs with third parties

Code Reference

Source Location

  • Repository: pentest-ai
  • File: engine/chain_capsule.py

Signature

def build_chain_capsule(
    chain: dict[str, Any],
    hops: list[dict[str, Any]],
    *,
    ptai_version: str = "",
    created_at: str | None = None,
) -> dict[str, Any]:
    """Assemble a tamper-evident proof capsule for one verified attack chain.
    Each hop: {"finding": dict, "receipt": Receipt|dict|None, "step_action": str}"""

async def prove_chain(
    chain: dict[str, Any], db: Any, session: Any, intensity: str = "normal"
) -> list[dict[str, Any]]:
    """Re-prove every step of a chain in order, returning a hop list."""

async def replay_chain_capsule(
    chain_capsule: dict[str, Any],
    session: Any,
    intensity: str = "normal",
    allowed_hosts: list[str] | None = None,
) -> dict[str, Any]:
    """Re-prove every hop against the live session. Fail-closed scope."""

Import

from engine.chain_capsule import build_chain_capsule, prove_chain, replay_chain_capsule

I/O Contract

Inputs (build_chain_capsule)

Name Type Required Description
chain dict[str, Any] Yes Chain metadata: id, name, description, severity, impact
hops list[dict] Yes dict|None, "step_action": str}
ptai_version str No Version string
created_at None No Timestamp

Outputs (replay_chain_capsule)

Name Type Description
returns dict[str, Any] {"status": "ok", "replayed_hops": [...], "all_verified": bool}
raises CapsuleScopeError If any hop host is off the allowlist

Usage Examples

Building and Replaying a Chain Capsule

import aiohttp
from engine.chain_capsule import build_chain_capsule, replay_chain_capsule

# 1. Build the chain capsule
capsule = build_chain_capsule(
    chain={"id": "chain-1", "name": "SSRF to RCE", "severity": "critical"},
    hops=[
        {"finding": ssrf_finding, "receipt": ssrf_receipt, "step_action": "Access metadata"},
        {"finding": rce_finding, "receipt": rce_receipt, "step_action": "Deploy via SSH key"},
    ],
    ptai_version="0.20.0",
)

# 2. Re-prove all hops
async with aiohttp.ClientSession() as session:
    result = await replay_chain_capsule(
        chain_capsule=capsule,
        session=session,
        allowed_hosts=["target.example.com"],
    )
    print(f"All verified: {result['all_verified']}")
    for hop in result["replayed_hops"]:
        print(f"  {hop['finding_id']}: {hop['verdict']}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment