Welcome to Notes Time πŸ‘‹

Notes Time is your trusted platform for free study notes, tutorials, and guides designed to make learning simple, clear, and effective.

Whether you’re exploring Full Stack Web Development, mastering Cyber Security, or diving into Digital Marketing β€” we’ve got you covered with easy-to-understand content and practical examples.

Learn smarter, grow faster, and upskill with Notes Time β€” your digital study companion for tech and career success.

Subscribe to our newsletter and get our newest updates right on your inbox.

Privilege Escalation via Docker / Container Escapes

By Himanshu Shekhar Β· 12 Feb 2026

Privilege Escalation via Docker / Container Escapes

Privilege Escalation via Docker / Container Escapes (Conceptual Overview)

Containers (Docker, LXC, Podman) provide operating-system-level virtualization. They share the host kernel but isolate processes, filesystems, and networks. Container escape occurs when a process breaks this isolation boundary and gains access to the host operating system.

⚠️ Strictly Educational & Defensive: This section explains how container misconfigurations create escape risks. No exploitation techniques are provided. Focus is on prevention and detection.

🐳 What Is Container Escape?

Container escape is a privilege escalation technique where a process running inside a container breaks the isolation boundary and executes code directly on the host system with host privileges.

Since containers share the host kernel, a kernel vulnerability or misconfiguration can allow escape.

πŸ“¦ Container vs VM

Container: Shares host kernel. Lightweight. Less isolation.

Virtual Machine: Separate kernel. Heavyweight. Strong isolation.

🚨 Docker Group = Root Equivalent: Users in the docker group can mount the host filesystem and execute commands as root without any exploit. This is not a vulnerabilityβ€”it is by designβ€”but it is a critical misconfiguration.

🧠 How Container Escapes Happen (High-Level)

βš™οΈ Misconfiguration-Based
  • βœ” Privileged containers – All capabilities, host device access
  • βœ” Host filesystem mounts – -v /:/host gives host access
  • βœ” Docker group membership – Full root without password
  • βœ” --pid=host – Process namespace sharing
  • βœ” --network=host – Network namespace sharing
πŸ’£ Kernel Vulnerability-Based
  • βœ” CVE-2019-5736 – runC container escape
  • βœ” CVE-2022-0492 – cgroup release_agent escape
  • βœ” CVE-2024-21626 – runC/workdir path traversal
  • βœ” Dirty Pipe (CVE-2022-0847) – host kernel exploit
πŸ’‘ Defensive focus: Misconfiguration-based escapes are FAR more common and completely preventable. Patch kernel vulnerabilities promptly.

πŸ”₯ High-Risk Container Misconfigurations

Misconfiguration Description Risk Level Defensive Action
Docker group membership Non-root user in docker group CRITICAL Remove user from docker group. Use sudo.
Privileged containers --privileged flag used CRITICAL Never use privileged containers. Drop capabilities.
Host filesystem mounts -v /:/host or --mount type=bind,source=/,target=/host CRITICAL Avoid host mounts. Use named volumes.
--pid=host Shares host process namespace HIGH Avoid unless absolutely necessary
--network=host Shares host network namespace HIGH Avoid; use bridge networks
Capabilities not dropped CAP_SYS_ADMIN, CAP_DAC_OVERRIDE present HIGH --cap-drop=ALL, add only required

🌍 Real-World Examples (Defensive View)

πŸ“‹ Example 1: Docker Group Privilege Creep

Situation: A developer is added to the docker group for "convenience" to run containers without sudo.

Three years later: Developer changes teams but group membership is never removed. Account is compromised via phishing.

Impact: Attacker runs:

docker run -v /:/mnt -it ubuntu chroot /mnt bash

Result: Full host root access. Entire server compromised.

Defense: Quarterly group membership audits. Never add users to docker group.

πŸ“‹ Example 2: "Temporary" Privileged Container

Situation: An administrator runs a privileged container to debug a networking issue.

