How automatanexus/nexusshield works
1. What this repo is
NexusShield is a single Rust workspace/crate that combines two runtime roles in one process: a security gateway and an endpoint protection engine. The main binary (src/bin/main.rs) hosts the HTTP server, reverse proxy, CLI, and optional endpoint monitors. A second binary (src/bin/daily_report.rs) is a reporting utility.
2. Top-level runtime shape
The primary executable is an async Rust server built on tokio + axum/hyper. It can run in:
- standalone mode: serves security endpoints and dashboard only
- proxy mode: inspects inbound requests and forwards clean traffic to an upstream app
- endpoint mode: enables local host monitoring and malware detection
3. Gateway request path
Incoming HTTP traffic flows through a layered defense pipeline before any upstream forwarding. The key request-side modules are:
- sql_firewall for SQL AST inspection
- ssrf_guard for IP/DNS-based destination checks
- rate_governor for adaptive throttling/banning
- fingerprint for behavioral fingerprinting
- email_guard, sanitizer, quarantine, and credential_vault for specific payload/data protections
These signals are combined by threat_score, which drives allow/warn/block decisions.
4. Central trust and audit boundary
audit_chain is the core cross-cutting subsystem. It records security events in a SHA-256 hash-chained log, so gateway events, endpoint detections, quarantine actions, and reportable incidents all share the same tamper-evident history. This audit stream is also the source for metrics, SSE, SIEM export, journaling, and compliance reporting.
5. Endpoint engine orchestration
src/endpoint/mod.rs is the coordinator for the endpoint side. It defines the scanner abstractions, result types, severity levels, and the orchestration path that fans out to multiple detectors. The engine can perform:
- real-time monitoring
- on-demand file/directory scans
- continuous background polling
- quarantine and alert dispatch
6. Endpoint input sources
Endpoint detection is driven by several OS-level feeds:
- watcher uses filesystem notifications for create/write events
- process_monitor polls /proc for suspicious process behavior
- network_monitor parses /proc/net/tcp
- memory_scanner inspects /proc/[pid]/maps
- usb_monitor watches /sys/block and mount state
- fim snapshots and rechecks critical system paths
- dns_filter acts as a local UDP DNS proxy and enforcement point
7. Detection engines
The actual malware/threat analysis is split across specialized scanners:
- signatures for SHA-256 exact matches from NDJSON databases
- heuristics for entropy, file-type mismatch, ELF/script anomalies, and embedded payloads
- yara_engine for YARA-like pattern matching without libyara
- allowlist for developer-tool awareness and false-positive suppression
- threat_intel for IOC lookups
- rootkit_detector, container_scanner, and supply_chain for host, image, and dependency risk
These scanners all feed back into the same endpoint result stream.
8. Quarantine and containment
When a threat is confirmed, file_quarantine moves it into an encrypted local vault and strips access permissions. That quarantine state is persistent and includes chain-of-custody metadata. On the gateway side, quarantine is also used for risky imported data such as CSV/JSON payloads.
9. Local state and persistence
The repo is designed to run mostly from local filesystem state, not an external database. Important stateful locations include:
- /etc/nexus-shield/config.toml for configuration
- ~/.nexus-shield/signatures.ndjson for custom signatures
- ~/.nexus-shield/threat-intel/ for IOC files
- ~/.nexus-shield/quarantine/ for isolated artifacts
- persisted baselines for FIM/rootkit-related checks
credential_vault adds encrypted local secret storage using AES-GCM.
10. Telemetry and external export
Multiple consumers read from the shared security event stream:
- metrics exposes Prometheus counters at /metrics
- sse_events pushes live events to /events
- journal writes structured events to the systemd journal
- siem_export forwards to Syslog, Elasticsearch, Splunk HEC, or generic webhooks
- webhook, ferrum_integration, and nexuspulse_integration push alerts to external notification systems
11. Operator-facing surfaces
The server also exposes read/report endpoints such as /health, /status, /audit, /stats, /report, and endpoint-specific /endpoint/* routes when monitoring is enabled. widget/index.html is the embedded dashboard UI, and compliance_report generates the HTML report used for audit/compliance views.
12. Control plane and deployment behavior
config.rs is the central configuration boundary, with CLI flags overriding TOML defaults. auth.rs protects sensitive endpoints with bearer tokens, while TLS is optional via rustls cert/key configuration. signature_updater periodically refreshes malware definitions from a remote feed, making signature data an operational input rather than a code-only asset.
13. Important architectural boundary
The dominant boundary in this repository is between network gateway enforcement and host endpoint monitoring, but both converge on the same internal event model: detections are scored, recorded in the audit chain, optionally quarantined, then exported to dashboards, metrics, logs, and external alerting systems. That shared event spine is what makes the system feel like one product rather than two separate tools.
Main entry points: mod.rs Endpoint engine · main.rs Main server · audit_chain.rs Audit chain · threat_score.rs Threat score
Components 23
Control plane
Configuration, auth, startup, and reporting entrypoints.
- Main server · Primary Rust binary hosting HTTP server, proxy, CLI, and optional endpoint mode.
src/bin/main.rs - Daily report · Secondary binary for report generation.
src/bin/daily_report.rs - Config · Central TOML and CLI configuration boundary.
src/config.rs - Auth · Bearer-token protection for sensitive endpoints.
src/auth.rs - Vault · Encrypted local storage for secrets and protected data.
src/credential_vault.rs - Signature updater · Periodic refresh of malware definitions from remote feeds.
src/signature_updater.rs
Gateway
HTTP request inspection and forwarding enforcement path.
- Gateway · HTTP inspection and decision pipeline before any upstream forwarding.
- Request guards · SQL, SSRF, rate, fingerprint, email, and sanitization checks.
- Threat score · Combines guard signals into allow, warn, or block decisions.
src/threat_score.rs - Quarantine · Gateway-side isolation for risky imported data and payloads.
src/quarantine.rs
Endpoint
Host monitoring, detection, and containment path.
- Endpoint engine · Coordinates scanning, monitoring, and alert dispatch on the host.
src/endpoint/mod.rs - Host feeds · Filesystem, process, network, memory, USB, FIM, and DNS enforcement inputs.
- Detectors · Signatures, heuristics, YARA-like matching, allowlisting, and threat intel.
- Host risk · Rootkit, container, and supply-chain checks for deeper host risk.
- File quarantine · Encrypted quarantine for confirmed malicious artifacts with custody metadata.
src/endpoint/file_quarantine.rs
Telemetry
Audit, metrics, logs, exports, and operator surfaces.
- Audit chain · Tamper-evident SHA-256 event history shared by gateway, endpoint, and reporting flows.
src/audit_chain.rs - Event bus · Shared event stream feeding metrics, SSE, journaling, export, and alerts.
- Metrics · Prometheus counters and operational stats.
src/metrics.rs - SSE events · Server-sent event stream for live security updates.
src/sse_events.rs - Journal · Structured logging to the systemd journal.
src/journal.rs - SIEM export · Forwarding to syslog, Elasticsearch, Splunk HEC, and webhooks.
src/siem_export.rs - Compliance report · HTML reporting used for audit and compliance views.
src/compliance_report.rs - Dashboard UI · Embedded operator dashboard served from widget/index.html.
widget/index.html
Connections 25
- Config → Main server: loads · CLI flags override TOML defaults at startup.
- Auth → Main server: protects · Secures sensitive server endpoints.
- Main server → Gateway: runs · Hosts the primary HTTP gateway and proxy path.
- Main server → Endpoint engine: enables · Turns on endpoint monitoring when configured.
- Main server → Dashboard UI: serves · Exposes the embedded operator UI.
- Gateway → Request guards: filters · Applies layered request inspection before forwarding.
- Request guards → Threat score: scores · Individual guard signals feed the decision engine.
- Threat score → Quarantine: diverts · Risky payloads can be isolated instead of forwarded.
- Quarantine → Vault: protects · Sensitive quarantined material and secrets remain encrypted locally.
- Endpoint engine → Host feeds: ingests · Consumes host-level monitoring and polling inputs.
- Endpoint engine → Detectors: dispatches · Fans out scan results to core detectors.
- Endpoint engine → Host risk: dispatches · Runs deeper host, container, and supply-chain analysis.
- Detectors → File quarantine: contains · Confirmed threats are moved into encrypted quarantine.
- Host risk → File quarantine: contains · High-confidence detections are isolated.
- Signature updater → Detectors: feeds · Refreshes signature-based detection data.
- Endpoint engine → Audit chain: records · Endpoint detections and actions are written to the shared audit log.
- Gateway → Audit chain: records · Gateway decisions and incidents are written to the shared audit log.
- Audit chain → Event bus: publishes · The audit stream is the source for downstream telemetry consumers.
- Event bus → Metrics: exports · Feeds operational counters and health data.
- Event bus → SSE events: streams · Pushes live events to operators.
- Event bus → Journal: logs · Writes structured records to the systemd journal.
- Event bus → SIEM export: forwards · Sends events to external SIEM and alerting endpoints.
- Event bus → Compliance report: summarizes · Provides source data for audit and compliance reports.
- Event bus → Dashboard UI: renders · Supplies live status and audit views in the UI.
- Daily report → Compliance report: generates · Standalone reporting binary builds the report artifact.