How epinna/tplmap works
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