Skill v1.0.1
currentAutomated scan100/100+7 new
name: detecting-container-escape-attempts description: Container escape is a critical attack technique where an adversary breaks out of container isolation to access the host system or other containers. Detection involves monitoring for escape indicators domain: cybersecurity subdomain: container-security tags:
- containers
- kubernetes
- docker
- security
- runtime-security
- escape-detection
version: '1.0' author: mahipal license: Apache-2.0 d3fend_techniques:
- Platform Monitoring
- Process Code Segment Verification
- Stack Frame Canary Validation
- Segment Address Offset Randomization
- Process Analysis
nist_csf:
- PR.PS-01
- PR.IR-01
- ID.AM-08
- DE.CM-01
mitre_attack:
- T1610
- T1611
- T1609
- T1525
Detecting Container Escape Attempts
Overview
Container escape is a critical attack technique where an adversary breaks out of container isolation to access the host system or other containers. Detection involves monitoring for escape indicators such as namespace manipulation, capability abuse, kernel exploits, mounted sensitive paths, and anomalous syscall patterns using runtime security tools like Falco, Sysdig, and custom seccomp/audit rules.
When to Use
- When investigating security incidents that require detecting container escape attempts
- When building detection rules or threat hunting queries for this domain
- When SOC analysts need structured procedures for this analysis type
- When validating security monitoring coverage for related attack techniques
Prerequisites
- Linux host with kernel 5.10+ (eBPF support)
- Falco 0.37+ installed (kernel module or eBPF probe)
- Docker Engine or containerd runtime
- auditd configured
- Root access for eBPF/kernel module loading
Core Concepts
Common Container Escape Vectors
| Vector | Technique | MITRE ID | |
|---|---|---|---|
| Privileged containers | Mount host filesystem, load kernel modules | T1611 | |
| Docker socket mount | Create privileged container from within | T1610 | |
| Kernel exploits | CVE-2022-0185 (fsconfig), Dirty Pipe, runc CVEs | T1068 | |
| Capability abuse | CAP_SYS_ADMIN, CAP_SYS_PTRACE, CAP_NET_ADMIN | T1548 | |
| Sensitive mounts | /proc/sysrq-trigger, /proc/kcore, cgroup release_agent | T1611 | |
| Namespace escape | nsenter, unshare to host namespaces | T1611 | |
| Symlink/bind mount | Escape through /proc/self/root | T1611 |
Detection Layers
- Syscall monitoring - eBPF/kernel module captures syscalls in real-time
- File integrity - Detect modification of escape-enabling paths
- Process monitoring - Track process creation, namespace changes
- Network monitoring - Detect container-to-host connections
- Audit logging - Linux auditd for capability and mount operations
Workflow
Step 1: Deploy Falco for Runtime Detection
# falco-values.yaml for Helm deploymentfalco:driver:kind: ebpf # or modern_ebpf for kernel 5.8+rules_files:- /etc/falco/falco_rules.yaml- /etc/falco/falco_rules.local.yaml- /etc/falco/rules.djson_output: truejson_include_output_property: truehttp_output:enabled: trueurl: "http://falcosidekick:2801"grpc:enabled: truepriority: warning
# Install Falco via Helmhelm repo add falcosecurity https://falcosecurity.github.io/chartshelm install falco falcosecurity/falco \--namespace falco-system --create-namespace \-f falco-values.yaml
Step 2: Custom Falco Rules for Escape Detection
# /etc/falco/rules.d/container_escape.yaml# Detect container escape via privileged container- rule: Container Escape via Privileged Modedesc: Detect attempts to escape container using privileged capabilitiescondition: >spawned_process and container and(proc.name in (nsenter, unshare, mount, umount, modprobe, insmod) or(proc.name = chroot and proc.args contains "/host"))output: >Container escape attempt via privileged operation(user=%user.name container=%container.name image=%container.image.repositorycommand=%proc.cmdline pid=%proc.pid %container.info)priority: CRITICALtags: [container, escape, T1611]# Detect Docker socket access from container- rule: Container Access to Docker Socketdesc: Detect container reading/writing to Docker socketcondition: >(open_read or open_write) and container andfd.name = /var/run/docker.sockoutput: >Docker socket accessed from container(user=%user.name container=%container.name image=%container.image.repositoryfd=%fd.name command=%proc.cmdline %container.info)priority: CRITICALtags: [container, escape, docker_socket]# Detect sensitive proc filesystem access- rule: Container Access to Sensitive Proc Pathsdesc: Detect container accessing host-sensitive proc pathscondition: >open_read and container and(fd.name startswith /proc/sysrq-trigger orfd.name startswith /proc/kcore orfd.name startswith /proc/kmsg orfd.name startswith /proc/kallsyms orfd.name startswith /sys/kernel)output: >Sensitive proc/sys access from container(user=%user.name container=%container.name path=%fd.namecommand=%proc.cmdline %container.info)priority: CRITICALtags: [container, escape, proc_access]# Detect cgroup escape technique- rule: Container Cgroup Escape Attemptdesc: Detect writing to cgroup release_agent (escape technique)condition: >open_write and container and(fd.name contains release_agent orfd.name contains notify_on_release)output: >Cgroup escape attempt detected(user=%user.name container=%container.name path=%fd.namecommand=%proc.cmdline %container.info)priority: CRITICALtags: [container, escape, cgroup]# Detect kernel module loading from container- rule: Container Loading Kernel Moduledesc: Detect container attempting to load kernel modulescondition: >spawned_process and container and(proc.name in (modprobe, insmod, rmmod) or(evt.type = init_module or evt.type = finit_module))output: >Kernel module load attempt from container(user=%user.name container=%container.name command=%proc.cmdline%container.info)priority: CRITICALtags: [container, escape, kernel_module]# Detect namespace manipulation- rule: Container Namespace Manipulationdesc: Detect setns/unshare syscalls from containercondition: >container and (evt.type = setns or evt.type = unshare) andnot proc.name in (containerd-shim, runc)output: >Namespace manipulation from container(user=%user.name container=%container.name syscall=%evt.typecommand=%proc.cmdline %container.info)priority: CRITICALtags: [container, escape, namespace]# Detect mount operations from container- rule: Container Mount Sensitive Filesystemdesc: Detect container mounting host filesystemscondition: >spawned_process and container and proc.name = mount and(proc.args contains "/dev/" or proc.args contains "proc" orproc.args contains "sysfs")output: >Sensitive mount operation from container(user=%user.name container=%container.name command=%proc.cmdline%container.info)priority: HIGHtags: [container, escape, mount]
Step 3: Configure Seccomp Profile for Escape Prevention
{"defaultAction": "SCMP_ACT_ERRNO","archMap": [{ "architecture": "SCMP_ARCH_X86_64", "subArchitectures": ["SCMP_ARCH_X86", "SCMP_ARCH_X32"] }],"syscalls": [{"names": ["read", "write", "open", "close", "stat", "fstat", "lstat","poll", "lseek", "mmap", "mprotect", "munmap", "brk","rt_sigaction", "rt_sigprocmask", "ioctl", "access","pipe", "select", "sched_yield", "dup", "dup2","nanosleep", "getpid", "socket", "connect", "accept","sendto", "recvfrom", "bind", "listen", "getsockname","getpeername", "socketpair", "setsockopt", "getsockopt","clone", "fork", "vfork", "execve", "exit", "wait4","kill", "getuid", "getgid", "geteuid", "getegid","epoll_create", "epoll_wait", "epoll_ctl", "epoll_create1","futex", "set_tid_address", "set_robust_list","openat", "newfstatat", "readlinkat", "fchownat","clock_gettime", "clock_getres", "clock_nanosleep","getrandom", "memfd_create", "statx", "rseq"],"action": "SCMP_ACT_ALLOW"},{"names": ["unshare", "setns", "mount", "umount2", "pivot_root","init_module", "finit_module", "delete_module","kexec_load", "kexec_file_load", "ptrace","reboot", "swapon", "swapoff", "sethostname","setdomainname", "keyctl", "bpf"],"action": "SCMP_ACT_LOG","comment": "Log escape-relevant syscalls for detection"}]}
Step 4: Audit Rules for Container Escape
# /etc/audit/rules.d/container-escape.rules# Monitor namespace operations-a always,exit -F arch=b64 -S setns -S unshare -k container_escape-a always,exit -F arch=b64 -S mount -S umount2 -k container_mount-a always,exit -F arch=b64 -S init_module -S finit_module -S delete_module -k kernel_module-a always,exit -F arch=b64 -S ptrace -k process_trace# Monitor sensitive paths-w /var/run/docker.sock -p rwxa -k docker_socket-w /proc/sysrq-trigger -p w -k sysrq-w /proc/kcore -p r -k kcore_read# Monitor container runtime-w /usr/bin/runc -p x -k container_runtime-w /usr/bin/containerd -p x -k container_runtime-w /usr/bin/docker -p x -k container_runtime
Step 5: Real-Time Alert Pipeline
# Falcosidekick configuration for alert routingconfig:slack:webhookurl: "https://hooks.slack.com/services/xxx"minimumpriority: "critical"messageformat: |*Container Escape Alert*Rule: {{ .Rule }}Priority: {{ .Priority }}Output: {{ .Output }}elasticsearch:hostport: "https://elasticsearch:9200"index: "falco-alerts"minimumpriority: "warning"pagerduty:routingkey: "xxxx"minimumpriority: "critical"
Validation Commands
# Test Falco rules with event generatorkubectl run falco-event-generator \--image=falcosecurity/event-generator \--restart=Never \-- run syscall --action PtraceAttachContainer# Check Falco alertskubectl logs -n falco-system -l app.kubernetes.io/name=falco --tail=50# Verify seccomp profile is loadeddocker inspect --format '{{.HostConfig.SecurityOpt}}' <container-id># Check audit logs for escape-related eventsausearch -k container_escape --interpret