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

# Linux 权限提升

Linux 权限提升笔记，涵盖 sudo 滥用、SUID 二进制、cron 任务、Linux capabilities、PATH 劫持、内核漏洞利用、Docker 逃逸、共享库、文件权限、NFS 共享、服务

Linux 提权是后渗透阶段，重点是从低权限 shell 提升到 root。目标是枚举本地系统、识别错误配置、滥用受信任的执行路径，并将薄弱权限转化为可靠的 root shell。

本节介绍在渗透测试、CTF 主机、实验环境以及本地后渗透审查中使用的实用 Linux 提权技术。

## 提权工作流

1. 稳定 shell，并识别当前用户、用户组、主机名、内核和发行版。
2. 枚举 sudo 权限、SUID 二进制文件、能力、可写文件、cron 任务、NFS 导出以及本地服务。
3. 检查 docker、lxd、adm 和 proxy 等组成员关系，寻找可直接滥用的路径。
4. 检查 PATH 使用、共享库加载、Python 导入以及可写的执行上下文。
5. 将内核和软件包版本与已知的本地提权 CVE 进行比对。
6. 利用已确认且最安全的路径，并保留命令顺序以便汇报。

## 手动枚举清单

当你进入一台 Linux 主机，需要在选择提权路径之前快速了解本地情况时使用此清单。

### 基本系统信息

```bash
uname -a
cat /proc/version
cat /etc/issue
cat /etc/*-release
lsb_release -a 2>/dev/null
lscpu
uptime
```

硬件和文件系统上下文：

```bash
cat /proc/cpuinfo
free -h
df -h
```

### 环境变量

```bash
env
set
echo $PATH
echo $HOME
echo $USER
```

### 用户枚举

```bash
whoami
id
groups
cat /etc/passwd
cut -d: -f1 /etc/passwd
grep -v '/nologin\|/false' /etc/passwd
cat /etc/shadow 2>/dev/null
cat /etc/group
```

用户活动和历史：

```bash
last
lastlog
history
cat ~/.bash_history 2>/dev/null
```

sudo 访问：

```bash
sudo -l
cat /etc/sudoers 2>/dev/null
```

### 网络枚举

接口和路由：

```bash
ifconfig -a 2>/dev/null
ip a
route 2>/dev/null
ip route
netstat -r 2>/dev/null
arp -a 2>/dev/null
ip neigh
```

端口和连接：

```bash
netstat -tuln 2>/dev/null
ss -tuln
netstat -tunap 2>/dev/null
ss -tunap
```

DNS、hosts 和防火墙：

```bash
cat /etc/resolv.conf
cat /etc/hosts
iptables -L 2>/dev/null
```

### 正在运行的服务

```bash
service --status-all 2>/dev/null
ps aux
ps -ef
pstree 2>/dev/null
systemctl list-units --type=service 2>/dev/null
service service_name status 2>/dev/null
```

启动脚本：

```bash
ls -la /etc/init.d/ 2>/dev/null
ls -la /etc/rc*.d/ 2>/dev/null
```

### 文件系统枚举

敏感配置和隐藏文件：

```bash
find / -name "*.conf" -o -name "*.config" 2>/dev/null
find /home -name ".*" -type f 2>/dev/null
```

密码和敏感痕迹：

```bash
grep -r "password" /etc/ 2>/dev/null
find /etc \( -name "*.conf" -o -name "*.config" \) -exec grep -l "password" {} \; 2>/dev/null
cat /var/apache2/config.inc 2>/dev/null
cat /var/lib/mysql/mysql/user.MYD 2>/dev/null
cat /root/anaconda-ks.cfg 2>/dev/null
cat ~/.bash_history 2>/dev/null
cat ~/.mysql_history 2>/dev/null
cat ~/.ssh/id_rsa 2>/dev/null
cat ~/.ssh/id_rsa.pub 2>/dev/null
```

查找有趣的文件：

```bash
find / -name "*.txt" 2>/dev/null
find / -name "*flag*" 2>/dev/null
find / -name "*.txt" 2>/dev/null | grep -i flag
grep -r "password" /home 2>/dev/null
grep -r "flag" /home 2>/dev/null
```

权限：

