#!/bin/bash # [STRG-1846] Disable drivers like firewire sudo tee /etc/modprobe.d/firewire-disable.conf > /dev/null < /dev/null sudo sed -i 's/^PresentControllerPolicy = .*/PresentControllerPolicy = apply-policy/' /etc/usbguard/usbguard-daemon.conf sudo systemctl enable --now usbguard # [NETW-3200] Disable unused network protocols sudo tee /etc/modprobe.d/network-protocols-disable.conf > /dev/null < /dev/null < /dev/null; then sudo pacman -R --noconfirm iptables fi sudo pacman -S --noconfirm --needed nftables echo "blacklist ip_tables" | sudo tee /etc/modprobe.d/blacklist-iptables.conf sudo tee /etc/modprobe.d/ip_tables-disable.conf > /dev/null < /dev/null < * hard core 0 * soft core 0 EOL # Append to /etc/profile to enforce core dump restriction system-wide echo '# Set the core dump soft limit to 0 (current enforceable limit)' | sudo tee -a /etc/profile > /dev/null echo 'ulimit -S -c 0 > /dev/null 2>&1' | sudo tee -a /etc/profile > /dev/null echo '# Set the hard limit to 0 (absolute maximum limit)' | sudo tee -a /etc/profile > /dev/null echo 'ulimit -H -c 0 > /dev/null 2>&1' | sudo tee -a /etc/profile > /dev/null # [KRNL-6000] Check sysctl settings for kernel hardening sudo tee /etc/sysctl.d/99-hardened.conf > /dev/null <<'EOL' # Kernel and filesystem hardening settings kernel.randomize_va_space = 2 kernel.kptr_restrict = 2 kernel.unprivileged_bpf_disabled = 1 kernel.modules_disabled = 1 kernel.sysrq = 0 kernel.core_uses_pid = 1 fs.suid_dumpable = 0 fs.protected_fifos = 2 fs.protected_hardlinks = 1 fs.protected_regular = 2 fs.protected_symlinks = 1 dev.tty.ldisc_autoload = 0 net.core.bpf_jit_harden = 2 net.ipv4.conf.all.forwarding = 0 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.all.log_martians = 1 net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.default.accept_redirects = 0 net.ipv4.conf.default.log_martians = 1 net.ipv6.conf.all.accept_redirects = 0 net.ipv6.conf.default.accept_redirects = 0 EOL # Apply settings now sudo sysctl --system # [SHLL-6220] Idle session handling sudo sed -i 's/^#\?TMOUT=.*/TMOUT=900/' /etc/profile sudo sed -i 's/^#\?readonly TMOUT.*/readonly TMOUT/' /etc/profile sudo sed -i 's/^#\?export TMOUT.*/export TMOUT/' /etc/profile # [MACF-6290] Enable MAC framework sudo pacman -S --noconfirm --needed apparmor apparmor.d-git sudo systemctl enable --now apparmor # [FILE-6344] Restricting process details to users ## Editing fstab if ! grep -q '^proc\s\+/proc\s\+proc\s\+' /etc/fstab; then echo '# /proc' | sudo tee -a /etc/fstab > /dev/null echo 'proc /proc proc defaults,hidepid=2,gid=wheel 0 0' | sudo tee -a /etc/fstab > /dev/null else sudo sed -i 's|^proc[[:space:]]\+/proc[[:space:]]\+proc[[:space:]]\+.*$|proc /proc proc defaults,hidepid=1,gid=wheel 0 0|' /etc/fstab fi ## Remount /proc to apply changes immediately sudo mount -o remount /proc # [FILE-6374] Check mount options # if /dev/shm is not in /etc/fstab, add it with the correct options if ! grep -q '^tmpfs\s\+/dev/shm\s\+tmpfs\s\+' /etc/fstab; then echo '# /dev/shm' | sudo tee -a /etc/fstab > /dev/null echo 'tmpfs /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0' | sudo tee -a /etc/fstab > /dev/null else sudo sed -i 's|^tmpfs[[:space:]]\+/dev/shm[[:space:]]\+tmpfs[[:space:]]\+.*$|tmpfs /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0|' /etc/fstab fi # Remount /dev/shm to apply changes immediately sudo mount -o remount /dev/shm # Replace /tmp mount if ! grep -q '^tmpfs\s\+/tmp\s\+tmpfs\s\+' /etc/fstab; then echo '# /tmp' | sudo tee -a /etc/fstab > /dev/null echo 'tmpfs /tmp tmpfs rw,nosuid,nodev,noexec 0 0' | sudo tee -a /etc/fstab > /dev/null else sudo sed -i 's|^tmpfs[[:space:]]\+/tmp[[:space:]]\+tmpfs[[:space:]]\+.*$|tmpfs /tmp tmpfs rw,nosuid,nodev,noexec 0 0|' /etc/fstab fi # Remount /tmp to apply changes immediately sudo mount -o remount /tmp # [FILE-6430] Disable mounting of some filesystems sudo tee /etc/modprobe.d/fs_blacklist.conf > /dev/null < /dev/null < /dev/null < /dev/null <