linux hardening - nullhyd

27
HARDENING LINUX SERVER A SECURE APPROACH

Upload: nu-the-open-security-community

Post on 17-Mar-2018

1.568 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: Linux Hardening - nullhyd

HARDENING LINUX SERVERA SECURE APPROACH

Page 2: Linux Hardening - nullhyd

Kaleem

Technical consultant / Operations engineer

CipherCloud

Email : [email protected]

Page 3: Linux Hardening - nullhyd

BENCHMARKS

• CIS Security Benchmarks for Linux

•NSA Security Configuration Guides for Linux

Page 4: Linux Hardening - nullhyd

CHOOSE A FLAVOUR ?

For better or worse, there’s no one “Linux”. Instead, there are loads of Linux

distributions that all run the Linux kernel.

" Server distributions differ from desktop versions,security distros both in

packages and in support "

Page 5: Linux Hardening - nullhyd

DIVISION OF LABOUR

Basic idea behind the protection of a Linux server is to have the

system administrator control the work of the entire server and

only use the packages that are necessary for the planned

services.

• BASIC

• SERVER (WEB,DNS,MAIL)

• DESKTOP

Page 6: Linux Hardening - nullhyd

KEEP IT SEPARATED ( FILE SYSTEM PARTITIONING)

Keep partitions Separate for a better administration and security

Page 7: Linux Hardening - nullhyd

ENCRYPTING THE FILESYSTEM

Page 8: Linux Hardening - nullhyd

ENCRYPTING THE RUNNING SERVER

• To encrypt a partition using dm-crypt+LUKS on Linux

• $ sudo yum install cryptsetup

• $ sudo cryptsetup --verbose --verify-passphrase luksFormat /dev/sdb1

• sudo cryptsetup luksDump /dev/sdb1

• sudo cryptsetup luksOpen /dev/sdb1 sdb1

• Follow the FIPS -140

• Install the dracut-fips package:

# yum install dracut-fips

• Recreate the INITRAMFS image:

# dracut -f

Page 9: Linux Hardening - nullhyd

SECURE THE BOOT

Root password to access run level 1:

echo "~~:S:wait:/sbin/sulogin" >> /etc/inittab

perl -npe 's/ca::ctrlaltdel:\/sbin\/shutdown/#ca::ctrlaltdel:\/sbin\/shutdown/' -i /etc/inittab

Password Protecting GRUB :

/sbin/grub-md5-crypt

password --md5 <password-hash>

Replace <password-hash> with the value returned by /sbin/grub-md5-crypt

The next time the system boots, the GRUB menu prevents access to the editor or command interface without first pressing p followed by the GRUB password.

Page 10: Linux Hardening - nullhyd

IPFILTERS & TCP WRAPPERS

IPTables has the following 4 built-in tables

• FILTER Table - (Input ,output ,Forward chain )

• NAT Table - (Pre routing,Post routing,output chain )

• MANGLE Table - (Pre routing, Output,Forward, Input, Post routing)

• RAW Table - (Pre routing , Output )

• Tcp warppers for a restrictive network

• # /etc/hosts.allow

• # /etc/hosts.deny

Page 11: Linux Hardening - nullhyd

EGRESS FILTERING FOR A HEALTHIER INTERNET

When your SERVER is compromised, you are no longer the innocent party

trying to defend yourself, to other machines you have become the attacker.

Just reverse the -d / --dport (destination address / destination port) and -s / -

-sport (source address / source port) arguments.

Page 12: Linux Hardening - nullhyd

JUST A SAMPLE FIREWALL RULE

Page 13: Linux Hardening - nullhyd

THE "RIGHTS"

Restrict the root :

No one other than root should be allowed in root's home directory. The default

settings are close to this, but not quite paranoid enough.

echo "tty1" > /etc/securetty

chmod 700 /root

USE SUDO :

sudo allows for granular control over privileged actions. This way administrator

can start, stop and otherwise manage the web server without being able to affect

other services.

Page 14: Linux Hardening - nullhyd

PERMISSIONS & PASSWORDS

• Narrow down rights for system files and folders

chmod 700 ( files owned by root )

chown root:root ( files owned by root )

Set a crotab to check the permissions periodically.

• Upgrade Password Hashing Algorithm to SHA-512

# authconfig --passalgo=sha512 --update

Page 15: Linux Hardening - nullhyd

PASSWORD POLICIES

Set Password Creation Requirement Parameters Using pam_cracklib

Recommended Values:

PASS_MAX_DAYS 90

PASS_MIN_DAYS 6

PASS_MIN_LEN 14

PASS_WARN_AGE 7

#sed -i 's/PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/g' /etc/login.defs

#sed -i 's/PASS_MIN_LEN.*/PASS_MIN_LEN 14/g' /etc/login.defs

#sed -i 's/PASS_MIN_LEN.*/PASS_MIN_DAYS 6/g' /etc/login.defs

#sed -i 's/PASS_WARN_AGE.*/PASS_WARN_AGE 7/g' /etc/login.defs

Page 16: Linux Hardening - nullhyd

CLEANUP !

Delete non-used user accounts

# userdel ( shutdown, halt, games, operator, gopher, games )

Disable unnecessary services

#for i in rpcbind restorecond nfslock lldpad fcoe rpcidmapd; do service $i stop;

chkconfig $i off; done

Remove unnecessary packages

# yum groupremove (package names )

