Skip to content
kraxnetPublic

About

Yet another network monitoring tool

Resources

Stars

0 stars

Watchers

2 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

Repository files navigation

Xmon

Network reconnaissance and monitoring tool for ezrecon.

Use DSL to describe your network and services, run periodic checks, and get notified when something changes.

Architecture

Xmon follows a two-stream architecture for Umrath integration — clean separation of raw observations (immutable source of truth) from derived analysis (deletable and rebuildable).

Stream Naming

Layer Bucket URL Pattern Purpose
Stream 1 (Scan) recon-scan .../streams/recon-scan/{AggregateType}/{id}/events:append Immutable raw measurements
Stream 2 (Eval) recon-eval .../streams/recon-eval/{AggregateType}/{id}/events:append Derived analytics (rebuildable)

Layer 1 — Raw Scan (facts)

Scan commands run network probes and emit raw observation events ("at time T, entity X had state Y") to the recon-scan bucket. No analysis, no comparison — just measured facts.

ezrecon.scan_domains  →  DomainScanResult   →  recon-scan/DomainScan/{id}
ezrecon.scan_hostnames → HostnameScanResult  →  recon-scan/HostnameScan/{id}
ezrecon.scan_certificates → TlsScanResult   →  recon-scan/TlsScan/{id}
ezrecon.scan_services → ServiceScanResult + HttpScanResult → recon-scan/*
ezrecon.scan_all      →  all of the above   →  (includes generate + all scans)

Layer 2 — Evaluate (derived, replayable)

The evaluate command reads raw scan streams, replays them chronologically, compares consecutive observations, and emits derived analytical events to the recon-eval bucket.

ezrecon.evaluate  →  reads recon-scan/*  →  emits to recon-eval/*

Use replay to apply detection rules to historical observations. Existing outcomes are deduplicated by source event, rule and port; removing a checkpoint alone does not delete or duplicate stored analysis. Shared-certificate results describe groups in the latest observed reachable TLS state, not every certificate ever seen on an endpoint.

Data Flow

┌─────────────────────────────────────────────────────────────┐
│  YAML Inventory (domains.yml, hostnames.yml, ip_ranges.yml) │
│  → xmon Inventory::Generator → output/ frontmatter pages    │
└──────────────────────────┬──────────────────────────────────┘
                           │
         ┌─────────────────▼──────────────────┐
         │  xmon Inventory::Scanner            │
         │  (DNS, RDAP, TLS, PTR)              │
         │  updates frontmatter in output/     │
         └─────────────────┬──────────────────┘
                           │
    ═══════════════════════╪═══════════════════════════════
    STREAM 1 (immutable)   │
                           ▼
         ┌──────────────────────────────────────┐
         │  EzreconWorkerHandlers (Layer 1)     │
         │  emit_domain_results()               │
         │  emit_hostname_results()             │
         │  emit_tls_results()                  │
         │                                      │
         │  → bucket: "recon-scan"              │
         │  → DomainScanResult, HostnameScan-   │
         │    Result, TlsScanResult             │
         └──────────────────┬───────────────────┘
                            │
    ════════════════════════╪═══════════════════════════════
    STREAM 2 (rebuildable)  │
                            ▼
         ┌──────────────────────────────────────┐
         │  EzreconEvaluator (Layer 2)          │
         │  reads: "recon-scan"                 │
         │  writes: "recon-eval"                │
         │                                      │
         │  evaluate_domains()                  │
         │  evaluate_hostnames()                │
         │  evaluate_tls_endpoints()            │
         │  detect_shared_certificates()        │
         │                                      │
         │  → DomainNameserversChanged          │
         │  → HostnameAddressChanged            │
         │  → CertificateChanged                │
         │  → EndpointBecameUnreachable         │
         │  → SharedCertificateDetected         │
         │  → ...                               │
         └──────────────────────────────────────┘

Metadata Tagging

Every event carries metadata.layer to distinguish its origin:

# Layer 1 (scan)
metadata: { source: "ezrecon", layer: "scan", version: "1.0" }

# Layer 2 (eval)
metadata: { source: "ezrecon-evaluator", layer: "eval", version: "1.0" }

Checkpoint & Replay Mechanism

The evaluator maintains a checkpoint file (.eval_checkpoint.json) tracking how many events per stream have been processed. On each run:

  1. State is always rebuilt from the beginning of the raw stream (so the evaluator knows what the "previous" value was)
  2. Derived events are only emitted for new observations (events past the checkpoint position)
  3. After successful processing, the checkpoint is replaced atomically. Corrupt, ahead-of-history checkpoints and partial history reads fail explicitly instead of pretending this is a first run.

For a full replay (payload.replay = true):

  1. The in-memory checkpoint is reset to empty
  2. All raw events are re-read from position 0
  3. State is rebuilt; only missing derived outcomes are appended
  4. This allows adding new detection rules (e.g. SharedCertificateDetected) and applying them retroactively to the entire scan history

Legacy Adapter

The older umrath_adapter.rb (used by Scanner.run when UMRATH_URL is set) writes directly to a single recon bucket. The new two-stream system in umrath_worker_handlers.rb + umrath_evaluator.rb uses separate recon-scan and recon-eval buckets. The legacy adapter is independent and may eventually be retired in favor of the worker-based flow.

Commands

Command Description
ezrecon.scan_domains DNS NS + RDAP lookup for all inventory domains
ezrecon.scan_hostnames DNS A/AAAA resolution for all hostnames
ezrecon.scan_certificates TLS scan for hostnames and IPv4 addresses
ezrecon.scan_services Common TCP services and HTTP response headers on inventory IPv4 addresses
ezrecon.scan_all Generate pages from inventory + run all scans
ezrecon.evaluate Read raw scans → detect changes → emit derived events

Evaluate payload options

{ "replay": true }

When replay is true, the evaluator ignores the checkpoint and reprocesses all raw events from the beginning.

Raw Events (Layer 1)

Event Type Aggregate Key Fields
DomainScanResult DomainScan/{id} domain_name, nameservers, registrant, registrar, expires
HostnameScanResult HostnameScan/{id} hostname, addresses[], dns_status
TlsScanResult TlsScan/{id} ip, port, hostname, cert_serial, cert_not_after, tls_status
ServiceScanResult ServiceScan/{id} ip, states (port → open/closed/filtered/unknown), scan_status
HttpScanResult HttpScan/{id} ip, port, http_status, status_code, http_headers

Derived Events (Layer 2)

Event Type Aggregate When
DomainNameserversChanged Domain/{id} NS set differs from previous scan
DomainExpiringSoon Domain/{id} Domain expires within 30 days
HostnameAddressChanged Hostname/{id} IP set differs (includes added/removed)
HostnameBecameUnreachable Hostname/{id} Was resolvable → NXDOMAIN
HostnameRecovered Hostname/{id} Was NXDOMAIN → resolvable
CertificateChanged Endpoint/{id} Different DER SHA-256 fingerprint on the same endpoint; legacy serial fallback
CertificateExpiringSoon Endpoint/{id} Certificate expires within 30 days
EndpointBecameReachable Endpoint/{id} Was refused/timeout → TLS reachable
EndpointBecameUnreachable Endpoint/{id} Was reachable → refused/timeout
SharedCertificateDetected Certificate/{sha256} Same SHA-256 on 2+ latest-observed reachable endpoints
DomainRegistrationChanged Domain/{id} Known registrar, registrant or expiry changes
DomainExpired, CertificateExpired Domain or Endpoint Already expired at the observation time
HttpHeadersChanged Endpoint or HttpEndpoint Software/version response headers change
ServicePortOpened Address/{id} New open service or a service becomes open again
ServicePortClosed Address/{id} Previously open TCP service explicitly becomes closed
ServicePortUnreachable Address/{id} Previously open TCP service becomes filtered, not confirmed closed

Measurement contract

  • DNS records include A and AAAA. Recovery clears a previous NXDOMAIN status; empty answers clear old addresses. Query failures are explicit observations, not address removals or stale successful results.
  • NS lookup is independent of RDAP. Czech domains use NIC.CZ; other domains use the RDAP.org redirect service. Requests have deadlines, missing optional RDAP entities are allowed, and errors do not become fresh registration data.
  • Certificates carry cert_sha256, the SHA-256 of DER, plus serial, issuer, validity and DNS SANs. A TLS success survives an HTTP failure. Old records lacking DER/hash cannot be used to prove shared identity retroactively. Certificate collection is not a CA trust-validation verdict.
  • TLS starts with 443 and includes known open direct-TLS ports (465, 636, 853, 993, 995, 2376, 5001, 5671, 6443, 8443, 8883, 9443), including SNI for inventory hostnames. Previously fingerprinted ports remain checked even after closing. STARTTLS is not implemented.
  • HTTP uses a bounded HEAD /, preserves case-normalized multi-value headers, does not follow redirects or download bodies, and redacts Set-Cookie values. Both TLS HTTP and known open plain-HTTP ports are covered. Version comparison uses VERSION_HEADERS in the evaluator; volatile Date/cookie changes do not create software-change alerts. All other response headers remain available in raw observations.
  • Only measurements made by the current command are emitted. Failed probes clear stale certificate/header fields; historical output pages are not re-emitted with an invented current timestamp.
  • Expiry is evaluated relative to scanned_at (or event occurrence time), not today's date when replaying an old scan.

Approved TCP profile (pre-deployment)

The fixed 59-port list is in ServiceProbe::COMMON_PORTS, plus every previously observed open port (known_tcp_ports). It includes low-port services, MQTT 1883/8883, 3000/4000, MySQL 3306, PostgreSQL 5432, RDP 3389 and web ports 8080/8081/8443. Closed previously discovered ports are retained for rechecks. This is not a random 1–1024 scan or a complete 1–65535 sweep; unlisted, never-discovered services are outside the profile. UDP is not scanned.

Nmap is an OS prerequisite. The probe uses unprivileged TCP connect (-sT), no DNS/discovery/service-version probes or NSE scripts, a maximum rate of 30 probes/second, one retry and a 120-second per-address deadline. Ambiguous or timed-out results stay unknown and cannot become false closure events. Only generated IPv4 pages inside current ip_ranges.yml are eligible; removed ranges are not regenerated and overlapping ranges do not duplicate IPs. Generate inventory first; missing/stale domain or hostname pages are errors.

The initial repair was validated offline. On 2026-11-18 the unchanged scope was approved for a controlled run: 100 domains, 212 hostnames and 456 IPv4 addresses in 11 ranges. Historical page IDs were preserved to retain stream continuity. Do not copy an old evaluator checkpoint into a new deployment.

The optional recon Compose profile now provides ezrecon-worker, built with make -C deploy build-ezrecon-worker. Provision the unchanged inventory YAML under REMOTE_CONFIG_DIR/inventory/ezrecon and seed historical Markdown pages under DATA_DIR/ezrecon/output before first generation. Never overwrite an already running output tree with historical pages.

Set EZRECON_USER to the state directory's UID:GID. The container runs unprivileged, drops all capabilities, contains Nmap and mounts inventory read-only. Output and evaluator state persist under DATA_DIR/ezrecon. The dedicated ezrecon-worker caller can claim, renew and finalize commands; raw observations retain the existing scanner/evaluator caller identities. On the VM, start only this service from the deployed Compose directory:

cd /opt/ezop
docker compose -p deploy --profile recon up -d --no-deps ezrecon-worker

Commands run serially with a 300-second lease, renewed every 30 seconds. The worker restarts after boot, but no periodic scheduler is configured. Submit domains, hostnames, services, certificates and evaluation as distinct stages so failures and long-running progress can be inspected separately. NIC.CZ returned HTTP 503 for 71 queries in the first fast pass; controlled retries used five-second spacing and a one-minute pause after another 503. Keep provider throttling in mind before repeating a whole domain batch.

Buckets

Bucket Content Deletable?
recon-scan Raw scan observations No (source of truth)
recon-eval Derived analytical events Yes (replayable from recon-scan)

CLI Usage

Inventory

# Generate pages from YAML inventory:
bin/xmon generate -i /path/to/ezrecon -o output

# Run scans (updates pages + optionally forwards to Umrath):
UMRATH_URL=http://localhost:8080 bin/xmon scan

# Other CLI commands:
bin/xmon check -d examples/nic.rb
bin/xmon stats
bin/xmon validate

bin/xmon scan remains the legacy single-recon-bucket path and does not start the new TCP profile. Use the worker commands for the two-layer pipeline; do not mix legacy CLI output with the new raw streams.

Worker Mode

Set environment variables and let the Umrath worker claim commands:

export UMRATH_URL=http://127.0.0.1:8080
export UMRATH_PROJECT_ID=ezop
export EZRECON_INVENTORY_DIR=/path/to/ezrecon
export EZRECON_OUTPUT_DIR=/path/to/ezrecon/output

Environment Variables

Variable Default Description
UMRATH_URL http://127.0.0.1:8080 Umrath server URL
UMRATH_PROJECT_ID ezop Umrath project ID
EZRECON_INVENTORY_DIR $PWD Path to ezrecon YAML files
EZRECON_OUTPUT_DIR $EZRECON_INVENTORY_DIR/output Path to generated pages
EZRECON_EVAL_CHECKPOINT .eval_checkpoint.json Evaluator checkpoint file

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

Run focused offline regressions with bundle exec rake test. Tests use fake DNS, HTTP, TLS and Nmap data. The final repair run passed 24 tests and 91 assertions inside Docker with --network none. A separate isolated-loopback smoke test verified actual Nmap open/closed results, HTTP HEAD collection without bodies, cookie redaction and a real TLS handshake with DER SHA-256. No inventory targets were contacted. Generating pages into a disposable directory requires no network; never use the real output directory for tests.

License

The gem is available as open source under the terms of the MIT License.

About

Yet another network monitoring tool

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages