2004-08-07 04:40:20 +00:00
|
|
|
.\" Copyright (C) 1998 Matthew Dillon. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
1998-12-20 20:12:17 +00:00
|
|
|
.\"
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1998-12-20 20:12:17 +00:00
|
|
|
.\"
|
2006-09-08 04:56:21 +00:00
|
|
|
.Dd September 8, 2006
|
1998-12-20 20:12:17 +00:00
|
|
|
.Dt SECURITY 7
|
2001-07-10 15:31:11 +00:00
|
|
|
.Os
|
1998-12-20 20:12:17 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm security
|
2006-05-12 17:42:48 +00:00
|
|
|
.Nd introduction to security under FreeBSD
|
1998-12-20 20:12:17 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
Security is a function that begins and ends with the system administrator.
|
|
|
|
While all
|
|
|
|
.Bx
|
1999-09-18 18:21:38 +00:00
|
|
|
multi-user systems have some inherent security, the job of building and
|
2002-02-18 00:20:12 +00:00
|
|
|
maintaining additional security mechanisms to keep users
|
2004-06-15 12:48:50 +00:00
|
|
|
.Dq honest
|
1999-03-02 03:45:47 +00:00
|
|
|
is probably
|
2004-06-15 12:48:50 +00:00
|
|
|
one of the single largest undertakings of the sysadmin.
|
|
|
|
Machines are
|
1998-12-20 20:12:17 +00:00
|
|
|
only as secure as you make them, and security concerns are ever competing
|
2001-07-14 19:41:16 +00:00
|
|
|
with the human necessity for convenience.
|
1999-03-02 03:45:47 +00:00
|
|
|
.Ux
|
|
|
|
systems,
|
1998-12-25 23:39:01 +00:00
|
|
|
in general, are capable of running a huge number of simultaneous processes
|
2004-06-15 12:48:50 +00:00
|
|
|
and many of these processes operate as servers \(em meaning that external
|
|
|
|
entities can connect and talk to them.
|
|
|
|
As yesterday's mini-computers and mainframes
|
1998-12-20 20:12:17 +00:00
|
|
|
become today's desktops, and as computers become networked and internetworked,
|
|
|
|
security becomes an ever bigger issue.
|
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
Security is best implemented through a layered onion approach.
|
|
|
|
In a nutshell,
|
1999-09-18 18:21:38 +00:00
|
|
|
what you want to do is to create as many layers of security as are convenient
|
2004-06-15 12:48:50 +00:00
|
|
|
and then carefully monitor the system for intrusions.
|
1999-09-18 18:21:38 +00:00
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
System security also pertains to dealing with various forms of attacks,
|
1999-09-18 18:21:38 +00:00
|
|
|
including attacks that attempt to crash or otherwise make a system unusable
|
2004-06-15 12:48:50 +00:00
|
|
|
but do not attempt to break root.
|
|
|
|
Security concerns can be split up into
|
1999-09-18 18:21:38 +00:00
|
|
|
several categories:
|
1998-12-20 20:12:17 +00:00
|
|
|
.Bl -enum -offset indent
|
|
|
|
.It
|
2004-06-15 12:48:50 +00:00
|
|
|
Denial of Service attacks (DoS)
|
1998-12-20 20:12:17 +00:00
|
|
|
.It
|
|
|
|
User account compromises
|
|
|
|
.It
|
1998-12-25 23:39:01 +00:00
|
|
|
Root compromise through accessible servers
|
1998-12-20 20:12:17 +00:00
|
|
|
.It
|
1998-12-25 23:39:01 +00:00
|
|
|
Root compromise via user accounts
|
1999-09-18 18:21:38 +00:00
|
|
|
.It
|
|
|
|
Backdoor creation
|
1998-12-20 20:12:17 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
A denial of service attack is an action that deprives the machine of needed
|
2004-06-15 12:48:50 +00:00
|
|
|
resources.
|
|
|
|
Typically, DoS attacks are brute-force mechanisms that attempt
|
1998-12-20 20:12:17 +00:00
|
|
|
to crash or otherwise make a machine unusable by overwhelming its servers or
|
2004-06-15 12:48:50 +00:00
|
|
|
network stack.
|
|
|
|
Some DoS attacks try to take advantages of bugs in the
|
|
|
|
networking stack to crash a machine with a single packet.
|
|
|
|
The latter can
|
|
|
|
only be fixed by applying a bug fix to the kernel.
|
|
|
|
Attacks on servers can
|
1999-09-18 18:21:38 +00:00
|
|
|
often be fixed by properly specifying options to limit the load the servers
|
2004-06-15 12:48:50 +00:00
|
|
|
incur on the system under adverse conditions.
|
|
|
|
Brute-force network attacks are harder to deal with.
|
|
|
|
A spoofed-packet attack, for example, is
|
2002-01-09 12:34:01 +00:00
|
|
|
nearly impossible to stop short of cutting your system off from the Internet.
|
|
|
|
It may not be able to take your machine down, but it can fill up Internet
|
1999-09-18 18:21:38 +00:00
|
|
|
pipe.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
A user account compromise is even more common than a DoS attack.
|
|
|
|
Many
|
|
|
|
sysadmins still run standard
|
|
|
|
.Xr telnetd 8 ,
|
|
|
|
.Xr rlogind 8 ,
|
|
|
|
.Xr rshd 8 ,
|
|
|
|
and
|
|
|
|
.Xr ftpd 8
|
|
|
|
servers on their machines.
|
|
|
|
These servers, by default, do not operate over encrypted
|
|
|
|
connections.
|
|
|
|
The result is that if you have any moderate-sized user base,
|
1998-12-20 20:12:17 +00:00
|
|
|
one or more of your users logging into your system from a remote location
|
2004-06-15 12:48:50 +00:00
|
|
|
(which is the most common and convenient way to log in to a system)
|
|
|
|
will have his or her password sniffed.
|
|
|
|
The attentive system administrator will analyze
|
1999-09-18 18:21:38 +00:00
|
|
|
his remote access logs looking for suspicious source addresses
|
1998-12-20 20:12:17 +00:00
|
|
|
even for successful logins.
|
|
|
|
.Pp
|
|
|
|
One must always assume that once an attacker has access to a user account,
|
2004-06-15 12:48:50 +00:00
|
|
|
the attacker can break root.
|
|
|
|
However, the reality is that in a well secured
|
1998-12-20 20:12:17 +00:00
|
|
|
and maintained system, access to a user account does not necessarily give the
|
2004-06-15 12:48:50 +00:00
|
|
|
attacker access to root.
|
|
|
|
The distinction is important because without access
|
1998-12-20 20:12:17 +00:00
|
|
|
to root the attacker cannot generally hide his tracks and may, at best, be
|
2001-11-24 19:47:12 +00:00
|
|
|
able to do nothing more than mess with the user's files or crash the machine.
|
1999-09-18 18:21:38 +00:00
|
|
|
User account compromises are very common because users tend not to take the
|
2002-01-09 12:34:01 +00:00
|
|
|
precautions that sysadmins take.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
2001-07-14 19:41:16 +00:00
|
|
|
System administrators must keep in mind that there are potentially many ways
|
2004-06-15 12:48:50 +00:00
|
|
|
to break root on a machine.
|
|
|
|
The attacker may know the root password,
|
1999-09-18 18:21:38 +00:00
|
|
|
the attacker
|
1998-12-20 20:12:17 +00:00
|
|
|
may find a bug in a root-run server and be able to break root over a network
|
2004-06-15 12:48:50 +00:00
|
|
|
connection to that server, or the attacker may know of a bug in an SUID-root
|
2001-07-14 19:41:16 +00:00
|
|
|
program that allows the attacker to break root once he has broken into a
|
2004-06-15 12:48:50 +00:00
|
|
|
user's account.
|
|
|
|
If an attacker has found a way to break root on a machine,
|
2000-05-09 14:02:06 +00:00
|
|
|
the attacker may not have a need to install a backdoor.
|
1999-09-18 18:21:38 +00:00
|
|
|
Many of the root holes found and closed to date involve a considerable amount
|
2004-06-15 12:48:50 +00:00
|
|
|
of work by the attacker to clean up after himself, so most attackers do install
|
|
|
|
backdoors.
|
|
|
|
This gives you a convenient way to detect the attacker.
|
|
|
|
Making
|
2004-05-18 17:50:08 +00:00
|
|
|
it impossible for an attacker to install a backdoor may actually be detrimental
|
2004-05-18 18:17:25 +00:00
|
|
|
to your security because it will not close off the hole the attacker used to
|
|
|
|
break in in the first place.
|
1999-09-18 18:21:38 +00:00
|
|
|
.Pp
|
|
|
|
Security remedies should always be implemented with a multi-layered
|
2004-06-15 12:48:50 +00:00
|
|
|
.Dq onion peel
|
1998-12-20 20:12:17 +00:00
|
|
|
approach and can be categorized as follows:
|
|
|
|
.Bl -enum -offset indent
|
|
|
|
.It
|
|
|
|
Securing root and staff accounts
|
|
|
|
.It
|
2004-06-15 12:48:50 +00:00
|
|
|
Securing root \(em root-run servers and SUID/SGID binaries
|
1998-12-20 20:12:17 +00:00
|
|
|
.It
|
|
|
|
Securing user accounts
|
|
|
|
.It
|
2001-07-14 19:41:16 +00:00
|
|
|
Securing the password file
|
1998-12-20 20:12:17 +00:00
|
|
|
.It
|
2002-12-12 17:26:04 +00:00
|
|
|
Securing the kernel core, raw devices, and file systems
|
1998-12-20 20:12:17 +00:00
|
|
|
.It
|
1999-09-18 18:21:38 +00:00
|
|
|
Quick detection of inappropriate changes made to the system
|
1998-12-20 20:12:17 +00:00
|
|
|
.It
|
|
|
|
Paranoia
|
|
|
|
.El
|
|
|
|
.Sh SECURING THE ROOT ACCOUNT AND SECURING STAFF ACCOUNTS
|
2004-06-15 12:48:50 +00:00
|
|
|
Do not bother securing staff accounts if you have not secured the root
|
|
|
|
account.
|
|
|
|
Most systems have a password assigned to the root account.
|
|
|
|
The
|
1999-03-02 03:45:47 +00:00
|
|
|
first thing you do is assume that the password is
|
2004-06-15 12:48:50 +00:00
|
|
|
.Em always
|
|
|
|
compromised.
|
|
|
|
This does not mean that you should remove the password.
|
|
|
|
The
|
1999-09-18 18:21:38 +00:00
|
|
|
password is almost always necessary for console access to the machine.
|
|
|
|
What it does mean is that you should not make it possible to use the password
|
|
|
|
outside of the console or possibly even with a
|
|
|
|
.Xr su 1
|
2004-06-15 12:48:50 +00:00
|
|
|
utility.
|
|
|
|
For example, make sure that your PTYs are specified as being
|
|
|
|
.Dq Li unsecure
|
2001-07-14 19:41:16 +00:00
|
|
|
in the
|
2004-06-15 12:48:50 +00:00
|
|
|
.Pa /etc/ttys
|
1999-09-18 18:21:38 +00:00
|
|
|
file
|
2004-06-15 12:48:50 +00:00
|
|
|
so that direct root logins via
|
|
|
|
.Xr telnet 1
|
|
|
|
or
|
|
|
|
.Xr rlogin 1
|
|
|
|
are disallowed.
|
|
|
|
If using
|
|
|
|
other login services such as
|
|
|
|
.Xr sshd 8 ,
|
|
|
|
make sure that direct root logins are
|
|
|
|
disabled there as well.
|
|
|
|
Consider every access method \(em services such as
|
|
|
|
.Xr ftp 1
|
|
|
|
often fall through the cracks.
|
|
|
|
Direct root logins should only be allowed
|
1999-09-18 18:21:38 +00:00
|
|
|
via the system console.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
1998-12-22 19:02:51 +00:00
|
|
|
Of course, as a sysadmin you have to be able to get to root, so we open up
|
2004-06-15 12:48:50 +00:00
|
|
|
a few holes.
|
|
|
|
But we make sure these holes require additional password
|
|
|
|
verification to operate.
|
|
|
|
One way to make root accessible is to add appropriate
|
|
|
|
staff accounts to the
|
|
|
|
.Dq Li wheel
|
|
|
|
group (in
|
2001-08-07 15:48:51 +00:00
|
|
|
.Pa /etc/group ) .
|
2004-06-15 12:48:50 +00:00
|
|
|
The staff members placed in the
|
|
|
|
.Li wheel
|
|
|
|
group are allowed to
|
|
|
|
.Xr su 1
|
|
|
|
to root.
|
|
|
|
You should never give staff
|
|
|
|
members native
|
|
|
|
.Li wheel
|
|
|
|
access by putting them in the
|
|
|
|
.Li wheel
|
|
|
|
group in their password entry.
|
|
|
|
Staff accounts should be placed in a
|
|
|
|
.Dq Li staff
|
|
|
|
group, and then added to the
|
|
|
|
.Li wheel
|
|
|
|
group via the
|
|
|
|
.Pa /etc/group
|
|
|
|
file.
|
|
|
|
Only those staff members who actually need to have root access
|
|
|
|
should be placed in the
|
|
|
|
.Li wheel
|
|
|
|
group.
|
|
|
|
It is also possible, when using an
|
|
|
|
authentication method such as Kerberos, to use Kerberos's
|
|
|
|
.Pa .k5login
|
1999-09-18 18:21:38 +00:00
|
|
|
file in the root account to allow a
|
|
|
|
.Xr ksu 1
|
2004-06-15 12:48:50 +00:00
|
|
|
to root without having to place anyone at all in the
|
|
|
|
.Li wheel
|
|
|
|
group.
|
|
|
|
This
|
|
|
|
may be the better solution since the
|
|
|
|
.Li wheel
|
|
|
|
mechanism still allows an
|
1999-09-18 18:21:38 +00:00
|
|
|
intruder to break root if the intruder has gotten hold of your password
|
2004-06-15 12:48:50 +00:00
|
|
|
file and can break into a staff account.
|
|
|
|
While having the
|
|
|
|
.Li wheel
|
|
|
|
mechanism
|
|
|
|
is better than having nothing at all, it is not necessarily the safest
|
1999-09-18 18:21:38 +00:00
|
|
|
option.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
|
|
|
An indirect way to secure the root account is to secure your staff accounts
|
|
|
|
by using an alternative login access method and *'ing out the crypted password
|
2004-06-15 12:48:50 +00:00
|
|
|
for the staff accounts.
|
|
|
|
This way an intruder may be able to steal the password
|
2004-05-18 17:50:08 +00:00
|
|
|
file but will not be able to break into any staff accounts or root, even if
|
|
|
|
root has a crypted password associated with it (assuming, of course, that
|
2004-06-15 12:48:50 +00:00
|
|
|
you have limited root access to the console).
|
|
|
|
Staff members
|
2001-07-14 19:41:16 +00:00
|
|
|
get into their staff accounts through a secure login mechanism such as
|
2005-01-21 12:01:00 +00:00
|
|
|
.Xr kerberos 8
|
1999-03-02 03:45:47 +00:00
|
|
|
or
|
|
|
|
.Xr ssh 1
|
|
|
|
using a private/public
|
2004-06-15 12:48:50 +00:00
|
|
|
key pair.
|
|
|
|
When you use something like Kerberos you generally must secure
|
|
|
|
the machines which run the Kerberos servers and your desktop workstation.
|
|
|
|
When you use a public/private key pair with SSH, you must generally secure
|
|
|
|
the machine you are logging in
|
|
|
|
.Em from
|
2001-08-07 15:48:51 +00:00
|
|
|
(typically your workstation),
|
1999-03-02 03:45:47 +00:00
|
|
|
but you can
|
2001-07-14 19:41:16 +00:00
|
|
|
also add an additional layer of protection to the key pair by password
|
1999-03-02 03:45:47 +00:00
|
|
|
protecting the keypair when you create it with
|
|
|
|
.Xr ssh-keygen 1 .
|
|
|
|
Being able
|
1998-12-25 23:39:01 +00:00
|
|
|
to *-out the passwords for staff accounts also guarantees that staff members
|
2004-06-15 12:48:50 +00:00
|
|
|
can only log in through secure access methods that you have set up.
|
|
|
|
You can
|
1998-12-20 20:12:17 +00:00
|
|
|
thus force all staff members to use secure, encrypted connections for
|
2004-06-15 12:48:50 +00:00
|
|
|
all their sessions which closes an important hole used by many intruders: that
|
1998-12-20 20:12:17 +00:00
|
|
|
of sniffing the network from an unrelated, less secure machine.
|
|
|
|
.Pp
|
|
|
|
The more indirect security mechanisms also assume that you are logging in
|
2004-06-15 12:48:50 +00:00
|
|
|
from a more restrictive server to a less restrictive server.
|
|
|
|
For example,
|
|
|
|
if your main box is running all sorts of servers, your workstation should not
|
|
|
|
be running any.
|
|
|
|
In order for your workstation to be reasonably secure
|
2001-07-14 19:41:16 +00:00
|
|
|
you should run as few servers as possible, up to and including no servers
|
1999-03-02 03:45:47 +00:00
|
|
|
at all, and you should run a password-protected screen blanker.
|
|
|
|
Of course, given physical access to
|
2004-06-15 12:48:50 +00:00
|
|
|
a workstation, an attacker can break any sort of security you put on it.
|
1998-12-20 20:12:17 +00:00
|
|
|
This is definitely a problem that you should consider but you should also
|
1998-12-25 23:39:01 +00:00
|
|
|
consider the fact that the vast majority of break-ins occur remotely, over
|
1998-12-22 19:02:51 +00:00
|
|
|
a network, from people who do not have physical access to your workstation or
|
1998-12-20 20:12:17 +00:00
|
|
|
servers.
|
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
Using something like Kerberos also gives you the ability to disable or
|
1998-12-20 20:12:17 +00:00
|
|
|
change the password for a staff account in one place and have it immediately
|
2004-06-15 12:48:50 +00:00
|
|
|
affect all the machines the staff member may have an account on.
|
|
|
|
If a staff
|
2001-07-14 19:41:16 +00:00
|
|
|
member's account gets compromised, the ability to instantly change his
|
2004-06-15 12:48:50 +00:00
|
|
|
password on all machines should not be underrated.
|
|
|
|
With discrete passwords, changing a password on N machines can be a mess.
|
|
|
|
You can also impose
|
|
|
|
re-passwording restrictions with Kerberos: not only can a Kerberos ticket
|
|
|
|
be made to timeout after a while, but the Kerberos system can require that
|
1999-03-02 03:45:47 +00:00
|
|
|
the user choose a new password after a certain period of time
|
2001-08-07 15:48:51 +00:00
|
|
|
(say, once a month).
|
2004-06-15 12:48:50 +00:00
|
|
|
.Sh SECURING ROOT \(em ROOT-RUN SERVERS AND SUID/SGID BINARIES
|
|
|
|
The prudent sysadmin only runs the servers he needs to, no more, no less.
|
|
|
|
Be aware that third party servers are often the most bug-prone.
|
|
|
|
For example,
|
|
|
|
running an old version of
|
|
|
|
.Xr imapd 8
|
|
|
|
or
|
2005-07-14 20:29:08 +00:00
|
|
|
.Xr popper 8 Pq Pa ports/mail/popper
|
2004-06-15 12:48:50 +00:00
|
|
|
is like giving a universal root
|
|
|
|
ticket out to the entire world.
|
|
|
|
Never run a server that you have not checked
|
|
|
|
out carefully.
|
|
|
|
Many servers do not need to be run as root.
|
|
|
|
For example,
|
|
|
|
the
|
|
|
|
.Xr talkd 8 ,
|
|
|
|
.Xr comsat 8 ,
|
|
|
|
and
|
|
|
|
.Xr fingerd 8
|
|
|
|
daemons can be run in special user
|
|
|
|
.Dq sandboxes .
|
|
|
|
A sandbox is not perfect unless you go to a large amount of trouble, but the
|
|
|
|
onion approach to security still stands: if someone is able to break in
|
1998-12-20 20:12:17 +00:00
|
|
|
through a server running in a sandbox, they still have to break out of the
|
2004-06-15 12:48:50 +00:00
|
|
|
sandbox.
|
|
|
|
The more layers the attacker must break through, the lower the
|
|
|
|
likelihood of his success.
|
|
|
|
Root holes have historically been found in
|
1998-12-20 20:12:17 +00:00
|
|
|
virtually every server ever run as root, including basic system servers.
|
2004-06-15 12:48:50 +00:00
|
|
|
If you are running a machine through which people only log in via
|
|
|
|
.Xr sshd 8
|
|
|
|
and never log in via
|
|
|
|
.Xr telnetd 8 ,
|
|
|
|
.Xr rshd 8 ,
|
|
|
|
or
|
|
|
|
.Xr rlogind 8 ,
|
|
|
|
then turn off those services!
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
1999-09-04 14:55:22 +00:00
|
|
|
.Fx
|
2004-06-15 12:48:50 +00:00
|
|
|
now defaults to running
|
|
|
|
.Xr talkd 8 ,
|
|
|
|
.Xr comsat 8 ,
|
|
|
|
and
|
|
|
|
.Xr fingerd 8
|
|
|
|
in a sandbox.
|
1998-12-20 20:12:17 +00:00
|
|
|
Another program which may be a candidate for running in a sandbox is
|
1999-03-02 03:45:47 +00:00
|
|
|
.Xr named 8 .
|
2004-06-15 12:48:50 +00:00
|
|
|
The default
|
|
|
|
.Pa rc.conf
|
|
|
|
includes the arguments necessary to run
|
|
|
|
.Xr named 8
|
|
|
|
in a sandbox in a commented-out form.
|
|
|
|
Depending on whether you
|
1998-12-20 20:12:17 +00:00
|
|
|
are installing a new system or upgrading an existing system, the special
|
2004-06-15 12:48:50 +00:00
|
|
|
user accounts used by these sandboxes may not be installed.
|
|
|
|
The prudent
|
1998-12-22 19:02:51 +00:00
|
|
|
sysadmin would research and implement sandboxes for servers whenever possible.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
|
|
|
There are a number of other servers that typically do not run in sandboxes:
|
2004-06-15 12:48:50 +00:00
|
|
|
.Xr sendmail 8 ,
|
|
|
|
.Xr popper 8 ,
|
|
|
|
.Xr imapd 8 ,
|
|
|
|
.Xr ftpd 8 ,
|
|
|
|
and others.
|
|
|
|
There are alternatives to
|
2005-07-18 21:33:00 +00:00
|
|
|
some of these, but installing them may require more work than you are willing
|
1999-03-02 03:45:47 +00:00
|
|
|
to put
|
2001-08-07 15:48:51 +00:00
|
|
|
(the convenience factor strikes again).
|
1999-03-02 03:45:47 +00:00
|
|
|
You may have to run these
|
1998-12-25 23:39:01 +00:00
|
|
|
servers as root and rely on other mechanisms to detect break-ins that might
|
1998-12-20 20:12:17 +00:00
|
|
|
occur through them.
|
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
The other big potential root hole in a system are the SUID-root and SGID
|
|
|
|
binaries installed on the system.
|
|
|
|
Most of these binaries, such as
|
|
|
|
.Xr rlogin 1 ,
|
1999-03-02 03:45:47 +00:00
|
|
|
reside in
|
2004-06-15 12:48:50 +00:00
|
|
|
.Pa /bin , /sbin , /usr/bin ,
|
1999-03-02 03:45:47 +00:00
|
|
|
or
|
|
|
|
.Pa /usr/sbin .
|
|
|
|
While nothing is 100% safe,
|
2004-06-15 12:48:50 +00:00
|
|
|
the system-default SUID and SGID binaries can be considered reasonably safe.
|
|
|
|
Still, root holes are occasionally found in these binaries.
|
|
|
|
A root hole
|
|
|
|
was found in Xlib in 1998 that made
|
2005-07-14 20:29:08 +00:00
|
|
|
.Xr xterm 1 Pq Pa ports/x11/xterm
|
2004-06-15 12:48:50 +00:00
|
|
|
(which is typically SUID)
|
1999-03-02 03:45:47 +00:00
|
|
|
vulnerable.
|
2004-06-15 12:48:50 +00:00
|
|
|
It is better to be safe than sorry and the prudent sysadmin will restrict SUID
|
1998-12-20 20:12:17 +00:00
|
|
|
binaries that only staff should run to a special group that only staff can
|
1999-03-02 03:45:47 +00:00
|
|
|
access, and get rid of
|
2004-06-15 12:48:50 +00:00
|
|
|
.Pq Dq Li "chmod 000"
|
|
|
|
any SUID binaries that nobody uses.
|
|
|
|
A server with no display generally does not need an
|
|
|
|
.Xr xterm 1
|
|
|
|
binary.
|
|
|
|
SGID binaries can be almost as dangerous.
|
|
|
|
If an intruder can break an SGID-kmem binary the
|
1999-03-02 03:45:47 +00:00
|
|
|
intruder might be able to read
|
|
|
|
.Pa /dev/kmem
|
|
|
|
and thus read the crypted password
|
2004-06-15 12:48:50 +00:00
|
|
|
file, potentially compromising any passworded account.
|
|
|
|
Alternatively an
|
|
|
|
intruder who breaks group
|
|
|
|
.Dq Li kmem
|
|
|
|
can monitor keystrokes sent through PTYs,
|
|
|
|
including PTYs used by users who log in through secure methods.
|
|
|
|
An intruder
|
|
|
|
that breaks the
|
|
|
|
.Dq Li tty
|
|
|
|
group can write to almost any user's TTY.
|
|
|
|
If a user
|
1999-09-18 18:21:38 +00:00
|
|
|
is running a terminal
|
2001-07-14 19:41:16 +00:00
|
|
|
program or emulator with a keyboard-simulation feature, the intruder can
|
|
|
|
potentially
|
1998-12-20 20:12:17 +00:00
|
|
|
generate a data stream that causes the user's terminal to echo a command, which
|
|
|
|
is then run as that user.
|
|
|
|
.Sh SECURING USER ACCOUNTS
|
2004-06-15 12:48:50 +00:00
|
|
|
User accounts are usually the most difficult to secure.
|
|
|
|
While you can impose
|
|
|
|
draconian access restrictions on your staff and *-out their passwords, you
|
|
|
|
may not be able to do so with any general user accounts you might have.
|
|
|
|
If
|
1998-12-20 20:12:17 +00:00
|
|
|
you do have sufficient control then you may win out and be able to secure the
|
2004-06-15 12:48:50 +00:00
|
|
|
user accounts properly.
|
|
|
|
If not, you simply have to be more vigilant in your
|
|
|
|
monitoring of those accounts.
|
|
|
|
Use of SSH and Kerberos for user accounts is
|
2001-07-14 19:41:16 +00:00
|
|
|
more problematic due to the extra administration and technical support
|
1999-09-18 18:21:38 +00:00
|
|
|
required, but still a very good solution compared to a crypted password
|
|
|
|
file.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Sh SECURING THE PASSWORD FILE
|
2001-07-14 19:41:16 +00:00
|
|
|
The only sure fire way is to *-out as many passwords as you can and
|
2004-06-15 12:48:50 +00:00
|
|
|
use SSH or Kerberos for access to those accounts.
|
|
|
|
Even though the
|
1999-03-02 03:45:47 +00:00
|
|
|
crypted password file
|
|
|
|
.Pq Pa /etc/spwd.db
|
|
|
|
can only be read by root, it may
|
2001-07-14 19:41:16 +00:00
|
|
|
be possible for an intruder to obtain read access to that file even if the
|
1998-12-20 20:12:17 +00:00
|
|
|
attacker cannot obtain root-write access.
|
|
|
|
.Pp
|
2001-07-14 19:41:16 +00:00
|
|
|
Your security scripts should always check for and report changes to
|
1999-03-02 03:45:47 +00:00
|
|
|
the password file
|
2001-08-07 15:48:51 +00:00
|
|
|
(see
|
2004-06-15 12:48:50 +00:00
|
|
|
.Sx CHECKING FILE INTEGRITY
|
2001-08-07 15:48:51 +00:00
|
|
|
below).
|
2002-12-12 17:26:04 +00:00
|
|
|
.Sh SECURING THE KERNEL CORE, RAW DEVICES, AND FILE SYSTEMS
|
1998-12-20 20:12:17 +00:00
|
|
|
If an attacker breaks root he can do just about anything, but there
|
2004-06-15 12:48:50 +00:00
|
|
|
are certain conveniences.
|
|
|
|
For example, most modern kernels have a packet sniffing device driver built in.
|
|
|
|
Under
|
1999-09-04 14:55:22 +00:00
|
|
|
.Fx
|
1999-03-02 03:45:47 +00:00
|
|
|
it is called
|
|
|
|
the
|
2004-06-15 12:48:50 +00:00
|
|
|
.Xr bpf 4
|
|
|
|
device.
|
|
|
|
An intruder will commonly attempt to run a packet sniffer
|
|
|
|
on a compromised machine.
|
|
|
|
You do not need to give the intruder the
|
|
|
|
capability and most systems should not have the
|
|
|
|
.Xr bpf 4
|
|
|
|
device compiled in.
|
|
|
|
.Pp
|
|
|
|
But even if you turn off the
|
|
|
|
.Xr bpf 4
|
|
|
|
device, you still have
|
1999-03-02 03:45:47 +00:00
|
|
|
.Pa /dev/mem
|
|
|
|
and
|
|
|
|
.Pa /dev/kmem
|
2004-06-15 12:48:50 +00:00
|
|
|
to worry about.
|
|
|
|
For that matter,
|
1999-09-18 18:21:38 +00:00
|
|
|
the intruder can still write to raw disk devices.
|
|
|
|
Also, there is another kernel feature called the module loader,
|
1999-03-02 03:45:47 +00:00
|
|
|
.Xr kldload 8 .
|
2001-07-14 19:41:16 +00:00
|
|
|
An enterprising intruder can use a KLD module to install
|
2004-06-15 12:48:50 +00:00
|
|
|
his own
|
|
|
|
.Xr bpf 4
|
|
|
|
device or other sniffing device on a running kernel.
|
1999-03-02 03:45:47 +00:00
|
|
|
To avoid these problems you have to run
|
2005-09-03 17:16:00 +00:00
|
|
|
the kernel at a higher security level, at least level 1.
|
|
|
|
The security level can be set with a
|
2004-06-15 12:48:50 +00:00
|
|
|
.Xr sysctl 8
|
|
|
|
on the
|
|
|
|
.Va kern.securelevel
|
|
|
|
variable.
|
|
|
|
Once you have
|
2005-09-03 17:16:00 +00:00
|
|
|
set the security level to 1, write access to raw devices will be denied and
|
2004-06-15 12:48:50 +00:00
|
|
|
special
|
|
|
|
.Xr chflags 1
|
|
|
|
flags, such as
|
|
|
|
.Cm schg ,
|
|
|
|
will be enforced.
|
|
|
|
You must also ensure
|
1999-03-02 03:45:47 +00:00
|
|
|
that the
|
2004-06-15 12:48:50 +00:00
|
|
|
.Cm schg
|
1999-03-02 03:45:47 +00:00
|
|
|
flag is set on critical startup binaries, directories, and
|
2005-09-03 17:16:00 +00:00
|
|
|
script files \(em everything that gets run
|
|
|
|
up to the point where the security level is set.
|
2004-06-15 12:48:50 +00:00
|
|
|
This might be overdoing it, and upgrading the system is much more
|
2005-09-03 17:16:00 +00:00
|
|
|
difficult when you operate at a higher security level.
|
2004-06-15 12:48:50 +00:00
|
|
|
You may compromise and
|
2005-09-03 17:16:00 +00:00
|
|
|
run the system at a higher security level but not set the
|
2004-06-15 12:48:50 +00:00
|
|
|
.Cm schg
|
|
|
|
flag for every
|
|
|
|
system file and directory under the sun.
|
|
|
|
Another possibility is to simply
|
|
|
|
mount
|
|
|
|
.Pa /
|
|
|
|
and
|
|
|
|
.Pa /usr
|
|
|
|
read-only.
|
|
|
|
It should be noted that being too draconian in
|
1999-09-18 18:21:38 +00:00
|
|
|
what you attempt to protect may prevent the all-important detection of an
|
|
|
|
intrusion.
|
2005-09-03 17:16:00 +00:00
|
|
|
.Pp
|
|
|
|
The kernel runs with five different security levels.
|
|
|
|
Any super-user process can raise the level, but no process
|
|
|
|
can lower it.
|
|
|
|
The security levels are:
|
|
|
|
.Bl -tag -width flag
|
|
|
|
.It Ic -1
|
|
|
|
Permanently insecure mode \- always run the system in insecure mode.
|
|
|
|
This is the default initial value.
|
|
|
|
.It Ic 0
|
|
|
|
Insecure mode \- immutable and append-only flags may be turned off.
|
|
|
|
All devices may be read or written subject to their permissions.
|
|
|
|
.It Ic 1
|
|
|
|
Secure mode \- the system immutable and system append-only flags may not
|
|
|
|
be turned off;
|
|
|
|
disks for mounted file systems,
|
2006-07-12 18:12:11 +00:00
|
|
|
.Pa /dev/mem
|
2005-09-03 17:16:00 +00:00
|
|
|
and
|
2006-07-12 18:12:11 +00:00
|
|
|
.Pa /dev/kmem
|
|
|
|
may not be opened for writing;
|
2005-09-03 17:16:00 +00:00
|
|
|
.Pa /dev/io
|
2006-07-12 18:12:11 +00:00
|
|
|
(if your platform has it) may not be opened at all;
|
2005-09-03 17:16:00 +00:00
|
|
|
kernel modules (see
|
|
|
|
.Xr kld 4 )
|
|
|
|
may not be loaded or unloaded.
|
|
|
|
.It Ic 2
|
|
|
|
Highly secure mode \- same as secure mode, plus disks may not be
|
|
|
|
opened for writing (except by
|
|
|
|
.Xr mount 2 )
|
|
|
|
whether mounted or not.
|
|
|
|
This level precludes tampering with file systems by unmounting them,
|
|
|
|
but also inhibits running
|
|
|
|
.Xr newfs 8
|
|
|
|
while the system is multi-user.
|
|
|
|
.Pp
|
|
|
|
In addition, kernel time changes are restricted to less than or equal to one
|
|
|
|
second.
|
|
|
|
Attempts to change the time by more than this will log the message
|
|
|
|
.Dq Time adjustment clamped to +1 second .
|
|
|
|
.It Ic 3
|
|
|
|
Network secure mode \- same as highly secure mode, plus
|
|
|
|
IP packet filter rules (see
|
|
|
|
.Xr ipfw 8 ,
|
|
|
|
.Xr ipfirewall 4
|
|
|
|
and
|
|
|
|
.Xr pfctl 8 )
|
|
|
|
cannot be changed and
|
|
|
|
.Xr dummynet 4
|
|
|
|
or
|
|
|
|
.Xr pf 4
|
|
|
|
configuration cannot be adjusted.
|
|
|
|
.El
|
|
|
|
.Pp
|
2006-01-19 20:01:43 +00:00
|
|
|
The security level can be configured with variables documented in
|
2005-09-03 17:16:00 +00:00
|
|
|
.Xr rc.conf 8 .
|
1998-12-20 20:12:17 +00:00
|
|
|
.Sh CHECKING FILE INTEGRITY: BINARIES, CONFIG FILES, ETC
|
|
|
|
When it comes right down to it, you can only protect your core system
|
|
|
|
configuration and control files so much before the convenience factor
|
2004-06-15 12:48:50 +00:00
|
|
|
rears its ugly head.
|
|
|
|
For example, using
|
|
|
|
.Xr chflags 1
|
|
|
|
to set the
|
|
|
|
.Cm schg
|
|
|
|
bit on most of the files in
|
|
|
|
.Pa /
|
|
|
|
and
|
|
|
|
.Pa /usr
|
|
|
|
is probably counterproductive because
|
|
|
|
while it may protect the files, it also closes a detection window.
|
|
|
|
The
|
2004-05-18 17:50:08 +00:00
|
|
|
last layer of your security onion is perhaps the most important \(em detection.
|
1999-09-18 18:21:38 +00:00
|
|
|
The rest of your security is pretty much useless (or, worse, presents you with
|
2004-06-15 12:48:50 +00:00
|
|
|
a false sense of safety) if you cannot detect potential incursions.
|
|
|
|
Half
|
2002-12-24 16:52:31 +00:00
|
|
|
the job of the onion is to slow down the attacker rather than stop him
|
2004-05-18 18:17:25 +00:00
|
|
|
in order to give the detection layer a chance to catch him in
|
1999-09-18 18:21:38 +00:00
|
|
|
the act.
|
|
|
|
.Pp
|
|
|
|
The best way to detect an incursion is to look for modified, missing, or
|
2004-06-15 12:48:50 +00:00
|
|
|
unexpected files.
|
|
|
|
The best
|
1999-09-18 18:21:38 +00:00
|
|
|
way to look for modified files is from another (often centralized)
|
|
|
|
limited-access system.
|
2001-07-14 19:41:16 +00:00
|
|
|
Writing your security scripts on the extra-secure limited-access system
|
2004-05-18 17:50:08 +00:00
|
|
|
makes them mostly invisible to potential attackers, and this is important.
|
1999-09-18 18:21:38 +00:00
|
|
|
In order to take maximum advantage you generally have to give the
|
|
|
|
limited-access box significant access to the other machines in the business,
|
|
|
|
usually either by doing a read-only NFS export of the other machines to the
|
2004-06-15 12:48:50 +00:00
|
|
|
limited-access box, or by setting up SSH keypairs to allow the limit-access
|
|
|
|
box to SSH to the other machines.
|
|
|
|
Except for its network traffic, NFS is
|
2004-05-18 17:50:08 +00:00
|
|
|
the least visible method \(em allowing you to monitor the file systems on each
|
2004-06-15 12:48:50 +00:00
|
|
|
client box virtually undetected.
|
|
|
|
If your
|
1999-09-18 18:21:38 +00:00
|
|
|
limited-access server is connected to the client boxes through a switch,
|
2004-06-15 12:48:50 +00:00
|
|
|
the NFS method is often the better choice.
|
|
|
|
If your limited-access server
|
1999-09-18 18:21:38 +00:00
|
|
|
is connected to the client boxes through a hub or through several layers
|
2004-06-15 12:48:50 +00:00
|
|
|
of routing, the NFS method may be too insecure (network-wise) and using SSH
|
|
|
|
may be the better choice even with the audit-trail tracks that SSH lays.
|
1999-09-18 18:21:38 +00:00
|
|
|
.Pp
|
|
|
|
Once you give a limit-access box at least read access to the client systems
|
2001-07-14 19:41:16 +00:00
|
|
|
it is supposed to monitor, you must write scripts to do the actual
|
2004-06-15 12:48:50 +00:00
|
|
|
monitoring.
|
|
|
|
Given an NFS mount, you can write scripts out of simple system
|
1999-09-18 18:21:38 +00:00
|
|
|
utilities such as
|
|
|
|
.Xr find 1
|
|
|
|
and
|
2004-06-15 12:48:50 +00:00
|
|
|
.Xr md5 1 .
|
|
|
|
It is best to physically
|
1999-09-18 18:21:38 +00:00
|
|
|
.Xr md5 1
|
2004-06-15 12:48:50 +00:00
|
|
|
the client-box files boxes at least once a
|
1999-09-19 05:30:12 +00:00
|
|
|
day, and to test control files such as those found in
|
|
|
|
.Pa /etc
|
|
|
|
and
|
|
|
|
.Pa /usr/local/etc
|
2004-06-15 12:48:50 +00:00
|
|
|
even more often.
|
|
|
|
When mismatches are found relative to the base MD5
|
1999-09-18 18:21:38 +00:00
|
|
|
information the limited-access machine knows is valid, it should scream at
|
2004-06-15 12:48:50 +00:00
|
|
|
a sysadmin to go check it out.
|
|
|
|
A good security script will also check for
|
|
|
|
inappropriate SUID binaries and for new or deleted files on system partitions
|
1999-09-18 18:21:38 +00:00
|
|
|
such as
|
|
|
|
.Pa /
|
1999-03-02 03:45:47 +00:00
|
|
|
and
|
2004-06-15 12:48:50 +00:00
|
|
|
.Pa /usr .
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
When using SSH rather than NFS, writing the security script is much more
|
|
|
|
difficult.
|
|
|
|
You essentially have to
|
|
|
|
.Xr scp 1
|
1999-09-18 18:21:38 +00:00
|
|
|
the scripts to the client box in order to run them, making them visible, and
|
2004-06-15 12:48:50 +00:00
|
|
|
for safety you also need to
|
|
|
|
.Xr scp 1
|
|
|
|
the binaries (such as
|
|
|
|
.Xr find 1 )
|
|
|
|
that those scripts use.
|
|
|
|
The
|
|
|
|
.Xr sshd 8
|
|
|
|
daemon on the client box may already be compromised.
|
|
|
|
All in all,
|
|
|
|
using SSH may be necessary when running over unsecure links, but it is also a
|
1999-09-18 18:21:38 +00:00
|
|
|
lot harder to deal with.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
|
|
|
A good security script will also check for changes to user and staff members
|
1999-09-19 05:30:12 +00:00
|
|
|
access configuration files:
|
2004-06-15 12:48:50 +00:00
|
|
|
.Pa .rhosts , .shosts , .ssh/authorized_keys
|
2004-07-03 18:29:24 +00:00
|
|
|
and so forth, files that might fall outside the purview of the MD5 check.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
1999-09-18 18:21:38 +00:00
|
|
|
If you have a huge amount of user disk space it may take too long to run
|
2004-06-15 12:48:50 +00:00
|
|
|
through every file on those partitions.
|
|
|
|
In this case, setting mount
|
2004-11-29 09:56:12 +00:00
|
|
|
flags to disallow SUID binaries on those partitions is a good
|
2004-06-15 12:48:50 +00:00
|
|
|
idea.
|
|
|
|
The
|
|
|
|
.Cm nosuid
|
2004-11-29 09:56:12 +00:00
|
|
|
option
|
2001-08-07 15:48:51 +00:00
|
|
|
(see
|
|
|
|
.Xr mount 8 )
|
2004-11-29 09:56:12 +00:00
|
|
|
is what you want to look into.
|
2004-06-15 12:48:50 +00:00
|
|
|
I would scan them anyway at least once a
|
1999-09-18 18:21:38 +00:00
|
|
|
week, since the object of this layer is to detect a break-in whether or
|
2004-02-18 18:52:09 +00:00
|
|
|
not the break-in is effective.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
1999-03-02 03:45:47 +00:00
|
|
|
Process accounting
|
2001-08-07 15:48:51 +00:00
|
|
|
(see
|
|
|
|
.Xr accton 8 )
|
1999-03-02 03:45:47 +00:00
|
|
|
is a relatively low-overhead feature of
|
1998-12-25 23:39:01 +00:00
|
|
|
the operating system which I recommend using as a post-break-in evaluation
|
2004-06-15 12:48:50 +00:00
|
|
|
mechanism.
|
|
|
|
It is especially useful in tracking down how an intruder has
|
1999-09-18 18:21:38 +00:00
|
|
|
actually broken into a system, assuming the file is still intact after
|
1998-12-25 23:39:01 +00:00
|
|
|
the break-in occurs.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
|
|
|
Finally, security scripts should process the log files and the logs themselves
|
2004-05-18 17:50:08 +00:00
|
|
|
should be generated in as secure a manner as possible \(em remote syslog can be
|
2004-06-15 12:48:50 +00:00
|
|
|
very useful.
|
|
|
|
An intruder tries to cover his tracks, and log files are critical
|
2001-07-14 19:41:16 +00:00
|
|
|
to the sysadmin trying to track down the time and method of the initial
|
2004-06-15 12:48:50 +00:00
|
|
|
break-in.
|
|
|
|
One way to keep a permanent record of the log files is to run
|
1999-09-18 18:21:38 +00:00
|
|
|
the system console to a serial port and collect the information on a
|
|
|
|
continuing basis through a secure machine monitoring the consoles.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Sh PARANOIA
|
2004-06-15 12:48:50 +00:00
|
|
|
A little paranoia never hurts.
|
|
|
|
As a rule, a sysadmin can add any number
|
2004-05-18 17:50:08 +00:00
|
|
|
of security features as long as they do not affect convenience, and
|
|
|
|
can add security features that do affect convenience with some added
|
2004-06-15 12:48:50 +00:00
|
|
|
thought.
|
|
|
|
Even more importantly, a security administrator should mix it up
|
2004-05-18 17:50:08 +00:00
|
|
|
a bit \(em if you use recommendations such as those given by this manual
|
1999-09-18 18:21:38 +00:00
|
|
|
page verbatim, you give away your methodologies to the prospective
|
2004-05-18 17:50:08 +00:00
|
|
|
attacker who also has access to this manual page.
|
2004-06-15 12:48:50 +00:00
|
|
|
.Sh SPECIAL SECTION ON DoS ATTACKS
|
|
|
|
This section covers Denial of Service attacks.
|
|
|
|
A DoS attack is typically a packet attack.
|
|
|
|
While there is not much you can do about modern spoofed
|
1998-12-20 20:12:17 +00:00
|
|
|
packet attacks that saturate your network, you can generally limit the damage
|
2001-07-14 19:41:16 +00:00
|
|
|
by ensuring that the attacks cannot take down your servers.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Bl -enum -offset indent
|
|
|
|
.It
|
|
|
|
Limiting server forks
|
|
|
|
.It
|
2004-06-15 12:48:50 +00:00
|
|
|
Limiting springboard attacks (ICMP response attacks, ping broadcast, etc.)
|
1998-12-20 20:12:17 +00:00
|
|
|
.It
|
|
|
|
Kernel Route Cache
|
|
|
|
.El
|
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
A common DoS attack is against a forking server that attempts to cause the
|
1998-12-25 23:39:01 +00:00
|
|
|
server to eat processes, file descriptors, and memory until the machine
|
2004-06-15 12:48:50 +00:00
|
|
|
dies.
|
|
|
|
The
|
|
|
|
.Xr inetd 8
|
|
|
|
server
|
1999-03-02 03:45:47 +00:00
|
|
|
has several options to limit this sort of attack.
|
1998-12-20 20:12:17 +00:00
|
|
|
It should be noted that while it is possible to prevent a machine from going
|
2001-07-14 19:41:16 +00:00
|
|
|
down it is not generally possible to prevent a service from being disrupted
|
2004-06-15 12:48:50 +00:00
|
|
|
by the attack.
|
|
|
|
Read the
|
|
|
|
.Xr inetd 8
|
|
|
|
manual page carefully and pay specific attention
|
1999-03-02 03:45:47 +00:00
|
|
|
to the
|
2004-06-15 12:48:50 +00:00
|
|
|
.Fl c , C ,
|
1999-03-02 03:45:47 +00:00
|
|
|
and
|
|
|
|
.Fl R
|
2004-06-15 12:48:50 +00:00
|
|
|
options.
|
|
|
|
Note that spoofed-IP attacks will circumvent
|
1999-03-02 03:45:47 +00:00
|
|
|
the
|
|
|
|
.Fl C
|
2004-06-15 12:48:50 +00:00
|
|
|
option to
|
|
|
|
.Xr inetd 8 ,
|
|
|
|
so typically a combination of options must be used.
|
2001-07-14 19:41:16 +00:00
|
|
|
Some standalone servers have self-fork-limitation parameters.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
The
|
|
|
|
.Xr sendmail 8
|
|
|
|
daemon has its
|
1999-03-02 03:45:47 +00:00
|
|
|
.Fl OMaxDaemonChildren
|
|
|
|
option which tends to work much
|
2004-06-15 12:48:50 +00:00
|
|
|
better than trying to use
|
|
|
|
.Xr sendmail 8 Ns 's
|
|
|
|
load limiting options due to the
|
|
|
|
load lag.
|
|
|
|
You should specify a
|
|
|
|
.Va MaxDaemonChildren
|
1999-03-02 03:45:47 +00:00
|
|
|
parameter when you start
|
2004-06-15 12:48:50 +00:00
|
|
|
.Xr sendmail 8
|
|
|
|
high enough to handle your expected load but not so high that the
|
|
|
|
computer cannot handle that number of
|
|
|
|
.Nm sendmail Ns 's
|
|
|
|
without falling on its face.
|
|
|
|
It is also prudent to run
|
|
|
|
.Xr sendmail 8
|
|
|
|
in
|
|
|
|
.Dq queued
|
|
|
|
mode
|
1999-03-02 03:45:47 +00:00
|
|
|
.Pq Fl ODeliveryMode=queued
|
2001-07-14 19:41:16 +00:00
|
|
|
and to run the daemon
|
2004-06-15 12:48:50 +00:00
|
|
|
.Pq Dq Nm sendmail Fl bd
|
1999-03-02 03:45:47 +00:00
|
|
|
separate from the queue-runs
|
2004-06-15 12:48:50 +00:00
|
|
|
.Pq Dq Nm sendmail Fl q15m .
|
|
|
|
If you still want real-time delivery you can run the queue
|
1999-03-02 03:45:47 +00:00
|
|
|
at a much lower interval, such as
|
|
|
|
.Fl q1m ,
|
|
|
|
but be sure to specify a reasonable
|
2004-06-15 12:48:50 +00:00
|
|
|
.Va MaxDaemonChildren
|
|
|
|
option for that
|
|
|
|
.Xr sendmail 8
|
|
|
|
to prevent cascade failures.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
The
|
|
|
|
.Xr syslogd 8
|
|
|
|
daemon can be attacked directly and it is strongly recommended that you use
|
2001-07-14 19:41:16 +00:00
|
|
|
the
|
1999-03-02 03:45:47 +00:00
|
|
|
.Fl s
|
|
|
|
option whenever possible, and the
|
|
|
|
.Fl a
|
|
|
|
option otherwise.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
|
|
|
You should also be fairly careful
|
2001-07-14 19:41:16 +00:00
|
|
|
with connect-back services such as tcpwrapper's reverse-identd, which can
|
2004-06-15 12:48:50 +00:00
|
|
|
be attacked directly.
|
|
|
|
You generally do not want to use the reverse-ident
|
1998-12-20 20:12:17 +00:00
|
|
|
feature of tcpwrappers for this reason.
|
|
|
|
.Pp
|
|
|
|
It is a very good idea to protect internal services from external access
|
2004-06-15 12:48:50 +00:00
|
|
|
by firewalling them off at your border routers.
|
|
|
|
The idea here is to prevent
|
2001-07-14 19:41:16 +00:00
|
|
|
saturation attacks from outside your LAN, not so much to protect internal
|
2004-06-15 12:48:50 +00:00
|
|
|
services from network-based root compromise.
|
|
|
|
Always configure an exclusive
|
|
|
|
firewall, i.e.,
|
1999-03-02 03:45:47 +00:00
|
|
|
.So
|
2004-05-18 17:50:08 +00:00
|
|
|
firewall everything
|
|
|
|
.Em except
|
|
|
|
ports A, B, C, D, and M-Z
|
1999-03-02 03:45:47 +00:00
|
|
|
.Sc .
|
|
|
|
This
|
1998-12-20 20:12:17 +00:00
|
|
|
way you can firewall off all of your low ports except for certain specific
|
2004-06-15 12:48:50 +00:00
|
|
|
services such as
|
|
|
|
.Xr named 8
|
2001-08-07 15:48:51 +00:00
|
|
|
(if you are primary for a zone),
|
2004-06-15 12:48:50 +00:00
|
|
|
.Xr talkd 8 ,
|
|
|
|
.Xr sendmail 8 ,
|
1998-12-20 20:12:17 +00:00
|
|
|
and other internet-accessible services.
|
|
|
|
If you try to configure the firewall the other
|
2004-05-18 17:50:08 +00:00
|
|
|
way \(em as an inclusive or permissive firewall, there is a good chance that you
|
2001-07-14 19:41:16 +00:00
|
|
|
will forget to
|
2004-06-15 12:48:50 +00:00
|
|
|
.Dq close
|
1999-03-02 03:45:47 +00:00
|
|
|
a couple of services or that you will add a new internal
|
2004-06-15 12:48:50 +00:00
|
|
|
service and forget to update the firewall.
|
|
|
|
You can still open up the
|
1998-12-20 20:12:17 +00:00
|
|
|
high-numbered port range on the firewall to allow permissive-like operation
|
2004-06-15 12:48:50 +00:00
|
|
|
without compromising your low ports.
|
|
|
|
Also take note that
|
1999-09-04 14:55:22 +00:00
|
|
|
.Fx
|
1999-03-02 03:45:47 +00:00
|
|
|
allows you to
|
1998-12-20 20:12:17 +00:00
|
|
|
control the range of port numbers used for dynamic binding via the various
|
2004-06-15 12:48:50 +00:00
|
|
|
.Va net.inet.ip.portrange
|
|
|
|
sysctl's
|
|
|
|
.Pq Dq Li "sysctl net.inet.ip.portrange" ,
|
1999-03-02 03:45:47 +00:00
|
|
|
which can also
|
2004-06-15 12:48:50 +00:00
|
|
|
ease the complexity of your firewall's configuration.
|
|
|
|
I usually use a normal
|
1998-12-20 20:12:17 +00:00
|
|
|
first/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then
|
1999-03-02 03:45:47 +00:00
|
|
|
block everything under 4000 off in my firewall
|
2001-08-07 15:48:51 +00:00
|
|
|
(except for certain specific
|
|
|
|
internet-accessible ports, of course).
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
Another common DoS attack is called a springboard attack \(em to attack a server
|
1998-12-20 20:12:17 +00:00
|
|
|
in a manner that causes the server to generate responses which then overload
|
2004-06-15 12:48:50 +00:00
|
|
|
the server, the local network, or some other machine.
|
|
|
|
The most common attack
|
|
|
|
of this nature is the ICMP PING BROADCAST attack.
|
|
|
|
The attacker spoofs ping
|
1998-12-20 20:12:17 +00:00
|
|
|
packets sent to your LAN's broadcast address with the source IP address set
|
2004-06-15 12:48:50 +00:00
|
|
|
to the actual machine they wish to attack.
|
|
|
|
If your border routers are not
|
1998-12-20 20:12:17 +00:00
|
|
|
configured to stomp on ping's to broadcast addresses, your LAN winds up
|
|
|
|
generating sufficient responses to the spoofed source address to saturate the
|
|
|
|
victim, especially when the attacker uses the same trick on several dozen
|
2004-06-15 12:48:50 +00:00
|
|
|
broadcast addresses over several dozen different networks at once.
|
|
|
|
Broadcast attacks of over a hundred and twenty megabits have been measured.
|
|
|
|
A second common springboard attack is against the ICMP error reporting system.
|
|
|
|
By
|
2001-07-14 19:41:16 +00:00
|
|
|
constructing packets that generate ICMP error responses, an attacker can
|
|
|
|
saturate a server's incoming network and cause the server to saturate its
|
2004-06-15 12:48:50 +00:00
|
|
|
outgoing network with ICMP responses.
|
|
|
|
This type of attack can also crash the
|
|
|
|
server by running it out of
|
|
|
|
.Vt mbuf Ns 's ,
|
|
|
|
especially if the server cannot drain the
|
|
|
|
ICMP responses it generates fast enough.
|
|
|
|
The
|
1999-09-04 14:55:22 +00:00
|
|
|
.Fx
|
1999-03-02 03:45:47 +00:00
|
|
|
kernel has a new kernel
|
2004-06-15 12:48:50 +00:00
|
|
|
compile option called
|
|
|
|
.Dv ICMP_BANDLIM
|
|
|
|
which limits the effectiveness of these
|
|
|
|
sorts of attacks.
|
|
|
|
The last major class of springboard attacks is related to
|
|
|
|
certain internal
|
|
|
|
.Xr inetd 8
|
|
|
|
services such as the UDP echo service.
|
|
|
|
An attacker
|
1998-12-20 20:12:17 +00:00
|
|
|
simply spoofs a UDP packet with the source address being server A's echo port,
|
|
|
|
and the destination address being server B's echo port, where server A and B
|
2004-06-15 12:48:50 +00:00
|
|
|
are both on your LAN.
|
|
|
|
The two servers then bounce this one packet back and
|
|
|
|
forth between each other.
|
|
|
|
The attacker can overload both servers and their
|
|
|
|
LANs simply by injecting a few packets in this manner.
|
|
|
|
Similar problems
|
|
|
|
exist with the internal chargen port.
|
|
|
|
A competent sysadmin will turn off all
|
|
|
|
of these
|
|
|
|
.Xr inetd 8 Ns -internal
|
|
|
|
test services.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Pp
|
|
|
|
Spoofed packet attacks may also be used to overload the kernel route cache.
|
2004-06-15 12:48:50 +00:00
|
|
|
Refer to the
|
|
|
|
.Va net.inet.ip.rtexpire , net.inet.ip.rtminexpire ,
|
|
|
|
and
|
|
|
|
.Va net.inet.ip.rtmaxcache
|
|
|
|
.Xr sysctl 8
|
|
|
|
variables.
|
|
|
|
A spoofed packet attack that uses a random source IP will cause
|
1998-12-20 20:12:17 +00:00
|
|
|
the kernel to generate a temporary cached route in the route table, viewable
|
1999-03-02 03:45:47 +00:00
|
|
|
with
|
2004-06-15 12:48:50 +00:00
|
|
|
.Dq Li "netstat -rna | fgrep W3" .
|
1999-03-02 03:45:47 +00:00
|
|
|
These routes typically timeout in 1600
|
2004-06-15 12:48:50 +00:00
|
|
|
seconds or so.
|
|
|
|
If the kernel detects that the cached route table has gotten
|
|
|
|
too big it will dynamically reduce the
|
|
|
|
.Va rtexpire
|
|
|
|
but will never decrease it to
|
|
|
|
less than
|
|
|
|
.Va rtminexpire .
|
|
|
|
There are two problems: (1) The kernel does not react
|
1998-12-20 20:12:17 +00:00
|
|
|
quickly enough when a lightly loaded server is suddenly attacked, and (2) The
|
2004-06-15 12:48:50 +00:00
|
|
|
.Va rtminexpire
|
|
|
|
is not low enough for the kernel to survive a sustained attack.
|
2001-07-14 19:41:16 +00:00
|
|
|
If your servers are connected to the internet via a T3 or better it may be
|
2004-06-15 12:48:50 +00:00
|
|
|
prudent to manually override both
|
|
|
|
.Va rtexpire
|
|
|
|
and
|
|
|
|
.Va rtminexpire
|
|
|
|
via
|
1999-03-15 15:43:10 +00:00
|
|
|
.Xr sysctl 8 .
|
1999-03-02 03:45:47 +00:00
|
|
|
Never set either parameter to zero
|
2001-08-07 15:48:51 +00:00
|
|
|
(unless you want to crash the machine :-)).
|
1998-12-20 20:12:17 +00:00
|
|
|
Setting both parameters to 2 seconds should be sufficient to protect the route
|
|
|
|
table from attack.
|
1999-09-18 18:21:38 +00:00
|
|
|
.Sh ACCESS ISSUES WITH KERBEROS AND SSH
|
2004-06-15 12:48:50 +00:00
|
|
|
There are a few issues with both Kerberos and SSH that need to be addressed
|
|
|
|
if you intend to use them.
|
|
|
|
Kerberos5 is an excellent authentication
|
|
|
|
protocol but the kerberized
|
|
|
|
.Xr telnet 1
|
|
|
|
and
|
|
|
|
.Xr rlogin 1
|
|
|
|
suck rocks.
|
|
|
|
There are bugs that make them unsuitable for dealing with binary streams.
|
|
|
|
Also, by default
|
|
|
|
Kerberos does not encrypt a session unless you use the
|
1999-09-18 18:21:38 +00:00
|
|
|
.Fl x
|
2004-06-15 12:48:50 +00:00
|
|
|
option.
|
|
|
|
SSH encrypts everything by default.
|
1999-09-18 18:21:38 +00:00
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
SSH works quite well in every respect except when it is set up to
|
2001-06-16 00:32:19 +00:00
|
|
|
forward encryption keys.
|
2001-07-14 19:41:16 +00:00
|
|
|
What this means is that if you have a secure workstation holding
|
2004-06-15 12:48:50 +00:00
|
|
|
keys that give you access to the rest of the system, and you
|
|
|
|
.Xr ssh 1
|
|
|
|
to an
|
|
|
|
unsecure machine, your keys become exposed.
|
|
|
|
The actual keys themselves are
|
|
|
|
not exposed, but
|
|
|
|
.Xr ssh 1
|
|
|
|
installs a forwarding port for the duration of your
|
2004-05-18 17:50:08 +00:00
|
|
|
login and if an attacker has broken root on the unsecure machine he can utilize
|
1999-09-18 18:21:38 +00:00
|
|
|
that port to use your keys to gain access to any other machine that your
|
|
|
|
keys unlock.
|
|
|
|
.Pp
|
2004-06-15 12:48:50 +00:00
|
|
|
We recommend that you use SSH in combination with Kerberos whenever possible
|
|
|
|
for staff logins.
|
|
|
|
SSH can be compiled with Kerberos support.
|
|
|
|
This reduces
|
|
|
|
your reliance on potentially exposable SSH keys while at the same time
|
|
|
|
protecting passwords via Kerberos.
|
|
|
|
SSH keys
|
2001-07-14 19:41:16 +00:00
|
|
|
should only be used for automated tasks from secure machines (something
|
2004-06-15 12:48:50 +00:00
|
|
|
that Kerberos is unsuited to).
|
|
|
|
We also recommend that you either turn off
|
|
|
|
key-forwarding in the SSH configuration, or that you make use of the
|
|
|
|
.Va from Ns = Ns Ar IP/DOMAIN
|
|
|
|
option that SSH allows in its
|
1999-09-18 18:21:38 +00:00
|
|
|
.Pa authorized_keys
|
2002-01-09 12:34:01 +00:00
|
|
|
file to make the key only usable to entities logging in from specific
|
1999-09-18 18:21:38 +00:00
|
|
|
machines.
|
1998-12-20 20:12:17 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr chflags 1 ,
|
|
|
|
.Xr find 1 ,
|
|
|
|
.Xr md5 1 ,
|
1999-09-04 14:55:22 +00:00
|
|
|
.Xr netstat 1 ,
|
2001-02-01 16:38:02 +00:00
|
|
|
.Xr openssl 1 ,
|
2001-07-06 16:46:48 +00:00
|
|
|
.Xr ssh 1 ,
|
2005-07-14 20:29:08 +00:00
|
|
|
.Xr xdm 1 Pq Pa ports/x11/xorg-clients ,
|
1999-09-18 18:21:38 +00:00
|
|
|
.Xr group 5 ,
|
1999-09-19 05:30:12 +00:00
|
|
|
.Xr ttys 5 ,
|
2000-03-07 13:59:26 +00:00
|
|
|
.Xr accton 8 ,
|
1999-09-18 18:21:38 +00:00
|
|
|
.Xr init 8 ,
|
2000-03-07 13:59:26 +00:00
|
|
|
.Xr sshd 8 ,
|
1999-09-19 05:30:12 +00:00
|
|
|
.Xr sysctl 8 ,
|
2000-03-07 13:59:26 +00:00
|
|
|
.Xr syslogd 8 ,
|
1999-09-19 05:30:12 +00:00
|
|
|
.Xr vipw 8
|
1998-12-20 20:12:17 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
1999-03-02 03:45:47 +00:00
|
|
|
manual page was originally written by
|
|
|
|
.An Matthew Dillon
|
2001-07-14 19:41:16 +00:00
|
|
|
and first appeared
|
1999-03-02 03:45:47 +00:00
|
|
|
in
|
1999-03-15 15:43:10 +00:00
|
|
|
.Fx 3.1 ,
|
1999-03-02 03:45:47 +00:00
|
|
|
December 1998.
|