Lab 7 – Securing Linux Systems
Materials Needed:
Assignment:
The original checklist was written by Gene Schultz of Berkeley Lab and has
been copyrighted in 2003 by the Regents of the
A.
Securing Your System’s Accounts and Groups
%syZ12Ghy#! would be a very strong
password, but do not use this particular example as your password! The root
account is the most important to protect, and the danger of it being
compromised is high, given that powerful password crackers such as John the
Ripper are freely available.
#cat
/etc/ftpusers
root
adm
sysop
daemon
lp
If the console is not
physically secure, you should limit who can login and what service they can
use. /etc/security/access.conf defines the users who can login using particular
services. For example, to keep everyone but root from logging in and using the
console, add the following entry to this file:
-:ALL EXCEPT root :console
bin
daemon
adm
lp
sync
mail
news
uucp
Caution: always test deletion of default accounts on
nonproduction hosts before deleting them on production systems.
#
cd <path_to_directory_that_contains_su>
# chgrp root su
# chmod o-x su
#
chage -M90 -W5 <username>
$
chage -l <username>
C. Securing Your System’s File System
#
chown user <file>
#
chgrp group <file>
#
find / -perm -002 -type f -print
#
chmod o-w <file>
For example, if the
permission is 666 and you want to allow world only read access to /etc/hosts, enter:
#
chmod 664 /etc/hosts
#
find / -user root -perm -4000 –print
#
find / -user root -perm -2000 –print
#
chmod 0XXX <file>
Setting the sticky bit
prevents users other than the owner of files in a temporary directory for which
the sticky bit is set from removing or renaming the files in that directory.
a.
To check whether the sticky bit is set on, enter
#
ls -ldg /tmp
drwxrwxrwt 1 root root
256
(Note that a “t” is
listed in the output to show that the sticky bit is set.)
b.
To set the sticky bit on /tmp, enter:
#
chmod 1XXX /tmp
OR
#
chmod o+t /tmp
umask puts a mask on permissions for newly created files
and directories you create to help prevent accidental assignment of
inappropriate permissions. It defines nonallowed default permission values in
octal.
#
umask 022
D. Securing Services that Run on Your System
This tool acts as
host-based firewall by screening out certain undesirable traffic from certain
hosts. Visit http://www.lbl.gov/ITSD/Security/services/install-banner.html#tcp
for procedures for installing the built-in TCP wrapper tool.
If you configure the TCP
wrapper, be sure to regularly check its output. /var/log/secure keeps records of connections. Transferred files are
recorded in /var/log/xferlog.
xinetd messages are saved in var/log/messages.
All the r-utilities
(rlogin, rsh, rdist, rcp, rexec, etc.)
tftp ftp
finger uucp
systat chargen
echo nfs
http dns
sendmail
#
chkconfig <service> on|off
#
/etc/rc.d/init.d/xinetd restart (only if the service is an xinetd-based service)
1) If so, stop sendmail
from running in daemon mode by editing etc/sysconfig/sendmail to have the
following entry:
DAEMON=no
2) Next, restart the
sendmail daemon by entering
#
/etc/rc.d/init.d/sendmail restart
#
/etc/rc.d/init.d/named stop
# rpm -e caching-nameserver
# rpm -e bind
1) Edit /etc/ftpaccess such that the following line:
class all real,guest,anonymous *
is changed to:
class all real *
2) You need to also
remove the FTP anonymous home directory by entering:
#
rpm -e anonftp
The /bin and /etc
directories need to be root-owned and to have permissions of 111. /pub should also be owned by root and should have
permissions of 2555.
2) Set up access through /etc/hosts.deny|allow by including the following entry:
in.ftpd : ALL
3) Additionally, to run
anonymous FTP more securely, use /etc/ftpaccess to restrict operations (e.g., to prevent anonymous
users from modifying file contents):
chmod no guest,anonymous
delete no guest,anonymous
overwrite no guest,anonymous
rename no guest,anonymous
1) allow
only write and execute access to it:
#
mkdir -m 333 /home/ftp/incoming
2) Additionally, add the
following entries in /etc/ftpaccess:
upload /home/ftp /incoming yes
root ftp 0600 nodirs
noretrieve /home/ftp /incoming/
(Note: The first entry
allows files to be uploaded to the /incoming directory, but they will be UID root and GID FTP, mode 0600, and
subdirectories cannot be created below this directory. The second prevents
anonymous users from downloading any files from /incoming.)
h.
If you need to
run the NFS service, make NFS access as secure as possible.
1) First, specify allowed addresses and/or address ranges in /etc/hosts.allow
For example, to allow NFS
mounts only by LBLnet hosts, include the following entry:
portmap : 131.243.0.0/255.255.0.0
128.3.0.0/255.255.0.0
2) Do not allow the root
volume to be NFS-mounted. Additionally, create entries in /etc/exports that allow read-only, not read/write access, per the
following:
<directory1>
<hostname> ro
<directory2>
<hostname> ro
#
/etc/rc.d/init.d/xinetd stop
# /sbin/chkconfig xinetd off
IMPORTANT NOTE: If you
need to run a Web server, you’ll need to ensure that it runs securely. An
insecure Web server can be one of the easiest ways an attacker can gain
unauthorized access to the host on which the Web server runs. See the Apache
Web Guideline.
–~.rhosts –/etc/hosts.equiv
#
find / -name hosts.equiv -print
ssh-keygen -t dsa
and then entering a passphrase (the first letters of each word from a fairly
long phrase) for SSH access.
A public-private key pair
will be generated; by default, both will be saved in the path $HOME/.ssh.
id_dsa.pub
will hold the public key and /id_dsa
will hold the private key.
<home_directory>/.ssh/authorized_keys2 [fn5]
#
ln -s /usr/bin/scp /usr/bin/rcp
# ln -s /usr/bin/ssh
/usr/bin/rsh
# ln -s /usr/bin/slogin /usr/bin/rlogin
E. Setting Up Host-based
Firewall Protection
To do so:
IPTables configuration is
not within the scope of this checklist, however. For more information, see Ziegler’s
excellent book (referenced below) on this topic.
kern.*
/var/log/kernel
*.warn;*.err /var/log/syslog
*.err @<loghost_address>
authpriv.*;auth.*
@<loghost_address>
touch /var/log/syslog
/var/log/kernel
chmod 600 /var/log/syslog /var/log/kernel
#
/etc/rc.d/init.d/syslog restart
In the example below, to
rotate every four weeks, send errors to root, create new empty logs after the
log files are rotated, and to compress log files, enter
weekly
rotate 4
errors root
create
compress
in /etc/logrotate.d/syslog
(You may also want to
check the default log rotation in /etc/logrotate.conf.)