How ronin15/rust_edr_agent works
1. Overall shape
This is a single Rust crate that builds an endpoint-detection agent. The code is organized as a library in src/lib.rs plus one main agent binary in src/edr_main.rs, with a few standalone test binaries under src/bin/ and top-level test drivers like test_linux_detection.rs.
2. Runtime and orchestration
agent.rs is the central coordinator. It owns the lifecycle of the monitoring pipeline: load config, start collectors, receive events, pass them through deduplication and detectors, then persist or emit alerts. The project is built around async execution with Tokio, which matters because collectors run concurrently.
3. Configuration boundary
config.rs loads YAML-based settings from the repo’s config.yaml files. Configuration controls which collectors are enabled, batching behavior, storage/compression settings, logging, and detection thresholds. This is the main externalized control plane for the agent.
4. Collection layer
src/collectors/manager.rs coordinates the individual data sources:
- process.rs for process lifecycle and behavior tracking
- file.rs for file-system activity and hashing
- network.rs for network connections and DNS observation
- registry.rs for Windows registry monitoring
These collectors are the system-boundary adapters: they translate OS-specific telemetry into the project’s internal event model.
5. Unified event model
events.rs defines the shared event structures that the rest of the system consumes. This is the normalization boundary between raw OS telemetry and higher-level security logic. The rest of the pipeline operates on these common events rather than directly on platform APIs.
6. Detection layer
src/detectors/manager.rs dispatches events into the active detectors:
- behavioral.rs for suspicious execution, process injection, and context-aware risk scoring
- dns_anomaly.rs for DNS tunneling, suspicious domains, and C2-style patterns
- registry.rs for registry-focused detections
This is the analysis boundary: raw activity becomes security findings and risk scores here.
7. Deduplication and alert suppression
deduplication.rs sits between event ingestion and downstream processing to reduce repeated noise. The readme makes clear that it is intentionally conservative: it preserves security-critical events while rate-limiting repetitive, low-value alerts. This module is important for diagramming because it changes the volume and shape of data flowing to detectors, storage, and logs.
8. Storage and retention
storage.rs handles persistence of collected output, with compression enabled for efficiency. The design emphasizes low memory use and retention cleanup, so the storage subsystem is not just a sink; it is also a lifecycle manager for historical event data.
9. Networking and external integrations
src/network.rs exists, but the readme explicitly says centralized management / phone-home networking is not implemented yet. So the architecture currently stops at local agent processing: no backend service, no SIEM connector, and no command-and-control channel in this repository.
10. Platform-specific boundaries
The repo is explicitly cross-platform, but not all capabilities are universal. Registry monitoring is Windows-only, while the behavioral and DNS detectors have Linux/macOS-specific test coverage in test_linux_detection.rs and test_mac_detection.rs. Conditional compilation and platform-aware rules are important architectural boundaries.
11. Validation and support tooling
The top-level test binaries exercise detection scenarios end-to-end, especially DNS anomaly handling and platform-specific behavioral rules. Documentation in docs/ is extensive and maps to the code modules, so the repo is designed to be understood and tuned as a security-monitoring system rather than a simple library.
12. Primary data flow
The core flow is:
system activity → collectors → unified events → deduplication → detectors → alerts/storage.
The important architectural point is that telemetry is normalized early, then fanned out into both storage and detection, with deduplication acting as a noise-control gate in the middle.
Main entry points: agent.rs Agent · lib.rs Library · detectors/manager.rs Detector mgr · collectors/manager.rs Collector mgr
Components 21
Core agent
Runtime, config, events, and pipeline orchestration
- Library · Public crate surface and module wiring
src/lib.rs - Agent · Owns lifecycle and end-to-end event flow
src/agent.rs - Config · Loads and applies agent configuration
src/config.rs - Events · Normalized internal event structures
src/events.rs - EDR main · Executable entry point for the agent
src/edr_main.rs
Collectors
OS telemetry adapters and collection coordination
- Collector mgr · Starts and coordinates OS-specific collectors
src/collectors/manager.rs - Process · Process lifecycle and behavior observation
src/collectors/process.rs - File · File activity and hashing collection
src/collectors/file.rs - Network · Connections and DNS observation
src/collectors/network.rs - Registry · Windows registry monitoring
src/collectors/registry.rs
Detection
Deduplication and security analysis
- Deduplication · Suppresses repetitive low-value events while preserving critical ones
src/deduplication.rs - Detector mgr · Routes events to active detectors
src/detectors/manager.rs - Behavioral · Suspicious execution, injection, and risk scoring
src/detectors/behavioral.rs - DNS anomaly · DNS tunneling and C2-style pattern detection
src/detectors/dns_anomaly.rs - Registry det · Registry-focused detection logic
src/detectors/registry.rs
Support
Persistence, networking stubs, and shared helpers
- Storage · Compressed persistence and retention management
src/storage.rs - Network API · Placeholder networking surface; no backend channel yet
src/network.rs
Validation
Standalone test drivers and platform coverage
- Integration test · End-to-end scenario coverage for the agent pipeline
src/bin/test_integration.rs - Linux test · Linux-focused detection scenarios
test_linux_detection.rs - Mac test · macOS-focused detection scenarios
test_mac_detection.rs - DNS test · DNS anomaly detection coverage
test_dns_anomaly_detection.rs
Connections 31
- Library → Agent: orchestrates · Library wires the agent runtime
- Library → Config: loads · Configuration boundary for the crate
- Library → Events: defines · Shared event model used across the pipeline
- Library → Collector mgr: exposes · Collector subsystem entry point
- Library → Deduplication: includes · Noise suppression layer
- Library → Detector mgr: exposes · Detection subsystem entry point
- Library → Storage: includes · Persistence and retention layer
- Agent → Config: reads · Agent bootstraps from config
- Agent → Collector mgr: starts · Agent enables collectors during runtime
- Agent → Deduplication: gates · Agent applies deduplication before downstream processing
- Agent → Detector mgr: dispatches · Agent sends normalized events to detectors
- Agent → Storage: persists · Agent stores collected output and findings
- Collector mgr → Process: runs · Process telemetry source
- Collector mgr → File: runs · File telemetry source
- Collector mgr → Network: runs · Network telemetry source
- Collector mgr → Registry: runs · Registry telemetry source
- Process → Events: emits · Collects into the shared event model
- File → Events: emits · Collects into the shared event model
- Network → Events: emits · Collects into the shared event model
- Registry → Events: emits · Collects into the shared event model
- Deduplication → Detector mgr: feeds · Reduced event stream enters analysis
- Detector mgr → Behavioral: dispatches · Behavioral analysis rules
- Detector mgr → DNS anomaly: dispatches · DNS anomaly rules
- Detector mgr → Registry det: dispatches · Registry detection rules
- Detector mgr → Storage: records · Detection output can be persisted
- Agent → Network API: does not use · Repository currently lacks a backend or phone-home channel
- EDR main → Agent: launches · Executable entry point starts the agent
- Integration test → Agent: exercises · End-to-end pipeline coverage
- Linux test → Behavioral: covers · Linux platform detection behavior
- Mac test → Behavioral: covers · macOS platform detection behavior
- DNS test → DNS anomaly: covers · DNS anomaly scenario coverage