How mythicagents/kharon works
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.