# mahmutp/mah-framework architecture

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

- Interactive diagram: https://gitdiagram.com/mahmutp/mah-framework
- Repository: https://github.com/mahmutp/mah-framework

## Overview

1. **What this repo is**
   - This is a Python 3.8+ CLI framework for security-oriented workflows, not a web app.
   - The runtime center is an interactive shell that lets users load modules, set options, run tasks, manage sessions, and launch payload handlers.

2. **Top-level entry and shell lifecycle**
   - `main.py` starts the application and supports startup modes like quiet launch, resource-file execution, and direct command execution.
   - The shell UI is built around `core/console.py`, with richer terminal interaction via `prompt_toolkit` and output formatting via `rich`.

3. **Command pipeline**
   - Built-in CLI commands live in `commands/` and cover framework control and orchestration: help, exit, banner, use, set/unset, run, show, resource, record, sessions, repo, plugins, reload, checkupdate, and others.
   - `core/command_manager.py` and `core/command.py` appear to route parsed input to the right command object, while `core/completer.py` and `core/history.py`-style behavior support shell ergonomics.

4. **Module loading and execution model**
   - The `modules/` tree is the main capability layer, organized by domain: `auxiliary`, `exploit`, `payloads`, `post`, and `example`.
   - `core/module_manager.py`, `core/module.py`, `core/option.py`, and `core/handler.py` likely define the common module contract: load metadata, expose options, accept runtime parameters, then execute.

5. **Functional module families**
   - `auxiliary/` contains recon, scanners, analysis, forensics, OS utilities, and helper tools.
   - `exploit/` contains exploit modules and a unified `multi/handler`.
   - `post/` contains post-exploitation tasks like gathering, persistence, and pivoting.
   - `payloads/` contains generators/handlers for multiple targets and transports, including Python, Linux shell, PHP, Java JSP, Windows HTA/PowerShell/ASPX, and the custom `mahpreter` family.

6. **Payload/agent architecture**
   - Payload folders usually split into `generate.py` plus a `handler.py`, indicating a two-sided design: generation of the artifact and a listener/receiver for incoming connections.
   - The Python `chimera` and `mahpreter` payload trees are special because they include agent code, examples, and dedicated handlers, suggesting a more interactive agent-based channel than one-shot payloads.

7. **Session and shared state**
   - `core/session_manager.py` is the state hub for multiple live connections, especially shells and payload sessions.
   - `core/shared_state.py` and `core/cont.py` likely carry cross-cutting runtime state between commands, modules, and handlers so that interactive tasks can be resumed, listed, or killed.

8. **Plugins and extensibility**
   - `plugins/` is a separate extension layer from `modules/`, with its own manager/downloader and examples like `audit_logger` and `resource_monitor`.
   - `core/plugin_manager.py`, `core/plugin_downloader.py`, and `core/plugin.py` indicate plugins are first-class runtime extensions rather than simple scripts.
   - `templates/plugin_template.py` and `templates/module_template.py` show the intended contribution boundary for new extensions.

9. **Repository/update/download subsystem**
   - The framework can pull content from remote sources via `core/repo_manager.py`, `core/module_downloader.py`, and `core/plugin_downloader.py`.
   - Commands like `repo`, `download`, `checkupdate`, and `reload` form the maintenance/update path, with `config/repos.json` and `config/aliases.json` acting as local registry/config inputs.
   - `modules/auxiliary/recon/github_tracker.py` also hints at external GitHub integration as part of the ecosystem.

10. **Encoders and transformation layer**
   - `core/encoders/` provides reusable transforms such as base64, hex, rot13, unicode escape, and xor.
   - This looks like a utility boundary used by payload generation, module output shaping, or obfuscation-adjacent workflows rather than by the shell itself.

11. **Build and obfuscation tooling**
   - `build/chimera_builder.py`, `build/chimera_obfuscator.py`, and `build/chimera_polymorphic.py` are a separate build-time subsystem for constructing or transforming Chimera artifacts.
   - These are not core shell components; they sit on the artifact-generation path and likely feed the `chimera` payload family.

