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 agents Findings CLI

From Leeroopedia
Knowledge Sources
Domains Security, Data_Storage, CLI
Last Updated 2026-10-22 12:00 GMT

Overview

Concrete CLI tool for persistent SQLite-backed engagement data management provided by the pentest-ai-agents toolkit.

Description

The findings.sh script is the primary data persistence layer for pentest-ai-agents. It provides a full CRUD interface over a SQLite database for tracking hosts, services, vulnerabilities, credentials, attack chains, and session logs across an engagement. It supports a dual-backend design: native sqlite3 when available, with an automatic python3 fallback using the stdlib sqlite3 module.

The CLI operates via a `main()` router that dispatches to `cmd_*` functions for each subcommand. All database writes go through `db_exec()` from `db/lib/common.sh`, which handles SQL escaping and backend selection. The active engagement is controlled by the `PENTEST_AI_ENGAGEMENT` environment variable.

Usage

  • Engagement initialization: Run `findings.sh init <id>` at the start of every engagement to create the SQLite record.
  • Data entry during testing: Use `findings.sh add host|service|vuln|cred|chain` after each discovery to persist findings.
  • Querying and tracking: Use `findings.sh list`, `findings.sh get`, and `findings.sh stats` to check progress and avoid duplicate work.
  • Validation updates: Use `findings.sh update vuln|chain|host` to record PoC results and status changes.
  • Reporting and export: Use `findings.sh export` for JSON output and `findings.sh stats` for engagement summaries.
  • Session logging: Use `findings.sh log <agent> <action> <summary>` to record all agent activity for audit trails.

Code Reference

Source Location

Signature

#!/usr/bin/env bash
# Main router dispatches to cmd_* functions:

main() {
    # Commands: init, use, add, update, list, get, stats, engagements, export, log
}

# ─── init ───────────────────────────────────────────────────────────
cmd_init() {
    local id="${1:-}"          # Engagement ID (required)
    # --client <name>           # Client organization
    # --type <type>             # external|internal|web|wireless|cloud|red team
    # --scope <scope>           # Authorized scope text
    # --notes <notes>           # Free-text notes
}

# ─── add ─────────────────────────────────────────────────────────────
cmd_add_host() {
    local ip="${1:-}"           # Target IP (required)
    # --hostname <name>        # Resolved hostname
    # --os <os>                 # Detected OS
    # --role <role>             # DC|file-server|etc.
    # --agent <name>            # Agent name for audit trail
    # --notes <notes>
}

cmd_add_service() {
    local host_ip="${1:-}"     # Host IP (required)
    local port="${2:-}"        # Port number (required)
    # --proto <proto>           # tcp (default)
    # --service <name>          # Service name
    # --version <ver>           # Service version
    # --banner <banner>         # Service banner
}

cmd_add_vuln() {
    local title="${1:-}"       # Vulnerability title (required)
    # --severity <S>            # critical|high|medium|low|info (required)
    # --host <ip>               # Affected host
    # --cve <id>                # CVE identifier
    # --cvss <score>            # CVSS score (float)
    # --mitre <id>              # ATT&CK technique ID
    # --tool <name>             # Scanning tool used
    # --evidence <path>         # Evidence file path
    # --agent <name>            # Agent name
    # --desc <description>      # Vulnerability description
    # --notes <notes>
}

cmd_add_cred() {
    local username="${1:-}"   # Username (required)
    local secret="${2:-}"     # Password/hash/key (required)
    # --type <T>               # cleartext|ntlm|krb5tgs|sha512|key (required)
    # --host <ip>              # Source host
    # --domain <domain>        # AD domain
    # --source <source>        # How credential was obtained
    # --access <level>         # Access level granted
    # --agent <name>           # Agent name
    # --notes <notes>
}

cmd_add_chain() {
    local name="${1:-}"       # Chain name (required)
    # --score <int>            # Impact score (0-100)
    # --steps '<JSON>'          # Step sequence
    # --mitre '<T-IDs>'         # Comma-separated ATT&CK IDs
    # --notes <notes>
}

cmd_log() {
    local agent="${1:-}"      # Agent name (required)
    local action="${2:-}"     # Action type (required)
    local summary="${3:-}"    # Human-readable summary (required)
    # --detail <detail>        # Optional detailed notes
}

# ─── update ──────────────────────────────────────────────────────────
cmd_update_vuln() {
    local id="${1:-}"         # Vuln record ID (required)
    # --status <status>         # confirmed|false_positive|unconfirmed
    # --poc-output <text>       # Proof of exploitation output
    # --confirmed-by <agent>    # Validating agent name
}

cmd_update_chain() {
    local id="${1:-}"         # Chain record ID (required)
    # --status <status>         # identified|in_progress|validated|exploited
    # --score <int>             # Updated impact score
}

cmd_update_host() {
    local id="${1:-}"         # Host record ID (required)
    # --os <os>                 # Updated OS info
    # --role <role>             # Updated host role
    # --status <status>         # Host status
}

