# bytecode77/r77-rootkit architecture

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

- Interactive diagram: https://gitdiagram.com/bytecode77/r77-rootkit
- Repository: https://github.com/bytecode77/r77-rootkit

## Overview

##### Project Type and Purpose
- The project is a security tool—in this case, a fileless user-mode (ring 3) rootkit—whose purpose is silently to hide and obfuscate system components.
- The README confirms that it hides files, directories, processes, registry keys, TCP/UDP connections, etc., using multiple evasion techniques (AMSI bypass, DLL unhooking, etc.), with its configuration stored in the Windows registry under a hidden key.

##### File Structure and Components
- Core Rootkit Modules:
- The “r77” directory contains the core source code (configuration, hooks, rootkit functionality).
- The “r77api” folder provides auxiliary API functions to interact with system components (such as manipulating PEB structures, setting hooks, etc.).
- Installation and Injection:
- “Install”, “InstallShellcode”, and “Uninstall” directories hold the installer and uninstaller programs, as well as the shellcode for fileless installation.
- “Stager” is responsible for the code injection and stager logic which helps launch the payload.
- Process Injection and Reflective Loading:
- “ReflectiveDllMain” supplies the reflective DLL entry-point mechanisms needed for injecting the rootkit code into other processes.
- Services and Runtime Components:
- “Service”, “Service32”, and “Service64” indicate components that run as services or background processes to maintain the rootkit's presence.
- Helper and Supporting Code:
- “Helper”, “Helper32”, “Helper64” directories provide common utilities and support files.
- The “TestConsole” and “Example” directories contain test applications and examples; “TestConsole” is especially important for inject testing and configuration system debugging.
- Assembly and Manual Code:
- “InstallShellcode” and “Unhook” include assembly files (with .asm extensions) that illustrate low-level operations, which are essential for AV/EDR evasion.
- Build Resources:
- The “SlnBin” directory holds important build artifacts such as the FASM binaries and supporting include files for hook-related APIs.

##### Key Components and Their Relationships
- Installation Phase:
- Installer (found in “Install” and “InstallShellcode”) is the entry point, which, when executed, loads the shellcode or runs Install.exe to inject the rootkit into running processes.
- The shellcode version demonstrates fileless installation techniques.
- Injection and Staging:
- The “Stager” module is used to inject the rootkit’s code into various processes.
- “ReflectiveDllMain” provides the entry point for the injection by enabling reflective DLL loading.
- Core Rootkit Engine:
- The “r77” and “r77api” modules are responsible for hooking APIs, hiding system components (files, directories, processes, etc.), and ensuring persistence.
- Global configurations and constants (in “Global” and configuration files) manage the dynamic configuration stored in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\$77config.
- Monitoring/Service Components:
- The “Service” set of projects is used to monitor system events (like process creation) and apply hooks dynamically.
- Auxiliary Tools:
- The “TestConsole” application acts as a control panel for testing, injecting, and debugging the rootkit behavior.
- The “Example” projects provide reference implementations for using core functionalities (e.g., CPU usage monitoring, control pipe communication).

##### Architectural Patterns and Design Principles to Highlight
- Fileless Execution: Emphasize that the rootkit resides purely in memory and does not leave traces on disk after installation.
- Dynamic Configuration: Illustrate the dynamic configuration mechanism that uses the registry (with the hidden “$77config” key) to control what is hidden and how.
- AV/EDR Evasion Techniques: Include components responsible for AMSI bypass, DLL unhooking, and low-level system patching.
- 32-bit vs. 64-bit Handling: Note that the project includes separate builds for 32-bit and 64-bit environments (e.g., directories Helper32, Helper64, Service32, Service64, r77-x86, and r77-x64).

##### Detail for the Principal Software Engineer
- Subsystem is clearly demarcated:
- Installer: “Install”, “InstallShellcode”
- Injection/Staging: “Stager”, “ReflectiveDllMain”
- Core Rootkit: “r77”, “r77api” (along with “Global” definitions and hooks)
- Evasion Techniques: “Unhook” module and FASM builds in “SlnBin”
- Support and testing: “TestConsole” and “Example”
- Modules written in C/C++ (core and system-level code)
- Modules written in C# (e.g., some helper or testing UIs)
- Assembly routines (for low-level AV bypass and injection)

