• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/samba-3.5.8/docs-xml/Samba3-HOWTO/
1<?xml version="1.0" encoding="iso-8859-1"?>
2<!DOCTYPE chapter PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
3<chapter id="securing-samba">
4
5<chapterinfo>
6	&author.tridge;
7	&author.jht;
8	<pubdate>May 26, 2003</pubdate>
9</chapterinfo>
10
11<title>Securing Samba</title>
12
13<sect1>
14<title>Introduction</title>
15
16<para>
17<indexterm><primary>security</primary></indexterm>
18<indexterm><primary>direct internet access</primary></indexterm>
19<indexterm><primary>firewall</primary></indexterm>
20<indexterm><primary>private network</primary></indexterm>
21<indexterm><primary>barriers</primary></indexterm>
22<indexterm><primary>deterents</primary></indexterm>
23<indexterm><primary>secured networks</primary></indexterm>
24The information contained in this chapter applies in general to all Samba installations. Security is
25everyone's concern in the information technology world. A surprising number of Samba servers are being
26installed on machines that have direct internet access, thus security is made more critical than it would have been had the
27server been located behind a firewall and on a private network. Paranoia regarding server security is causing
28some  network administrators to insist on the installation of robust firewalls even on servers that are located
29inside secured networks. This chapter provides information to assist the administrator who understands
30how to create the needed barriers and deterents against <quote>the enemy</quote>, no matter where [s]he may
31come from.
32</para>
33
34<blockquote>
35<para>
36A new apprentice reported for duty to the chief engineer of a boiler house. He said, <quote>Here I am,
37if you will show me the boiler I'll start working on it.</quote> Then engineer replied, <quote>You're leaning
38on it!</quote>
39</para>
40</blockquote>
41
42<para>
43Security concerns are just like that. You need to know a little about the subject to appreciate
44how obvious most of it really is. The challenge for most of us is to discover that first morsel
45of knowledge with which we may unlock the secrets of the masters.
46</para>
47
48</sect1>
49
50<sect1>
51<title>Features and Benefits</title>
52
53<para>
54<indexterm><primary>moderately secure</primary></indexterm>
55<indexterm><primary>perimeter firewall</primary></indexterm>
56<indexterm><primary>host security</primary></indexterm>
57<indexterm><primary>Samba security</primary></indexterm>
58There are three levels at which security principles must be observed in order to render a site
59at least moderately secure. They are the perimeter firewall, the configuration of the host
60server that is running Samba, and Samba itself.
61</para>
62
63<para>
64Samba permits a most flexible approach to network security. As far as possible Samba implements
65the latest protocols to permit more secure MS Windows file and print operations.
66</para>
67
68<para>
69<indexterm><primary>host-based protection</primary></indexterm>
70<indexterm><primary>interface-based exclusion</primary></indexterm>
71<indexterm><primary>resource-based exclusion</primary></indexterm>
72Samba can be secured from connections that originate from outside the local network. This can be done using
73<emphasis>host-based protection</emphasis>, using Samba's implementation of a technology known as
74<quote>tcpwrappers,</quote> or it may be done be using <emphasis>interface-based exclusion</emphasis> so
75&smbd; will bind only to specifically permitted interfaces. It is also possible to set specific share- or
76resource-based exclusions, for example, on the <smbconfsection name="[IPC$]"/> autoshare. The <smbconfsection
77name="[IPC$]"/> share is used for browsing purposes as well as to establish TCP/IP connections.
78</para>
79
80<para>
81<indexterm><primary>Access Control Entries</primary><see>ACE</see></indexterm>
82<indexterm><primary>ACL</primary></indexterm>
83<indexterm><primary>controls</primary></indexterm>
84Another method by which Samba may be secured is by setting Access Control Entries (ACEs) in an Access 
85Control List (ACL) on the shares themselves. This is discussed in
86<link linkend="AccessControls">File, Directory, and Share Access Controls</link>.
87</para>
88
89</sect1>
90
91<sect1>
92<title>Technical Discussion of Protective Measures and Issues</title>
93
94<para>
95The key challenge of security is that protective measures suffice at best
96only to close the door on known exploits and breach techniques. Never assume that
97because you have followed these few measures, the Samba server is now an impenetrable
98fortress! Given the history of information systems so far, it is only a matter of time
99before someone will find yet another vulnerability.
100</para>
101
102	<sect2>
103	<title>Using Host-Based Protection</title>
104
105	<para>
106<indexterm><primary>outside threat</primary></indexterm>
107<indexterm><primary>insecure</primary></indexterm>
108<indexterm><primary>Internet</primary></indexterm>
109	In many installations of Samba, the greatest threat comes from outside
110	your immediate network. By default, Samba accepts connections from
111	any host, which means that if you run an insecure version of Samba on
112	a host that is directly connected to the Internet, you can be
113	especially vulnerable.
114	</para>
115
116	<para>
117<indexterm><primary>allow access</primary></indexterm>
118<indexterm><primary>range of hosts</primary></indexterm>
119	One of the simplest fixes in this case is to use the <smbconfoption name="hosts allow"/> and
120	<smbconfoption name="hosts deny"/> options in the Samba &smb.conf; configuration file to
121	allow access to your server only from a specific range of hosts. An example might be:
122	<smbconfblock>
123	<smbconfoption name="hosts allow">127.0.0.1 192.168.2.0/24 192.168.3.0/24</smbconfoption>
124	<smbconfoption name="hosts deny">0.0.0.0/0</smbconfoption>
125	</smbconfblock>
126	</para>
127
128	<para>
129<indexterm><primary>localhost</primary></indexterm>
130<indexterm><primary>private networks</primary></indexterm>
131<indexterm><primary>called name</primary></indexterm>
132	The above will allow SMB connections only from <constant>localhost</constant> (your own
133	computer) and from the two private networks 192.168.2 and 192.168.3. All other
134	connections will be refused as soon as the client sends its first packet. The refusal
135	will be marked as <literal>not listening on called name</literal> error.
136	</para>
137
138	</sect2>
139
140	<sect2>
141	<title>User-Based Protection</title>
142
143	<para>
144	If you want to restrict access to your server to valid users only, then the following
145	method may be of use. In the &smb.conf; <smbconfsection name="[global]"/> section put:
146	<smbconfblock>
147	<smbconfoption name="valid users">@smbusers, jacko</smbconfoption>
148	</smbconfblock>
149	</para>
150
151	<para>
152<indexterm><primary>smbusers</primary></indexterm>
153	This restricts all server access either to the user <emphasis>jacko</emphasis>
154	or to members of the system group <emphasis>smbusers</emphasis>.
155	</para>
156
157	</sect2>
158
159	<sect2>
160
161	<title>Using Interface Protection</title>
162
163	<para>
164<indexterm><primary>network interface</primary></indexterm>
165<indexterm><primary>accept connections</primary></indexterm>
166<indexterm><primary>Internet</primary></indexterm>
167	By default, Samba accepts connections on any network interface that
168	it finds on your system. That means if you have an ISDN line or a PPP
169	connection to the Internet then Samba will accept connections on those
170	links. This may not be what you want.
171	</para>
172
173	<para>
174	You can change this behavior using options like this:
175	<smbconfblock>
176	<smbconfoption name="interfaces">eth* lo</smbconfoption>
177	<smbconfoption name="bind interfaces only">yes</smbconfoption>
178	</smbconfblock>
179	</para>
180
181	<para>
182<indexterm><primary>interfaces</primary></indexterm>
183<indexterm><primary>loopback interface</primary></indexterm>
184<indexterm><primary>Ethernet adapters</primary></indexterm>
185<indexterm><primary>listen for connections</primary></indexterm>
186	This tells Samba to listen for connections only on interfaces with a name starting with
187	<constant>eth</constant> such as <constant>eth0</constant> or <constant>eth1</constant>, plus on the loopback interface called
188	<constant>lo</constant>. The name you will need to use depends on what OS you are using. In the above, I used
189	the common name for Ethernet adapters on Linux.
190	</para>
191
192	<para>
193<indexterm><primary>PPP</primary></indexterm>
194<indexterm><primary>SMB</primary></indexterm>
195<indexterm><primary>cracker</primary></indexterm>
196<indexterm><primary>confirm address</primary></indexterm>
197	If you use the above and someone tries to make an SMB connection to your host over a PPP interface called
198	<constant>ppp0</constant>, then [s]he will get a TCP connection refused reply. In that case, no Samba code
199	is run at all, because the operating system has been told not to pass connections from that interface to any
200	Samba process. However, the refusal helps a would-be cracker by confirming that the IP address provides
201	valid active services.
202	</para>
203
204	<para>
205<indexterm><primary>ignore connection</primary></indexterm>
206<indexterm><primary>refusing connection</primary></indexterm>
207<indexterm><primary>exploitation</primary></indexterm>
208<indexterm><primary>denial of service</primary></indexterm>
209<indexterm><primary>firewall</primary></indexterm>
210	A better response would be to ignore the connection (from, for example, ppp0) altogether. The
211	advantage of ignoring the connection attempt, as compared with refusing it, is that it foils those who
212	probe an interface with the sole intention of finding valid IP addresses for later use in exploitation
213	or denial of service attacks. This method of dealing with potential malicious activity demands the
214	use of appropriate firewall mechanisms.
215	</para>
216
217	</sect2>
218
219	<sect2 id="firewallports">
220	<title>Using a Firewall</title>
221
222	<para>
223<indexterm><primary>deny access</primary></indexterm>
224<indexterm><primary>exposed</primary></indexterm>
225<indexterm><primary>firewall active</primary></indexterm>
226	Many people use a firewall to deny access to services they do not want exposed outside their network. This can
227	be a good idea, although I recommend using it in conjunction with the above methods so you are protected even
228	if your firewall is not active for some reason.
229	</para>
230
231	<para>
232	If you are setting up a firewall, you need to know what TCP and UDP ports to allow and block. Samba uses
233	the following:
234<indexterm><primary>Port 135/TCP</primary></indexterm>
235<indexterm><primary>Port 137/UDP</primary></indexterm>
236<indexterm><primary>Port 138/UDP</primary></indexterm>
237<indexterm><primary>Port 139/TCP</primary></indexterm>
238<indexterm><primary>Port 445/TCP</primary></indexterm>
239	</para>
240
241	<simplelist>
242		<member>Port 135/TCP - used by smbd</member>
243		<member>Port 137/UDP - used by nmbd</member>
244		<member>Port 138/UDP - used by nmbd</member>
245		<member>Port 139/TCP - used by smbd</member>
246		<member>Port 445/TCP - used by smbd</member>
247	</simplelist>
248
249	<para>
250<indexterm><primary>firewall setups</primary></indexterm>
251	The last one is important because many older firewall setups may not be aware of it, given that this port
252	was only added to the protocol in recent years.
253	</para>
254
255	<para>
256<indexterm><primary>configuring a firewall</primary></indexterm>
257<indexterm><primary>high order ports</primary></indexterm>
258<indexterm><primary>block incoming packets</primary></indexterm>
259	When configuring a firewall, the high order ports (1024-65535) are often used for outgoing connections and
260	therefore should be permitted through the firewall. It is prudent to block incoming packets on the high order
261	ports except for established connections.
262	</para>
263
264	</sect2>
265
266	<sect2>
267	<title>Using IPC$ Share-Based Denials </title>
268
269	<para>
270<indexterm><primary>IPC$</primary></indexterm>
271<indexterm><primary>deny</primary></indexterm>
272<indexterm><primary>security hole</primary></indexterm>
273	If the above methods are not suitable, then you could also place a more specific deny on the IPC$ share that
274	is used in the recently discovered security hole. This allows you to offer access to other shares while
275	denying access to IPC$ from potentially untrustworthy hosts.
276	</para>
277
278	<para>
279	To do this you could use:
280	<smbconfblock>
281	<smbconfsection name="[IPC$]"/>
282	<smbconfoption name="hosts allow">192.168.115.0/24 127.0.0.1</smbconfoption>
283	<smbconfoption name="hosts deny">0.0.0.0/0</smbconfoption>
284	</smbconfblock>
285	</para>
286
287	<para>
288<indexterm><primary>IPC$</primary></indexterm>
289<indexterm><primary>protection against attackers</primary></indexterm>
290<indexterm><primary>valid username/password</primary></indexterm>
291	This instructs Samba that IPC$ connections are not allowed from anywhere except the two listed network
292	addresses (localhost and the 192.168.115 subnet). Connections to other shares are still allowed. Because the
293	IPC$ share is the only share that is always accessible anonymously, this provides some level of protection
294	against attackers who do not know a valid username/password for your host.
295	</para>
296
297	<para>
298<indexterm><primary>access denied</primary></indexterm>
299<indexterm><primary>IPC$</primary></indexterm>
300<indexterm><primary>browse shares</primary></indexterm>
301	If you use this method, then clients will be given an <literal>`access denied'</literal> reply when they try
302	to access the IPC$ share. Those clients will not be able to browse shares and may also be unable to access
303	some other resources.  This is not recommended unless for some reason you cannot use one of the other methods
304	just discussed.
305	</para>
306
307	</sect2>
308
309	<sect2>
310	<title>NTLMv2 Security</title>
311
312	<para>
313<indexterm><primary>NTLMv2</primary></indexterm>
314	To configure NTLMv2 authentication, the following registry keys are worth knowing about:
315	</para>
316
317	<para>
318		<screen>
319		[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
320		"lmcompatibilitylevel"=dword:00000003
321		</screen>
322	</para>
323
324	<para>
325	The value 0x00000003 means to send NTLMv2 response only. Clients will use NTLMv2 authentication;
326	use NTLMv2 session security if the server supports it. Domain controllers accept LM,
327	NTLM, and NTLMv2 authentication.
328	</para>
329
330	<para>
331		<screen>
332		[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
333		"NtlmMinClientSec"=dword:00080000
334		</screen>
335	</para>
336
337	<para>
338	The value 0x00080000 means permit only NTLMv2 session security. If either NtlmMinClientSec or
339	NtlmMinServerSec is set to 0x00080000, the connection will fail if NTLMv2
340	session security is negotiated.
341	</para>
342	</sect2>
343</sect1>
344
345<sect1>
346<title>Upgrading Samba</title>
347
348<para>
349<indexterm><primary>updates</primary></indexterm>
350<indexterm><primary>important announcements</primary></indexterm>
351<indexterm><primary>security vulnerability</primary></indexterm>
352Please check regularly on <ulink noescape="1" url="http://www.samba.org/">http://www.samba.org/</ulink> for
353updates and important announcements. Occasionally security releases are made, and it is highly recommended to
354upgrade Samba promptly when a security vulnerability is discovered. Check with your OS vendor for OS-specific
355upgrades.
356</para>
357
358</sect1>
359
360<sect1>
361<title>Common Errors</title>
362
363<para>
364If all Samba and host platform configurations were really as intuitive as one might like them to be, this
365chapter would not be necessary. Security issues are often vexing for a support person to resolve, not because
366of the complexity of the problem, but because most administrators who post what turns out to be a security
367problem request are totally convinced that the problem is with Samba.
368</para>
369
370	<sect2>
371	<title>Smbclient Works on Localhost, but the Network Is Dead</title>
372
373	<para>
374	This is a common problem. Linux vendors tend to install a default firewall.
375	With the default firewall in place, only traffic on the loopback adapter (IP address 127.0.0.1)
376	is allowed through the firewall.
377	</para>
378
379	<para>
380	The solution is either to remove the firewall (stop it) or modify the firewall script to
381	allow SMB networking traffic through. See <link linkend="firewallports">the Using a 
382	Firewall</link> section.
383	</para>
384
385	</sect2>
386
387	<sect2>
388	<title>Why Can Users Access Other Users' Home Directories?</title>
389
390	<para>
391	<quote>
392<indexterm><primary>mapping home directory</primary></indexterm>
393<indexterm><primary>own home directory</primary></indexterm>
394	We are unable to keep individual users from mapping to any other user's home directory once they have
395	supplied a valid password! They only need to enter their own password. I have not found any method to
396	configure Samba so that users may map only their own home directory.
397	</quote>
398	</para>
399
400	<para><quote>
401	User xyzzy can map his home directory. Once mapped, user xyzzy can also map anyone else's home directory.
402	</quote></para>
403
404	<para>
405<indexterm><primary>security flaw</primary></indexterm>
406<indexterm><primary>defined shares</primary></indexterm>
407	This is not a security flaw, it is by design. Samba allows users to have exactly the same access to the UNIX
408	file system as when they were logged on to the UNIX box, except that it only allows such views onto the file
409	system as are allowed by the defined shares.
410	</para>
411
412	<para>
413<indexterm><primary>UNIX home directories</primary></indexterm>
414<indexterm><primary>permissions</primary></indexterm>
415	If your UNIX home directories are set up so that one user can happily <command>cd</command>
416	into another user's directory and execute <command>ls</command>, the UNIX security solution is to change file
417	permissions on the user's home directories so that the <command>cd</command> and <command>ls</command> are denied.
418	</para>
419
420	<para>
421<indexterm><primary>security policies</primary></indexterm>
422<indexterm><primary>permissions</primary></indexterm>
423	Samba tries very hard not to second guess the UNIX administrator's security policies and
424	trusts the UNIX admin to set the policies and permissions he or she desires.
425	</para>
426
427	<para>
428	Samba allows the behavior you require. Simply put the <smbconfoption name="only user">%S</smbconfoption>
429	option in the <smbconfsection name="[homes]"/> share definition.
430	</para>
431
432	<para>
433	The <smbconfoption name="only user"></smbconfoption> works in conjunction with the <smbconfoption name="users">list</smbconfoption>,
434	so to get the behavior you require, add the line:
435	<smbconfblock>
436	<smbconfoption name="users">%S</smbconfoption>
437	</smbconfblock>
438	This is equivalent to adding
439	<smbconfblock>
440	<smbconfoption name="valid users">%S</smbconfoption>
441	</smbconfblock>
442	to the definition of the <smbconfsection name="[homes]"/> share, as recommended in
443	the &smb.conf; man page.
444	</para>
445	</sect2>
446
447</sect1>
448</chapter>
449