```bash
find / -type f -perm -o+w -not -path "/proc/*" 2>/dev/null
find / -type f -perm -o+w -not -path "/proc/*" -not -path "/sys/*" 2>/dev/null
find / -type d -perm -o+w -not -path "/proc/*" 2>/dev/null
find / -type f -perm -u=s 2>/dev/null
find / -type f -perm -g=s 2>/dev/null
find / -perm -o+x -type f 2>/dev/null
find / -type f -mtime -1 2>/dev/null
```

### 计划任务

```bash
cat /etc/crontab
ls -la /etc/cron.d/
ls -la /etc/cron.daily/
ls -la /etc/cron.hourly/
ls -la /etc/cron.monthly/
ls -la /etc/cron.weekly/
crontab -l
```

### 已安装软件

```bash
dpkg -l 2>/dev/null
rpm -qa 2>/dev/null
which command_name 2>/dev/null
```

Web 服务器路径：

```bash
cat /etc/apache2/apache2.conf 2>/dev/null
cat /etc/httpd/conf/httpd.conf 2>/dev/null
ls -la /var/www/ 2>/dev/null
ls -la /srv/www/ 2>/dev/null
```

### 快速提权检查

```bash
find / -perm -4000 -type f -exec ls -la {} \; 2>/dev/null
ls -la /etc/passwd
sudo -l
echo $PATH | tr ':' '\n' | xargs -I {} ls -ld {} 2>/dev/null
find /etc/cron* -type f -perm -o+w 2>/dev/null
getcap -r / 2>/dev/null
```

### 自动化枚举工具

将自动化工具作为辅助，而不是证据。保留其输出，并在利用前手动验证每一项发现。

```bash
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
chmod +x LinEnum.sh
./LinEnum.sh
wget https://raw.githubusercontent.com/diego-treitos/linux-smart-enumeration/master/lse.sh
chmod +x lse.sh
./lse.sh -l1
wget https://raw.githubusercontent.com/mzet-/linux-exploit-suggester/master/linux-exploit-suggester.sh
chmod +x linux-exploit-suggester.sh
./linux-exploit-suggester.sh
```

### 逐步排查

1. 收集操作系统、内核、发行版、CPU、存储和运行时间。
2. 确认当前用户、用户组、shell、sudo 访问以及可读的账户文件。
3. 枚举 SUID/SGID 二进制文件、sudo 规则、能力、cron 任务、PATH、NFS 和服务。
4. 寻找可写文件、可写目录、凭据、密钥、历史记录以及最近的更改。
5. 如果允许，运行自动化枚举，然后手动验证有价值的发现。
6. 在排除更安全的错误配置路径之前，将内核利用视为最后手段。

## Linux 提权技术

