
Asistente de endurecimiento de Systemd - Espejo de https://github.com/desbma/shh

Endurecimiento automático de servicios systemd guiado por el perfilado con strace.
SHH puede generar un conjunto óptimo de opciones de endurecimiento para cada uno de tus servicios, de modo que puedas aumentar el nivel de seguridad de tu sistema sin preocuparte por errores aleatorios en producción causados por un sandboxing demasiado restrictivo.
Repositorio oficial - Repositorio espejo
Strace debe estar instalado y su ejecutable accesible en PATH. Actualmente se requiere Strace >= 6.6.
Necesitas un entorno de compilación de Rust, por ejemplo desde rustup.
Ejecuta en el repositorio actual:
cargo build --release
install -Dm 755 -t /usr/local/bin target/release/shh
crates.iosudo cargo install --root /usr/local systemd-hardening-helper
Consulta las versiones de GitHub para obtener paquetes Debian compilados para cada versión etiquetada.
Los usuarios de Arch Linux pueden instalar el paquete shh de AUR.
Los usuarios de NixOS/Nix pueden instalar el último paquete desde la rama inestable.
Para endurecer una unidad del sistema llamada SERVICE.service:
shh service start-profile SERVICE. El servicio se reiniciará con el perfilado de strace.shh service finish-profile SERVICE -a. El servicio se reiniciará con una configuración endurecida creada a partir del perfilado de ejecución anterior, para permitir que se ejecute de forma segura tal como se observó durante el período de perfilado y para denegar otras acciones peligrosas del sistema.Ejecuta shh -h para obtener la referencia completa de la línea de comandos, o añade -h a un subcomando para obtener ayuda.
[!WARNING] Las opciones de endurecimiento generadas por
shhno son portables entre diferentes sistemas por construcción. Dependen de muchos factores y pueden romper el servicio si cualquiera de ellos cambia:
- la ruta de código cubierta durante el perfilado
- la versión del kernel de Linux
- la libc utilizada
- la versión de systemd
Reutilizar opciones generadas por
shhen un sistema con un entorno diferente (es decir, una distribución de Linux distinta) muy probablemente romperá el servicio.
Si quieres ejecutar una prueba rápida para ver qué opciones se generarían, puedes usar shh run -- COMMAND.
Tanto el directorio actual como la variable de entorno PATH influyen en la ejecución del programa; restablece ambos primero:
$ cd /
export PATH=/usr/local/bin:/usr/bin:/bin
Luego, para ver qué opciones se generarían para una invocación de 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 para aplicar el mayor sandboxing posible:
$ shh run --mode aggressive --filesystem-whitelisting --network-firewalling -- curl https://www.example.com -o /dev/null
...
-------- 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
SystemCallArchitectures=native
ReadOnlyPaths=-/
ReadWritePaths=-/dev
InaccessiblePaths=-/boot -/home -/lost+found -/media -/mnt -/opt -/root -/srv -/sys -/tmp -/var
TemporaryFileSystem=/usr:ro
BindReadOnlyPaths=-/usr/bin -/usr/lib -/usr/lib64 -/usr/local -/usr/share
NoExecPaths=-/
ExecPaths=-/usr/bin/curl -/usr/lib/x86_64-linux-gnu
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_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 --------