# ─── list ────────────────────────────────────────────────────────────
cmd_list_hosts()     # [--role <role>] [--status <status>]
cmd_list_services()  # [--host <ip>] [--port <port>]
cmd_list_vulns()     # [--severity <S>] [--status <status>] [--host <ip>]
cmd_list_creds()     # [--domain <domain>] [--type <type>] [--access <level>]
cmd_list_chains()    # [--status <status>]
cmd_list_log()       # [--agent <name>] [--limit <N>]

# ─── get ─────────────────────────────────────────────────────────────
cmd_get_vuln()       # <id>
cmd_get_host()       # <id|ip>
cmd_get_chain()      # <id>

# ─── stats ──────────────────────────────────────────────────────────
cmd_stats()          # No parameters; uses PENTEST_AI_ENGAGEMENT

# ─── export ─────────────────────────────────────────────────────────
cmd_export()         # No parameters; outputs JSON to stdout

Import

# The CLI is invoked directly, not sourced:
findings.sh <command> [options]

# Ensure it is in PATH (installed by install.sh to ~/.pentest-ai/bin/):
export PATH="$HOME/.pentest-ai/bin:$PATH"

# Set active engagement:
export PENTEST_AI_ENGAGEMENT="<engagement-id>"

I/O Contract

Inputs

Name Type Required Description
PENTEST_AI_ENGAGEMENT env var Yes (for most cmds) Active engagement ID
PENTEST_AI_DB env var No Database path (default: ~/.pentest-ai/findings.db)
id str Yes (init) Unique engagement identifier
ip str Yes (add host) Target IP address
host_ip + port str + int Yes (add service) Host IP and port number
title str Yes (add vuln) Vulnerability title
--severity str Yes (add vuln) critical, high, medium, low, info
username + secret str Yes (add cred) Credential username and secret value
--type str Yes (add cred) cleartext, ntlm, krb5tgs, sha512, key
name str Yes (add chain) Attack chain name
agent + action + summary str Yes (log) Agent name, action type, summary text
id int Yes (update/get) Record ID to update or retrieve

Outputs

Name Type Description
Confirmation message stdout "Host added: <ip> (id=<N>)" style messages
Query results stdout (TSV) Tab-separated values with headers (list, get commands)
Engagement stats stdout Formatted summary with counts by severity
JSON export stdout (JSON) Full engagement data as JSON object
SQLite rows database Rows in hosts, services, vulns, credentials, chains, session_log tables

Usage Examples

Initialize an Engagement

# Create a new engagement record
findings.sh init "acme-2026-q4" --client "Acme Corp" --type "internal" --scope "10.10.0.0/24"

# Activate it for this session
export PENTEST_AI_ENGAGEMENT="acme-2026-q4"

Record Discovered Hosts and Services

# After scanning, add a discovered host
findings.sh add host 10.10.1.50 --hostname "dc01.acme.local" --os "Windows Server 2019" --role "DC" --agent "recon-advisor"

# Add services found on that host
findings.sh add service 10.10.1.50 445 --service "SMB" --version "Windows Server 2019"
findings.sh add service 10.10.1.50 88 --service "Kerberos" --proto tcp

Record a Vulnerability

# Add a confirmed vulnerability with full metadata
findings.sh add vuln "EternalBlue SMB RCE" \
  --severity critical \
  --host 10.10.1.50 \
  --cve "CVE-2017-0144" \
  --cvss 8.1 \
  --mitre "T1210" \
  --tool "nmap" \
  --agent "vuln-scanner" \
  --desc "MS17-010 SMB RCE vulnerability detected on port 445"

Validate and Update a Vulnerability

# After PoC validation, update the status
findings.sh update vuln 5 --status confirmed --confirmed-by "poc-validator" --poc-output "RCE confirmed: whoami=SYSTEM"

# Check what still needs validation
findings.sh list vulns --status unconfirmed

Record an Attack Chain

# After executing an exploit chain
findings.sh add chain "EternalBlue to Domain Admin" \
  --score 92 \
  --steps "EternalBlue RCE -> Mimikatz -> DCSync -> Domain Admin" \
  --mitre "T1210,T1003,T1006"

# Update chain status as execution progresses
findings.sh update chain 3 --status exploited --score 92

Query and Export

# View engagement statistics
findings.sh stats

# List all critical vulnerabilities
findings.sh list vulns --severity critical

# Export full engagement data as JSON
findings.sh export > engagement_acme_2026q4.json

Log Agent Activity

# Log a scan action
findings.sh log "recon-advisor" "nmap-scan" "Full TCP scan of 10.10.0.0/24 completed"

# Log with detailed notes
findings.sh log "exploit-chainer" "chain-execution" "Step 1 of 3: EternalBlue RCE successful" \
  --detail "Gained SYSTEM on 10.10.1.50, extracted credentials via Mimikatz"

Related Pages

Implements Principles

Requires Environment

Related Implementations

Page Connections

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