Skip to content
RCE Disclosed report Intermediate

Urgent: Server side template injection via Smarty template allows for RCE

The application used the Smarty templating engine and inserted user-controlled profile fields into invitation emails without sanitising them, so template syntax in those fields was evaluated. An attacker could run PHP code on the server and read local files such as the password file.

yaworsk Follow

Originally disclosed on HackerOne

  • Disclosed after 12 months

Hi All, I've found an issue which has allowed me to execute file_get_contents and extract your /etc/passwd file.

##Description It appears as though you are using smarty on the backend for templating. Entering a malicious payload as my firstname, lastname and nickname and then inviting a user to join the site results in the code being executed.

To start, I began with the payload {7*7} and received a template error in the email I received

ssti_rce_initial_payload_error.png
ssti_rce_initial_payload_error.png From the original on HackerOne

Recognizing the injection, I then was able to confirm the version of smarty used via {$smarty.version} Next I was able to test {php} tags by using {php}print "Hello"{/php} . Finally I used file_get_contents to begin extracting the etc/pass file {php}$s = file_get_contents('/etc/passwd',NULL, NULL, 0, 100); var_dump($s);{/php}

ssti_rce_etc_passwd.png
ssti_rce_etc_passwd.png From the original on HackerOne

##Steps to reproduce

  1. Edit your profile
  2. Add the payload {php}$s = file_get_contents('/etc/passwd',NULL, NULL, 0, 100); var_dump($s);{/php} as your first name, last name and user name (I'm not sure which field is vulnerable)
  3. Invite a friend using another email of yours
  4. View the email and you will see part of the etc file dumped

##Vulnerability Since the {php} tags are being parsed and executed, we can execute php functions. In this case, you'll see I'm able to extract the etc/passwd file. While I haven't tried, an attacker can more than likely create a shell on the server.

Please let me know if you have any questions. Pete

The original report as published on HackerOne, by yaworsk. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

How it worked

Root cause

Likely user-supplied profile fields were passed directly into Smarty templates without escaping or sandboxing, so template tags in those fields were compiled and executed.

Impact

An attacker could execute PHP functions on the server and read local files, and the reporter suggests a shell could likely be created, though that was not tried.

What the attacker needed

A user account; ability to edit profile fields; ability to send an invitation

How it was found

  1. Edit the profile.
  2. Put a template payload in the first name, last name and user name fields.
  3. Invite a friend using another email address.
  4. Open the invitation email and see part of the system file dumped.

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 report has not been written yet. The Original tab links to the source.

Templating engines let websites fill in placeholders like a name inside an email. If the engine is given raw user input, it treats special markers in that input as instructions and runs them. Here the markers let the attacker run PHP code on the server, which is why they could read a system file.

What is RCE?

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

More by yaworsk

View all

21 more disclosed reports, best first.

More from Unikrn

View all

The newest disclosed reports for this program.

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.