UNIX and Linux Security Checklist
UNIX and Linux Security Checklist
Checklist v3.0
AusCERT public release
2007-07-25
Introduction
This document has been published by the Australian Computer
Emergency Response Team (AusCERT). It provides a checklist of
steps to improve the security of UNIX and Linux systems. We
encourage system administrators to review all sections of this
document and if appropriate modify their systems to fix potential
weaknesses.
Before using this document, please ensure you have the latest
version. New versions of this checklist will be available via the URL
listed above and should be checked for periodically.
Disclaimer
AusCERT advises that this information is provided without warranty -
sites should ensure that actions and procedures taken from
information in this document are verified and in accordance with
security policies that are in place within their organisation. Listing of
software products or tools within this document does not constitute
endorsement by AusCERT or The University of Queensland.
Contents
1. A. Determine Appropriate Security
2. B. Installation
3. C. Patch and Update
4. D. Minimise
5. E. Secure Base OS
6. F. Secure Major Services
7. G. Add Monitoring Capability
8. H. Connect to Net
9. I. Test Backup/Rebuild Strategy
10. J. Maintain
1. References
First decide on and document the role of this computer. This means
specifying exactly which services the computer will provide.
handled
The following steps will help to determine the security needs of this
system:
• office emails
• client personal data
• private keys and certificates
• source code being developed in-house
Targeted attacks:
Targeted attacks refer to those where attackers may specifically
target your business or your customers. Depending on the kind of
information processed, threats may include malicious changes by a
disgruntled insider, a denial of service attack for the purpose of
extortion, or industrial espionage or sabotage.
Indiscriminate attacks:
All computers on the Internet are subject to these threats. Some
organisations believe that their systems will not be of interest to
attackers; this is incorrect. Attackers are interested in controlling
your computers for a number of reasons, including to launch attacks
on other organisations, to send spam, or to capture users'
authentication credentials.
3. Impacts if threats are realised
Making explicit the threats and impacts in this way will highlight
what the priorities should be for protecting each kind of information
on the system.
met
Consider how reliable this computer is expected to be, and what the
impact will be if these uptime requirements are not met.
for role
Document which TCP and UDP port numbers this computer will need
to communicate on to perform its role, including the direction (in or
outbound).
B. Installation
If using MD5 or SHA1 hashes, make sure that the list of hashes itself
comes from a trusted source (either digitally signed (preferably) or
from a trusted SSL authenticated web site).
Use separate partitions for /, /usr, /var, /tmp and /home. Good
planning of the partition scheme is essential.
After the first install, consider applying patches and updates while
disconnected from the network, either:
D. Minimise
After the initial installation is complete, minimise the amount of
software that is present by uninstalling or disabling the unneeded
software packages, leaving a minimal set of software. Ideally, only
the software that will be used in performing the computer's role, as
decided in A.1 above, should remain.
FreeBSD, AIX
Solaris, HP-UX
Ensure that the files in the tftp area are not writable, unless
this is required for the system's role.
Solaris, AIX
The way startup scripts are used to start services when the system
boots is different on different variants of UNIX. See your vendor's
documentation for specific details.
Solaris, AIX
The reason is that these are large, complex software systems with
components that must run with privileged access to the computer's
hardware.
If IPv6 is not being used, then consider also turning off the IPv6
stack.
OpenBSD
E. Secure Base OS
Consider having a paper User Registration Form for each user on the
system. This form includes a section that the user signs, stating that
they have read your security policy or acceptable use policy and
what the consequences are if they contravene the policy.
Have a process for staff transfers and role changes, to ensure that
appropriate changes are made to the user's authorisation and
access rights on the system.
Ensure that there are no shared accounts other than root. (i.e. more
than one person should not know the password to an account)
Disable any guest accounts (accounts that can be used without any
authentication) and do not create guest accounts. (Note: Even now,
some systems come preconfigured with guest accounts.)
IRIX
Reasons:
1. For accountability. This is particularly important if there is
more than one person who logs on to this computer.
2. It also makes an attacker do more work to get to root.
Secure terminals:
The relevant configuration file may be called /etc/ttys,
/etc/default/login, /etc/security or /etc/securetty depending on the
system. See the manual pages for file format and usage
information.
Check that the secure option is removed from any local entries that
don't need root login capabilities. The secure option should be
removed from console if you do not want users to be able to reboot
in single user mode. [Note: This does not affect usability of the su
command.]
Check that the current directory "." is not in the PATH. Note that an
empty string is interpreted to mean the same as "." so also make
sure the PATH does not contain any empty strings. For example, the
following PATH is insecure:
/sbin:/bin:/usr/sbin::/usr/bin This PATH advice is especially important
for the root account.
Do specify absolute path names when writing scripts and cron jobs.
(e.g. /bin/su, /bin/find, /bin/passwd.) This is to ensure that even if
scripts get run in an environment with a different PATH, they can not
be tricked into executing a malicious program. One way to address
this is explicitly to set the PATH variable at the start of the script,
giving it a minimal list of directories.
Note: when using su, it is good practice to use the dash parameter,
i.e. "/bin/su -" to reset the environment. While this does not give any
significant protection if the user account were compromised, it does
prevent bad environment variables from being unintentionally
inherited by the privileged shell.
E.3 Authentication
Verify that all accounts have passwords. (i.e. the password field is
not empty) Check NIS+ passwords too, if you have them.
Debian
Have a clear password policy for your organisation. See the AusCERT
Advisory SA-93.04 for guidelines on developing password policies.
For PAM systems this can be done by a PAM module. If your PAM
enabled system does not have such a module, you can use the
pam_passwdqc module available from
http://www.openwall.com/passwdqc/ which supports Linux, Solaris,
FreeBSD and HP-UX.
For a multi-user system which does not have any mechanism for
enforcing difficult passwords, password auditing is discussed in
section J.7.3
HP-UX AIX
HP-UX
% ldd /usr/bin/login
/usr/bin/login:
libutil.so.5 => /lib/libutil.so.5 (0x28077000)
libpam.so.3 => /usr/lib/libpam.so.3 (0x28083000)
libc.so.6 => /lib/libc.so.6 (0x2808a000)
Note the libpam.so.3, this shows the program is linked with PAM.
Consider enforcing user resource limits with PAM: This may be done
using the pam_limits.so module with configuration in /etc/limits.conf
where available.
E.3.5 LDAP
Ensure that LDAP access controls are correct for all attributes that
contain authentication credentials or other sensitive data. In
particular, password hashes should not be readable by other users,
whether authenticated or not.
Ensure the sticky-bit is set on /tmp, /var/tmp and any other world-
writable directories that exist. This is often denoted by a "t" in the
last column of permissions when listing with ls -ld
Some systems ship files and directories owned by user "bin" (or
"sys"). This varies from system to system and may have security
implications, especially if filesystems are exported with NFS. Change
all non-setuid files and all non-setgid files and directories owned by
"bin" that are world readable but not world or group writable to be
owned by root instead, with group ownership by group id 0.
Solaris
Any binary that might get run as root, as well as all parent
directories of that binary, must be owned by root and also not be
writable by any other user or group. This means:
Ensure root's login files do not source any other files not owned by
root or which are group or world writable.
Ensure root cron job files do not source any other files not owned by
root or which are group or world writable.
Check the contents of the following files for the root account. Any
programs or scripts referenced in these files should have the
permissions recommended above:
There are two different schemes in use for arranging UNIX groups,
and these lead to different recommendations for home directory
permissions and umask.
HP-UX
Ensure the umask for each user is set to a restrictive value within
the user's shell startup scripts. The appropriate umask will depend
on whether a User Private Group scheme is used. If the traditional
group scheme is being used, ensure a umask of 077 or 027 is set in
the users' shell startup scripts.
Ensure user home directories are owned by the user, and are not
writable by any other user or group.
If the traditional group scheme is in use, the group ownership on
home directories may be set to the common group, so ensure that
the directory is not group-writable.
Linux, FreeBSD
Consider using Role Based Access Control (RBAC) to split the role of
root, if available for your system. (See OS specific footnotes)
E.4.4 sudo
The sudo utility is available for practically all UNIX variants and can
help minimise the need to use the root account.
For systems administered by more than one person, sudo can also
be helpful to split the power of root to some extent if full Role Based
Access Control is not available.
sudo allows users or groups of users to execute specific authorized
commands as another user, such as the root user. It requires
unprivileged users to enter their own user password in order to
execute privileged commands. This enables administrative tasks to
be distributed among different users, while limiting the distribution
of the root password.
Linux
E.5 Other
E.5.1 Cron
Ensure that the permissions for root's crontab are set to 600 and
that the owner is set to root.
Configure the mount options nosuid, nodev and noexec for /var
and /tmp in your /etc/fstab or vfstab file.
For user home partitions, use nosuid and nodev and consider using
noexec.
Mount external filesystems with the nosuid and nodev options. This
includes both removable media such as CDs and USB drives as well
as network filesystems. Consider also using the noexec and read-
only options for these filesystems where practical.
AIX
Ensure that any startup scripts use a umask of 022 or better. This
should already be the case for vendor-supplied startup scripts.
Do not use .netrc files. Instead use SSH and scp, or rsync over SSH if
automated file transfers or execution are required.
F.1 Confinement
The software and files deployed within the chroot environment can
then be minimized to those only needed by that specific service.
F.2 tcp_wrappers
There are two ways that tcp_wrappers may be used on the system:
HP-UX
If the service is only required for use on the local host, then it should
listen only on the loopback interface where possible, with address
127.0.0.1
stunnel is a free tool that can be used to add TLS (or SSL)
authentication and encryption capabilities to any existing client and
server that uses TCP. For example, it can be used to secure access
to POP3, or to secure an existing in-house application that
communicates using TCP.
F.4 SSH
RhostsAuthentication
HostBasedAuthentication
RhostsRSAAuthentication (not good for accountability)
F.6 RPC/portmapper
Look for the specific facilities provided by your operating system for
securing RPC access with authentication and/or encryption. The
security features available vary greatly between UNIX variants.
F.7.1 NFS
Filter NFS traffic at the router, blocking TCP/UDP on port 111 and
TCP/UDP on port 2049. This will help prevent machines not on the
local subnet from accessing file systems exported by this host.
Configure NFS to use TCP rather than UDP. This is supported by all
NFS 3 implementations.
Verify that you run a portmapper or rpcbind that does not forward
mount requests from clients. With older portmappers a malicious
remote NFS client could ask the host's portmapper daemon to
forward requests to the mount daemon, which would then process
the request as if it came directly from the local host. If a file system
is exported to the local machine this then gives the remote client
unauthorised access to the file system.
Check that any important exported files that clients should not be
able to modify are owned by root, and not owned by bin or any
other account.
Solaris
F.7.2 Samba
The Samba service provides filesystem and printer shares using the
CIFS protocol that is also used in Microsoft Windows.
If users in your environment authenticate to Active Directory for
other services, then consider pointing to the same AD server for
Samba authentication, setting
security = ADS
See the Samba HOWTO for further details on implementing this:
HOWTO
Protect the Samba services with firewall rules to ensure they can not
be accessed from hosts outside the local network. Samba uses ports
137 and 138 (UDP) and ports 139 and 445 (TCP).
F.8.1 Sendmail
On most UNIX and Linux systems the default MTA will be Sendmail.
This section provides configuration recommendations specifically for
Sendmail, though the same configuration goals can be applied to
other MTAs.
If this computer is not a mail server, then:
In both cases:
• /etc/mail/aliases
check that any programs executed from this file are owned by
root, have permissions 755 and are stored in the smrsh
configuration directory, e.g. /etc/smrsh
Sendmail is the most fully featured MTA software. On the other hand
it is also a large and complex program. The complexity leaves more
scope for security vulnerabilities through misconfiguration or
software flaws.
Do not use host based access control. Remove all instances of the
xhost command from the system-wide Xsession file, from user
.xsession files, and from any application programs or shell scripts
that use X.
xdm may bypass the normal getty and login functions, which means
that quotas for the user, ownership of /dev/console and possibly
other preventive measures put in place by you may be ignored.
Ensure familiarity with the man pages for xauth and Xsecurity. This
information will be useful in configuring the security you require.
The chapter on X Window System security in the X Window System
Administrator's Guide is also a good reference.
F.10.1 BIND
For most UNIX systems, BIND will be the default domain name
server software provided.
Turn off dynamic updates unless they are really required, for
example to support Active Directory.
Apache is the most common web server on Unix systems. If you are
using Apache, implement the security recommendations outlined in
http://httpd.apache.org/docs/misc/security_tips.html
Consider running the web server in a chroot jail (see section F.2.1).
Some systems supply the web server in this configuration by
default. Example steps for chrooting Apache on Linux and Solaris
can be found at http://penguin.triumf.ca/chroot.html. A simpler way
to chroot Apache is now provided by the mod_security's
SecChrootDir option, as described here.
Confirm that the private key file can not be read by the unprivileged
account that the httpd process runs as (usually www or nobody).
Note that Squid ACLs use the first rule that matches. If none match,
the last rule checked is used inverted. So to avoid unintended
access it is best to put a catch-all deny rule last:
http_access deny all
F.13 CVS
Create a UNIX account on the computer for each CVS user, and limit
their SSH session so it is only able execute the command "cvs
server".
Ensure that your FTP server does not have the SITE EXEC command,
or that this command is disabled correctly.
Test with:
% telnet localhost 21
USER username
PASS password
SITE EXEC
Ensure that you have set up the file /etc/ftpusers. This file specifies
those users that are not allowed to connect to your ftpd. This should
include, as a minimum, the entries: root, bin, uucp, ingres, daemon,
news, nobody and ALL vendor supplied accounts.
Check all default configuration options on your FTP server. Not all
versions of ftp daemons are configurable. If you have a configurable
version of ftp (e.g., WU-FTP) then make sure that all delete,
overwrite, rename, chmod and umask options (there may be others)
are not allowed for guests and anonymous users. In general,
anonymous users should not have any unnecessary privileges.
Ensure there are no shells, interpreters or system commands in
~ftp/bin, ~ftp/usr/bin, ~ftp/sbin or similar directories. It may be
necessary to keep some commands, such as uncompress, in these
locations. Consider the inclusion of each command on a case by
case basis and be aware that the presence of such commands may
make it possible for local users to gain unauthorised access. Be
wary of including commands that can execute arbitrary commands.
For example, some versions of tar may allow you to execute an
arbitrary file.
Ensure that you use an invalid password and user shell for the ftp
entry in the system password file and the shadow password file (if
you have one). It should look something like:
ftp:*:400:400:Anonymous
ftp:/home/ftp:/bin/false
where /home/ftp is the anonymous FTP area.
Set the permissions of the FTP home directory ~ftp/ to 555 (read
nowrite execute), and check that this directory is owned by root
(ftp).
Make sure that you do not have a copy of your real /etc/passwd file
as ~ftp/etc/passwd. Create one from scratch with permissions 444,
owned by root. It should not contain the names of any accounts in
your real password file. It should contain only root and ftp. These
should be dummy entries with disabled passwords e.g.:
root:*:0:0:Ftp maintainer::
ftp:*:400:400:Anonymous ftp::
The password file is used only to provide uid to username mapping
for ls listings within ftp.
Make sure that you do not have a copy of your real /etc/group file as
~ftp/etc/group. Create one from scratch with permissions 444,
owned by root.
Set the login shell of the ftp account to a non-functional shell such
as /bin/false.
Ensure that the directories ~ftp/etc and ~ftp/bin are owned by root
with permissions 111.
Ensure that any files in ~ftp/bin are owned by root with permissions
111.
Ensure that files in ~ftp/etc are owned by root with permissions 444.
Ensure that there is a mail alias for ftp to avoid mail bounces.
Ensure the mail spool file for the ftp daemon account is owned by
root with permissions 400. (Depending on the system this will be in
a location such as /var/mail/ftp or /usr/spool/mail/ftp )
Never mount disks from other machines to the ~ftp hierarchy unless
they are mounted read-only.
HP-UX
To disable anonymous FTP, move or delete all files in ~ftp/ and then
remove the "ftp" user account from the system.
Ensure that if you want to use anonymous FTP you have configured
your server correctly. In general, anonymous users should not be
allowed to create directories, delete anything, change the file
system in any way (for instance change the permissions of a file) or
upload files. If you intend to allow anonymous users to upload files,
read the section below about upload directories.
Ensure that the anonymous ftp user account cannot create files or
directories in ANY directory unless required.
Verify that the anonymous ftp user account can only read
information in public areas.
Check that any writable directories are owned by root and have
permissions 1733. (note sticky bit set)
Unless this computer is a log server, ensure that syslog will not
accept incoming log packets over the network. On some systems
this is the default. On others it may be implemented by starting
syslog with the -t option (nolisten).
Consider increasing the level of logging provided by syslog.
Check that all login attempts are logged, both successful and
unsuccessful. There may be several different ways to log in, such as
at the console, through X and through SSH.
OpenBSD, AIX
Logs and audit trails are only of limited use unless people are
actively monitoring them. Decide on a specific time period within
which people will monitor the logs.
Check that process accounting log files are owned by root and have
permissions 600.
G.4.3 lsof
lsof is a tool for monitoring open system files that can be useful in
checking current activity on the system. lsof may be included with
your operating system, and is also available from the source at
ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
H. Connect to Net
Ensure that the following ports can NOT be accessed over the
network:
If the IPv6 stack on this computer has not been disabled, then verify
that the firewall rules correctly handle IPv6 packets coming from the
local LAN. Some firewall configurations ignore IPv6. Even on an IPv4
network this may give unintended access if the attacker already
controls another point on the LAN.
Solaris, FreeBSD
The kernel's network settings can be tuned and made more secure,
usually using the sysctl command or configuration file. The details of
how to do this are very specific to each operating system. It is
recommended to check the following settings:
If using this tool, run it only on an image copy of the original hard
disk, on a non-networked machine.
Solaris
J. Maintain
Design and put into action a process to re-assess the security of the
system at regular intervals.
Regularly audit the system for dormant accounts and disable any
that have not been used for a specified period of time, in
accordance with your site's security policy.
At this stage also audit the password files for unauthorised additions
or inconsistencies.