- How the installation/injection process initiates the rootkit’s operation,
- How core engine components hook and hide system objects,
- How auxiliary modules such as the configuration system and TestConsole integrate with the main engine,
- And how AV/EDR evasion strategies are implemented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Installation Phase
    subgraph "Installation Phase"
        a1("Install (Installer)"):::installer
        a2("InstallShellcode (Shellcode Installer)"):::installer
    end

    %% Injection Phase
    subgraph "Injection Phase"
        b("Stager (Code Injector)"):::injection
        c("ReflectiveDllMain (Reflective Loading)"):::injection
    end

    %% Core Engine and Configuration
    subgraph "Core Engine and Configuration"
        d("r77 (Rootkit Core)"):::core
        e("r77api (API Hooks)"):::core
        f("Global Config"):::config
        g("r77api Config"):::config
    end

    %% Subsystems
    subgraph "Subsystems"
        h("Service/Monitoring"):::subsystem
        i("Helper Utilities"):::subsystem
        j("AV/EDR Evasion"):::subsystem
        k("TestConsole"):::subsystem
        m("Example"):::subsystem
    end

    %% External Dependencies
    subgraph "External Dependencies"
        l("Registry ($77config)"):::registry
    end

    %% Connections: Installation to Injection
    a1 --> b
    a2 --> b
    b --> c

    %% Connections: Injection to Core Engine
    c --> d
    c --> e

    %% Connections: Registry drives Configuration
    l --> f
    l --> g
    f --> d
    g --> e

    %% Connections: Core Engine to Subsystems
    d --> h
    d --> i
    d --> j
    d --> k
    d --> m
    e --> h
    e --> i
    e --> j
    e --> k
    e --> m

    %% Click Events
    click a1 "https://github.com/bytecode77/r77-rootkit/blob/master/Install/Install.c"
    click a2 "https://github.com/bytecode77/r77-rootkit/blob/master/InstallShellcode/InstallShellcode.asm"
    click b "https://github.com/bytecode77/r77-rootkit/blob/master/Stager/Stager.cs"
    click c "https://github.com/bytecode77/r77-rootkit/blob/master/ReflectiveDllMain/ReflectiveDllMain.c"
    click d "https://github.com/bytecode77/r77-rootkit/tree/master/r77"
    click e "https://github.com/bytecode77/r77-rootkit/tree/master/r77api"
    click f "https://github.com/bytecode77/r77-rootkit/blob/master/Global/GlobalAssemblyInfo.cs"
    click g "https://github.com/bytecode77/r77-rootkit/blob/master/r77api/r77config.[ch]"
    click h "https://github.com/bytecode77/r77-rootkit/blob/master/Service/Service.c"
    click i "https://github.com/bytecode77/r77-rootkit/blob/master/Helper/Helper.c"
    click j "https://github.com/bytecode77/r77-rootkit/blob/master/Unhook/Unhook.c"
    click k "https://github.com/bytecode77/r77-rootkit/tree/master/TestConsole"
    click m "https://github.com/bytecode77/r77-rootkit/tree/master/Example"

    %% Styles
    classDef installer fill:#f9c74f,stroke:#000,stroke-width:1px;
    classDef injection fill:#90be6d,stroke:#000,stroke-width:1px;
    classDef core fill:#577590,stroke:#000,stroke-width:1px,color:#fff;
    classDef config fill:#f94144,stroke:#000,stroke-width:1px,color:#fff;
    classDef subsystem fill:#f3722c,stroke:#000,stroke-width:1px,color:#fff;
    classDef registry fill:#277da1,stroke:#000,stroke-width:1px,color:#fff;
    
    class a1,a2 installer;
    class b,c injection;
    class d,e core;
    class f,g config;
    class h,i,j,k,m subsystem;
    class l registry;
```
