# epinna/tplmap architecture

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

- Interactive diagram: https://gitdiagram.com/epinna/tplmap
- Repository: https://github.com/epinna/tplmap

## Overview

##### Project Type and Purpose
- Tplmap is a Python-based offensive security tool (CLI application) for automatically detecting and exploiting Server-Side Template Injection (SSTI) vulnerabilities across many template engines.
- It also ships a Burp Suite plugin for in-IDE testing and exploitation.

##### High-level Structure (from the file tree and README)
- Entry point: tplmap.py (command-line interface)
- Core logic in the “core” package (discovery, scanning, plugin loader, TCP server for shells)
- Plugin architecture under “plugins”:
- engines/ — engine-specific payloads and tests (Jinja2, Mako, ejs, Smarty, etc.)
- languages/ — generic code-eval contexts (python, php, ruby, javascript, java)
- Burp Suite extension in burp_extension/
- Utilities in utils/ (config parsing, argument parsing, logging, helpers)
- Configuration in config.yml
- Tests under tests/
- Docker environments under docker-envs/

##### Components
A.  CLI Application (tplmap.py)
- Parses command-line args (utils/cliparser.py)
- Loads config (utils/config.py → config.yml)
- Invokes core.clis.run()
B.  Core Framework (core/)
- Plugin Manager (core/plugin.py): discovers and loads plugins from plugins/
- Channel Abstraction (core/channel.py): handles HTTP requests and blind injections
- Scanner Checks (core/checks.py, core/scanner_check.py): runs detection and exploitation routines
- TCP Server (core/tcpserver.py): bind/reverse shell listeners
- Command dispatch (core/clis.py): maps CLI switches (--os-shell, --download, etc.) to actions
C.  Plugin Modules (plugins/)
- Engine Plugins: for each template engine, implement fingerprint, injection patterns, escape techniques
- Language Plugins: for generic code-eval contexts
D.  Burp Extension (burp_extension/)
- Uses Burp’s API to integrate into HTTP proxy, provides GUI tabs (config_tab.py), channels via burp_extender.py
- Reuses core/channel.py and core/scanner_check.py for scanning in the IDE
E.  Utilities (utils/)
- Logging (utils/loggers.py), string helpers, random payloads, closure templates
F.  External Dependencies and Services
- Target web application (HTTP/S server under test)
- Optional Docker test environments for each language
- Burp Suite (for the Burp plugin)

##### Relationships and Data Flow
- User runs tplmap.py → CLI parser → Core dispatcher
- Core loads and initializes plugins → for each parameter and plugin:
- Channel sends HTTP payloads to Target Web App
- Scanner Check orchestrates fingerprint tests, blind tests, exploitation routines
- On success, core/tcpserver may open a reverse or bind shell back to attacker
- Burp extension registers with Burp, hooks into HTTP traffic, delegates to core/channel and core/scanner_check

##### Architectural Patterns and Principles
- Plugin / Strategy pattern: engines and languages are decoupled modules discovered at runtime
- Single Responsibility: core handles orchestration, plugins encapsulate engine-specific logic, utils provide support functions
- Separation of Concerns: CLI vs core vs plugin vs extension vs tests
- Configuration-driven: YAML config and dynamic plugin loading

