| Security Principles in Linux |
|
Linux is secure by design but often unsecure by configuration three core principles The Principle of Least Privilege
no user, program or service should carry more permissions than necessaryevery extra permission you grant is a potential weapon for an attacker Attack Surface Reduction
attack surface is the sum of all different points where an attacker can enter the systemevery open port is a door every app is a potential window remove vulnerabilities
Defense in Depth
assume every layer will fail
|
| User Account Security: Strong Passwords, Account Policies |
|
policies which mitigate risk
Enforcing Strong Passwords with PAM
PAM (Pluggable Authentication Modules) frameworksits between login/SSH and the authentication mechanism can plugin a module into PAM which checks password strength Install on Ubunutu and Debian
use module libpam-pwquality
sudo apt install libpam-pwqualityonce installed config the file /etc/pam.d/common-passwordopen file with a text editor sudo nano /etc/pam.d/common-passwordfind the line referring to pam_pwQuality.so password requisite pam_pwquality.so retry=3can add options to the command
example using flags password requisite pam_pwquality.so retry=3 minlen=12 difok=3 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1 Password Aging and Expiration
forcing users to periodically change their passwords can lead to weak passwordscan manage passwords with the Chnage Age chage command to see current setting for use bob sudo chage -l bobto force bob to change his password every 90 days sudo chage -M 90 bobto warn bob 7 days before his password expires sudo chage -W 7 bob Locking Accounts
if user leaves the company or an account is suspect it can be disbaleddelting the user can delete files needed for later audits two ways to lock an account
Auditing for Empty Passwords
an account with an empty password is a major security holeinspect /etc/shadow if the second field is empty there is no password to find those accounts run the command sudo awk -F:'($22 == ""){print $1}' /etc/shadow
if command return any accounts either disable them or create a password for them
|
| Using UFW (Uncomplicated Firewall) for Beginners |
|
firewall Netfilter is built into the kernel difficult to use easier to use userspace tools The Classic: iptables
iptables ws along time standard tooluses a system of 'Tables' and 'Chains'
an iptables command looks like sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTtranslates to Append a rule to the INPUT chain. If the protocol is TCP and the destination port is 22 (SSH), then Jump to ACCEPT (allow it).iptables is
The Modern Red Hat Way: firewalld
default tool is firewallduses concept of Zones can assign network interfaces to zones like "Public", "Work" etc. then apply rules to zones The Modern Ubuntu Way: UFW
UFW is a simplified interface for iptablesset up an Ubuntu firewall from scratch
Deleting Rules
have UFW number the rules
sudo ufw status numberedoutput will be a numbered list to delete a rule sudo ufw delete <rule number> Advanced UFW: Rate Limiting
can limit a portprevents brute force attacks denies connections from an IP address from an IP address which has attempted to initiate 6 or more connections in 30 seconds sudo ufw limit ssh |
| Understanding SELinux and AppArmor |
|
Discretionary Access Control (DAC) is the standard user/group/other permission system owner of file makes decision Mandatory Access Control (MAC) system makes policy-based decisions two main MAC systems in Linux AppArmor (Applcation Armor)
default with Ubuntu and Debianassigns profiles to executables profile is a text file listing what files an app can read, write or excute
to check AppArmor status sudo aa-statusgenerally no need to manually config packages come with their own profiles which are enabled automatically SELinux (Security Enhanced Linux)
system developed by the NSAused in Red Hat, CentOS and Fedora more complex and powerful than AppArmor labels every file, process and port witha context a policy defines which contexts can interact to check its status sestatus The SELinux "Disable It" Myth
CentOS permission errors are sometimes blamed on SELinuxdo not disable SELinux error usually means labels are incorrect to fix labels resorecon -R /var/www/htmlcommand looks up what labels should be for the directory and corrects them to troubleshoot install settroubleshoot tools when a error occurs run sudo audi2why < /var/log/audit/audit.logtool reads log explains why the action was blocked often suggests command to resolve problem |
| Automatic Security Updates |
use unattended-upgrades tool for automatic security updates
Kernel Live Patching
normally updating the kernel requires a rebootCanonical offers livepatch service allows kernel to be patched in memory free for personal use fot up to 3 machines |
| Securing SSH: Disabling Root Login, Changing Ports, Fail2Ban |
|
Disable Password Authentication
once SSH keys are working turn off password authenticationedit /etc/ssh/sshd_config PasswordAuthentication no ChallengeResponseAuthentication norestart SSH sudo systemctl restart ssh Disable Root Login
never allow root to log in directlyedit /etc/ssh/sshd_config PermitRootLogin no Change Default Port (optional)
bots blindly attack port 22configure SSH to run on port 2222 security thru obscurity install fail2ban Use Fail2Ban
service watches the logsif someone fails to log in 5 times in a row, it bans theirIP address using the firewall sudo apt install fail2banThe default config is in /etc/fail2ban/jail.conf should not edit it create a local copy called jail.local sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local sudo nano /etc/fail2ban/jail.localscroll down to the [sshd] section customize the settings [sshd] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log maxretry = 3 bantime = 3600enables SSH sets max retires to 3 bands IP for 1 hour Starting Fail2Ban
sudo systemctl enable --now fail2ban Checking Status
see who is in jail
sudo fail2ban-client status sshdlist currently band IPs and list of IP addresses Unbanning an IP
sudo fail2ban-client set sshd unbanip <dotted quad> |
| File Integrity Monitoring Basics |
|
File Integrity Monitoring (FIM) tool calculates a cryptographic checksum for critical files run a check daily FIM tool alerts to any changes AIDE (Advanced Intrusion Detection Environment)
popualr open source tool
sudo apt install aidemust create an initial database with clean snapshot of system sudo aideinitinstall new db as the active master database sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.dbto run a check sudo aide --checkwhen installing new software or change config files aide will report the changes update the database sudo aide --update |
| Security Best Practices and Hardening Checklists |
check list for new server
|
| Summary |
covers
key points
|