How mahmutp/mah-framework works
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: module_manager.py Module loader · __init__.py Built-ins · payloads Payloads · command_manager.py Command router
Components 21
Runtime core
Interactive shell, command routing, and shared state
- Launcher · Starts the CLI and selects launch mode
main.py - Shell UI · Prompt-driven console and terminal output layer
core/console.py - Command router · Parses input and dispatches built-in commands
core/command_manager.py - Built-ins · Framework control, workflow, and maintenance commands
commands/__init__.py - Sessions · Tracks live shells and payload connections
core/session_manager.py - Shared state · Cross-cutting state shared across commands and handlers
core/shared_state.py - Logging · Application logging, history, and recording support
core/logger.py
Extensions
Modules, payloads, plugins, and build-time artifact tooling
- Module loader · Loads modules, options, and execution metadata
core/module_manager.py - Module API · Common module, option, and handler abstractions
core/module.py - Auxiliary · Recon, scanning, analysis, forensics, and OS utilities
modules/auxiliary - Exploits · Exploit modules and multi/handler coordination
modules/exploit - Post-exploit · Gathering, persistence, and pivoting tasks
modules/post - Payloads · Generators and handlers for multi-target payloads
modules/payloads - Chimera · Python agent-based payload with generate, handler, and examples
modules/payloads/python/chimera - Mahpreter · Interactive Python and HTTP/DNS payload family
modules/payloads/python/mahpreter - Plugins · First-class runtime extensions separate from modules
plugins - Repo sync · Remote repository, download, and update workflow
core/repo_manager.py - Build tools · Chimera construction, obfuscation, and polymorphism
build/chimera_builder.py - Encoders · Reusable payload and output transformations
core/encoders/manager.py
Assets
Configuration, templates, and local data files
- Config data · Repos, aliases, and bundled wordlists
config/repos.json - Templates · Starter files for modules and plugins
templates/module_template.py
Connections 24
- 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