Skip to content
RCE Write-up Beginner

Basic Server-Side Template Injection (SSTI) in ERB (Ruby)

The web application inserted user-supplied input from a message parameter directly into an ERB template without sanitisation, allowing an attacker to execute arbitrary Ruby code on the server. The attacker could then run system commands, such as deleting a file in another user's home directory.

medium.com

Published on medium.com

This lab, Basic server-side template injection, demonstrates a critical security flaw rooted in unsafe handling of ERB (Embedded Ruby) templates. Specifically, the web application inserts user-supplied input directly into an ERB template, in this case, via a message parameter without any sanitization.

Bash Overflow, 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 input directly into an ERB template without sanitisation or sandboxing, so ERB evaluated the input as Ruby code.

Impact

An attacker could execute arbitrary Ruby code on the server, leading to remote code execution and sensitive data exposure, and in this lab could delete files in another user's home directory.

What the attacker needed

Access to the lab application; ability to send HTTP requests (e.g., via Burp)

How it was found

  1. Open the lab and find an article that returns a message parameter.
  2. In Burp, locate the request that returns the message and send it to Repeater.
  3. Replace the message value with a test string to confirm reflection.
  4. Replace the value with an ERB expression that calculates 7*7 and observe 49.
  5. Use Ruby directory listing commands to explore the filesystem and find the user carlos.
  6. Send a payload that runs a shell command to delete the target file.

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 (SSTI) happens when a website takes text you type and puts it into a template that the server later fills in. If the template engine can run code, like Ruby's ERB, then your text can become code that runs on the server. Here, the message parameter was placed straight into an ERB template, so a simple calculation was executed and later a system command was run.

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.