docker run --privileged -it ubuntu bash

Problem: The container is left running. A separate web application vulnerability allows RCE inside the container.

Impact: From the privileged container, the attacker:

  • Mounts host disk devices
  • Adds SSH key to host root
  • Installs persistence mechanism

Defense: Never run privileged containers. Use --cap-add for specific needs.

πŸ“‹ Example 3: Read-Only Filesystem Bypass

Situation: Container runs with --read-only for security, but /tmp is mounted as writable.

Vulnerability: Kernel flaw allows mounting filesystems inside user namespaces.

Result: Attacker mounts new filesystem, bypasses read-only restriction.

Defense: Combine --read-only with --tmpfs /tmp:noexec,nosuid and kernel patches.


πŸ” Detecting Container Escape Risks

🐳 Docker Audit Commands
  • βœ” groups | grep docker – Check docker group membership
  • βœ” docker ps --quiet | xargs docker inspect --format='{{.Name}} {{.HostConfig.Privileged}}' – Find privileged containers
  • βœ” docker ps --quiet | xargs -I {} docker inspect {} --format='{{.Name}} Mounts: {{.HostConfig.Binds}}' – Find host mounts
  • βœ” docker ps --quiet | xargs -I {} docker inspect {} --format='{{.Name}} CapDrop: {{.HostConfig.CapDrop}}' – Check dropped capabilities
πŸ›‘οΈ Host Detection
  • βœ” auditd rules for mount, nsenter syscalls
  • βœ” Falco/Tracee – Runtime security monitoring
  • βœ” Docker Bench Security – Automated assessment
  • βœ” Unusual process ancestry (container parent β†’ host child)

πŸ›‘οΈ Preventing Container Escapes

βœ… Docker Security Best Practices
πŸ”Ή Runtime Security
  • Never add users to docker group – Use sudo
  • Avoid privileged containers – Use --cap-drop=ALL
  • Read-only root filesystem – --read-only flag
  • No new privileges – --security-opt=no-new-privileges:true
  • Drop all capabilities – Add only required
πŸ”Ή Isolation & Configuration
  • User namespaces – --userns=remap
  • Resource limits – --memory, --cpus
  • AppArmor/SELinux – Enable confinement
  • Seccomp profiles – Restrict syscalls
  • Image scanning – Trivy, Clair, Docker Scout
πŸ“‹ Secure Docker Run Example
docker run -d \
  --name web-secure \
  --read-only \
  --security-opt=no-new-privileges:true \
  --cap-drop=ALL \
  --cap-add=NET_BIND_SERVICE \
  --cap-add=NET_RAW \
  --user 1000:1000 \
  --tmpfs /tmp:rw,noexec,nosuid,size=128m \
  --tmpfs /var/run:rw,noexec,nosuid \
  --security-opt=apparmor:docker-default \
  nginx:alpine

βœ… This container runs as non-root, read-only, with only necessary capabilities, and no new privileges.


🧾 Key Takeaways

  • βœ” Docker group = root – Never add users to docker group
  • βœ” Privileged containers = host access – Never use --privileged
  • βœ” Drop all capabilities – Default containers have too many privileges
  • βœ” Read-only + no-new-privileges – Prevents container modification
  • βœ” User namespaces – Map container root to unprivileged host user
  • βœ” Patch kernels – Most vulnerability-based escapes target kernel flaws

🐳 Docker/Container – Command Awareness (Defensive Auditing)

Commands used by security teams and system administrators to audit container environments. Shown for defensive hardening and verification only.

⚠️ Awareness only. These commands audit configurationsβ€”they do not exploit anything.

πŸ‘₯ Docker Group Audit
  • Check if current user is in docker group
    groups | grep docker
    If output contains "docker", user has root-equivalent access.
  • List all users in docker group
    getent group docker
    Audit quarterly; remove any non-admin users.