12. **Configuration, wordlists, and local assets**
   - `config/` contains runtime configuration, local repo metadata, aliases, and bundled wordlists for directories, subdomains, and passwords.
   - That means many scanners/recon modules are data-driven and depend on local curated input files rather than external services.

13. **Logging, history, and recording**
   - `core/logger.py` and the README’s `config/logs/` note indicate structured application logging with rotation/retention.
   - `commands/record.py`, `commands/history.py`, and the `.mah_history` mechanism form a command audit/replay path for user workflows and macro generation.

14. **Testing and quality boundaries**
   - The repo has extensive `pytest` coverage under `tests/`, including dedicated Chimera, module-loading, plugin, session, repo, scanner, and handler tests.
   - This suggests the main architectural seams are the command dispatcher, module/plugin loaders, payload handlers, and the session/protocol layers.

15. **How to diagram it**
   - A good architecture diagram should show: user input → shell/command manager → command dispatch → module/plugin/repo/session subsystems → handlers/sessions/logging.
   - Then branch the capabilities into `modules/`, `payloads/`, `post/`, `plugins/`, and `build/`, with `config/` and `templates/` as supporting assets.

Main entry points: [`core/module_manager.py`](https://github.com/mahmutp/mah-framework/blob/main/core/module_manager.py) (Module loader), [`commands/__init__.py`](https://github.com/mahmutp/mah-framework/blob/main/commands/__init__.py) (Built-ins), [`modules/payloads`](https://github.com/mahmutp/mah-framework/tree/main/modules/payloads) (Payloads), [`core/command_manager.py`](https://github.com/mahmutp/mah-framework/blob/main/core/command_manager.py) (Command router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime core"]
  node_main["Launcher<br/>entrypoint<br/>[main.py]"]
  node_console["Shell UI<br/>interactive shell<br/>[console.py]"]
  node_cmdmgr["Command router<br/>dispatcher<br/>[command_manager.py]"]
  node_cmds["Built-ins<br/>commands<br/>[__init__.py]"]
  node_session["Sessions<br/>state manager<br/>[session_manager.py]"]
  node_shared["Shared state<br/>runtime state<br/>[shared_state.py]"]
  node_logger["Logging<br/>observability<br/>[logger.py]"]
end

subgraph group_extensions["Extensions"]
  node_modulemgr["Module loader<br/>module manager<br/>[module_manager.py]"]
  node_modulebase["Module API<br/>module contract<br/>[module.py]"]
  node_aux["Auxiliary<br/>module family"]
  node_exploit["Exploits<br/>module family"]
  node_post["Post-exploit<br/>module family"]
  node_payloads["Payloads<br/>artifact family"]
  node_chimera["Chimera<br/>agent payload"]
  node_mahpreter["Mahpreter<br/>agent payload"]
  node_plugins["Plugins<br/>extension layer"]
  node_repo["Repo sync<br/>content manager<br/>[repo_manager.py]"]
  node_builder["Build tools<br/>artifact build<br/>[chimera_builder.py]"]
  node_encoders["Encoders<br/>transform layer<br/>[manager.py]"]
end

subgraph group_assets["Assets"]
  node_config[("Config data<br/>local assets<br/>[repos.json]")]
  node_templates["Templates<br/>scaffolding<br/>[module_template.py]"]
end

node_main -->|"starts"| node_console
node_main -->|"bootstraps"| node_cmdmgr
node_console -->|"submits"| node_cmdmgr
node_cmdmgr -->|"routes"| node_cmds
node_cmds -->|"use/run"| node_modulemgr
node_cmds -->|"sessions"| node_session
node_cmds -->|"repo/download"| node_repo
node_cmds -->|"plugins"| node_plugins
node_cmds -->|"record/history"| node_logger
node_cmdmgr -->|"shares"| node_shared
node_modulemgr -->|"contracts"| node_modulebase
node_modulemgr -->|"loads"| node_aux
node_modulemgr -->|"loads"| node_exploit
node_modulemgr -->|"loads"| node_post
node_modulemgr -->|"loads"| node_payloads
node_payloads -->|"specializes"| node_chimera
node_payloads -->|"specializes"| node_mahpreter
node_payloads -->|"feeds"| node_builder
node_payloads -->|"transforms"| node_encoders
node_plugins -->|"configures"| node_config
node_aux -->|"uses"| node_config
node_repo -->|"reads"| node_config
node_modulemgr -.->|"scaffolds"| node_templates
node_plugins -.->|"scaffolds"| node_templates

click node_main "https://github.com/mahmutp/mah-framework/blob/main/main.py"
click node_console "https://github.com/mahmutp/mah-framework/blob/main/core/console.py"
click node_cmdmgr "https://github.com/mahmutp/mah-framework/blob/main/core/command_manager.py"
click node_cmds "https://github.com/mahmutp/mah-framework/blob/main/commands/__init__.py"
click node_session "https://github.com/mahmutp/mah-framework/blob/main/core/session_manager.py"
click node_shared "https://github.com/mahmutp/mah-framework/blob/main/core/shared_state.py"
click node_modulemgr "https://github.com/mahmutp/mah-framework/blob/main/core/module_manager.py"
click node_modulebase "https://github.com/mahmutp/mah-framework/blob/main/core/module.py"
click node_aux "https://github.com/mahmutp/mah-framework/tree/main/modules/auxiliary"
click node_exploit "https://github.com/mahmutp/mah-framework/tree/main/modules/exploit"
click node_post "https://github.com/mahmutp/mah-framework/tree/main/modules/post"
click node_payloads "https://github.com/mahmutp/mah-framework/tree/main/modules/payloads"
click node_chimera "https://github.com/mahmutp/mah-framework/tree/main/modules/payloads/python/chimera"
click node_mahpreter "https://github.com/mahmutp/mah-framework/tree/main/modules/payloads/python/mahpreter"
click node_plugins "https://github.com/mahmutp/mah-framework/tree/main/plugins"
click node_repo "https://github.com/mahmutp/mah-framework/blob/main/core/repo_manager.py"
click node_builder "https://github.com/mahmutp/mah-framework/blob/main/build/chimera_builder.py"
click node_encoders "https://github.com/mahmutp/mah-framework/blob/main/core/encoders/manager.py"
click node_config "https://github.com/mahmutp/mah-framework/blob/main/config/repos.json"
click node_templates "https://github.com/mahmutp/mah-framework/blob/main/templates/module_template.py"
click node_logger "https://github.com/mahmutp/mah-framework/blob/main/core/logger.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_console,node_cmdmgr,node_cmds,node_session,node_shared,node_logger toneBlue
class node_modulemgr,node_modulebase,node_aux,node_exploit,node_post,node_payloads,node_chimera,node_mahpreter,node_plugins,node_repo,node_builder,node_encoders toneAmber
class node_config,node_templates toneMint
```

## Components

### Runtime core

Interactive shell, command routing, and shared state

- [Launcher](https://github.com/mahmutp/mah-framework/blob/main/main.py): entrypoint · Starts the CLI and selects launch mode · `main.py`
- [Shell UI](https://github.com/mahmutp/mah-framework/blob/main/core/console.py): interactive shell · Prompt-driven console and terminal output layer · `core/console.py`
- [Command router](https://github.com/mahmutp/mah-framework/blob/main/core/command_manager.py): dispatcher · Parses input and dispatches built-in commands · `core/command_manager.py`
- [Built-ins](https://github.com/mahmutp/mah-framework/blob/main/commands/__init__.py): commands · Framework control, workflow, and maintenance commands · `commands/__init__.py`
- [Sessions](https://github.com/mahmutp/mah-framework/blob/main/core/session_manager.py): state manager · Tracks live shells and payload connections · `core/session_manager.py`
- [Shared state](https://github.com/mahmutp/mah-framework/blob/main/core/shared_state.py): runtime state · Cross-cutting state shared across commands and handlers · `core/shared_state.py`
- [Logging](https://github.com/mahmutp/mah-framework/blob/main/core/logger.py): observability · Application logging, history, and recording support · `core/logger.py`

### Extensions

Modules, payloads, plugins, and build-time artifact tooling

- [Module loader](https://github.com/mahmutp/mah-framework/blob/main/core/module_manager.py): module manager · Loads modules, options, and execution metadata · `core/module_manager.py`
- [Module API](https://github.com/mahmutp/mah-framework/blob/main/core/module.py): module contract · Common module, option, and handler abstractions · `core/module.py`
- [Auxiliary](https://github.com/mahmutp/mah-framework/tree/main/modules/auxiliary): module family · Recon, scanning, analysis, forensics, and OS utilities · `modules/auxiliary`
- [Exploits](https://github.com/mahmutp/mah-framework/tree/main/modules/exploit): module family · Exploit modules and multi/handler coordination · `modules/exploit`
- [Post-exploit](https://github.com/mahmutp/mah-framework/tree/main/modules/post): module family · Gathering, persistence, and pivoting tasks · `modules/post`
- [Payloads](https://github.com/mahmutp/mah-framework/tree/main/modules/payloads): artifact family · Generators and handlers for multi-target payloads · `modules/payloads`
- [Chimera](https://github.com/mahmutp/mah-framework/tree/main/modules/payloads/python/chimera): agent payload · Python agent-based payload with generate, handler, and examples · `modules/payloads/python/chimera`
- [Mahpreter](https://github.com/mahmutp/mah-framework/tree/main/modules/payloads/python/mahpreter): agent payload · Interactive Python and HTTP/DNS payload family · `modules/payloads/python/mahpreter`
- [Plugins](https://github.com/mahmutp/mah-framework/tree/main/plugins): extension layer · First-class runtime extensions separate from modules · `plugins`
- [Repo sync](https://github.com/mahmutp/mah-framework/blob/main/core/repo_manager.py): content manager · Remote repository, download, and update workflow · `core/repo_manager.py`
- [Build tools](https://github.com/mahmutp/mah-framework/blob/main/build/chimera_builder.py): artifact build · Chimera construction, obfuscation, and polymorphism · `build/chimera_builder.py`
- [Encoders](https://github.com/mahmutp/mah-framework/blob/main/core/encoders/manager.py): transform layer · Reusable payload and output transformations · `core/encoders/manager.py`

### Assets

Configuration, templates, and local data files

- [Config data](https://github.com/mahmutp/mah-framework/blob/main/config/repos.json): local assets · Repos, aliases, and bundled wordlists · `config/repos.json`
- [Templates](https://github.com/mahmutp/mah-framework/blob/main/templates/module_template.py): scaffolding · Starter files for modules and plugins · `templates/module_template.py`

## Connections

- Launcher → Shell UI: starts · Launches the interactive shell
- Launcher → Command router: bootstraps · Initializes command routing and startup modes
- Shell UI → Command router: submits · Feeds parsed user input into command dispatch
- Command router → Built-ins: routes · Resolves built-in command objects
- Built-ins → Module loader: use/run · Loads and executes modules through the manager
- Built-ins → Sessions: sessions · Lists, selects, and controls live sessions
- Built-ins → Repo sync: repo/download · Maintains remote content and updates
- Built-ins → Plugins: plugins · Enables and reloads runtime extensions
- Built-ins → Logging: record/history · Captures command workflows and audit trail
- Command router → Shared state: shares · Uses shared runtime state across commands
- Module loader → Module API: contracts · Applies the common module/option/handler API
- Module loader → Auxiliary: loads · Discovers auxiliary capability modules
- Module loader → Exploits: loads · Discovers exploit modules
- Module loader → Post-exploit: loads · Discovers post-exploitation modules
- Module loader → Payloads: loads · Discovers payload generators and handlers
- Payloads → Chimera: specializes · Chimera agent payload pipeline
- Payloads → Mahpreter: specializes · Mahpreter agent and transport payloads
- Payloads → Build tools: feeds · Build tooling supports payload artifact creation
- Payloads → Encoders: transforms · Payload generation can reuse encoders
- Plugins → Config data: configures · Uses local registries and bundled data
- Auxiliary → Config data: uses · Data-driven recon and scanner inputs
- Repo sync → Config data: reads · Uses repository metadata and aliases
- Module loader → Templates: scaffolds · Supports new module creation from templates
- Plugins → Templates: scaffolds · Supports new plugin creation from templates
