# dobin/rededr architecture

> Architecture diagram of the GitHub repository dobin/rededr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dobin/rededr
- Repository: https://github.com/dobin/rededr

## Overview

##### Main Components
a. Client Interface & Main Application:
- RedEdr.exe is the core executable that initiates the telemetry consumption, configures the consumers, and potentially provides the web server functionality (via webserver.cpp) to present data.
b. Event Telemetry Consumers:
- ETW Consumer: Captures ETW events from various Windows channels (e.g., Kernel-Process, Security-Auditing).
- ETW-TI Consumer: Integrated with the PPL service (RedEdrPplService) using an ELAM driver for threat intelligence.
- Kernel Callbacks: Uses routines like PsSetCreateProcessNotifyRoutine, etc.
- AMSI-style ntdll.dll Hooking: Performed by both kernelspace (via KAPC injection) and userspace (via ETW-based methods).
- Process Query Mechanisms: For detailed process information (using the PEB, loaded DLLs, etc.).
c. Supporting Modules:
- Event Aggregation: The pipeline where events, once captured, are passed on downstream for further processing.
- Data/Output: Stores JSON files (as seen in the Data/ folder) and provides web server outputs.
d. Inter-Process Communication (IPC):

##### Relationships & Data Flow
- The event sources (ETW, kernel callbacks, and ntdll.dll hooking via DLL injection) deliver their events (raw telemetry) to a central Event Aggregator or Pipeline within RedEdr.exe.
- The Event Aggregator then sends the event data to the Event Processor, which might involve separate submodules:
- Event Augmenter: Enriches or correlates the event data.
- Event Detection: Applies rules to flag anomalies or malicious behavior.
- Process Query: Gathers additional process information.
- Processed events are subsequently output via multiple interfaces: Web server logs, file-based JSON output in the Data folder, and possibly alerts.
- The IPC channels manage configuration, control, and continuous event delivery between these modules and the external components (e.g., the kernel module, DLL injection module, ETW-TI service).

##### Architectural Patterns
- A layered/pipeline architecture is evident – from event capture, through aggregation and processing, to final output.
- The design uses modularity for clear separation: each telemetry consumer (ETW, Kernel, etc.) is separated, and the processing pipeline is split into distinct functional blocks.

##### Relevant Technologies & Libraries
- C++ is the primary language, compiled with Visual Studio (as indicated by .vcxproj files).
- Windows-specific APIs like VirtualAlloc, CreateThread, and ETW APIs are in use.
- The presence of kernel driver components necessitates inclusion of the driver module and its relationship to the main application (e.g., how configuration data and event streams are exchanged via IOCTL and pipe communication).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Space"
        MainApp["Main Executable (RedEdr.exe)"]:::user
        ETWReader["ETW Reader"]:::user
        EventAggregator["Event Aggregator"]:::user
        DLLInjector["DLL Injector"]:::user
        InjectedDLL["Injected DLL (RedEdrDll)"]:::user
        EventAugmenter["Event Augmenter"]:::user
        EventDetector["Event Detector"]:::user
        ProcessQuery["Process Query"]:::user
        WebServer["Web Server (Output)"]:::user
        DataOutput["Data Output (JSON)"]:::user
        KernelInterface["Kernel Interface"]:::user
        PipingUtility["Piping Utility"]:::user
    end

    subgraph "Kernel Space"
        KernelDriver["Kernel Driver"]:::kernel
        PPLService["ETW-TI Service (PPL)"]:::kernel
    end

    %% Data Flow in User Space
    MainApp -->|"capturesTelemetry"| ETWReader
    ETWReader -->|"forwardsEvents"| EventAggregator
    EventAggregator -->|"enrichesData"| EventAugmenter
    EventAugmenter -->|"detectsAnomalies"| EventDetector
    EventDetector -->|"queriesProcess"| ProcessQuery
    ProcessQuery -->|"outputsData"| WebServer
    ProcessQuery -->|"savesJSON"| DataOutput
    MainApp -->|"initiatesInjection"| DLLInjector
    DLLInjector -->|"injectsHook"| InjectedDLL

    %% IPC Communication between User Space and Kernel Space
    MainApp -->|"IPC:KERNEL_PIPE"| KernelDriver
    MainApp -->|"IPC:DLL_PIPE"| InjectedDLL
    MainApp -->|"IPC:PPL_PIPE"| PPLService
    KernelDriver ---|"IOCTL"| MainApp

    %% Supporting IPC Utilities
    MainApp ---|"uses"| KernelInterface
    MainApp ---|"uses"| PipingUtility

    %% Click Events
    click MainApp "https://github.com/dobin/rededr/blob/master/RedEdr/RedEdr.cpp"
    click ETWReader "https://github.com/dobin/rededr/blob/master/RedEdr/etwreader.cpp"
    click EventAggregator "https://github.com/dobin/rededr/blob/master/RedEdr/event_aggregator.cpp"
    click DLLInjector "https://github.com/dobin/rededr/blob/master/RedEdr/dllinjector.cpp"
    click InjectedDLL "https://github.com/dobin/rededr/blob/master/RedEdrDll/dllmain.cpp"
    click EventAugmenter "https://github.com/dobin/rededr/blob/master/RedEdr/event_augmenter.cpp"
    click EventDetector "https://github.com/dobin/rededr/blob/master/RedEdr/event_detector.cpp"
    click ProcessQuery "https://github.com/dobin/rededr/blob/master/RedEdrShared/process_query.cpp"
    click WebServer "https://github.com/dobin/rededr/blob/master/RedEdr/webserver.cpp"
    click DataOutput "https://github.com/dobin/rededr/blob/master/Data/dostuff.events.json"
    click KernelInterface "https://github.com/dobin/rededr/blob/master/RedEdr/kernelinterface.cpp"
    click PipingUtility "https://github.com/dobin/rededr/blob/master/RedEdrShared/piping.cpp"
    click KernelDriver "https://github.com/dobin/rededr/blob/master/RedEdrDriver/kcallbacks.c"
    click PPLService "https://github.com/dobin/rededr/blob/master/RedEdrPplService/RedEdrPplService.cpp"

    %% Styles
    classDef user fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef kernel fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef ipc fill:#d4edda,stroke:#155724,stroke-width:2px;
```