##### Essential Elements to Capture
- Explicit labels for:
- Entry point (tplmap.py)
- Core modules and their roles
- Plugin directories and their categories
- Utilities and config
- External dependencies (Target app, Docker, Burp Suite)
- CLI Layer
- Core Orchestration Layer
- Plugins Layer
- Integration/Extension Layer
- External Systems Layer

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI["tplmap.py"]:::core
        Cliparser["Command-line Parser"]:::util
        ConfigLoader["Config Loader"]:::util
        CliDispatcher["CLI Dispatcher"]:::core
    end

    %% Core Orchestration Layer
    subgraph "Core Orchestration Layer"
        PluginMgr["Plugin Manager"]:::core
        Channel["Channel Abstraction"]:::core
        Scanner["Scanner Checks"]:::core
        TCPServer["TCP Server"]:::core
    end

    %% Plugins Layer
    subgraph "Plugins Layer"
        subgraph "Engine Plugins" 
            Dot["dot"]:::plugin
            Dust["dust"]:::plugin
            EJS["ejs"]:::plugin
            ERB["erb"]:::plugin
            Freemarker["freemarker"]:::plugin
            Jinja2["jinja2"]:::plugin
            Mako["mako"]:::plugin
            Marko["marko"]:::plugin
            Nunjucks["nunjucks"]:::plugin
            Pug["pug"]:::plugin
            Slim["slim"]:::plugin
            Smarty["smarty"]:::plugin
            Tornado["tornado"]:::plugin
            Twig["twig"]:::plugin
            Velocity["velocity"]:::plugin
        end
        subgraph "Language Plugins"
            Bash["bash"]:::plugin
            JavaLang["java"]:::plugin
            JS["javascript"]:::plugin
            PHP["php"]:::plugin
            PythonLang["python"]:::plugin
            RubyLang["ruby"]:::plugin
        end
    end

    %% Extension Layer
    subgraph "Integration/Extension Layer"
        BurpExtender["Burp Extender"]:::ext
        BurpChannel["Burp Channel"]:::ext
        BurpScanner["Burp ScannerCheck"]:::ext
        ConfigTab["Config Tab"]:::ext
        ScanIssue["Scan Issue"]:::ext
    end

    %% Utilities & Config
    subgraph "Utilities & Config"
        Loggers["Loggers"]:::util
        Strings["Strings"]:::util
        Rand["Random Payloads"]:::util
        Closures["Closures"]:::util
        ConfigUtil["Config Utility"]:::util
        ConfigYML["config.yml"]:::util
    end

    %% External Systems
    subgraph "External Systems"
        Target["Target Web App"]:::external
        Docker["Docker Envs"]:::external
        BurpSuite["Burp Suite"]:::external
    end

    %% Connections
    CLI -->|parses args| Cliparser
    CLI -->|loads config| ConfigLoader
    CLI -->|dispatches commands| CliDispatcher

    CliDispatcher -->|initializes| PluginMgr
    CliDispatcher -->|uses| Channel
    CliDispatcher -->|uses| Scanner

    PluginMgr -->|discovers| Dot & Dust & EJS & ERB & Freemarker & Jinja2 & Mako & Marko & Nunjucks & Pug & Slim & Smarty & Tornado & Twig & Velocity
    PluginMgr -->|discovers| Bash & JavaLang & JS & PHP & PythonLang & RubyLang

    Scanner -->|runs checks via| Channel
    Channel -->|send payload| Target
    Target -->|response| Channel
    Scanner -->|on success spawns| TCPServer

    BurpSuite -->|hooks| BurpExtender
    BurpExtender -->|uses| BurpChannel
    BurpExtender -->|uses| BurpScanner
    BurpChannel -->|delegates| Channel
    BurpScanner -->|delegates| Scanner

    CLI -->|logs via| Loggers
    CLI -->|uses helpers| Strings & Rand & Closures
    ConfigLoader -->|reads| ConfigYML
    ConfigUtil -->|parses| ConfigYML

    Docker -->|provides| Target

    %% Click Events - CLI
    click CLI "https://github.com/epinna/tplmap/blob/master/tplmap.py"
    click Cliparser "https://github.com/epinna/tplmap/blob/master/utils/cliparser.py"
    click ConfigLoader "https://github.com/epinna/tplmap/blob/master/utils/config.py"
    click CliDispatcher "https://github.com/epinna/tplmap/blob/master/core/clis.py"

    %% Click Events - Core
    click PluginMgr "https://github.com/epinna/tplmap/blob/master/core/plugin.py"
    click Channel "https://github.com/epinna/tplmap/blob/master/core/channel.py"
    click Scanner "https://github.com/epinna/tplmap/blob/master/core/checks.py"
    click TCPServer "https://github.com/epinna/tplmap/blob/master/core/tcpserver.py"

    %% Click Events - Engine Plugins
    click Dot "https://github.com/epinna/tplmap/blob/master/plugins/engines/dot.py"
    click Dust "https://github.com/epinna/tplmap/blob/master/plugins/engines/dust.py"
    click EJS "https://github.com/epinna/tplmap/blob/master/plugins/engines/ejs.py"
    click ERB "https://github.com/epinna/tplmap/blob/master/plugins/engines/erb.py"
    click Freemarker "https://github.com/epinna/tplmap/blob/master/plugins/engines/freemarker.py"
    click Jinja2 "https://github.com/epinna/tplmap/blob/master/plugins/engines/jinja2.py"
    click Mako "https://github.com/epinna/tplmap/blob/master/plugins/engines/mako.py"
    click Marko "https://github.com/epinna/tplmap/blob/master/plugins/engines/marko.py"
    click Nunjucks "https://github.com/epinna/tplmap/blob/master/plugins/engines/nunjucks.py"
    click Pug "https://github.com/epinna/tplmap/blob/master/plugins/engines/pug.py"
    click Slim "https://github.com/epinna/tplmap/blob/master/plugins/engines/slim.py"
    click Smarty "https://github.com/epinna/tplmap/blob/master/plugins/engines/smarty.py"
    click Tornado "https://github.com/epinna/tplmap/blob/master/plugins/engines/tornado.py"
    click Twig "https://github.com/epinna/tplmap/blob/master/plugins/engines/twig.py"
    click Velocity "https://github.com/epinna/tplmap/blob/master/plugins/engines/velocity.py"

    %% Click Events - Language Plugins
    click Bash "https://github.com/epinna/tplmap/blob/master/plugins/languages/bash.py"
    click JavaLang "https://github.com/epinna/tplmap/blob/master/plugins/languages/java.py"
    click JS "https://github.com/epinna/tplmap/blob/master/plugins/languages/javascript.py"
    click PHP "https://github.com/epinna/tplmap/blob/master/plugins/languages/php.py"
    click PythonLang "https://github.com/epinna/tplmap/blob/master/plugins/languages/python.py"
    click RubyLang "https://github.com/epinna/tplmap/blob/master/plugins/languages/ruby.py"

    %% Click Events - Burp Extension
    click BurpExtender "https://github.com/epinna/tplmap/blob/master/burp_extension/burp_extender.py"
    click BurpChannel "https://github.com/epinna/tplmap/blob/master/burp_extension/channel.py"
    click BurpScanner "https://github.com/epinna/tplmap/blob/master/burp_extension/scanner_check.py"
    click ConfigTab "https://github.com/epinna/tplmap/blob/master/burp_extension/config_tab.py"
    click ScanIssue "https://github.com/epinna/tplmap/blob/master/burp_extension/scan_issue.py"

    %% Click Events - Utilities
    click Loggers "https://github.com/epinna/tplmap/blob/master/utils/loggers.py"
    click Strings "https://github.com/epinna/tplmap/blob/master/utils/strings.py"
    click Rand "https://github.com/epinna/tplmap/blob/master/utils/rand.py"
    click Closures "https://github.com/epinna/tplmap/blob/master/utils/closures.py"
    click ConfigUtil "https://github.com/epinna/tplmap/blob/master/utils/config.py"
    click ConfigYML "https://github.com/epinna/tplmap/blob/master/config.yml"

    %% External - Docker envs
    click Docker "https://github.com/epinna/tplmap/blob/master/docker-envs/docker-compose.yml"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000;
    classDef plugin fill:#90EE90,stroke:#000;
    classDef util fill:#D3D3D3,stroke:#000;
    classDef ext fill:#FFA500,stroke:#000;
    classDef external fill:#FFFF99,stroke:#000;
```
