Tag 7: Host-Betriebssystem minimieren
Ziel: Du findest offene Ports, unnötige Dienste, Pakete, Konten, SUID-Dateien und Kernel-Module auf einem Node und entfernst oder sperrst sie, ohne den Cluster zu stören. · Dauer: ca. 60 min · Voraussetzung: Tag 6
Briefing
- CKS: System Hardening (10 %) – „Minimize host OS footprint (reduce attack surface)“, „Using least-privilege identity and access management“, „Minimize external access to the network“.
- Jeder Dienst auf einem Node ist ein Weg zu kubelet-Schlüsseln und Container-Daten. Ein Node braucht: sshd, containerd, kubelet, CNI (Cilium), kube-proxy – kaum mehr.
- Reihenfolge in der Prüfung: Port finden → Prozess → systemd-Unit →
Paket → abschalten (
disable --now,mask) oder entfernen (apt purge). - Gearbeitet wird per
sshauf den Workern, nicht aufcp1.
Vorbereitung (Altlasten einspielen, von cp1 aus).
nfs-common bringt rpcbind mit,
vsftpd ist ein FTP-Server:
ssh [email protected]
sudo apt-get install -y nfs-common
dpkg -l | awk '/^ii/{print $2}' > ~/pakete-vorher.txt
sudo apt-get install -y vsftpd
exit
ssh [email protected] 'sudo apt-get install -y nfs-common'Drill 1: Offene Ports finden
Auf worker1 (ssh [email protected]).
-t TCP, -u UDP, -l lauschend,
-n Ziffern statt Namen, -p Prozess,
-H ohne Kopfzeile. Loopback-Adressen interessieren nicht –
sie sind von außen nicht erreichbar:
sudo ss -tlnpH | grep -v 127.0.0 | awk '{print $4, $6}' | sort -u
sudo ss -ulnpH | grep -v -E '127.0.0|%lo' | awk '{print $4, $6}'Erwartet (gekürzt):
*:10250 users:(("kubelet",pid=19026,fd=17))
*:10256 users:(("kube-proxy",pid=17690,fd=13))
*:21 users:(("vsftpd",pid=21117,fd=3))
*:4244 users:(("cilium-agent",pid=3100,fd=64))
0.0.0.0:111 users:(("rpcbind",pid=638,fd=4),("systemd",pid=1,fd=189))
0.0.0.0:22 users:(("sshd",pid=895,fd=3),("systemd",pid=1,fd=118))
0.0.0.0:9964 users:(("cilium-envoy",pid=2778,fd=24))
172.16.0.228:4240 users:(("cilium-agent",pid=3100,fd=156))
...
172.16.0.228%eth0:68 users:(("systemd-network",pid=667,fd=21))
0.0.0.0:111 users:(("rpcbind",pid=638,fd=5),("systemd",pid=1,fd=192))
0.0.0.0:8472
| Port | Dienst | Nötig? |
|---|---|---|
| 22, 10250, 10256 | sshd, kubelet-API, kube-proxy-Health | ja |
| 4240, 4244, 9964, 8472/udp | Cilium-Health, Hubble, Envoy-Metriken, VXLAN | ja |
| 68/udp | DHCP-Client | ja |
| 21, 111 (tcp+udp) | FTP, RPC-Portmapper | nein |
8472/udp hat keinen Prozess: Das VXLAN-Gerät lebt im Kernel. Ohne
sudo zeigt ss die Spalte users:
gar nicht.
Fortschritt speichern? Kostenlos registrieren
Drill 2: Vom Port zum Paket
Erst von außen prüfen (auf cp1), dann auf
worker1 den Weg zur Quelle gehen:
nc -zv -w2 172.16.0.228 21
nc -zv -w2 172.16.0.228 111Erwartet:
Connection to 172.16.0.228 21 port [tcp/ftp] succeeded!
Connection to 172.16.0.228 111 port [tcp/sunrpc] succeeded!
Auf worker1:
P=$(pidof vsftpd)
sudo readlink /proc/$P/exe
ps -o unit= -p $P
dpkg -S /usr/sbin/vsftpd
apt-cache rdepends --installed rpcbindErwartet:
/usr/sbin/vsftpd
vsftpd.service
vsftpd: /usr/sbin/vsftpd
rpcbind
Reverse Depends:
nfs-common
nfs-common
Prozess → Binary → Unit → Paket. rpcbind ist eine
Abhängigkeit von nfs-common – wer es entfernt, entfernt den
NFS-Client mit. Darum gehen die beiden in Drill 3 und 4 verschiedene
Wege.
Fortschritt speichern? Kostenlos registrieren
Drill 3: Dienste abschalten und maskieren
sudo systemctl disable --now vsftpd
systemctl is-active vsftpd
sudo systemctl stop rpcbind
sudo ss -tlnp 'sport = :111'Erwartet (gekürzt):
Removed "/etc/systemd/system/multi-user.target.wants/vsftpd.service".
inactive
Stopping 'rpcbind.service', but its triggering units are still active:
rpcbind.socket
LISTEN 0 4096 0.0.0.0:111 0.0.0.0:* users:(("systemd",pid=1,fd=219))
LISTEN 0 4096 [::]:111 [::]:* users:(("systemd",pid=1,fd=224))
Die Falle heißt Socket-Aktivierung: Port 111 hält jetzt
systemd selbst und startet rpcbind beim
nächsten Zugriff neu. Abschalten heißt also Socket und
Service, und mask verhindert, dass eine Abhängigkeit sie
wieder hochzieht:
sudo systemctl disable --now rpcbind.socket rpcbind.service
sudo systemctl mask rpcbind.socket rpcbind.service
sudo systemctl start rpcbind
systemctl is-enabled rpcbind.socket rpcbind.service
sudo ss -tulnp 'sport = :111'Erwartet (gekürzt):
Created symlink /etc/systemd/system/rpcbind.socket → /dev/null.
Created symlink /etc/systemd/system/rpcbind.service → /dev/null.
Failed to start rpcbind.service: Unit rpcbind.service is masked.
masked
masked
Netid State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
Gegenprobe auf cp1:
nc -zv -w2 172.16.0.228 111 meldet
Connection refused. Rückgängig ginge es mit
systemctl unmask und enable --now.
Fortschritt speichern? Kostenlos registrieren
Drill 4: Pakete entfernen
Typische Kandidaten auf einem Node: Server für FTP, Telnet, SNMP, NFS, RPC:
dpkg -l | grep -E \
'^ii +(inetutils-)?(telnet|ftp|vsftpd|rsh|nis|snmp|rpcbind|nfs|tftp)' \
| awk '{print $2}'
sudo apt-get purge -y vsftpd
sudo apt-get autoremove --purge -y
dpkg -l | awk '/^ii/{print $2}' | diff ~/pakete-vorher.txt -
ls /etc/vsftpd.confErwartet (gekürzt):
ftp
inetutils-telnet
nfs-common
rpcbind
telnet
vsftpd
The following packages will be REMOVED:
vsftpd*
The following packages will be REMOVED:
ssl-cert*
ls: cannot access '/etc/vsftpd.conf': No such file or directory
purge löscht auch die Konfiguration,
autoremove die mitgebrachten Abhängigkeiten
(ssl-cert). Der leere diff zeigt: Paketstand
wie vorher. ftp und telnet sind nur Clients
ohne offenen Port. nfs-common bleibt, weil NFS-Volumes
mount.nfs auf dem Node brauchen – dort ist Maskieren (Drill
3) die richtige Härtung.
Fortschritt speichern? Kostenlos registrieren
Drill 5: Benutzer, Gruppen, sudo
awk -F: '$3==0' /etc/passwd
getent passwd | awk -F: '$7 !~ /(nologin|false)$/ {print $1, $3, $7}'
getent group sudo adm
sudo grep -rn NOPASSWD /etc/sudoers /etc/sudoers.d
sudo passwd -S rootErwartet:
root:x:0:0:root:/root:/bin/bash
root 0 /bin/bash
sync 4 /bin/sync
ubuntu 1000 /bin/bash
sudo:x:27:ubuntu
adm:x:4:syslog,ubuntu
/etc/sudoers.d/90-cloud-init-users:4:ubuntu ALL=(ALL) NOPASSWD:ALL
/etc/sudoers.d/90-ubuntu-nopasswd:1:ubuntu ALL=(ALL) NOPASSWD:ALL
root L 2026-06-15 0 99999 7 -1
Nur ein Konto mit UID 0, root ist gesperrt
(L), der einzige Mensch ist ubuntu – mit sudo
ohne Passwort, der Cloud-Image-Standard (in Produktion: Schlüssel plus
Passwort oder ein PAM-Modul). Ein vergessenes Konto stilllegen und
entfernen:
sudo useradd -m -s /bin/bash altlast
sudo usermod -L -s /usr/sbin/nologin altlast
sudo passwd -S altlast
sudo su - altlast -c id
sudo userdel -r altlastErwartet (gekürzt):
altlast L 2026-11-18 0 99999 7 -1
This account is currently not available.
userdel: altlast mail spool (/var/mail/altlast) not found
-L sperrt das Passwort, nologin die Shell –
erst beides zusammen verhindert jede Anmeldung (ein ssh-Schlüssel umgeht
die Passwortsperre). userdel -r löscht das Home.
Fortschritt speichern? Kostenlos registrieren
Drill 6: SUID-Dateien finden
Ein SUID-Binary läuft mit den Rechten seines Besitzers, meist root.
Container-Layer unter /var/lib/containerd liefern
Duplikate, darum ausschließen:
sudo find / -xdev -type f -perm -4000 -not -path '/var/lib/containerd/*' 2>/dev/null
sudo install -m 4755 /usr/bin/id /usr/local/bin/id-suid
/usr/local/bin/id-suidErwartet (gekürzt):
/usr/bin/chfn
/usr/bin/passwd
/usr/bin/su
/usr/bin/sudo
...
/usr/sbin/mount.nfs
uid=1000(ubuntu) gid=1000(ubuntu) euid=0(root) groups=1000(ubuntu),4(adm),...
euid=0: Die Kopie läuft als root. Was gehört zu keinem
Paket?
for f in $(sudo find / -xdev -type f -perm -4000 \
-not -path '/var/lib/containerd/*' 2>/dev/null); do
dpkg -S "$f" >/dev/null 2>&1 || echo "kein Paket: $f"
done
sudo chmod u-s /usr/local/bin/id-suid
sudo rm /usr/local/bin/id-suidErwartet:
kein Paket: /usr/local/bin/id-suid
kein Paket: /usr/bin/fusermount3
fusermount3 ist ein Fehlalarm: Seit usrmerge kennt dpkg
die Datei als /bin/fusermount3
(dpkg -S fusermount3 zeigt fuse3).
id-suid ist der echte Fund.
Fortschritt speichern? Kostenlos registrieren
Drill 7: Kernel-Module sperren
Selten genutzte Protokolle wie DCCP hatten wiederholt Kernel-Lücken.
blacklist allein verhindert nur das automatische Laden per
Alias – ein ausdrückliches modprobe lädt trotzdem:
echo 'blacklist dccp' | sudo tee /etc/modprobe.d/cks-blacklist.conf
sudo modprobe -n -v dccp
echo 'install dccp /bin/false' | sudo tee -a /etc/modprobe.d/cks-blacklist.conf
sudo modprobe -n -v dccp
sudo modprobe dccp
lsmod | grep -c dccpErwartet:
blacklist dccp
insmod /lib/modules/6.8.0-149-generic/kernel/net/dccp/dccp.ko.zst
install dccp /bin/false
install /bin/false
modprobe: ERROR: ../libkmod/libkmod-module.c:1084 command_do() Error running install
command '/bin/false' for module dccp: retcode 1
modprobe: ERROR: could not insert 'dccp': Invalid argument
0
-n -v ist der Trockenlauf: Er zeigt, was
modprobe täte. Ein schon geladenes Modul entfernt
sudo modprobe -r <modul>. Ubuntu bringt eigene
Sperrlisten mit (ls /etc/modprobe.d/, z. B.
blacklist-rare-network.conf).
Fortschritt speichern? Kostenlos registrieren
Drill 8: Host-Firewall mit nftables
ufw ist installiert, aber aus
(sudo ufw status → inactive). Ein
ufw enable mit „deny incoming“ sperrt kubelet (10250),
VXLAN (8472/udp), Cilium-Health (4240) und alle NodePorts – der Node
fällt aus dem Cluster. Gezielte Regeln in einer eigenen
nftables-Tabelle lassen die Tabellen von kube-proxy und Cilium
unberührt. Testdienst auf worker1 (endet nach 15 min von
selbst):
sudo systemd-run --unit=tag07-listen -p RuntimeMaxSec=900 nc -lk 8000
sudo nft add table inet cks
sudo nft add chain inet cks input \
'{ type filter hook input priority 0; policy accept; }'
sudo nft add rule inet cks input tcp dport 8000 ip saddr != 172.16.0.126 drop
sudo nft list table inet cksErwartet:
Running as unit: tag07-listen.service; invocation ID: e3ea1ebbf2c14488893c1abb9f7ef3a1
table inet cks {
chain input {
type filter hook input priority filter; policy accept;
tcp dport 8000 ip saddr != 172.16.0.126 drop
}
}
Probe von cp1 und von worker2
(ssh [email protected]):
nc -zv -w2 172.16.0.228 8000Erwartet: auf cp1
Connection to 172.16.0.228 8000 port [tcp/*] succeeded!,
auf worker2
nc: connect to 172.16.0.228 port 8000 (tcp) timed out: Operation now in progress.
Ein drop in irgendeiner Tabelle ist endgültig; ein
accept in deiner Tabelle hebt dagegen keinen
drop anderer Tabellen auf. Aufräumen auf
worker1:
sudo nft delete table inet cks
sudo systemctl stop tag07-listenFortschritt speichern? Kostenlos registrieren
Übung: Speed-Drills
- Welcher Prozess lauscht auf
worker1auf TCP 10256? Zeitziel: 30 s - Finde auf
worker2alle SUID-Dateien außerhalb der Container-Layer, die zu keinem Paket gehören. Zeitziel: 2 min - Liste auf
worker1alle Konten mit Login-Shell und alle sudo-Regeln ohne Passwort. Zeitziel: 1 min - Sorge auf
worker2dauerhaft dafür, dass das Modulsctpnicht geladen werden kann, und weise es nach. Danach zurückbauen. Zeitziel: 1 min
Lösung
ssh [email protected] "sudo ss -tlnp 'sport = :10256'"
ssh [email protected]
sudo find / -xdev -type f -perm -4000 -not -path '/var/lib/containerd/*' \
-exec dpkg -S {} \; 2>&1 >/dev/null
echo 'install sctp /bin/false' | sudo tee /etc/modprobe.d/cks-sctp.conf
sudo modprobe sctp
sudo rm /etc/modprobe.d/cks-sctp.conf
exit
ssh [email protected]
getent passwd | awk -F: '$7 !~ /(nologin|false)$/ {print $1}'
sudo grep -rn NOPASSWD /etc/sudoers /etc/sudoers.d
exitErwartet (gekürzt):
LISTEN 0 4096 *:10256 *:* users:(("kube-proxy",pid=17690,fd=13))
dpkg-query: no path found matching pattern /usr/bin/fusermount3
install sctp /bin/false
modprobe: ERROR: ../libkmod/libkmod-module.c:1084 command_do() Error running install
command '/bin/false' for module sctp: retcode 1
modprobe: ERROR: could not insert 'sctp': Invalid argument
root
sync
ubuntu
/etc/sudoers.d/90-cloud-init-users:4:ubuntu ALL=(ALL) NOPASSWD:ALL
/etc/sudoers.d/90-ubuntu-nopasswd:1:ubuntu ALL=(ALL) NOPASSWD:ALL
In Aufgabe 2 dreht 2>&1 >/dev/null die
Ausgaben: Nur die Fehlermeldungen von dpkg -S – also die
Dateien ohne Paket – bleiben stehen.
Fortschritt speichern? Kostenlos registrieren
Kontrollpunkt
ssh [email protected] "sudo ss -tlnp | grep -E ':(21|111) '"Erwartet: keine Ausgabe.
ssh [email protected] 'dpkg -l vsftpd'Erwartet:
dpkg-query: no packages found matching vsftpd
ssh [email protected] 'systemctl is-enabled rpcbind.socket rpcbind.service'Erwartet: zweimal masked.
ssh [email protected] 'sudo modprobe -n -v dccp'Erwartet: install /bin/false
ssh [email protected] 'sudo nft list tables | grep cks'Erwartet: keine Ausgabe.
k get nodesErwartet: alle drei Nodes Ready.
Im Labor bleiben: rpcbind maskiert auf
beiden Workern (nach der Challenge), die DCCP-Sperre
/etc/modprobe.d/cks-blacklist.conf auf
worker1.
Challenge
Auf worker2 sollen nur noch Dienste von außen erreichbar
sein, die Kubernetes, Cilium oder ssh gehören. Finde den Rest und sorge
dafür, dass er auch nach einem Neustart nicht wieder lauscht – ohne
Pakete zu entfernen.
Hinweis: Filtere die bekannten Prozesse aus der
ss-Ausgabe heraus, und denk an die Socket-Units.
Lösung
ssh [email protected]
sudo ss -tulnp | grep -v -E '127\.0\.0|%lo|kubelet|kube-proxy|cilium|sshd'Erwartet (gekürzt):
Netid State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
udp UNCONN 0 0 172.16.0.83%eth0:68 0.0.0.0:* users:(("systemd-n…
udp UNCONN 0 0 0.0.0.0:111 0.0.0.0:* users:(("rpcbind",…
udp UNCONN 0 0 0.0.0.0:8472 0.0.0.0:*
tcp LISTEN 0 4096 0.0.0.0:111 0.0.0.0:* users:(("rpcbind",…
...
68/udp (DHCP) und 8472/udp (VXLAN) sind nötig, übrig bleibt
rpcbind:
sudo systemctl disable --now rpcbind.socket rpcbind.service
sudo systemctl mask rpcbind.socket rpcbind.service
sudo ss -tulnp | grep -c ':111 '
exit
nc -zv -w2 172.16.0.83 111Erwartet (gekürzt, das nc auf
cp1):
Created symlink /etc/systemd/system/rpcbind.socket → /dev/null.
Created symlink /etc/systemd/system/rpcbind.service → /dev/null.
0
nc: connect to 172.16.0.83 port 111 (tcp) failed: Connection refused
Fortschritt speichern? Kostenlos registrieren
Prüfungstipp
ss -tulpnauswendig können; ohnesudofehlen die Prozesse.ps -o unit= -p <PID>liefert die systemd-Unit,dpkg -S <pfad>das Paket.- Socket-aktivierte Dienste (
*.socket) kommen nachstopzurück: Socket abschalten, im Zweifelmask. Prüfe danach immer mitss, nicht nur mitsystemctl. - Wenn die Aufgabe „entfernen“ sagt,
apt purge(bzw.apt-get purge), sonst reichtdisable --now. Danachk get nodes– ein gestoppter Node-Dienst darf den Node nichtNotReadymachen.
Enterprise-Notiz
- Minimal-Images für Nodes (Talos, Flatcar, Bottlerocket) haben keinen Paketmanager, Talos und Bottlerocket auch keine Shell – Härtung durch Weglassen statt Aufräumen.
- Node-Images werden gebaut und ersetzt, nicht nachträglich gepflegt; CIS-Benchmarks für das Betriebssystem prüfen das per Pipeline (z. B. OpenSCAP, Ubuntu Security Guide).
- IAM in der Cloud: Node-Rollen (Instance Profile, Managed Identity) auf das Nötigste beschränken, Metadaten-Dienst für Pods sperren (Tag 2) und Workload-Identität statt Node-Rolle nutzen.
- Menschliche Zugänge über zentrale Identitäten (SSO, kurzlebige ssh-Zertifikate) statt lokaler Konten; sudo mit Passwort oder Freigabe, alles protokolliert.
- Host-Firewalls zentral als Code (Cloud-Security-Groups, Cilium Host Policies) statt Handarbeit pro Node.