Repository navigation
Agent: ingest_scan_output for nmap XML files (worker, additive) - #214
Merged
Merged
Conversation
A worker can write nmap output with -oX and call ingest_scan_output with the format and path. The file is parsed deterministically: assets go through the insert_assets handler, each host becomes one tool_output fact listing its open ports, and the model gets only counters and at most 20 notable items per type. - path is resolved under the run working directory; "..", an absolute path outside it and a symlink leading outside are refused; 256 MiB cap - the XML is streamed host by host with encoding/xml; a file cut short keeps the complete hosts and returns truncated: true - target text (banners, products, hostnames) is kept only as a Go-quoted string in the fact detail - re-ingesting a file upserts the same assets and skips identical facts Worker-only, like ingest_bbot. nuclei, httpx and ffuf follow separately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Adds
ingest_scan_output, a worker tool that ingests an nmap XML file already written to disk, so the model never reads the raw scanner output.The worker runs nmap with
-oX <file>, then callsingest_scan_outputwithformat: "nmap-xml"and the filepath. The tool parses the file deterministically and writes without the LLM:insert_assetshandler: oneipasset per host with its open ports, one service asset per open port, and an HTTP service asset with URL and port for http/https services. Onlytype="user"hostnames are bound to the IP; PTR names stay in the fact detail.record_factfact per host (sourcetool_output) listing its open ports.The model receives only a compact summary: counters (
hosts,ports,urls,events,skipped,truncated,assets_written,facts_written,facts_existing) and at most 20 notable items per type (hosts,ports,urls). Neither the raw content nor a full dump is returned.Additive
ingest_bbotand adding the tool to the target gate'snoTargetToolslist, asingest_bbotis, because its input names a file, not a target.encoding/xml,encoding/json).Scope of this PR
ingest_bbot(registered inWorkerTools()). The tool is seeded into the tools catalog throughBuiltinToolSeeds(), asingest_bbotis.Limits and safety
pathis resolved under the run's working directory (ToolContext.WorkingDir, the directory Bash runs in). A path with a..element, an absolute path outside it, and a symlink, file or directory, that resolves outside it are refused (filepath.EvalSymlinks+filepath.Rel). The tool needs theToolContext, whichwriteExpTooldoes not pass on, so it is built with the sameactool.SpecaswriteToolinside the sameneedExplorationguard.statand enforced again withio.LimitReader. Only regular files are read.xml.Decoder, one<host>element at a time, never read whole into memory. The 64 KiB-per-line cap for the JSONL formats comes with PR2.strconv.Quote) compact JSON string. Summaries and notable items carry only validated typed fields: IP, port/protocol, service-name token, URL.truncated: true. A file that is not nmap XML is refused. Parser errors are not echoed, because they can quote the file.facts_existing, not written again.Tests
.., absolute outside path, file symlink and directory symlink leaving the directory, directory, missing file, over-cap sparse file, no working directory).bbot_ingest_tool_pg_test.go): real task,insert_assetsandrecord_fact, asset rows and facts checked, re-ingestion keeps counters with no new asset row or fact, symlink escape refused through the tool.go build ./...,go vet ./agent,go test -count=1 ./agent,go test -count=1 -race ./agent,go test -count=1 ./intercept,gofmt -lon changed files.Limitations
EvalSymlinks+Rel) andos.Open. A process in the working directory could swap a path component for a symlink in between. Hardening (for exampleO_NOFOLLOWor aSameFilecheck after opening) is not in this PR.-oXformat. Nothing was tested against real scanner output.