<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-terminal" style="color:$primary;">:terminal:</i></h3></td><td><h4>sudoers</h4></td><td>Linux sudoers 提权技术、sudo -l 滥用、允许的二进制文件、符号链接滥用以及 sudo 版本漏洞。</td><td><a href="/zh/privesc/sudoers.md">Sudoers</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>Linux SUID 提权笔记，涵盖易受攻击的二进制文件、GTFOBins 流程、PwnKit、Nmap、PHP、screen 以及自定义 SUID 二进制文件。</td><td><a href="/zh/privesc/suid.md">SUID</a></td></tr><tr><td><h3><i class="fa-clock" style="color:$primary;">:clock:</i></h3></td><td><h4>Cron 任务</h4></td><td>Cron 任务提权笔记，涵盖可写脚本、周期性 root 任务、pspy64、Logstash 任务以及 ImageMagick 滥用。</td><td><a href="/zh/privesc/cron-jobs.md">Cron 任务</a></td></tr><tr><td><h3><i class="fa-linux" style="color:$primary;">:linux:</i></h3></td><td><h4>Dirty Pipe</h4></td><td>Linux 提权技术笔记，包含实用枚举、利用示例和验证。</td><td><a href="/zh/privesc/dirty-pipe-linux-privilege-escalation.md">Dirty Pipe</a></td></tr><tr><td><h3><i class="fa-shield-halved" style="color:$primary;">:shield-halved:</i></h3></td><td><h4>权限</h4></td><td>Linux 权限错误配置笔记，涵盖可写文件、/etc/passwd 滥用、Smart Enumeration 以及最小权限检查。</td><td><a href="/zh/privesc/permissions.md">权限</a></td></tr><tr><td><h3><i class="fa-spinner" style="color:$primary;">:spinner:</i></h3></td><td><h4>Capabilities</h4></td><td>Linux capabilities 提权笔记，涵盖 cap_setuid、cap_dac_read_search、GTFOBins、Python、Perl、Vim、tac 和 tar 滥用。</td><td><a href="/zh/privesc/capabilities.md">Capabilities</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>PATH 劫持</h4></td><td>PATH 劫持提权笔记，涵盖相对路径二进制调用、可写 PATH 优先级以及恶意命令替换。</td><td><a href="/zh/privesc/path-hijacking.md">PATH 劫持</a></td></tr><tr><td><h3><i class="fa-microchip" style="color:$primary;">:microchip:</i></h3></td><td><h4>内核利用</h4></td><td>Linux 内核利用笔记，涵盖本地提权、Linux Exploit Suggester、Dirty COW、OverlayFS 以及 Ubuntu 内核 CVE。</td><td><a href="/zh/privesc/kernel-exploitation.md">内核利用</a></td></tr><tr><td><h3><i class="fa-network-wired" style="color:$primary;">:network-wired:</i></h3></td><td><h4>NFS 共享</h4></td><td>NFS 共享提权笔记，涵盖 no_root_squash、可写导出、攻击者挂载的共享以及 SUID 载荷验证。</td><td><a href="/zh/privesc/nfs-shares.md">NFS 共享</a></td></tr><tr><td><h3><i class="fa-server" style="color:$primary;">:server:</i></h3></td><td><h4>服务与 Systemd</h4></td><td>Linux 服务提权笔记，涵盖可写服务文件、服务二进制文件、systemd 单元以及不安全的守护进程配置。</td><td><a href="/zh/privesc/services.md">服务和 Systemd</a></td></tr><tr><td><h3><i class="fa-python" style="color:$primary;">:python:</i></h3></td><td><h4>Python 库劫持</h4></td><td>Python 库劫持笔记，涵盖在 sudo 执行的 Python 脚本中滥用导入解析顺序和可写工作目录。</td><td><a href="/zh/privesc/python-library-hijacking.md">Python 库劫持</a></td></tr><tr><td><h3><i class="fa-users" style="color:$primary;">:users:</i></h3></td><td><h4>用户组</h4></td><td>Linux 本地组提权笔记，涵盖 docker、lxd、adm、proxy、日志、主机规则以及容器滥用。</td><td><a href="/zh/privesc/user-groups.md">用户组</a></td></tr><tr><td><h3><i class="fa-docker" style="color:$primary;">:docker:</i></h3></td><td><h4>Docker 逃逸</h4></td><td>Docker 逃逸提权笔记，涵盖默认 Docker Toolbox 凭据、SUID 操作、密码复用以及 SSH 密钥跳转。</td><td><a href="/zh/privesc/docker-escape.md">Docker 逃逸</a></td></tr><tr><td><h3><i class="fa-link" style="color:$primary;">:link:</i></h3></td><td><h4>共享库劫持</h4></td><td>共享库劫持笔记，涵盖滥用由特权 Linux 二进制文件加载的缺失或可写共享对象。</td><td><a href="/zh/privesc/shared-library-hijacking.md">共享库劫持</a></td></tr></tbody></table>

## 推荐工具

* [LinPEAS](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS) 用于自动化 Linux 提权枚举。
* [pspy64](/zh/privesc/cron-jobs/pspy64-cron-enumeration-linux-privilege-escalation.md) 用于在没有 root 的情况下检测 cron 任务和进程。
* [Linux Exploit Suggester](/zh/privesc/kernel-exploitation/linux-exploit-suggester-linux-privilege-escalation.md) 用于内核利用候选项。
* [GTFOBins](https://gtfobins.github.io/) 用于 sudo、SUID、capabilities 和 shell 逃逸载荷。
* [智能枚举](/zh/privesc/permissions/smart-enumeration-linux-privilege-escalation.md) 用于结构化的本地错误配置检查。


---

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