# sudo apt-get remove pino

Make sure no non-root accounts have UID set to 0

# % awk -F: '($3 == "0") {print}' /etc/passwd

Page 17: Linux Hardening - nullhyd

BASH HARDENING

• Define Read-Only environment variables -> To avoid

being overwriten by users (declare –r

HISTFILE=~/.bash_history && chattr +I .bash_history)

• HISTFILESIZE -> Maximum number of lines to keep

• HISTFSIZE -> Maximum stored commands in memory

• HISTTIMEFORMAT -> Date/Time format to store

commands execution

• Force to commit HISTFILE every time a command is

typed instead of logout -> readonly || declare -r

PROMPT_COMMAND="history -a"

• Limit Timeout login session -> declare -r TMOUT=120

Page 18: Linux Hardening - nullhyd

AVOID THE FORK BOMBS

• The ulimit and sysctl programs allow to limit system-wide resource use. This can help a lot in

system administration, e.g. when a user starts too many processes and therefore makes the system

unresponsive for other users.

• # ulimit -u 30

# ulimit -a

max user processes (-u) 30

• # sysctl -a

vm.swappiness = 60

• # sysctl vm.swappiness=0

vm.swappiness = 0

• "fork: resource temporarily unavailable".

Page 19: Linux Hardening - nullhyd

STRIPPING DOWN LINUX( REMOVE THE UNNECESSARY PACKAGES)

• One of the simplest ways to hinder an intruder is to remove unnecessary

system binaries.On a typical Linux server, there are many unneeded tools,

which can be useful to an attacker if he gains entry.

• Unnecessary Binaries

• Network Utilities

• Compilers and Interpreters

Page 20: Linux Hardening - nullhyd

SECURE REMOTE ADMINISTRATION

• Remove the legacy , unsecure tools.

• Make sure to keep the crypto libraries updated ( Patch them)

• Avoid installing ssh client

• Harden the SSH

• Use jumphosts, vpn to connect.

• Avoid using passwords, start using key based authentication.

• Remove the non-ssl processes

# yum remove erase xinetd tftp-server ypserv telnet-server rsh-server

Page 21: Linux Hardening - nullhyd

SSH HARDENING PARAMETERS

Page 22: Linux Hardening - nullhyd

KEY BASED AUTHENTICATION

# ssh-keygen

Created directory '/home/username/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again:

Your identification has been saved in /home/username/.ssh/id_rsa. Your public key has been saved in /home/username/.ssh/id_rsa.pub. The key fingerprint is: a9:49:2e:2a:5e:33:3e:a9:de:4e:77:11:58:b6:90:26 username@remote_host The key's randomart image is: +--[ RSA 2048]----+ | ..o | | E o= . | | o. o | | .. | | ..S | | o o. | | =o.+. | |. =++.. | |o=++. | +-----------------+

Page 23: Linux Hardening - nullhyd

KERNEL HARDENING: DISABLE AND BLACKLIST LINUX MODULES

• The Linux kernel is modular, which makes it more flexible than monolithic kernels. New

functionality can be easily added to a run kernel, by loading the related module.

One option to disallow loading modules, is by blacklisting them.

# modinfo

# modprobe --showconfig | grep blacklist

# /etc/modprobe.d/blacklist-firewire.conf

# modprobe --showconfig | grep "^install" | grep "/bin"

By using the kernel setting kernel.modules_disabled and set its value to 1, we can make sure

things are really tightened. Even the root user can not load any modules anymore.

Page 24: Linux Hardening - nullhyd

TUNING KERNEL FOR BETTER SECURITY

• Enable TCP SYN Cookie Protection - net.ipv4.tcp_syncookies = 1

• Disable IP Source Routing - net.ipv4.conf.all.accept_source_route = 0

• Disable ICMP Redirect Acceptance - net.ipv4.conf.all.accept_redirects = 0

• Enable IP Spoofing Protection - net.ipv4.conf.all.rp_filter = 1

• Enable Ignoring to ICMP Requests - net.ipv4.icmp_echo_ignore_all = 1

• Enable Ignoring Broadcasts Request - net.ipv4.icmp_echo_ignore_broadcasts = 1

• Enable Logging of Spoofed Packets, Source Routed Packets, Redirect Packets

• (net.ipv4.conf.all.log_martians = 1 )

Page 25: Linux Hardening - nullhyd

CRITICAL,UNKNOWN AND THIRD PARTY

• SE LINUX Security-Enhanced Linux (SELinux) is a Linux feature that

provides a variety of security policies for Linux kernel.

• APP ARMOUR (Application Armor) is another security software for Linux

which maintained and released by Novell under GPL. AppArmor was

created as an alternative to SELinux. AppArmor works with file paths.

• GRSECURITY is a set of patches for the Linux kernel with an emphasis on

enhancing security. It utilizes a multi-layered detection, prevention, and

containment model.

Page 26: Linux Hardening - nullhyd

AUDIT ,LOG, INTEGRITY CHECK

Record Events That Modify Date and Time Information,

System's Network Environment ,System's Mandatory Access

Controls ,Unsuccessful Unauthorized Access Attempts to Files

Install AIDE, Implement Periodic Execution of File Integrity.

( TRIP WIRE ,AIDE ,AUDITD,LOGWATCH)

Page 27: Linux Hardening - nullhyd

QUESTIONS & SUGGESTIONS