xref: /freebsd/share/man/man7/security.7 (revision 454ba76889e54fa2926b23ef60d0dc1d106e0fe2)
13128fa34SMatthew Dillon.\" Copyright (c) 1998, Matthew Dillon.  Terms and conditions are those of
23128fa34SMatthew Dillon.\" the BSD Copyright as specified in the file "/usr/src/COPYRIGHT" in
33128fa34SMatthew Dillon.\" the source tree.
4f063d76aSMatthew Dillon.\"
57f3dea24SPeter Wemm.\" $FreeBSD$
6f063d76aSMatthew Dillon.\"
7d93b26d6SMatthew Dillon.Dd September 18, 1999
8f063d76aSMatthew Dillon.Dt SECURITY 7
93d45e180SRuslan Ermilov.Os
10f063d76aSMatthew Dillon.Sh NAME
11f063d76aSMatthew Dillon.Nm security
12454ba768SRuslan Ermilov.Nd introduction to security under
13454ba768SRuslan Ermilov.Fx
14f063d76aSMatthew Dillon.Sh DESCRIPTION
15f063d76aSMatthew DillonSecurity is a function that begins and ends with the system administrator.
16f063d76aSMatthew DillonWhile all
17f063d76aSMatthew Dillon.Bx
18d93b26d6SMatthew Dillonmulti-user systems have some inherent security, the job of building and
19992e4638SRobert Watsonmaintaining additional security mechanisms to keep users
20454ba768SRuslan Ermilov.Dq honest
21568e4cbbSGuy Helmeris probably
22454ba768SRuslan Ermilovone of the single largest undertakings of the sysadmin.
23454ba768SRuslan ErmilovMachines are
24f063d76aSMatthew Dillononly as secure as you make them, and security concerns are ever competing
25568e4cbbSGuy Helmerwith the human necessity for convenience.
26568e4cbbSGuy Helmer.Ux
27568e4cbbSGuy Helmersystems,
286ac7e896SDavid E. O'Brienin general, are capable of running a huge number of simultaneous processes
29454ba768SRuslan Ermilovand many of these processes operate as servers \(em meaning that external
30454ba768SRuslan Ermiloventities can connect and talk to them.
31454ba768SRuslan ErmilovAs yesterday's mini-computers and mainframes
32f063d76aSMatthew Dillonbecome today's desktops, and as computers become networked and internetworked,
33f063d76aSMatthew Dillonsecurity becomes an ever bigger issue.
34f063d76aSMatthew Dillon.Pp
35454ba768SRuslan ErmilovSecurity is best implemented through a layered onion approach.
36454ba768SRuslan ErmilovIn a nutshell,
37d93b26d6SMatthew Dillonwhat you want to do is to create as many layers of security as are convenient
38454ba768SRuslan Ermilovand then carefully monitor the system for intrusions.
39454ba768SRuslan ErmilovYou do not want to
407c86a74bSMike Pritchardoverbuild your security or you will interfere with the detection side, and
41d93b26d6SMatthew Dillondetection is one of the single most important aspects of any security
42454ba768SRuslan Ermilovmechanism.
43454ba768SRuslan ErmilovFor example, it makes little sense to set the
44454ba768SRuslan Ermilov.Cm schg
45d93b26d6SMatthew Dillonflags
46c4d9468eSRuslan Ermilov(see
47c4d9468eSRuslan Ermilov.Xr chflags 1 )
48d93b26d6SMatthew Dillonon every system binary because while this may temporarily protect the
4947afd1f8SDaniel Harrisbinaries, it prevents an attacker who has broken in from making an
50d93b26d6SMatthew Dilloneasily detectable change that may result in your security mechanisms not
5147afd1f8SDaniel Harrisdetecting the attacker at all.
52d93b26d6SMatthew Dillon.Pp
53454ba768SRuslan ErmilovSystem security also pertains to dealing with various forms of attacks,
54d93b26d6SMatthew Dillonincluding attacks that attempt to crash or otherwise make a system unusable
55454ba768SRuslan Ermilovbut do not attempt to break root.
56454ba768SRuslan ErmilovSecurity concerns can be split up into
57d93b26d6SMatthew Dillonseveral categories:
58f063d76aSMatthew Dillon.Bl -enum -offset indent
59f063d76aSMatthew Dillon.It
60454ba768SRuslan ErmilovDenial of Service attacks (DoS)
61f063d76aSMatthew Dillon.It
62f063d76aSMatthew DillonUser account compromises
63f063d76aSMatthew Dillon.It
646ac7e896SDavid E. O'BrienRoot compromise through accessible servers
65f063d76aSMatthew Dillon.It
666ac7e896SDavid E. O'BrienRoot compromise via user accounts
67d93b26d6SMatthew Dillon.It
68d93b26d6SMatthew DillonBackdoor creation
69f063d76aSMatthew Dillon.El
70f063d76aSMatthew Dillon.Pp
71f063d76aSMatthew DillonA denial of service attack is an action that deprives the machine of needed
72454ba768SRuslan Ermilovresources.
73454ba768SRuslan ErmilovTypically, DoS attacks are brute-force mechanisms that attempt
74f063d76aSMatthew Dillonto crash or otherwise make a machine unusable by overwhelming its servers or
75454ba768SRuslan Ermilovnetwork stack.
76454ba768SRuslan ErmilovSome DoS attacks try to take advantages of bugs in the
77454ba768SRuslan Ermilovnetworking stack to crash a machine with a single packet.
78454ba768SRuslan ErmilovThe latter can
79454ba768SRuslan Ermilovonly be fixed by applying a bug fix to the kernel.
80454ba768SRuslan ErmilovAttacks on servers can
81d93b26d6SMatthew Dillonoften be fixed by properly specifying options to limit the load the servers
82454ba768SRuslan Ermilovincur on the system under adverse conditions.
83454ba768SRuslan ErmilovBrute-force network attacks are harder to deal with.
84454ba768SRuslan ErmilovA spoofed-packet attack, for example, is
857c86a74bSMike Pritchardnearly impossible to stop short of cutting your system off from the Internet.
867c86a74bSMike PritchardIt may not be able to take your machine down, but it can fill up Internet
87d93b26d6SMatthew Dillonpipe.
88f063d76aSMatthew Dillon.Pp
89454ba768SRuslan ErmilovA user account compromise is even more common than a DoS attack.
90454ba768SRuslan ErmilovMany
91454ba768SRuslan Ermilovsysadmins still run standard
92454ba768SRuslan Ermilov.Xr telnetd 8 ,
93454ba768SRuslan Ermilov.Xr rlogind 8 ,
94454ba768SRuslan Ermilov.Xr rshd 8 ,
95454ba768SRuslan Ermilovand
96454ba768SRuslan Ermilov.Xr ftpd 8
97454ba768SRuslan Ermilovservers on their machines.
98454ba768SRuslan ErmilovThese servers, by default, do not operate over encrypted
99454ba768SRuslan Ermilovconnections.
100454ba768SRuslan ErmilovThe result is that if you have any moderate-sized user base,
101f063d76aSMatthew Dillonone or more of your users logging into your system from a remote location
102c4d9468eSRuslan Ermilov(which is the most common and convenient way to log in to a system)
103454ba768SRuslan Ermilovwill have his or her password sniffed.
104454ba768SRuslan ErmilovThe attentive system administrator will analyze
105d93b26d6SMatthew Dillonhis remote access logs looking for suspicious source addresses
106f063d76aSMatthew Dilloneven for successful logins.
107f063d76aSMatthew Dillon.Pp
108f063d76aSMatthew DillonOne must always assume that once an attacker has access to a user account,
109454ba768SRuslan Ermilovthe attacker can break root.
110454ba768SRuslan ErmilovHowever, the reality is that in a well secured
111f063d76aSMatthew Dillonand maintained system, access to a user account does not necessarily give the
112454ba768SRuslan Ermilovattacker access to root.
113454ba768SRuslan ErmilovThe distinction is important because without access
114f063d76aSMatthew Dillonto root the attacker cannot generally hide his tracks and may, at best, be
115b94231daSDima Dorfmanable to do nothing more than mess with the user's files or crash the machine.
116d93b26d6SMatthew DillonUser account compromises are very common because users tend not to take the
1177c86a74bSMike Pritchardprecautions that sysadmins take.
118f063d76aSMatthew Dillon.Pp
119d93b26d6SMatthew DillonSystem administrators must keep in mind that there are potentially many ways
120454ba768SRuslan Ermilovto break root on a machine.
121454ba768SRuslan ErmilovThe attacker may know the root password,
122d93b26d6SMatthew Dillonthe attacker
123f063d76aSMatthew Dillonmay find a bug in a root-run server and be able to break root over a network
124454ba768SRuslan Ermilovconnection to that server, or the attacker may know of a bug in an SUID-root
125f063d76aSMatthew Dillonprogram that allows the attacker to break root once he has broken into a
126454ba768SRuslan Ermilovuser's account.
127454ba768SRuslan ErmilovIf an attacker has found a way to break root on a machine,
128f167d7fbSSheldon Hearnthe attacker may not have a need to install a backdoor.
129d93b26d6SMatthew DillonMany of the root holes found and closed to date involve a considerable amount
13047afd1f8SDaniel Harrisof work by the attacker to clean up after himself, so most attackers do install
131454ba768SRuslan Ermilovbackdoors.
132454ba768SRuslan ErmilovThis gives you a convenient way to detect the attacker.
133454ba768SRuslan ErmilovMaking
13447afd1f8SDaniel Harrisit impossible for an attacker to install a backdoor may actually be detrimental
1354c0d8029SDaniel Harristo your security because it will not close off the hole the attacker used to
1364c0d8029SDaniel Harrisbreak in in the first place.
137f063d76aSMatthew Dillon.Pp
138d93b26d6SMatthew DillonSecurity remedies should always be implemented with a multi-layered
139454ba768SRuslan Ermilov.Dq onion peel
140f063d76aSMatthew Dillonapproach and can be categorized as follows:
141f063d76aSMatthew Dillon.Bl -enum -offset indent
142f063d76aSMatthew Dillon.It
143f063d76aSMatthew DillonSecuring root and staff accounts
144f063d76aSMatthew Dillon.It
145454ba768SRuslan ErmilovSecuring root \(em root-run servers and SUID/SGID binaries
146f063d76aSMatthew Dillon.It
147f063d76aSMatthew DillonSecuring user accounts
148f063d76aSMatthew Dillon.It
149f063d76aSMatthew DillonSecuring the password file
150f063d76aSMatthew Dillon.It
151f063d76aSMatthew DillonSecuring the kernel core, raw devices, and file systems
152f063d76aSMatthew Dillon.It
153d93b26d6SMatthew DillonQuick detection of inappropriate changes made to the system
154f063d76aSMatthew Dillon.It
155f063d76aSMatthew DillonParanoia
156f063d76aSMatthew Dillon.El
157f063d76aSMatthew Dillon.Sh SECURING THE ROOT ACCOUNT AND SECURING STAFF ACCOUNTS
158454ba768SRuslan ErmilovDo not bother securing staff accounts if you have not secured the root
159454ba768SRuslan Ermilovaccount.
160454ba768SRuslan ErmilovMost systems have a password assigned to the root account.
161454ba768SRuslan ErmilovThe
162568e4cbbSGuy Helmerfirst thing you do is assume that the password is
163454ba768SRuslan Ermilov.Em always
164454ba768SRuslan Ermilovcompromised.
165454ba768SRuslan ErmilovThis does not mean that you should remove the password.
166454ba768SRuslan ErmilovThe
167d93b26d6SMatthew Dillonpassword is almost always necessary for console access to the machine.
168d93b26d6SMatthew DillonWhat it does mean is that you should not make it possible to use the password
169d93b26d6SMatthew Dillonoutside of the console or possibly even with a
170d93b26d6SMatthew Dillon.Xr su 1
171454ba768SRuslan Ermilovutility.
172454ba768SRuslan ErmilovFor example, make sure that your PTYs are specified as being
173454ba768SRuslan Ermilov.Dq Li unsecure
174d93b26d6SMatthew Dillonin the
175454ba768SRuslan Ermilov.Pa /etc/ttys
176d93b26d6SMatthew Dillonfile
177454ba768SRuslan Ermilovso that direct root logins via
178454ba768SRuslan Ermilov.Xr telnet 1
179454ba768SRuslan Ermilovor
180454ba768SRuslan Ermilov.Xr rlogin 1
181454ba768SRuslan Ermilovare disallowed.
182454ba768SRuslan ErmilovIf using
183454ba768SRuslan Ermilovother login services such as
184454ba768SRuslan Ermilov.Xr sshd 8 ,
185454ba768SRuslan Ermilovmake sure that direct root logins are
186454ba768SRuslan Ermilovdisabled there as well.
187454ba768SRuslan ErmilovConsider every access method \(em services such as
188454ba768SRuslan Ermilov.Xr ftp 1
189454ba768SRuslan Ermilovoften fall through the cracks.
190454ba768SRuslan ErmilovDirect root logins should only be allowed
191d93b26d6SMatthew Dillonvia the system console.
192f063d76aSMatthew Dillon.Pp
1937626ae52SMatthew DillonOf course, as a sysadmin you have to be able to get to root, so we open up
194454ba768SRuslan Ermilova few holes.
195454ba768SRuslan ErmilovBut we make sure these holes require additional password
196454ba768SRuslan Ermilovverification to operate.
197454ba768SRuslan ErmilovOne way to make root accessible is to add appropriate
198454ba768SRuslan Ermilovstaff accounts to the
199454ba768SRuslan Ermilov.Dq Li wheel
200454ba768SRuslan Ermilovgroup (in
201c4d9468eSRuslan Ermilov.Pa /etc/group ) .
202454ba768SRuslan ErmilovThe staff members placed in the
203454ba768SRuslan Ermilov.Li wheel
204454ba768SRuslan Ermilovgroup are allowed to
205454ba768SRuslan Ermilov.Xr su 1
206454ba768SRuslan Ermilovto root.
207454ba768SRuslan ErmilovYou should never give staff
208454ba768SRuslan Ermilovmembers native
209454ba768SRuslan Ermilov.Li wheel
210454ba768SRuslan Ermilovaccess by putting them in the
211454ba768SRuslan Ermilov.Li wheel
212454ba768SRuslan Ermilovgroup in their password entry.
213454ba768SRuslan ErmilovStaff accounts should be placed in a
214454ba768SRuslan Ermilov.Dq Li staff
215454ba768SRuslan Ermilovgroup, and then added to the
216454ba768SRuslan Ermilov.Li wheel
217454ba768SRuslan Ermilovgroup via the
218454ba768SRuslan Ermilov.Pa /etc/group
219454ba768SRuslan Ermilovfile.
220454ba768SRuslan ErmilovOnly those staff members who actually need to have root access
221454ba768SRuslan Ermilovshould be placed in the
222454ba768SRuslan Ermilov.Li wheel
223454ba768SRuslan Ermilovgroup.
224454ba768SRuslan ErmilovIt is also possible, when using an
225454ba768SRuslan Ermilovauthentication method such as Kerberos, to use Kerberos's
226454ba768SRuslan Ermilov.Pa .k5login
227d93b26d6SMatthew Dillonfile in the root account to allow a
228d93b26d6SMatthew Dillon.Xr ksu 1
229454ba768SRuslan Ermilovto root without having to place anyone at all in the
230454ba768SRuslan Ermilov.Li wheel
231454ba768SRuslan Ermilovgroup.
232454ba768SRuslan ErmilovThis
233454ba768SRuslan Ermilovmay be the better solution since the
234454ba768SRuslan Ermilov.Li wheel
235454ba768SRuslan Ermilovmechanism still allows an
236d93b26d6SMatthew Dillonintruder to break root if the intruder has gotten hold of your password
237454ba768SRuslan Ermilovfile and can break into a staff account.
238454ba768SRuslan ErmilovWhile having the
239454ba768SRuslan Ermilov.Li wheel
240454ba768SRuslan Ermilovmechanism
241454ba768SRuslan Ermilovis better than having nothing at all, it is not necessarily the safest
242d93b26d6SMatthew Dillonoption.
243f063d76aSMatthew Dillon.Pp
244f063d76aSMatthew DillonAn indirect way to secure the root account is to secure your staff accounts
245f063d76aSMatthew Dillonby using an alternative login access method and *'ing out the crypted password
246454ba768SRuslan Ermilovfor the staff accounts.
247454ba768SRuslan ErmilovThis way an intruder may be able to steal the password
24847afd1f8SDaniel Harrisfile but will not be able to break into any staff accounts or root, even if
24947afd1f8SDaniel Harrisroot has a crypted password associated with it (assuming, of course, that
250454ba768SRuslan Ermilovyou have limited root access to the console).
251454ba768SRuslan ErmilovStaff members
252f063d76aSMatthew Dillonget into their staff accounts through a secure login mechanism such as
253568e4cbbSGuy Helmer.Xr kerberos 1
254568e4cbbSGuy Helmeror
255568e4cbbSGuy Helmer.Xr ssh 1
256568e4cbbSGuy Helmerusing a private/public
257454ba768SRuslan Ermilovkey pair.
258454ba768SRuslan ErmilovWhen you use something like Kerberos you generally must secure
259454ba768SRuslan Ermilovthe machines which run the Kerberos servers and your desktop workstation.
260454ba768SRuslan ErmilovWhen you use a public/private key pair with SSH, you must generally secure
261454ba768SRuslan Ermilovthe machine you are logging in
262454ba768SRuslan Ermilov.Em from
263c4d9468eSRuslan Ermilov(typically your workstation),
264568e4cbbSGuy Helmerbut you can
265f063d76aSMatthew Dillonalso add an additional layer of protection to the key pair by password
266568e4cbbSGuy Helmerprotecting the keypair when you create it with
267568e4cbbSGuy Helmer.Xr ssh-keygen 1 .
268568e4cbbSGuy HelmerBeing able
2696ac7e896SDavid E. O'Briento *-out the passwords for staff accounts also guarantees that staff members
270454ba768SRuslan Ermilovcan only log in through secure access methods that you have set up.
271454ba768SRuslan ErmilovYou can
272f063d76aSMatthew Dillonthus force all staff members to use secure, encrypted connections for
273454ba768SRuslan Ermilovall their sessions which closes an important hole used by many intruders: that
274f063d76aSMatthew Dillonof sniffing the network from an unrelated, less secure machine.
275f063d76aSMatthew Dillon.Pp
276f063d76aSMatthew DillonThe more indirect security mechanisms also assume that you are logging in
277454ba768SRuslan Ermilovfrom a more restrictive server to a less restrictive server.
278454ba768SRuslan ErmilovFor example,
279454ba768SRuslan Ermilovif your main box is running all sorts of servers, your workstation should not
280454ba768SRuslan Ermilovbe running any.
281454ba768SRuslan ErmilovIn order for your workstation to be reasonably secure
282f063d76aSMatthew Dillonyou should run as few servers as possible, up to and including no servers
283f063d76aSMatthew Dillonat all, and you should run a password-protected screen blanker.
284f063d76aSMatthew DillonOf course, given physical access to
285454ba768SRuslan Ermilova workstation, an attacker can break any sort of security you put on it.
286f063d76aSMatthew DillonThis is definitely a problem that you should consider but you should also
2876ac7e896SDavid E. O'Brienconsider the fact that the vast majority of break-ins occur remotely, over
2887626ae52SMatthew Dillona network, from people who do not have physical access to your workstation or
289f063d76aSMatthew Dillonservers.
290f063d76aSMatthew Dillon.Pp
291454ba768SRuslan ErmilovUsing something like Kerberos also gives you the ability to disable or
292f063d76aSMatthew Dillonchange the password for a staff account in one place and have it immediately
293454ba768SRuslan Ermilovaffect all the machines the staff member may have an account on.
294454ba768SRuslan ErmilovIf a staff
295f063d76aSMatthew Dillonmember's account gets compromised, the ability to instantly change his
296454ba768SRuslan Ermilovpassword on all machines should not be underrated.
297454ba768SRuslan ErmilovWith discrete passwords, changing a password on N machines can be a mess.
298454ba768SRuslan ErmilovYou can also impose
299454ba768SRuslan Ermilovre-passwording restrictions with Kerberos: not only can a Kerberos ticket
300454ba768SRuslan Ermilovbe made to timeout after a while, but the Kerberos system can require that
301568e4cbbSGuy Helmerthe user choose a new password after a certain period of time
302c4d9468eSRuslan Ermilov(say, once a month).
30347afd1f8SDaniel Harris.Sh SECURING ROOT \(em ROOT-RUN SERVERS AND SUID/SGID BINARIES
304454ba768SRuslan ErmilovThe prudent sysadmin only runs the servers he needs to, no more, no less.
305454ba768SRuslan ErmilovBe aware that third party servers are often the most bug-prone.
306454ba768SRuslan ErmilovFor example,
307454ba768SRuslan Ermilovrunning an old version of
308454ba768SRuslan Ermilov.Xr imapd 8
309454ba768SRuslan Ermilovor
310454ba768SRuslan Ermilov.Xr popper 8
311454ba768SRuslan Ermilovis like giving a universal root
312454ba768SRuslan Ermilovticket out to the entire world.
313454ba768SRuslan ErmilovNever run a server that you have not checked
314454ba768SRuslan Ermilovout carefully.
315454ba768SRuslan ErmilovMany servers do not need to be run as root.
316454ba768SRuslan ErmilovFor example,
317454ba768SRuslan Ermilovthe
318454ba768SRuslan Ermilov.Xr talkd 8 ,
319454ba768SRuslan Ermilov.Xr comsat 8 ,
320454ba768SRuslan Ermilovand
321454ba768SRuslan Ermilov.Xr fingerd 8
322454ba768SRuslan Ermilovdaemons can be run in special user
323454ba768SRuslan Ermilov.Dq sandboxes .
324454ba768SRuslan ErmilovA sandbox is not perfect unless you go to a large amount of trouble, but the
325454ba768SRuslan Ermilovonion approach to security still stands: if someone is able to break in
326f063d76aSMatthew Dillonthrough a server running in a sandbox, they still have to break out of the
327454ba768SRuslan Ermilovsandbox.
328454ba768SRuslan ErmilovThe more layers the attacker must break through, the lower the
329454ba768SRuslan Ermilovlikelihood of his success.
330454ba768SRuslan ErmilovRoot holes have historically been found in
331f063d76aSMatthew Dillonvirtually every server ever run as root, including basic system servers.
332454ba768SRuslan ErmilovIf you are running a machine through which people only log in via
333454ba768SRuslan Ermilov.Xr sshd 8
334454ba768SRuslan Ermilovand never log in via
335454ba768SRuslan Ermilov.Xr telnetd 8 ,
336454ba768SRuslan Ermilov.Xr rshd 8 ,
337454ba768SRuslan Ermilovor
338454ba768SRuslan Ermilov.Xr rlogind 8 ,
339454ba768SRuslan Ermilovthen turn off those services!
340f063d76aSMatthew Dillon.Pp
341f6f8f44dSAlexey Zelkin.Fx
342454ba768SRuslan Ermilovnow defaults to running
343454ba768SRuslan Ermilov.Xr talkd 8 ,
344454ba768SRuslan Ermilov.Xr comsat 8 ,
345454ba768SRuslan Ermilovand
346454ba768SRuslan Ermilov.Xr fingerd 8
347454ba768SRuslan Ermilovin a sandbox.
348f063d76aSMatthew DillonAnother program which may be a candidate for running in a sandbox is
349568e4cbbSGuy Helmer.Xr named 8 .
350454ba768SRuslan ErmilovThe default
351454ba768SRuslan Ermilov.Pa rc.conf
352454ba768SRuslan Ermilovincludes the arguments necessary to run
353454ba768SRuslan Ermilov.Xr named 8
354454ba768SRuslan Ermilovin a sandbox in a commented-out form.
355454ba768SRuslan ErmilovDepending on whether you
356f063d76aSMatthew Dillonare installing a new system or upgrading an existing system, the special
357454ba768SRuslan Ermilovuser accounts used by these sandboxes may not be installed.
358454ba768SRuslan ErmilovThe prudent
3597626ae52SMatthew Dillonsysadmin would research and implement sandboxes for servers whenever possible.
360f063d76aSMatthew Dillon.Pp
361f063d76aSMatthew DillonThere are a number of other servers that typically do not run in sandboxes:
362454ba768SRuslan Ermilov.Xr sendmail 8 ,
363454ba768SRuslan Ermilov.Xr popper 8 ,
364454ba768SRuslan Ermilov.Xr imapd 8 ,
365454ba768SRuslan Ermilov.Xr ftpd 8 ,
366454ba768SRuslan Ermilovand others.
367454ba768SRuslan ErmilovThere are alternatives to
368f063d76aSMatthew Dillonsome of these, but installing them may require more work then you are willing
369568e4cbbSGuy Helmerto put
370c4d9468eSRuslan Ermilov(the convenience factor strikes again).
371568e4cbbSGuy HelmerYou may have to run these
3726ac7e896SDavid E. O'Brienservers as root and rely on other mechanisms to detect break-ins that might
373f063d76aSMatthew Dillonoccur through them.
374f063d76aSMatthew Dillon.Pp
375454ba768SRuslan ErmilovThe other big potential root hole in a system are the SUID-root and SGID
376454ba768SRuslan Ermilovbinaries installed on the system.
377454ba768SRuslan ErmilovMost of these binaries, such as
378454ba768SRuslan Ermilov.Xr rlogin 1 ,
379568e4cbbSGuy Helmerreside in
380454ba768SRuslan Ermilov.Pa /bin , /sbin , /usr/bin ,
381568e4cbbSGuy Helmeror
382568e4cbbSGuy Helmer.Pa /usr/sbin .
383568e4cbbSGuy HelmerWhile nothing is 100% safe,
384454ba768SRuslan Ermilovthe system-default SUID and SGID binaries can be considered reasonably safe.
385454ba768SRuslan ErmilovStill, root holes are occasionally found in these binaries.
386454ba768SRuslan ErmilovA root hole
387454ba768SRuslan Ermilovwas found in Xlib in 1998 that made
388454ba768SRuslan Ermilov.Xr xterm 1
389454ba768SRuslan Ermilov(which is typically SUID)
390568e4cbbSGuy Helmervulnerable.
391454ba768SRuslan ErmilovIt is better to be safe than sorry and the prudent sysadmin will restrict SUID
392f063d76aSMatthew Dillonbinaries that only staff should run to a special group that only staff can
393568e4cbbSGuy Helmeraccess, and get rid of
394454ba768SRuslan Ermilov.Pq Dq Li "chmod 000"
395454ba768SRuslan Ermilovany SUID binaries that nobody uses.
396454ba768SRuslan ErmilovA server with no display generally does not need an
397454ba768SRuslan Ermilov.Xr xterm 1
398454ba768SRuslan Ermilovbinary.
399454ba768SRuslan ErmilovSGID binaries can be almost as dangerous.
400454ba768SRuslan ErmilovIf an intruder can break an SGID-kmem binary the
401568e4cbbSGuy Helmerintruder might be able to read
402568e4cbbSGuy Helmer.Pa /dev/kmem
403568e4cbbSGuy Helmerand thus read the crypted password
404454ba768SRuslan Ermilovfile, potentially compromising any passworded account.
405454ba768SRuslan ErmilovAlternatively an
406454ba768SRuslan Ermilovintruder who breaks group
407454ba768SRuslan Ermilov.Dq Li kmem
408454ba768SRuslan Ermilovcan monitor keystrokes sent through PTYs,
409454ba768SRuslan Ermilovincluding PTYs used by users who log in through secure methods.
410454ba768SRuslan ErmilovAn intruder
411454ba768SRuslan Ermilovthat breaks the
412454ba768SRuslan Ermilov.Dq Li tty
413454ba768SRuslan Ermilovgroup can write to almost any user's TTY.
414454ba768SRuslan ErmilovIf a user
415d93b26d6SMatthew Dillonis running a terminal
416d93b26d6SMatthew Dillonprogram or emulator with a keyboard-simulation feature, the intruder can
417d93b26d6SMatthew Dillonpotentially
418f063d76aSMatthew Dillongenerate a data stream that causes the user's terminal to echo a command, which
419f063d76aSMatthew Dillonis then run as that user.
420f063d76aSMatthew Dillon.Sh SECURING USER ACCOUNTS
421454ba768SRuslan ErmilovUser accounts are usually the most difficult to secure.
422454ba768SRuslan ErmilovWhile you can impose
423454ba768SRuslan Ermilovdraconian access restrictions on your staff and *-out their passwords, you
424454ba768SRuslan Ermilovmay not be able to do so with any general user accounts you might have.
425454ba768SRuslan ErmilovIf
426f063d76aSMatthew Dillonyou do have sufficient control then you may win out and be able to secure the
427454ba768SRuslan Ermilovuser accounts properly.
428454ba768SRuslan ErmilovIf not, you simply have to be more vigilant in your
429454ba768SRuslan Ermilovmonitoring of those accounts.
430454ba768SRuslan ErmilovUse of SSH and Kerberos for user accounts is
431d93b26d6SMatthew Dillonmore problematic due to the extra administration and technical support
432d93b26d6SMatthew Dillonrequired, but still a very good solution compared to a crypted password
433d93b26d6SMatthew Dillonfile.
434f063d76aSMatthew Dillon.Sh SECURING THE PASSWORD FILE
435f063d76aSMatthew DillonThe only sure fire way is to *-out as many passwords as you can and
436454ba768SRuslan Ermilovuse SSH or Kerberos for access to those accounts.
437454ba768SRuslan ErmilovEven though the
438568e4cbbSGuy Helmercrypted password file
439568e4cbbSGuy Helmer.Pq Pa /etc/spwd.db
440568e4cbbSGuy Helmercan only be read by root, it may
441568e4cbbSGuy Helmerbe possible for an intruder to obtain read access to that file even if the
442f063d76aSMatthew Dillonattacker cannot obtain root-write access.
443f063d76aSMatthew Dillon.Pp
444f063d76aSMatthew DillonYour security scripts should always check for and report changes to
445568e4cbbSGuy Helmerthe password file
446c4d9468eSRuslan Ermilov(see
447454ba768SRuslan Ermilov.Sx CHECKING FILE INTEGRITY
448c4d9468eSRuslan Ermilovbelow).
449f063d76aSMatthew Dillon.Sh SECURING THE KERNEL CORE, RAW DEVICES, AND FILE SYSTEMS
450f063d76aSMatthew DillonIf an attacker breaks root he can do just about anything, but there
451454ba768SRuslan Ermilovare certain conveniences.
452454ba768SRuslan ErmilovFor example, most modern kernels have a packet sniffing device driver built in.
453454ba768SRuslan ErmilovUnder
454f6f8f44dSAlexey Zelkin.Fx
455568e4cbbSGuy Helmerit is called
456568e4cbbSGuy Helmerthe
457454ba768SRuslan Ermilov.Xr bpf 4
458454ba768SRuslan Ermilovdevice.
459454ba768SRuslan ErmilovAn intruder will commonly attempt to run a packet sniffer
460454ba768SRuslan Ermilovon a compromised machine.
461454ba768SRuslan ErmilovYou do not need to give the intruder the
462454ba768SRuslan Ermilovcapability and most systems should not have the
463454ba768SRuslan Ermilov.Xr bpf 4
464454ba768SRuslan Ermilovdevice compiled in.
465f063d76aSMatthew Dillon.Pp
466454ba768SRuslan ErmilovBut even if you turn off the
467454ba768SRuslan Ermilov.Xr bpf 4
468454ba768SRuslan Ermilovdevice, you still have
469568e4cbbSGuy Helmer.Pa /dev/mem
470568e4cbbSGuy Helmerand
471568e4cbbSGuy Helmer.Pa /dev/kmem
472454ba768SRuslan Ermilovto worry about.
473454ba768SRuslan ErmilovFor that matter,
474d93b26d6SMatthew Dillonthe intruder can still write to raw disk devices.
475d93b26d6SMatthew DillonAlso, there is another kernel feature called the module loader,
476568e4cbbSGuy Helmer.Xr kldload 8 .
477568e4cbbSGuy HelmerAn enterprising intruder can use a KLD module to install
478454ba768SRuslan Ermilovhis own
479454ba768SRuslan Ermilov.Xr bpf 4
480454ba768SRuslan Ermilovdevice or other sniffing device on a running kernel.
481568e4cbbSGuy HelmerTo avoid these problems you have to run
482454ba768SRuslan Ermilovthe kernel at a higher secure level, at least securelevel 1.
483454ba768SRuslan ErmilovThe securelevel can be set with a
484454ba768SRuslan Ermilov.Xr sysctl 8
485454ba768SRuslan Ermilovon the
486454ba768SRuslan Ermilov.Va kern.securelevel
487454ba768SRuslan Ermilovvariable.
488454ba768SRuslan ErmilovOnce you have
489f063d76aSMatthew Dillonset the securelevel to 1, write access to raw devices will be denied and
490454ba768SRuslan Ermilovspecial
491454ba768SRuslan Ermilov.Xr chflags 1
492454ba768SRuslan Ermilovflags, such as
493454ba768SRuslan Ermilov.Cm schg ,
494454ba768SRuslan Ermilovwill be enforced.
495454ba768SRuslan ErmilovYou must also ensure
496568e4cbbSGuy Helmerthat the
497454ba768SRuslan Ermilov.Cm schg
498568e4cbbSGuy Helmerflag is set on critical startup binaries, directories, and
49947afd1f8SDaniel Harrisscript files \(em everything that gets run up to the point where the securelevel
500454ba768SRuslan Ermilovis set.
501454ba768SRuslan ErmilovThis might be overdoing it, and upgrading the system is much more
502454ba768SRuslan Ermilovdifficult when you operate at a higher secure level.
503454ba768SRuslan ErmilovYou may compromise and
504454ba768SRuslan Ermilovrun the system at a higher secure level but not set the
505454ba768SRuslan Ermilov.Cm schg
506454ba768SRuslan Ermilovflag for every
507454ba768SRuslan Ermilovsystem file and directory under the sun.
508454ba768SRuslan ErmilovAnother possibility is to simply
509454ba768SRuslan Ermilovmount
510454ba768SRuslan Ermilov.Pa /
511454ba768SRuslan Ermilovand
512454ba768SRuslan Ermilov.Pa /usr
513454ba768SRuslan Ermilovread-only.
514454ba768SRuslan ErmilovIt should be noted that being too draconian in
515d93b26d6SMatthew Dillonwhat you attempt to protect may prevent the all-important detection of an
516d93b26d6SMatthew Dillonintrusion.
517f063d76aSMatthew Dillon.Sh CHECKING FILE INTEGRITY: BINARIES, CONFIG FILES, ETC
518f063d76aSMatthew DillonWhen it comes right down to it, you can only protect your core system
519f063d76aSMatthew Dillonconfiguration and control files so much before the convenience factor
520454ba768SRuslan Ermilovrears its ugly head.
521454ba768SRuslan ErmilovFor example, using
522454ba768SRuslan Ermilov.Xr chflags 1
523454ba768SRuslan Ermilovto set the
524454ba768SRuslan Ermilov.Cm schg
525454ba768SRuslan Ermilovbit on most of the files in
526454ba768SRuslan Ermilov.Pa /
527454ba768SRuslan Ermilovand
528454ba768SRuslan Ermilov.Pa /usr
529454ba768SRuslan Ermilovis probably counterproductive because
530454ba768SRuslan Ermilovwhile it may protect the files, it also closes a detection window.
531454ba768SRuslan ErmilovThe
53247afd1f8SDaniel Harrislast layer of your security onion is perhaps the most important \(em detection.
533d93b26d6SMatthew DillonThe rest of your security is pretty much useless (or, worse, presents you with
534454ba768SRuslan Ermilova false sense of safety) if you cannot detect potential incursions.
535454ba768SRuslan ErmilovHalf
536074ad115SRuslan Ermilovthe job of the onion is to slow down the attacker rather than stop him
5374c0d8029SDaniel Harrisin order to give the detection layer a chance to catch him in
538d93b26d6SMatthew Dillonthe act.
539f063d76aSMatthew Dillon.Pp
540d93b26d6SMatthew DillonThe best way to detect an incursion is to look for modified, missing, or
541454ba768SRuslan Ermilovunexpected files.
542454ba768SRuslan ErmilovThe best
543d93b26d6SMatthew Dillonway to look for modified files is from another (often centralized)
544d93b26d6SMatthew Dillonlimited-access system.
545d93b26d6SMatthew DillonWriting your security scripts on the extra-secure limited-access system
54647afd1f8SDaniel Harrismakes them mostly invisible to potential attackers, and this is important.
547d93b26d6SMatthew DillonIn order to take maximum advantage you generally have to give the
548d93b26d6SMatthew Dillonlimited-access box significant access to the other machines in the business,
549d93b26d6SMatthew Dillonusually either by doing a read-only NFS export of the other machines to the
550454ba768SRuslan Ermilovlimited-access box, or by setting up SSH keypairs to allow the limit-access
551454ba768SRuslan Ermilovbox to SSH to the other machines.
552454ba768SRuslan ErmilovExcept for its network traffic, NFS is
55347afd1f8SDaniel Harristhe least visible method \(em allowing you to monitor the file systems on each
554454ba768SRuslan Ermilovclient box virtually undetected.
555454ba768SRuslan ErmilovIf your
556d93b26d6SMatthew Dillonlimited-access server is connected to the client boxes through a switch,
557454ba768SRuslan Ermilovthe NFS method is often the better choice.
558454ba768SRuslan ErmilovIf your limited-access server
559d93b26d6SMatthew Dillonis connected to the client boxes through a hub or through several layers
560454ba768SRuslan Ermilovof routing, the NFS method may be too insecure (network-wise) and using SSH
561454ba768SRuslan Ermilovmay be the better choice even with the audit-trail tracks that SSH lays.
562d93b26d6SMatthew Dillon.Pp
563d93b26d6SMatthew DillonOnce you give a limit-access box at least read access to the client systems
564d93b26d6SMatthew Dillonit is supposed to monitor, you must write scripts to do the actual
565454ba768SRuslan Ermilovmonitoring.
566454ba768SRuslan ErmilovGiven an NFS mount, you can write scripts out of simple system
567d93b26d6SMatthew Dillonutilities such as
568d93b26d6SMatthew Dillon.Xr find 1
569d93b26d6SMatthew Dillonand
570454ba768SRuslan Ermilov.Xr md5 1 .
571454ba768SRuslan ErmilovIt is best to physically
572d93b26d6SMatthew Dillon.Xr md5 1
573454ba768SRuslan Ermilovthe client-box files boxes at least once a
574ad27d066SMatthew Dillonday, and to test control files such as those found in
575ad27d066SMatthew Dillon.Pa /etc
576ad27d066SMatthew Dillonand
577ad27d066SMatthew Dillon.Pa /usr/local/etc
578454ba768SRuslan Ermiloveven more often.
579454ba768SRuslan ErmilovWhen mismatches are found relative to the base MD5
580d93b26d6SMatthew Dilloninformation the limited-access machine knows is valid, it should scream at
581454ba768SRuslan Ermilova sysadmin to go check it out.
582454ba768SRuslan ErmilovA good security script will also check for
583454ba768SRuslan Ermilovinappropriate SUID binaries and for new or deleted files on system partitions
584d93b26d6SMatthew Dillonsuch as
585d93b26d6SMatthew Dillon.Pa /
586568e4cbbSGuy Helmerand
587454ba768SRuslan Ermilov.Pa /usr .
588f063d76aSMatthew Dillon.Pp
589454ba768SRuslan ErmilovWhen using SSH rather than NFS, writing the security script is much more
590454ba768SRuslan Ermilovdifficult.
591454ba768SRuslan ErmilovYou essentially have to
592454ba768SRuslan Ermilov.Xr scp 1
593d93b26d6SMatthew Dillonthe scripts to the client box in order to run them, making them visible, and
594454ba768SRuslan Ermilovfor safety you also need to
595454ba768SRuslan Ermilov.Xr scp 1
596454ba768SRuslan Ermilovthe binaries (such as
597454ba768SRuslan Ermilov.Xr find 1 )
598454ba768SRuslan Ermilovthat those scripts use.
599454ba768SRuslan ErmilovThe
600454ba768SRuslan Ermilov.Xr sshd 8
601454ba768SRuslan Ermilovdaemon on the client box may already be compromised.
602454ba768SRuslan ErmilovAll in all,
603454ba768SRuslan Ermilovusing SSH may be necessary when running over unsecure links, but it is also a
604d93b26d6SMatthew Dillonlot harder to deal with.
605f063d76aSMatthew Dillon.Pp
606f063d76aSMatthew DillonA good security script will also check for changes to user and staff members
607ad27d066SMatthew Dillonaccess configuration files:
608454ba768SRuslan Ermilov.Pa .rhosts , .shosts , .ssh/authorized_keys
609ad27d066SMatthew Dillonand so forth... files that might fall outside the purview of the MD5 check.
610f063d76aSMatthew Dillon.Pp
611d93b26d6SMatthew DillonIf you have a huge amount of user disk space it may take too long to run
612454ba768SRuslan Ermilovthrough every file on those partitions.
613454ba768SRuslan ErmilovIn this case, setting mount
614454ba768SRuslan Ermilovflags to disallow SUID binaries and devices on those partitions is a good
615454ba768SRuslan Ermilovidea.
616454ba768SRuslan ErmilovThe
617454ba768SRuslan Ermilov.Cm nodev
618d93b26d6SMatthew Dillonand
619454ba768SRuslan Ermilov.Cm nosuid
620d93b26d6SMatthew Dillonoptions
621c4d9468eSRuslan Ermilov(see
622c4d9468eSRuslan Ermilov.Xr mount 8 )
623454ba768SRuslan Ermilovare what you want to look into.
624454ba768SRuslan ErmilovI would scan them anyway at least once a
625d93b26d6SMatthew Dillonweek, since the object of this layer is to detect a break-in whether or
626a30de06bSCeri Daviesnot the break-in is effective.
627f063d76aSMatthew Dillon.Pp
628568e4cbbSGuy HelmerProcess accounting
629c4d9468eSRuslan Ermilov(see
630c4d9468eSRuslan Ermilov.Xr accton 8 )
631568e4cbbSGuy Helmeris a relatively low-overhead feature of
6326ac7e896SDavid E. O'Brienthe operating system which I recommend using as a post-break-in evaluation
633454ba768SRuslan Ermilovmechanism.
634454ba768SRuslan ErmilovIt is especially useful in tracking down how an intruder has
635d93b26d6SMatthew Dillonactually broken into a system, assuming the file is still intact after
6366ac7e896SDavid E. O'Brienthe break-in occurs.
637f063d76aSMatthew Dillon.Pp
638f063d76aSMatthew DillonFinally, security scripts should process the log files and the logs themselves
63947afd1f8SDaniel Harrisshould be generated in as secure a manner as possible \(em remote syslog can be
640454ba768SRuslan Ermilovvery useful.
641454ba768SRuslan ErmilovAn intruder tries to cover his tracks, and log files are critical
642d93b26d6SMatthew Dillonto the sysadmin trying to track down the time and method of the initial
643454ba768SRuslan Ermilovbreak-in.
644454ba768SRuslan ErmilovOne way to keep a permanent record of the log files is to run
645d93b26d6SMatthew Dillonthe system console to a serial port and collect the information on a
646d93b26d6SMatthew Dilloncontinuing basis through a secure machine monitoring the consoles.
647f063d76aSMatthew Dillon.Sh PARANOIA
648454ba768SRuslan ErmilovA little paranoia never hurts.
649454ba768SRuslan ErmilovAs a rule, a sysadmin can add any number
65047afd1f8SDaniel Harrisof security features as long as they do not affect convenience, and
65147afd1f8SDaniel Harriscan add security features that do affect convenience with some added
652454ba768SRuslan Ermilovthought.
653454ba768SRuslan ErmilovEven more importantly, a security administrator should mix it up
65447afd1f8SDaniel Harrisa bit \(em if you use recommendations such as those given by this manual
655d93b26d6SMatthew Dillonpage verbatim, you give away your methodologies to the prospective
65647afd1f8SDaniel Harrisattacker who also has access to this manual page.
657454ba768SRuslan Ermilov.Sh SPECIAL SECTION ON DoS ATTACKS
658454ba768SRuslan ErmilovThis section covers Denial of Service attacks.
659454ba768SRuslan ErmilovA DoS attack is typically a packet attack.
660454ba768SRuslan ErmilovWhile there is not much you can do about modern spoofed
661f063d76aSMatthew Dillonpacket attacks that saturate your network, you can generally limit the damage
662f063d76aSMatthew Dillonby ensuring that the attacks cannot take down your servers.
663f063d76aSMatthew Dillon.Bl -enum -offset indent
664f063d76aSMatthew Dillon.It
665f063d76aSMatthew DillonLimiting server forks
666f063d76aSMatthew Dillon.It
667454ba768SRuslan ErmilovLimiting springboard attacks (ICMP response attacks, ping broadcast, etc.)
668f063d76aSMatthew Dillon.It
669f063d76aSMatthew DillonKernel Route Cache
670f063d76aSMatthew Dillon.El
671f063d76aSMatthew Dillon.Pp
672454ba768SRuslan ErmilovA common DoS attack is against a forking server that attempts to cause the
6736ac7e896SDavid E. O'Brienserver to eat processes, file descriptors, and memory until the machine
674454ba768SRuslan Ermilovdies.
675454ba768SRuslan ErmilovThe
676454ba768SRuslan Ermilov.Xr inetd 8
677454ba768SRuslan Ermilovserver
678568e4cbbSGuy Helmerhas several options to limit this sort of attack.
679f063d76aSMatthew DillonIt should be noted that while it is possible to prevent a machine from going
680f063d76aSMatthew Dillondown it is not generally possible to prevent a service from being disrupted
681454ba768SRuslan Ermilovby the attack.
682454ba768SRuslan ErmilovRead the
683454ba768SRuslan Ermilov.Xr inetd 8
684454ba768SRuslan Ermilovmanual page carefully and pay specific attention
685568e4cbbSGuy Helmerto the
686454ba768SRuslan Ermilov.Fl c , C ,
687568e4cbbSGuy Helmerand
688568e4cbbSGuy Helmer.Fl R
689454ba768SRuslan Ermilovoptions.
690454ba768SRuslan ErmilovNote that spoofed-IP attacks will circumvent
691568e4cbbSGuy Helmerthe
692568e4cbbSGuy Helmer.Fl C
693454ba768SRuslan Ermilovoption to
694454ba768SRuslan Ermilov.Xr inetd 8 ,
695454ba768SRuslan Ermilovso typically a combination of options must be used.
696f063d76aSMatthew DillonSome standalone servers have self-fork-limitation parameters.
697f063d76aSMatthew Dillon.Pp
698454ba768SRuslan ErmilovThe
699454ba768SRuslan Ermilov.Xr sendmail 8
700454ba768SRuslan Ermilovdaemon has its
701568e4cbbSGuy Helmer.Fl OMaxDaemonChildren
702568e4cbbSGuy Helmeroption which tends to work much
703454ba768SRuslan Ermilovbetter than trying to use
704454ba768SRuslan Ermilov.Xr sendmail 8 Ns 's
705454ba768SRuslan Ermilovload limiting options due to the
706454ba768SRuslan Ermilovload lag.
707454ba768SRuslan ErmilovYou should specify a
708454ba768SRuslan Ermilov.Va MaxDaemonChildren
709568e4cbbSGuy Helmerparameter when you start
710454ba768SRuslan Ermilov.Xr sendmail 8
711454ba768SRuslan Ermilovhigh enough to handle your expected load but not so high that the
712454ba768SRuslan Ermilovcomputer cannot handle that number of
713454ba768SRuslan Ermilov.Nm sendmail Ns 's
714454ba768SRuslan Ermilovwithout falling on its face.
715454ba768SRuslan ErmilovIt is also prudent to run
716454ba768SRuslan Ermilov.Xr sendmail 8
717454ba768SRuslan Ermilovin
718454ba768SRuslan Ermilov.Dq queued
719454ba768SRuslan Ermilovmode
720568e4cbbSGuy Helmer.Pq Fl ODeliveryMode=queued
721568e4cbbSGuy Helmerand to run the daemon
722454ba768SRuslan Ermilov.Pq Dq Nm sendmail Fl bd
723568e4cbbSGuy Helmerseparate from the queue-runs
724454ba768SRuslan Ermilov.Pq Dq Nm sendmail Fl q15m .
725454ba768SRuslan ErmilovIf you still want real-time delivery you can run the queue
726568e4cbbSGuy Helmerat a much lower interval, such as
727568e4cbbSGuy Helmer.Fl q1m ,
728568e4cbbSGuy Helmerbut be sure to specify a reasonable
729454ba768SRuslan Ermilov.Va MaxDaemonChildren
730454ba768SRuslan Ermilovoption for that
731454ba768SRuslan Ermilov.Xr sendmail 8
732454ba768SRuslan Ermilovto prevent cascade failures.
733f063d76aSMatthew Dillon.Pp
734454ba768SRuslan ErmilovThe
735454ba768SRuslan Ermilov.Xr syslogd 8
736454ba768SRuslan Ermilovdaemon can be attacked directly and it is strongly recommended that you use
737568e4cbbSGuy Helmerthe
738568e4cbbSGuy Helmer.Fl s
739568e4cbbSGuy Helmeroption whenever possible, and the
740568e4cbbSGuy Helmer.Fl a
741568e4cbbSGuy Helmeroption otherwise.
742f063d76aSMatthew Dillon.Pp
743f063d76aSMatthew DillonYou should also be fairly careful
744f063d76aSMatthew Dillonwith connect-back services such as tcpwrapper's reverse-identd, which can
745454ba768SRuslan Ermilovbe attacked directly.
746454ba768SRuslan ErmilovYou generally do not want to use the reverse-ident
747f063d76aSMatthew Dillonfeature of tcpwrappers for this reason.
748f063d76aSMatthew Dillon.Pp
749f063d76aSMatthew DillonIt is a very good idea to protect internal services from external access
750454ba768SRuslan Ermilovby firewalling them off at your border routers.
751454ba768SRuslan ErmilovThe idea here is to prevent
752f063d76aSMatthew Dillonsaturation attacks from outside your LAN, not so much to protect internal
753454ba768SRuslan Ermilovservices from network-based root compromise.
754454ba768SRuslan ErmilovAlways configure an exclusive
755454ba768SRuslan Ermilovfirewall, i.e.,
756568e4cbbSGuy Helmer.So
75747afd1f8SDaniel Harrisfirewall everything
75847afd1f8SDaniel Harris.Em except
75947afd1f8SDaniel Harrisports A, B, C, D, and M-Z
760568e4cbbSGuy Helmer.Sc .
761568e4cbbSGuy HelmerThis
762f063d76aSMatthew Dillonway you can firewall off all of your low ports except for certain specific
763454ba768SRuslan Ermilovservices such as
764454ba768SRuslan Ermilov.Xr named 8
765c4d9468eSRuslan Ermilov(if you are primary for a zone),
766454ba768SRuslan Ermilov.Xr talkd 8 ,
767454ba768SRuslan Ermilov.Xr sendmail 8 ,
768f063d76aSMatthew Dillonand other internet-accessible services.
769f063d76aSMatthew DillonIf you try to configure the firewall the other
77047afd1f8SDaniel Harrisway \(em as an inclusive or permissive firewall, there is a good chance that you
771568e4cbbSGuy Helmerwill forget to
772454ba768SRuslan Ermilov.Dq close
773568e4cbbSGuy Helmera couple of services or that you will add a new internal
774454ba768SRuslan Ermilovservice and forget to update the firewall.
775454ba768SRuslan ErmilovYou can still open up the
776f063d76aSMatthew Dillonhigh-numbered port range on the firewall to allow permissive-like operation
777454ba768SRuslan Ermilovwithout compromising your low ports.
778454ba768SRuslan ErmilovAlso take note that
779f6f8f44dSAlexey Zelkin.Fx
780568e4cbbSGuy Helmerallows you to
781f063d76aSMatthew Dilloncontrol the range of port numbers used for dynamic binding via the various
782454ba768SRuslan Ermilov.Va net.inet.ip.portrange
783454ba768SRuslan Ermilovsysctl's
784454ba768SRuslan Ermilov.Pq Dq Li "sysctl net.inet.ip.portrange" ,
785568e4cbbSGuy Helmerwhich can also
786454ba768SRuslan Ermilovease the complexity of your firewall's configuration.
787454ba768SRuslan ErmilovI usually use a normal
788f063d76aSMatthew Dillonfirst/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then
789568e4cbbSGuy Helmerblock everything under 4000 off in my firewall
790c4d9468eSRuslan Ermilov(except for certain specific
791c4d9468eSRuslan Ermilovinternet-accessible ports, of course).
792f063d76aSMatthew Dillon.Pp
793454ba768SRuslan ErmilovAnother common DoS attack is called a springboard attack \(em to attack a server
794f063d76aSMatthew Dillonin a manner that causes the server to generate responses which then overload
795454ba768SRuslan Ermilovthe server, the local network, or some other machine.
796454ba768SRuslan ErmilovThe most common attack
797454ba768SRuslan Ermilovof this nature is the ICMP PING BROADCAST attack.
798454ba768SRuslan ErmilovThe attacker spoofs ping
799f063d76aSMatthew Dillonpackets sent to your LAN's broadcast address with the source IP address set
800454ba768SRuslan Ermilovto the actual machine they wish to attack.
801454ba768SRuslan ErmilovIf your border routers are not
802f063d76aSMatthew Dillonconfigured to stomp on ping's to broadcast addresses, your LAN winds up
803f063d76aSMatthew Dillongenerating sufficient responses to the spoofed source address to saturate the
804f063d76aSMatthew Dillonvictim, especially when the attacker uses the same trick on several dozen
805454ba768SRuslan Ermilovbroadcast addresses over several dozen different networks at once.
806454ba768SRuslan ErmilovBroadcast attacks of over a hundred and twenty megabits have been measured.
807454ba768SRuslan ErmilovA second common springboard attack is against the ICMP error reporting system.
808454ba768SRuslan ErmilovBy
809f063d76aSMatthew Dillonconstructing packets that generate ICMP error responses, an attacker can
810f063d76aSMatthew Dillonsaturate a server's incoming network and cause the server to saturate its
811454ba768SRuslan Ermilovoutgoing network with ICMP responses.
812454ba768SRuslan ErmilovThis type of attack can also crash the
813454ba768SRuslan Ermilovserver by running it out of
814454ba768SRuslan Ermilov.Vt mbuf Ns 's ,
815454ba768SRuslan Ermilovespecially if the server cannot drain the
816454ba768SRuslan ErmilovICMP responses it generates fast enough.
817454ba768SRuslan ErmilovThe
818f6f8f44dSAlexey Zelkin.Fx
819568e4cbbSGuy Helmerkernel has a new kernel
820454ba768SRuslan Ermilovcompile option called
821454ba768SRuslan Ermilov.Dv ICMP_BANDLIM
822454ba768SRuslan Ermilovwhich limits the effectiveness of these
823454ba768SRuslan Ermilovsorts of attacks.
824454ba768SRuslan ErmilovThe last major class of springboard attacks is related to
825454ba768SRuslan Ermilovcertain internal
826454ba768SRuslan Ermilov.Xr inetd 8
827454ba768SRuslan Ermilovservices such as the UDP echo service.
828454ba768SRuslan ErmilovAn attacker
829f063d76aSMatthew Dillonsimply spoofs a UDP packet with the source address being server A's echo port,
830f063d76aSMatthew Dillonand the destination address being server B's echo port, where server A and B
831454ba768SRuslan Ermilovare both on your LAN.
832454ba768SRuslan ErmilovThe two servers then bounce this one packet back and
833454ba768SRuslan Ermilovforth between each other.
834454ba768SRuslan ErmilovThe attacker can overload both servers and their
835454ba768SRuslan ErmilovLANs simply by injecting a few packets in this manner.
836454ba768SRuslan ErmilovSimilar problems
837454ba768SRuslan Ermilovexist with the internal chargen port.
838454ba768SRuslan ErmilovA competent sysadmin will turn off all
839454ba768SRuslan Ermilovof these
840454ba768SRuslan Ermilov.Xr inetd 8 Ns -internal
841454ba768SRuslan Ermilovtest services.
842f063d76aSMatthew Dillon.Pp
843f063d76aSMatthew DillonSpoofed packet attacks may also be used to overload the kernel route cache.
844454ba768SRuslan ErmilovRefer to the
845454ba768SRuslan Ermilov.Va net.inet.ip.rtexpire , net.inet.ip.rtminexpire ,
846454ba768SRuslan Ermilovand
847454ba768SRuslan Ermilov.Va net.inet.ip.rtmaxcache
848454ba768SRuslan Ermilov.Xr sysctl 8
849454ba768SRuslan Ermilovvariables.
850454ba768SRuslan ErmilovA spoofed packet attack that uses a random source IP will cause
851f063d76aSMatthew Dillonthe kernel to generate a temporary cached route in the route table, viewable
852568e4cbbSGuy Helmerwith
853454ba768SRuslan Ermilov.Dq Li "netstat -rna | fgrep W3" .
854568e4cbbSGuy HelmerThese routes typically timeout in 1600
855454ba768SRuslan Ermilovseconds or so.
856454ba768SRuslan ErmilovIf the kernel detects that the cached route table has gotten
857454ba768SRuslan Ermilovtoo big it will dynamically reduce the
858454ba768SRuslan Ermilov.Va rtexpire
859454ba768SRuslan Ermilovbut will never decrease it to
860454ba768SRuslan Ermilovless than
861454ba768SRuslan Ermilov.Va rtminexpire .
862454ba768SRuslan ErmilovThere are two problems: (1) The kernel does not react
863f063d76aSMatthew Dillonquickly enough when a lightly loaded server is suddenly attacked, and (2) The
864454ba768SRuslan Ermilov.Va rtminexpire
865454ba768SRuslan Ermilovis not low enough for the kernel to survive a sustained attack.
866f063d76aSMatthew DillonIf your servers are connected to the internet via a T3 or better it may be
867454ba768SRuslan Ermilovprudent to manually override both
868454ba768SRuslan Ermilov.Va rtexpire
869454ba768SRuslan Ermilovand
870454ba768SRuslan Ermilov.Va rtminexpire
871454ba768SRuslan Ermilovvia
87285752545SGuy Helmer.Xr sysctl 8 .
873568e4cbbSGuy HelmerNever set either parameter to zero
874c4d9468eSRuslan Ermilov(unless you want to crash the machine :-)).
875f063d76aSMatthew DillonSetting both parameters to 2 seconds should be sufficient to protect the route
876f063d76aSMatthew Dillontable from attack.
877d93b26d6SMatthew Dillon.Sh ACCESS ISSUES WITH KERBEROS AND SSH
878454ba768SRuslan ErmilovThere are a few issues with both Kerberos and SSH that need to be addressed
879454ba768SRuslan Ermilovif you intend to use them.
880454ba768SRuslan ErmilovKerberos5 is an excellent authentication
881454ba768SRuslan Ermilovprotocol but the kerberized
882454ba768SRuslan Ermilov.Xr telnet 1
883454ba768SRuslan Ermilovand
884454ba768SRuslan Ermilov.Xr rlogin 1
885454ba768SRuslan Ermilovsuck rocks.
886454ba768SRuslan ErmilovThere are bugs that make them unsuitable for dealing with binary streams.
887454ba768SRuslan ErmilovAlso, by default
888454ba768SRuslan ErmilovKerberos does not encrypt a session unless you use the
889d93b26d6SMatthew Dillon.Fl x
890454ba768SRuslan Ermilovoption.
891454ba768SRuslan ErmilovSSH encrypts everything by default.
892d93b26d6SMatthew Dillon.Pp
893454ba768SRuslan ErmilovSSH works quite well in every respect except when it is set up to
8949baaab27SDima Dorfmanforward encryption keys.
8959baaab27SDima DorfmanWhat this means is that if you have a secure workstation holding
896454ba768SRuslan Ermilovkeys that give you access to the rest of the system, and you
897454ba768SRuslan Ermilov.Xr ssh 1
898454ba768SRuslan Ermilovto an
899454ba768SRuslan Ermilovunsecure machine, your keys become exposed.
900454ba768SRuslan ErmilovThe actual keys themselves are
901454ba768SRuslan Ermilovnot exposed, but
902454ba768SRuslan Ermilov.Xr ssh 1
903454ba768SRuslan Ermilovinstalls a forwarding port for the duration of your
90447afd1f8SDaniel Harrislogin and if an attacker has broken root on the unsecure machine he can utilize
905d93b26d6SMatthew Dillonthat port to use your keys to gain access to any other machine that your
906d93b26d6SMatthew Dillonkeys unlock.
907d93b26d6SMatthew Dillon.Pp
908454ba768SRuslan ErmilovWe recommend that you use SSH in combination with Kerberos whenever possible
909454ba768SRuslan Ermilovfor staff logins.
910454ba768SRuslan ErmilovSSH can be compiled with Kerberos support.
911454ba768SRuslan ErmilovThis reduces
912454ba768SRuslan Ermilovyour reliance on potentially exposable SSH keys while at the same time
913454ba768SRuslan Ermilovprotecting passwords via Kerberos.
914454ba768SRuslan ErmilovSSH keys
915d93b26d6SMatthew Dillonshould only be used for automated tasks from secure machines (something
916454ba768SRuslan Ermilovthat Kerberos is unsuited to).
917454ba768SRuslan ErmilovWe also recommend that you either turn off
918454ba768SRuslan Ermilovkey-forwarding in the SSH configuration, or that you make use of the
919454ba768SRuslan Ermilov.Va from Ns = Ns Ar IP/DOMAIN
920454ba768SRuslan Ermilovoption that SSH allows in its
921d93b26d6SMatthew Dillon.Pa authorized_keys
9227c86a74bSMike Pritchardfile to make the key only usable to entities logging in from specific
923d93b26d6SMatthew Dillonmachines.
924f063d76aSMatthew Dillon.Sh SEE ALSO
925f063d76aSMatthew Dillon.Xr chflags 1 ,
926f063d76aSMatthew Dillon.Xr find 1 ,
927f063d76aSMatthew Dillon.Xr md5 1 ,
928f6f8f44dSAlexey Zelkin.Xr netstat 1 ,
9298596de53SNik Clayton.Xr openssl 1 ,
9305521ff5aSRuslan Ermilov.Xr ssh 1 ,
9316ac7e896SDavid E. O'Brien.Xr xdm 1 ,
932d93b26d6SMatthew Dillon.Xr group 5 ,
933ad27d066SMatthew Dillon.Xr ttys 5 ,
9348596de53SNik Clayton.Xr accton 8 ,
935d93b26d6SMatthew Dillon.Xr init 8 ,
9368596de53SNik Clayton.Xr sshd 8 ,
937ad27d066SMatthew Dillon.Xr sysctl 8 ,
9388596de53SNik Clayton.Xr syslogd 8 ,
939ad27d066SMatthew Dillon.Xr vipw 8
940f063d76aSMatthew Dillon.Sh HISTORY
941f063d76aSMatthew DillonThe
942f063d76aSMatthew Dillon.Nm
943568e4cbbSGuy Helmermanual page was originally written by
944568e4cbbSGuy Helmer.An Matthew Dillon
945568e4cbbSGuy Helmerand first appeared
946568e4cbbSGuy Helmerin
94785752545SGuy Helmer.Fx 3.1 ,
948568e4cbbSGuy HelmerDecember 1998.
949