Skip to content
← RegistryDossier · 6 steps · 5 edges

SSTI (Jinja2) → sandbox escape → RCE

User input rendered as a Jinja2 template instead of escaped. Escape the sandbox via __class__.__mro__ to reach subprocess and execute commands.

Filed by AD Knowledge Base
§ Kill-chainDrag · zoom · scroll

§ Context

Assumed environment: a Flask / Django / FastAPI app uses Jinja2 to render user-controllable strings (often in name greetings, error messages, custom email templates).

§ Steps

  1. 01
    Reverse shellExecution
    T1059Command and Scripting Interpreter
  2. 02
    Execute shell commandsExecution
    W-CMDIOS Command Injection
  3. 03
    Reach subprocess.Popen / os.popenExecution
    W-SSTI-FLASKSSTI — Jinja2 / Flask
  4. 04
    Escape sandbox via __class__.__mro__Execution
    W-SSTI-FLASKSSTI — Jinja2 / Flask

    {{ ''.__class__.__mro__[1].__subclasses__() }}

  5. 05
    Confirm Jinja2 SSTIExecution
    W-SSTI-FLASKSSTI — Jinja2 / Flask
  6. 06
    Fingerprint engineReconnaissance
    W-RECON-FINGERPRINTTech Stack Fingerprinting

    {{7*7}} vs ${{7*7}} vs <%= 7*7 %> — narrow down the engine.

§ References

§ Frequently asked

What is the "SSTI (Jinja2) → sandbox escape → RCE" attack path?
User input rendered as a Jinja2 template instead of escaped. Escape the sandbox via __class__.__mro__ to reach subprocess and execute commands. It chains 6 steps drawn from real-world offensive-security techniques.
What starting position does this attack require?
The first step is Reverse shell (T1059) — a execution primitive. Assumed environment: a Flask / Django / FastAPI app uses Jinja2 to render user-controllable strings (often in name greetings, error messages, custom email templates).
What is the final impact of this kill-chain?
The final step lands on Fingerprint engine (W-RECON-FINGERPRINT), which falls under Reconnaissance. From here, an operator typically pivots into post-exploitation or maintains persistence.
How can defenders detect or prevent this attack?
Detection and prevention vary per step. Refer to each linked MITRE ATT&CK entry under "References" — every technique on that page lists defensive controls, detection telemetry, and known threat-actor usage.

§ Related dossiers