Skip to content
RCE Write-up Intermediate

Exploiting Server-Side Template Injection (SSTI) with a Custom Ex

A server-side template injection flaw in the 'Preferred name' field allowed arbitrary template expressions to be evaluated. The attacker used this to call internal functions on the user object, ultimately deleting a file on the server.

A Z O Follow

Published on medium.com

In this blog post, we’ll dive into Server-Side Template Injection (SSTI) vulnerabilities by exploring a practical lab exercise provided by PortSwigger. SSTI is a powerful and dangerous vulnerability that allows attackers to execute arbitrary code on a server by injecting malicious templates.

A Z O, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the application passed user-controlled input into a Twig template without sanitising it, so template expressions were evaluated on the server.

Impact

An attacker could execute arbitrary template expressions and call internal functions, leading to file deletion on the server.

What the attacker needed

A free account; ability to intercept requests

How it was found

  1. Log in with the provided credentials and open the account settings page.
  2. Intercept the request that updates the 'Preferred name' field and note the 'blog-post-author-display' parameter.
  3. Inject a simple arithmetic expression into that parameter and submit the request.
  4. Visit a blog post, submit a comment, and refresh to see the evaluated result.
  5. Trigger an error by setting the parameter to the user object to identify the template engine.
  6. Use the setAvatar function to point the avatar at a target file, then call gdprDelete to delete it.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Server-side template injection happens when a website puts user input directly into a template that the server later fills in. If the input is treated as template code instead of plain text, an attacker can make the server run expressions or call functions. Here, the 'Preferred name' field was evaluated as a template, letting the attacker reach internal functions.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.