# mythicagents/kharon architecture

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

- Interactive diagram: https://gitdiagram.com/mythicagents/kharon
- Repository: https://github.com/mythicagents/kharon

## Overview

##### Project Type & Purpose
- Type: A multi-component C2 (Command & Control) Agent for the Mythic framework.
- Purpose:
– Agent: Position-Independent Code (PIC) shellcode that executes in memory, supports various execution methods (DOTNET, PowerShell, shellcode, BOF).
– Loader: A small executable that drops/executes the agent in memory.
– Modules: Precompiled Beacon Object Files (BOFs), shellcode binaries, and .NET executables providing payload functionality.
– Mythic Integration: Python code that translates tasks to agent instructions and communicates over RabbitMQ.

##### File Structure
– Payload_Type/kharon/Agent: C++ code (Include/, Source/, Makefile) producing PIC shellcode.
– Payload_Type/kharon/Loader: C++ loader that invokes the agent in memory.
– Payload_Type/kharon/Modules:
- BOF subfolder: dozens of .x64.o modules.
- Dotnet: .exe payloads.
- Shellcode: .bin payloads.
– Payload_Type/kharon/Mythic: Python scripts for AgentFunctions, BrowserScripts, Translator, plus rabbitmq_config.json.
– Root files: config.json, agent_capabilities.json, example_profile.conf, README.md.

##### README Insights
– Agent supports HTTP/S and SMB named-pipe C2 channels.
– Evasion features: hardware breakpoints, sleep/heap obfuscation, indirect syscalls, call-stack spoofing.
– Execution methods: .NET, PowerShell (via PowerPick), generic shellcode, BOF.
– Lateral movement: WMI, SCM, WinRM via COM.
– Misc commands: registry, SC manager, token manipulation, network info, Slack cookies, Kerberos.

##### Main Components & Interactions
a. Target Host Components (Payload_Type/kharon):
1) Loader.exe
– Starts the agent in memory.
– Configured by Loader/Config.h and Makefile.
2) Agent Shellcode (PIC)
– Core engine (Source/Main.cc) with submodules: Communication, Evasion, Internals, Misc.
– Implements C2 beacons via HTTP/S or SMB.
3) Payload Modules
– BOF (.o), .NET executables, shellcode binaries injected and executed inline.
b. C2 Infrastructure (Mythic Server):
1) RabbitMQ Broker (rabbitmq_config.json)
2) Translator: Python service mapping Mythic tasks ↔ agent payloads (Translator/Translator.py).
3) AgentFunctions: Python scripts per command (e.g., arp.py, dns cache) that define how tasks are executed on target.
4) BrowserScripts: JS snippets for Mythic UI to launch tasks.
c. Data Flows & Relationships
– Loader.exe → injects Agent Shellcode into Target Process.
– Agent Shellcode ↔ RabbitMQ via C2 channels (HTTP/S or SMB).
– RabbitMQ → Translator → Mythic Core UI/Tasks.
– Mythic UI → AgentFunctions → RabbitMQ → Agent.
– Agent downloads and loads Payload Modules at runtime.

##### Architectural Patterns & Principles
– Modular design: Agent code is organized by function (Communication, Evasion, Internals, Misc).
– Plugin architecture: Modules folder holds payloads; new BOFs or shellcode can be dropped in.
– Message broker (RabbitMQ) decouples server UI (Mythic) from agent comms.
– Position-Independent Code for stealth and in-memory execution.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Target Host Components
    subgraph "Target Host"
        direction TB
        Loader["Loader.exe"]:::target
        subgraph "Agent Shellcode (PIC)"
            direction TB
            AgentCore["Core Engine"]:::target
            Com["Communication Layer"]:::target
            Eva["Evasion Layer"]:::target
            Int["Internals"]:::target
            Misc["Misc Utilities"]:::target
        end
        Modules["Payload Modules"]:::modules
    end

    %% C2 Infrastructure
    subgraph "C2 Infrastructure"
        direction TB
        RabbitMQ["RabbitMQ Broker"]:::server
        Translator["Translator Service"]:::server
        AF["AgentFunctions"]:::server
        BS["BrowserScripts"]:::server
        UI["Mythic UI"]:::server
    end

    %% Data Flows
    Loader -->|"injects into"| AgentCore
    AgentCore -->|"loads modules"| Modules
    AgentCore -->|"HTTP/S"| RabbitMQ
    AgentCore -.->|"SMB Named Pipe"| RabbitMQ
    RabbitMQ -->|"messages"| Translator
    Translator -->|"tasks"| UI
    UI -->|"user commands"| AF
    AF -->|"instructions"| RabbitMQ
    RabbitMQ -->|"C2 traffic"| AgentCore

    %% Click Events
    click Loader "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Loader/Bin/Kharon.x64.exe"
    click Loader "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Loader/Main.cc"
    click Loader "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Loader/Config.h"
    click Loader "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Loader/Externs.h"
    click Loader "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Loader/Makefile"
    click AgentCore "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Agent/Source/Main.cc"
    click AgentCore "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Agent/Makefile"
    click AgentCore "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Agent/Linker.ld"
    click Com "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Agent/Source/Communication/"
    click Eva "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Agent/Source/Evasion/"
    click Int "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Agent/Source/Internals/"
    click Misc "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Agent/Source/Misc/"
    click Modules "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Modules/BOF/"
    click Modules "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Modules/Dotnet/"
    click Modules "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Modules/Shellcode/"
    click RabbitMQ "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Mythic/rabbitmq_config.json"
    click Translator "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Mythic/Translator/Translator.py"
    click Translator "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Mythic/Translator/ToAgent.py"
    click Translator "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Mythic/Translator/ToC2.py"
    click Translator "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Mythic/Translator/Utils.py"
    click AF "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Mythic/Kharon/AgentFunctions/"
    click BS "https://github.com/mythicagents/kharon/tree/main/Payload_Type/kharon/Mythic/Kharon/BrowserScripts/"
    click UI "https://github.com/mythicagents/kharon/blob/main/Payload_Type/kharon/Mythic/main.py"

    %% Styles
    classDef target fill:#ff6666,stroke:#aa0000,color:#000
    classDef modules fill:#ffcc66,stroke:#cc9900,color:#000
    classDef server fill:#66ccff,stroke:#0099cc,color:#000
```
