Kicksecure / security-misc

Kernel Hardening; Protect Linux User Accounts against Brute Force Attacks; Improve Entropy Collection; Strong Linux User Account Separation; Enhances Misc Security Settings - https://www.kicksecure.com/wiki/Security-misc
https://www.kicksecure.com/wiki/Impressum
Other
515 stars 51 forks source link
kernel-hardening kspp security

Enhances miscellaneous security settings

Kernel hardening

This section is inspired by the Kernel Self Protection Project (KSPP). It attempts to implement all recommended Linux kernel settings by the KSPP and many more sources.

sysctl

sysctl settings are configured via the /usr/lib/sysctl.d/990-security-misc.conf configuration file and significant hardening is applied to a myriad of components.

Kernel space:

User space:

Core dumps:

Swap space:

Networking:

Boot parameters

Mitigations for known CPU vulnerabilities are enabled in their strictest form and simultaneous multithreading (SMT) is disabled. See the /etc/default/grub.d/40_cpu_mitigations.cfg configuration file.

Boot parameters relating to kernel hardening, DMA mitigations, and entropy generation are outlined in the /etc/default/grub.d/40_kernel_hardening.cfg configuration file.

Kernel space:

Direct memory access:

Entropy:

Networking:

mmap ASLR

Kernel Self Protection Project (KSPP) compliance status

Summary:

security-misc is in full compliance with KSPP recommendations wherever feasible. However, there are a few cases of partial or non-compliance due to technical limitations.

Full compliance:

More than 30 kernel boot parameters and over 30 sysctl settings are fully aligned with the KSPP's recommendations.

Partial compliance:

  1. sysctl kernel.yama.ptrace_scope=3

Completely disables ptrace(). Can be enabled easily if needed.

  1. sysctl kernel.panic=-1

Forces an immediate reboot on kernel panic. This can be enabled, but it may lead to unexpected system crashes.

Non-compliance:

  1. sysctl user.max_user_namespaces=0

Disables user namespaces entirely. Not recommended due to the potential for widespread breakages.

  1. sysctl fs.binfmt_misc.status=0

Disables the registration of interpreters for miscellaneous binary formats. Currently not feasible due to compatibility issues with Firefox.

Kernel Modules

Kernel Module Signature Verification

Not yet implemented due to issues:

See:

Disables the loading of new modules to the kernel after the fact

Not yet implemented due to issues:

A systemd service dynamically sets the kernel parameter modules_disabled to 1, preventing new modules from being loaded. Since this isn't configured directly within systemctl, it does not break the loading of legitimate and necessary modules for the user, like drivers etc., given they are plugged in on startup.

Blacklist and disable kernel modules

Conntrack: Deactivates Netfilter's connection tracking helper module which increases kernel attack surface by enabling superfluous functionality such as IRC parsing in the kernel. See /etc/modprobe.d/30_security-misc_conntrack.conf.

Certain kernel modules are blacklisted by default to reduce attack surface via /etc/modprobe.d/30_security-misc_blacklist.conf. Blacklisting prevents kernel modules from automatically starting.

Specific kernel modules are entirely disabled to reduce attack surface via /etc/modprobe.d/30_security-misc_disable.conf. Disabling prohibits kernel modules from starting. This approach should not be considered comprehensive; rather, it is a form of badness enumeration. Any potential candidates for future disabling should first be blacklisted for a suitable amount of time.

Hardware modules:

File system modules:

Networking modules:

Miscellaneous modules:

Other

/etc/kernel/postinst.d/30_remove-system-map

/lib/systemd/system/remove-system-map.service

/usr/libexec/security-misc/remove-system.map

/etc/security/limits.d/30_security-misc.conf

/etc/sysctl.d/30_security-misc.conf

/lib/systemd/coredump.conf.d/30_security-misc.conf

Network hardening

Not yet implemented due to issues:

See:

Bluetooth Hardening

Bluetooth Status: Enabled but Defaulted to Off

Configuration Details

Understanding Bluetooth Terms

Quick Toggle Guide

Entropy collection improvements

Restrictive mount options

A systemd service is triggered on boot to remount all sensitive partitions and directories with significantly more secure hardened mount options. Since this would require manual tuning for a given specific system, we handle it by creating a very solid configuration file for that very system on package installation.

Not enabled by default yet. In development. Help welcome.

Root access restrictions

This package does not yet automatically lock the root account password. It is not clear if this would be sane in such a package, although it is recommended to lock and expire the root account.

In new Kicksecure builds, the root account will be locked by package dist-base-files.

See:

However, a locked root password will break rescue and emergency shell. Therefore, this package enables passwordless rescue and emergency shell. This is the same solution that Debian will likely adopt for the Debian installer: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=802211

See:

Adverse security effects can be prevented by setting up BIOS password protection, GRUB password protection, and/or full disk encryption.

Console lockdown

This uses pam_access to allow members of group console to use the console but restrict everyone else (except members of group console-unrestricted) from using the console with ancient, unpopular login methods such as /bin/login over networks as this might be exploitable. (CVE-2001-0797)

This is not enabled by default in this package since this package does not know which users should be added to group 'console' and thus, would break console access.

See:

Brute force attack protection

User accounts are locked after 50 failed login attempts using pam_faillock.

Informational output during Linux PAM:

See:

Access rights restrictions

Strong user account separation

Permission Lockdown

Read, write, and execute access for "others" are removed during package installation, upgrade, or PAM mkhomedir for all users who have home folders in /home by running, for example:

chmod o-rwx /home/user

This will be done only once per folder in /home so users who wish to relax file permissions are free to do so. This is to protect files in a home folder that were previously created with lax file permissions prior to the installation of this package.

See:

umask

Default umask is set to 027 for files created by non-root users such as user user. Broken. Disabled. See:

This is done using the PAM module pam_mkhomedir.so umask=027.

This means files created by non-root users cannot be read by other non-root users by default. While Permission Lockdown already protects the /home folder, this protects other folders such as /tmp.

group read permissions are not removed. This is unnecessary due to Debian's use of User Private Groups (UPGs). See also: https://wiki.debian.org/UserPrivateGroups

Default umask is unchanged for root because then configuration files created in /etc by the system administrator would be unreadable by "others" and break applications. Examples include /etc/firefox-esr and /etc/thunderbird.

See:

SUID / SGID removal and permission hardening

SUID / SGID removal

A systemd service removes SUID / SGID bits from non-essential binaries as these are often used in privilege escalation attacks.

File permission hardening

Various file permissions are reset with more secure and hardened defaults. These include but are not limited to:

permission-hardener

permission-hardener removes SUID / SGID bits from non-essential binaries as these are often used in privilege escalation attacks. It is enabled by default and applied at security-misc package installation and upgrade time.

There is also an optional systemd unit which does the same at boot time that can be enabled by running systemctl enable permission-hardener.service as root. The hardening at boot time is not the default because this slows down the boot process too much.

See:

Access rights relaxations

This is not enabled yet because hidepid is not enabled by default.

Calls to pkexec are redirected to lxqt-sudo because pkexec is incompatible with hidepid=2.

See:

Application-specific hardening

Project scope of application-specific hardening

Added in December 2023.

Before sending pull requests to harden arbitrary applications, please note the scope of security-misc is limited to default installed applications in Kicksecure and Whonix. This includes:

It will not be possible to review and merge "1500" settings profiles for arbitrary applications outside of this context.

The main objective of security-misc is to harden Kicksecure and its derivatives, such as Whonix, by implementing robust security settings. It's designed to be compatible with Debian, reflecting a commitment to clean implementation and sound design principles. However, it's important to note that security-misc is a component of Kicksecure, not a substitute for it. The intention isn't to recreate Kicksecure within security-misc. Instead, specific security enhancements, like recommending a curated list of security-focused default packages (e.g., libpam-tmpdir), should be integrated directly into those appropriate areas of Kicksecure (e.g. kicksecure-meta-packages).

Discussion: https://github.com/Kicksecure/security-misc/issues/154

Development philosophy

Added in December 2023.

Maintainability is a key priority [1]. Before modifying settings in the downstream security-misc, it's essential to first engage with upstream developers to propose these changes as defaults. This step should only be bypassed if there's a clear, prior indication from upstream that such changes won't be accepted. Additionally, before implementing any workarounds, consulting with upstream is necessary to avoid future unmaintainable complexity.

If debugging features are disabled, pull requests won't be merged until there is a corresponding pull request for the debug-misc package to re-enable these. This is to avoid configuring the system into a corner where it can no longer be debugged.

[1] https://www.kicksecure.com/wiki/Dev/maintainability

Opt-in hardening

Some hardening is opt-in as it causes too much breakage to be enabled by default.

Miscellaneous

Legal

/usr/lib/issue.d/20_security-misc.issue

https://github.com/Kicksecure/security-misc/pull/167

Related

Discussion

Happening primarily in forums.

https://forums.whonix.org/t/kernel-hardening/7296

How to install security-misc

See https://www.kicksecure.com/wiki/Security-misc#install

How to Build deb Package from Source Code

Can be build using standard Debian package build tools such as:

dpkg-buildpackage -b

See instructions. (Replace generic-package with the actual name of this package security-misc.)

Contact

Donate

security-misc requires donations to stay alive!