πŸ” Container Runtime Audit
  • List running containers
    docker ps
  • Find privileged containers
    docker ps --quiet | xargs -I {} docker inspect {} --format='{{.Name}} Privileged: {{.HostConfig.Privileged}}'
    Privileged: true = CRITICAL finding
  • Find containers with host filesystem mounts
    docker ps --quiet | xargs -I {} docker inspect {} --format='{{.Name}} Mounts: {{.HostConfig.Binds}}'
    Mounts containing / or /etc = CRITICAL
  • Check dropped capabilities
    docker ps --quiet | xargs -I {} docker inspect {} --format='{{.Name}} CapDrop: {{.HostConfig.CapDrop}}'
    Empty or missing CAP_DROP = excessive privileges
  • Check read-only root filesystem
    docker ps --quiet | xargs -I {} docker inspect {} --format='{{.Name}} ReadOnly: {{.HostConfig.ReadonlyRootfs}}'
    ReadOnly: false = writable container filesystem
  • Check user namespace
    docker ps --quiet | xargs -I {} docker inspect {} --format='{{.Name}} UsernsMode: {{.HostConfig.UsernsMode}}'
    UsernsMode: host = user namespaces disabled

πŸ“¦ Image Security Audit
  • Scan image for vulnerabilities
    docker scan nginx:latest
    Or use Trivy: trivy image nginx:latest
  • Check image user
    docker inspect --format='{{.Config.User}}' nginx:latest
    Blank or "0" = root. Should be non-root user.

πŸ›‘οΈ Remediation Commands (Defensive)
  • Remove user from docker group
    sudo gpasswd -d username docker
  • Recreate container without privileged mode
    docker run --cap-drop=ALL --cap-add=NET_BIND_SERVICE ...
  • Enable user namespace remapping
    # Edit /etc/docker/daemon.json
    {
      "userns-remap": "default"
    }

πŸ›‘οΈ Defender Takeaways
  • βœ” Audit weekly: docker group, privileged containers, host mounts
  • βœ” Harden: Drop all capabilities, read-only rootfs, no-new-privileges
  • βœ” Monitor: Falco/Tracee for runtime container escapes
  • βœ” Scan: All images for vulnerabilities and root users
βœ… Container Security = Kernel Patches + Minimal Capabilities + Read-only + User Namespaces
πŸ“š

πŸ“š Related Blogs

Privilege Escalation via Writable /etc/passwd & Shadow Abuse

By Himanshu Shekhar Β· 12 Feb 2026

Privilege Escalation via Writable /etc/passwd & Sh...

Privilege Escalation via Weak File Permissions & Group Membership Abuse

By Himanshu Shekhar Β· 12 Feb 2026

Privilege Escalation via Weak File Permissions & G...

Privilege Escalation via Linux Capabilities

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Linux Capabilities (Conce...

Privilege Escalation via SUID (Conceptual Guide)

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via SUID (Conceptual Overview...

DC-1 VulnHub: Drupal 7 Exploitation and SUID Privilege Escalation

By Himanshu Shekhar Β· 10 Feb 2026

DC-1 VulnHub Walkthr...

Privilege Escalation via Misconfigured NFS

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Misconfigured NFS (Concep...

Privilege Escalation via PATH Variable Manipulation

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via PATH Variable Manipulatio...

Privilege Escalation via Cron Jobs

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Cron Jobs...

TryHackMe BLOG Room – Full Walkthrough

By Himanshu Shekhar Β· 10 Feb 2026

πŸ§ͺ TryHackMe – BLOG Room (Full Lab Walkthrough)...

Active Directory Domain Services – Setup Windows Server Conceptual

By Himanshu Shekhar Β· 10 Feb 2026

πŸ› οΈ Step-by-Step: Set...

Privilege Escalation via Kernel Vulnerabilities

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Kernel Vulnerabilities...

Privilege Escalation via Sudo Misconfiguration

By Himanshu Shekhar Β· 10 Feb 2026

Privilege Escalation via Sudo (Conceptual Overv...

+