|
| 1 | +# Title: Container - Writable bind mounts without nosuid (SUID risk) |
| 2 | +# ID: CT_RW_bind_mounts_nosuid |
| 3 | +# Author: HT Bot |
| 4 | +# Last Update: 17-09-2025 |
| 5 | +# Description: Detect writable bind-mounted paths inside containers that are not mounted with nosuid. |
| 6 | +# If the container user is root and the mount is a host bind mount without nosuid, an attacker may |
| 7 | +# be able to drop a SUID binary on the shared path and execute it from the host to escalate to root |
| 8 | +# (classic container-to-host breakout via writable bind mount). |
| 9 | +# License: GNU GPL |
| 10 | +# Version: 1.0 |
| 11 | +# Functions Used: containerCheck, print_2title, print_list, print_info |
| 12 | +# Global Variables: $inContainer |
| 13 | +# Initial Functions: containerCheck |
| 14 | +# Generated Global Variables: $CT_RW_bind_mounts_matches |
| 15 | +# Fat linpeas: 0 |
| 16 | +# Small linpeas: 1 |
| 17 | + |
| 18 | +containerCheck |
| 19 | + |
| 20 | +if [ "$inContainer" ]; then |
| 21 | + echo "" |
| 22 | + print_2title "Container - Writable bind mounts w/o nosuid (SUID persistence risk)" |
| 23 | + print_info "https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/index.html#writable-bind-mounts" |
| 24 | + |
| 25 | + if [ -r /proc/self/mountinfo ]; then |
| 26 | + CT_RW_bind_mounts_matches=$(grep -E "(^| )bind( |$)" /proc/self/mountinfo 2>/dev/null | grep -E "(^|,)rw(,|$)" | grep -v "nosuid" || true) |
| 27 | + else |
| 28 | + CT_RW_bind_mounts_matches=$(mount -l 2>/dev/null | grep -E "bind" | grep -E "(^|,)rw(,|$)" | grep -v "nosuid" || true) |
| 29 | + fi |
| 30 | + |
| 31 | + if [ -z "$CT_RW_bind_mounts_matches" ]; then |
| 32 | + print_list "Writable bind mounts without nosuid ............ No" |
| 33 | + else |
| 34 | + print_list "Writable bind mounts without nosuid ............ Yes" | sed -${E} "s,Yes,${SED_RED}," |
| 35 | + echo "$CT_RW_bind_mounts_matches" | sed -${E} "s,/proc/self/mountinfo,${SED_GREEN}," |
| 36 | + echo "" |
| 37 | + if [ "$(id -u 2>/dev/null)" = "0" ]; then |
| 38 | + print_list "Note"; echo ": You are root inside a container and there are writable bind mounts without nosuid." | sed -${E} "s,.*,${SED_RED}," |
| 39 | + echo " If the path is shared with the host and executable there, you may plant a SUID binary (e.g., copy /bin/bash and chmod 6777)" |
| 40 | + echo " and execute it from the host to obtain root. Ensure proper authorization before testing." |
| 41 | + else |
| 42 | + print_list "Note"; echo ": Current user is not root; if you obtain container root, these mounts may enable host escalation via SUID planting." | sed -${E} "s,.*,${SED_RED}," |
| 43 | + fi |
| 44 | + fi |
| 45 | + echo "" |
| 46 | +fi |
0 commit comments