
Systemd Hardening Helper - Mirror di https://github.com/desbma/shh

Hardening automatico dei servizi systemd guidato dalla profilazione con strace.
SHH può generare un insieme ottimale di opzioni di hardening per ciascuno dei tuoi servizi, così puoi aumentare il livello di sicurezza del tuo sistema senza preoccuparti di errori casuali in produzione causati da un sandboxing troppo restrittivo.
Repository ufficiale - Repository mirror
Strace deve essere installato e il suo eseguibile deve essere raggiungibile nel PATH. Al momento è richiesta la versione di Strace >= 6.6.
È necessario un ambiente di build Rust, ad esempio da rustup.
Esegui nel repository corrente:
cargo build --release
install -Dm 755 -t /usr/local/bin target/release/shh
crates.iosudo cargo install --root /usr/local systemd-hardening-helper
Vedi le release su GitHub per i pacchetti Debian compilati per ogni versione con tag.
Gli utenti di Arch Linux possono installare il pacchetto AUR shh.
Gli utenti Nixos/Nix possono installare l'ultimo pacchetto dal branch unstable.
Per rafforzare un'unità di sistema denominata SERVICE.service:
shh service start-profile SERVICE. Il servizio verrà riavviato con la profilazione strace.shh service finish-profile SERVICE -a. Il servizio verrà riavviato con una configurazione rafforzata costruita dalla precedente profilazione a runtime, per consentirgli di funzionare in modo sicuro come osservato durante il periodo di profilazione, e per negare altre azioni di sistema pericolose.Esegui shh -h per il riferimento completo della riga di comando, oppure aggiungi -h a un sottocomando per ottenere l'aiuto.
[!WARNING] Le opzioni di rafforzamento generate da
shhsono per costruzione non portabili tra sistemi diversi. Dipendono da molti fattori e potrebbero rompere il servizio se uno di questi cambia:
- il percorso del codice coperto durante la profilazione
- la versione del kernel Linux
- la libc utilizzata
- la versione di systemd
Riusare le opzioni generate da
shhsu un sistema con un ambiente diverso (ad es. una distribuzione Linux diversa) molto probabilmente romperà il servizio.
Se vuoi eseguire un test rapido per vedere quali opzioni verrebbero generate, puoi usare shh run -- COMMAND.
La directory corrente e la variabile d'ambiente PATH influenzano entrambe l'esecuzione del programma, reimpostale prima:
$ cd /
export PATH=/usr/local/bin:/usr/bin:/bin
Poi, per vedere quali opzioni verrebbero generate per un'invocazione curl https://www.example.com:
$ shh run -- curl https://www.example.com
...
-------- Start of suggested service options --------
ProtectSystem=strict
ProtectHome=true
PrivateTmp=disconnected
PrivateDevices=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
ProtectProc=ptraceable
LockPersonality=true
RestrictRealtime=true
ProtectClock=true
MemoryDenyWriteExecute=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
SocketBindDeny=ipv4:tcp
SocketBindDeny=ipv4:udp
SocketBindDeny=ipv6:tcp
SocketBindDeny=ipv6:udp
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_BPF CAP_CHOWN CAP_MKNOD CAP_NET_RAW CAP_PERFMON CAP_SYS_BOOT CAP_SYS_CHROOT CAP_SYS_MODULE CAP_SYS_NICE CAP_SYS_PACCT CAP_SYS_PTRACE CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM
SystemCallFilter=~@aio:EPERM @chown:EPERM @clock:EPERM @cpu-emulation:EPERM @debug:EPERM @ipc:EPERM @keyring:EPERM @memlock:EPERM @module:EPERM @mount:EPERM @obsolete:EPERM @pkey:EPERM @privileged:EPERM @raw-io:EPERM @reboot:EPERM @resources:EPERM @sandbox:EPERM @setuid:EPERM @swap:EPERM @sync:EPERM @timer:EPERM
-------- End of suggested service options --------
O per isolare il più possibile:
$ shh run --mode aggressive --filesystem-whitelisting --network-firewalling -- curl https://www.example.com -o /dev/null
...
-------- Start of suggested service options --------
ProtectSystem=strict
PrivateTmp=disconnected
PrivateDevices=true
PrivateMounts=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
ProtectProc=ptraceable
LockPersonality=true
RestrictRealtime=true
ProtectClock=true
MemoryDenyWriteExecute=true
SystemCallArchitectures=native
ReadOnlyPaths=-/
InaccessiblePaths=-/boot -/data -/efi -/mnt -/opt -/root -/srv -/sys -/tmp -/var
TemporaryFileSystem=/dev:ro /home:ro /usr:ro
BindReadOnlyPaths=-/dev -/home -/usr
NoExecPaths=-/
ExecPaths=-/usr/bin -/usr/lib
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
SocketBindDeny=ipv4:tcp
SocketBindDeny=ipv4:udp
SocketBindDeny=ipv6:tcp
SocketBindDeny=ipv6:udp
IPAddressDeny=any
IPAddressAllow=[redacted]
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_BPF CAP_CHOWN CAP_IPC_LOCK CAP_MKNOD CAP_NET_RAW CAP_PERFMON CAP_SYS_BOOT CAP_SYS_CHROOT CAP_SYS_MODULE CAP_SYS_NICE CAP_SYS_PACCT CAP_SYS_PTRACE CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM
SystemCallFilter=~@aio:EPERM @chown:EPERM @clock:EPERM @cpu-emulation:EPERM @debug:EPERM @ipc:EPERM @keyring:EPERM @memlock:EPERM @module:EPERM @mount:EPERM @obsolete:EPERM @pkey:EPERM @privileged:EPERM @raw-io:EPERM @reboot:EPERM @resources:EPERM @sandbox:EPERM @setuid:EPERM @swap:EPERM @sync:EPERM @timer:EPERM
-------- End of suggested service options --------