Skip to content

Add ingest_bbot tool (bbot JSONL, typed scope split) - #200

Merged
BaaRai merged 1 commit into
mainfrom
feat/ingest-bbot
Nov 12, 2026
Merged

BaaRai merged 1 commit into
mainfrom
feat/ingest-bbot

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Adds ingest_bbot: reads a bbot JSONL output file from a path and ingests it under the existing target-scope rules, reusing the typed parser from #199 unchanged.

Behaviour

  • Reader: the file is read one line at a time with a fixed cap, bbotMaxLineBytes = 64 KiB (newline included). A longer line is skipped and counted (oversized_lines), never buffered whole. Each kept line goes through parseBbotJSONL.
  • In scope (scope_distance == 0): assetItems() → the existing insert_assets handler (t.insertAssets().Call). No asset SQL here. In-scope events that are not assets (e.g. FINDING) are only counted (in_scope_not_asset).
  • Intel (any other scope_distance, or missing): one fact each via recordOneFact (the record_fact path), source = third_party_intel. The summary is built from typed fields only; the free text is stored in detail as the inert Go-quoted string from the parser.
  • Intel never reaches insert_assets or task_scope. Free text and non-JSON lines never create an asset.

Wiring

  • WorkerTools() gains t.ingestBbot(). The existing BuiltinToolSeeds → SeedTool loop inserts its row on startup: a new key, so the insert happens on fresh and existing DBs alike. No extra seed migration.
  • intercept/target_extract.go: ingest_bbot is added to noTargetTools (its input is a local path). TestDomainToolsDeclareNoTarget requires every domain tool to be listed.

Tests

  • TestReadBbotJSONLLineCap (pure): the valid fixture is parsed line by line; a line over the cap is skipped and counted and the lines around it are kept; a line exactly at the cap is kept; a single over-cap line with no newline is dropped.
  • TestIngestBbotScopeSplit (PG, ARTEX_PG_DSN): a benign fixture using example.com / example.net / example.org. Expected: one subdomain asset (the in-scope host); 3 third_party_intel facts with quoted detail; no asset and no task_scope row for out-of-scope hosts or the host named in free text; 1 non-JSON line skipped.
  • Mutation check (run by hand against a throwaway PG):
    • InScope routed to intel → fails in-scope host: 0 subdomain assets, want 1.
    • Intel lines sent to insert_assets → fails 2 assets created from out-of-scope lines or free text.

Verification (Kali, go1.26.10 linux/amd64, throwaway postgres:16-alpine)

  • gofmt -l on changed files: no output
  • go build ./..., go vet ./...: exit 0
  • go test -count=1 ./agent/: ok
  • go test -count=1 -run Extract ./intercept/, go test -count=1 -run Tool ./server/: ok

ingest_bbot reads a bbot output file by path and ingests it through
the typed parser from #199 (parseBbotJSONL), one line at a time:

- Lines are read with a fixed cap (bbotMaxLineBytes = 64 KiB, newline
  included). A longer line is skipped and counted, never buffered whole.
- scope_distance == 0 events that are assets (assetItems) go through
  the existing insert_assets handler; no asset SQL is written here.
- Every other event is recorded as a fact with source
  third_party_intel. The summary is built from typed fields only; the
  free text is stored in detail as the inert Go-quoted string.
- Intel never reaches insert_assets or task_scope.

The tool is in WorkerTools, so the existing BuiltinToolSeeds/SeedTool
loop inserts its row (a new key, inserted on fresh and existing DBs).
It is listed in the target gate's noTargetTools: its input is a local
path, not a network target (TestDomainToolsDeclareNoTarget).
@BaaRai
BaaRai merged commit f90589c into main Nov 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant