All Projects → pyllyukko → Harden.sh

pyllyukko / Harden.sh

Slackware hardening script

Programming Languages

shell
77523 projects

Labels

Projects that are alternatives of or similar to Harden.sh

Aws Gate
Better AWS SSM Session manager CLI client
Stars: ✭ 294 (+454.72%)
Mutual labels:  hardening
Jshielder
Hardening Script for Linux Servers/ Secure LAMP-LEMP Deployer/ CIS Benchmark
Stars: ✭ 483 (+811.32%)
Mutual labels:  hardening
Hardening
Hardening Ubuntu. Systemd edition.
Stars: ✭ 705 (+1230.19%)
Mutual labels:  hardening
Cis Docker Benchmark
CIS Docker Benchmark - InSpec Profile
Stars: ✭ 324 (+511.32%)
Mutual labels:  hardening
Suhosin
SUHOSIN [수호신] for PHP 5.x - The PHP security extension.
Stars: ✭ 466 (+779.25%)
Mutual labels:  hardening
Linux Baseline
DevSec Linux Baseline - InSpec Profile
Stars: ✭ 524 (+888.68%)
Mutual labels:  hardening
apache-baseline
DevSec Apache Baseline - InSpec Profile
Stars: ✭ 37 (-30.19%)
Mutual labels:  hardening
Smokinglinuxeveryday
Smoking Linux Every Day!
Stars: ✭ 47 (-11.32%)
Mutual labels:  hardening
Hardened malloc
Hardened allocator designed for modern systems. It has integration into Android's Bionic libc and can be used externally with musl and glibc as a dynamic library for use on other Linux-based platforms. It will gain more portability / integration over time.
Stars: ✭ 472 (+790.57%)
Mutual labels:  hardening
Graphenex
Automated System Hardening Framework
Stars: ✭ 665 (+1154.72%)
Mutual labels:  hardening
Ckss Certified Kubernetes Security Specialist
This repository is a collection of resources to prepare for the Certified Kubernetes Security Specialist (CKSS) exam.
Stars: ✭ 333 (+528.3%)
Mutual labels:  hardening
Chef Os Hardening
This chef cookbook provides numerous security-related configurations, providing all-round base protection.
Stars: ✭ 386 (+628.3%)
Mutual labels:  hardening
Terraform Aws Secure Baseline
Terraform module to set up your AWS account with the secure baseline configuration based on CIS Amazon Web Services Foundations and AWS Foundational Security Best Practices.
Stars: ✭ 596 (+1024.53%)
Mutual labels:  hardening
Prowler
Prowler is a security tool to perform AWS security best practices assessments, audits, incident response, continuous monitoring, hardening and forensics readiness. It contains more than 200 controls covering CIS, ISO27001, GDPR, HIPAA, SOC2, ENS and other security frameworks.
Stars: ✭ 4,561 (+8505.66%)
Mutual labels:  hardening
Ansible Ssh Hardening
This Ansible role provides numerous security-related ssh configurations, providing all-round base protection.
Stars: ✭ 746 (+1307.55%)
Mutual labels:  hardening
H2t
h2t (HTTP Hardening Tool) scans a website and suggests security headers to apply
Stars: ✭ 268 (+405.66%)
Mutual labels:  hardening
Snuffleupagus
Security module for php7 and php8 - Killing bugclasses and virtual-patching the rest!
Stars: ✭ 509 (+860.38%)
Mutual labels:  hardening
Sshd config
K4YT3X's Hardened OpenSSH Server Configuration
Stars: ✭ 49 (-7.55%)
Mutual labels:  hardening
Stronghold
Easily configure macOS security settings from the terminal.
Stars: ✭ 813 (+1433.96%)
Mutual labels:  hardening
Zeus
AWS Auditing & Hardening Tool
Stars: ✭ 630 (+1088.68%)
Mutual labels:  hardening

harden.sh

This is a script to harden your Linux installation.

asciicast

Why I made this

  • Bastille is obsolete
  • Not a member of CIS, so no downloading of the ready made scripts
  • For learning
  • For minimizing the effort needed to tweak fresh installations
    • Also for consistency

What does it do?

Common

  • Enables TCP wrappers
  • Creates legal banners
  • Disable core dumps in /etc/security/limits.conf
  • sysctl settings hardening
  • Hardens mount options (creates /etc/fstab.new)
    • Also, mount /proc with hidepid=2
  • Disables the use of certain kernel modules via modprobe
  • Configures shells
    • Creates an option to use restricted shell (rbash)
      • Also sets it as default for new users
    • Restricts the number of available shells (/etc/shells)
  • Configures basic auditing based on stig.rules if audit is installed
    • NOTE: non-PAM systems (namely Slackware) don't set the loginuid properly, so some of the rules don't work when they have -F auid!=4294967295
  • Enables system accounting (sysstat)
    • Sets it's log retention to 99999 days (the logs are really small, so it doesn't eat up disk space)
  • Configures password policies
    • Maximum age for password
    • Minimum age for password
    • Password warn age
    • Does this for existing users also
    • Note: password strength should be enforced with applicable PAM module (such as pam_passwdqc or pam_pwquality)
  • Reduce the amount of trusted CAs
    • Doesn't work in CentOS/RHEL
  • Create a strict securetty
  • Sets default umask to a more stricter 077
  • Sets console session timeout via $TMOUT (Bash)
  • PAM:
    • Configures /etc/security/namespace.conf
    • Configures /etc/security/access.conf
    • Configures /etc/security/pwquality.conf if available
    • Require pam_wheel in /etc/pam.d/su
    • Creates a secure /etc/pam.d/other
  • Disables unnecessary systemd services
  • Configures sshd_config
  • Display managers:
    • Disables user lists in GDM3 & LightDM
    • Disables guest sessions in LightDM

User accounts

  • Configures failure limits (faillog)
  • Creates /etc/ftpusers
  • Restricts the use of cron and at
  • Properly locks down system accounts (0 - SYS_UID_MAX && !root)
    • Lock the user's password
    • Sets shell to nologin
    • Expire the account
    • Adds the accounts to /etc/ftpusers
  • Sets strict permissions to users home directories
  • Configures the default password inactivity period

Debian specific

  • Enables AppArmor
  • Sets the authorized_default to USB devices via rc.local
  • APT:
    • Configures APT not to install suggested packages
    • Configure SUITE in debsecan (if installed)

PAM

Creates bunch of pam-configs that are toggleable with pam-auth-update:

PAM module Type Description
pam_wheel1 auth Require wheel group membership (su)
pam_succeed_if auth & account Require UID >= 1000 && UID <= 60000 (or 0 & login)
pam_unix1 auth Remove nullok
pam_faildelay auth Delay on authentication failure
pam_tally2 auth & account Deter brute-force attacks
pam_access account Use login ACL (/etc/security/access.conf)
pam_time account /etc/security/time.conf
pam_lastlog account Lock out inactive users (no login in 90 days)
pam_namespace session Polyinstantiated temp directories
pam_umask session Set file mode creation mask
pam_lastlog session Display info about last login and update the lastlog and wtmp files2
pam_pwhistory password Limit password reuse
  1. Not a pam-config, but a modification to existing /etc/pam.d/ files
  2. For all login methods and not just the console login

CentOS/RHEL specific

  • PAM configuration with authconfig:
    • Enables pam_faillock
    • Configures pwquality

Slackware specific

See SLACKWARE.md.

Additional features

  • SSH moduli creation
  • Some hardening steps utilize Lynis to verify themselves (to be improved/extended over time)

PGP

The import_pgp_keys() function imports a bunch of PGP keys to your trustedkeys.gpg keyring, so you can verify downloaded files/packages with gpgv. The keys that are imported are listed in the PGP_URLS[] and PGP_KEYS[] arrays.

Notes

  • Rebooting the system after running this is highly recommended, since many startup scripts are modified
  • The script is quite verbose, so you might want to record it with script
  • It is best to run this script on a fresh installation for best results

Other security software

Antivirus

I think it's justified and recommended to run an antivirus software on all of your Linux servers. This is because, even though the server's role would not be something like a file sharing server or a mail server, a proper antivirus is able to detect much more than these "traditional" malwares. I'm talking about rootkits, exploits, PHP shells and the like. Something that a malicious user might be holding at their home dirs or maybe some PHP shell was dropped through a vulnerable web application. If you would get an early warning from an antivirus software, it just might save you on that one occasion :)

So consider getting ClamAV.

Post-hardening checklist

After running the hardening script, the following actions still need to be performed manually:

  • [ ] Set LILO/GRUB password
    • [ ] Update LILO/GRUB with lilo || update-grub
  • Install at least the following additional software:
    • [ ] audit (and run harden.sh -S afterwards)
    • [ ] Aide
    • [ ] ClamAV
    • [ ] arpwatch
    • [ ] rngd (if you have HRNG)
  • [ ] Make sure NTP is running
  • [ ] Configure remote log host
  • [ ] Add legit users to:
    • /etc/porttime
    • To the users group

References

Hardening guides

Some of these documents are quite old, but most of the stuff still applies.

Other docs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].