# Basic server-side template injection

Description:

This lab is vulnerable to server-side template injection due to the unsafe construction of an ERB template.

To solve the lab, review the ERB documentation to find out how to execute arbitrary code, then delete the `morale.txt` file from Carlos's home directory.

Proof of concept:

1. Analisa pada web target
2. Dari hasil analisa didapati ketika product tidak tersedia atau out of stock akan mengirim pesan melalui parameter `message`. Jika stok product tersedia, akan diarahkan ke halaman detail product<br>

   <figure><img src="/files/0hqiESyTqR8e6xRgDgd1" alt=""><figcaption></figcaption></figure>
3. Inputkan basic payload SSTI yaitu `{{7*7}}`<br>

   <figure><img src="/files/3FBBJFArUTGgvOYWNxIo" alt=""><figcaption></figcaption></figure>
4. Outputnya akan tetap `{{7*7}}` dikarenakan dari informasi yang didapati pada lab description sistem target menggunakan teknologi `ERB ruby`, maka inputkan payload basic SSTI ERB seperti yang dapat dilihat di <https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#erb-ruby> sebagai contoh disini menggunakan payload `<%= 7*7 %>` maka akan ditampilkan nilai `49`. Artinya sistem rentan terhadap SSTI Attack<br>

   <figure><img src="/files/vdie81qleEHDRT1edqGb" alt=""><figcaption></figcaption></figure>
5. Selanjutnya, untuk memastikan lainnya coba gunakan payload SSTI ERB ruby `<%= system('cat /etc/passwd') %>` untuk menampilkan data-data sensitive yang berada pada file `/etc/passwd`<br>

   <figure><img src="/files/yEMoLKYZKacgfyMdTvcV" alt=""><figcaption></figcaption></figure>
6. Setelah berhasil, cari tahu username dari user yang berjalan pada server target dengan menggunakan perintah atau payload SSTI ERB ruby berikut `<%= system("whoami") %>`<br>

   <figure><img src="/files/gmTW7or2QXRGkBWMcRGb" alt=""><figcaption></figcaption></figure>
7. Dan cari informasi mengenai direktori yang ada pada direktori home dengan menggunakan payload `<%= Dir.entries('/home') %>`<br>

   <figure><img src="/files/d6U3JYn87MPqDZcVkm4T" alt=""><figcaption></figcaption></figure>
8. Selanjutnya, untuk menyelesaikan tangtangan lab ini gunakan payload `<%= system('rm /home/carlos/morale.txt') %>`<br>

   <figure><img src="/files/aAW4tLUNqH8oOhe3gcAv" alt=""><figcaption></figcaption></figure>

Thanks, Stay Ethical & Happy Hacking! 🍻


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://easpyy.gitbook.io/portswigger/basic-server-side-template-injection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
