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

本节涵盖在渗透测试、CTF 靶机、实验环境以及本地后渗透审查中使用的实用 Linux 权限提升技术。

## 权限提升工作流

1. 稳定 shell，并识别当前用户、用户组、主机名、内核和发行版。
2. 枚举 sudo 权限、SUID 二进制文件、capabilities、可写文件、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 规则、capabilities、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="/pages/b48d386971b40d820cdc14f7dd131f157a61a700">/pages/b48d386971b40d820cdc14f7dd131f157a61a700</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="/pages/7478556b3a4b6e198ac318f5a0d218d0cfbc51c3">/pages/7478556b3a4b6e198ac318f5a0d218d0cfbc51c3</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="/pages/6c46cd2a0da9ed27fdffc8bad6f2701afd5c883b">/pages/6c46cd2a0da9ed27fdffc8bad6f2701afd5c883b</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="/pages/4dfe183338a6645288f2d64a121bf74643f79b9b">/pages/4dfe183338a6645288f2d64a121bf74643f79b9b</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="/pages/5eff5b8378eea475729e9076bc1119ac1df7882c">/pages/5eff5b8378eea475729e9076bc1119ac1df7882c</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="/pages/aec8c8ecfd6e08e04501b2dd1374c84de77b7b2a">/pages/aec8c8ecfd6e08e04501b2dd1374c84de77b7b2a</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="/pages/86a3444508fe497db8bf6c6373090c0924df0aa7">/pages/86a3444508fe497db8bf6c6373090c0924df0aa7</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="/pages/25fd609a7a96fb0ab28a949ec03e483ea545054e">/pages/25fd609a7a96fb0ab28a949ec03e483ea545054e</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="/pages/c74a09eb57780d10598e5f947b4b90b4294612ba">/pages/c74a09eb57780d10598e5f947b4b90b4294612ba</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="/pages/7c85362d4f23b1b209a1948449c3ab286d3f245e">/pages/7c85362d4f23b1b209a1948449c3ab286d3f245e</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="/pages/6eedd7f6a6d5a148a3b2015d3df101f863f8f5e6">/pages/6eedd7f6a6d5a148a3b2015d3df101f863f8f5e6</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="/pages/7a96ec3906af0c16a2a13f2ee1b7b37d9c5bd3ee">/pages/7a96ec3906af0c16a2a13f2ee1b7b37d9c5bd3ee</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="/pages/3e5e80fe2682b12eabcbf24b45e58ffe0136580d">/pages/3e5e80fe2682b12eabcbf24b45e58ffe0136580d</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="/pages/5eefb08e86b4616c9c44b54821bae58435022ded">/pages/5eefb08e86b4616c9c44b54821bae58435022ded</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) 用于检测 cron 任务和无需 root 的进程。
* [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 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.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.
