Add a scanner
A scanner is a component of the nightwatch binary. It reads targets from a Redis stream and
publishes findings to another stream. It never touches MongoDB. Read
How it works first. The full guide, with code, is
scanner/docs/ADDING_SERVICES.md.
The js_dependency_scanner and http_header_scanner packages are good examples to copy.
Layout
Section titled “Layout”scanner/src/internal/active_recon/<scanner_name>/├── constants.go # consumer group name├── models.go # scanner-specific models (optional)├── service.go # orchestration: call the scanner, convert and publish findings├── consumer.go # Redis consumer└── scanner/ # the scanning logic, with no Redis or MongoDB └── scanner.goKeep the scanning logic in the scanner/ package so that you can test it without
infrastructure.
- Consumer group. Define a group name such as
my_scanner_serviceinconstants.go. - Consume. Most scanners read
domain_scan_triggers. Scanners of open ports also readport_scan_triggers. Create the group from the latest message ($), withCreateConsumerGroupFromLatest. - Publish findings. Convert results to
shared.SecurityFinding, setSourceto a short lowercase name, and publish toshared.StreamSecurityFindings. Skip jobs without anorg_id. - Tracing. Extract the trace context from each message you consume, and inject it into each finding you publish.
- Register the component in
consumers()insrc/cmd/nightwatch/main.go, and add its group tocreateConsumerGroups(). - Scan completion. Add the (stream, group) pair to
scanPipelineGroups()insrc/internal/scan_coordinator/pipeline.go, and toTestScanPipelineGroups. If you forget this, scans are marked done before your scanner has finished. - Registry. Add the component to
scanner/docs/SERVICE_REGISTRY.md. - External tools. If the scanner runs a command-line tool, install a pinned version with a
checksum check in
scanner/Dockerfile. The image runs as a non-root user. - Settings. Read settings with
config.GetEnv*. Add the ones users should set to the root.env.exampleanddocker-compose.yml.
Scanners send real traffic to real systems. Do not add checks that change data, try to log in with guessed passwords, or can take a service down.