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">
8
<pubdate>May 26, 2003</pubdate>
11
<title>Securing Samba</title>
14
<title>Introduction</title>
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>
24
The information contained in this chapter applies in general to all Samba installations. Security is
25
everyone's concern in the information technology world. A surprising number of Samba servers are being
26
installed on machines that have direct internet access, thus security is made more critical than it would have been had the
27
server been located behind a firewall and on a private network. Paranoia regarding server security is causing
28
some network administrators to insist on the installation of robust firewalls even on servers that are located
29
inside secured networks. This chapter provides information to assist the administrator who understands
30
how to create the needed barriers and deterents against <quote>the enemy</quote>, no matter where [s]he may
36
A new apprentice reported for duty to the chief engineer of a boiler house. He said, <quote>Here I am,
37
if you will show me the boiler I'll start working on it.</quote> Then engineer replied, <quote>You're leaning
43
Security concerns are just like that. You need to know a little about the subject to appreciate
44
how obvious most of it really is. The challenge for most of us is to discover that first morsel
45
of knowledge with which we may unlock the secrets of the masters.
51
<title>Features and Benefits</title>
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>
58
There are three levels at which security principles must be observed in order to render a site
59
at least moderately secure. They are the perimeter firewall, the configuration of the host
60
server that is running Samba, and Samba itself.
64
Samba permits a most flexible approach to network security. As far as possible Samba implements
65
the latest protocols to permit more secure MS Windows file and print operations.
69
<indexterm><primary>host-based protection</primary></indexterm>
70
<indexterm><primary>interface-based exclusion</primary></indexterm>
71
<indexterm><primary>resource-based exclusion</primary></indexterm>
72
Samba 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
76
resource-based exclusions, for example, on the <smbconfsection name="[IPC$]"/> autoshare. The <smbconfsection
77
name="[IPC$]"/> share is used for browsing purposes as well as to establish TCP/IP connections.
81
<indexterm><primary>Access Control Entries</primary><see>ACE</see></indexterm>
82
<indexterm><primary>ACL</primary></indexterm>
83
<indexterm>controls<primary></primary></indexterm>
84
Another method by which Samba may be secured is by setting Access Control Entries (ACEs) in an Access
85
Control List (ACL) on the shares themselves. This is discussed in
86
<link linkend="AccessControls">File, Directory, and Share Access Controls</link>.
92
<title>Technical Discussion of Protective Measures and Issues</title>
95
The key challenge of security is that protective measures suffice at best
96
only to close the door on known exploits and breach techniques. Never assume that
97
because you have followed these few measures, the Samba server is now an impenetrable
98
fortress! Given the history of information systems so far, it is only a matter of time
99
before someone will find yet another vulnerability.
103
<title>Using Host-Based Protection</title>
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.
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:
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>
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.
141
<title>User-Based Protection</title>
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:
147
<smbconfoption name="valid users">@smbusers, jacko</smbconfoption>
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>.
161
<title>Using Interface Protection</title>
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.
174
You can change this behavior using options like this:
176
<smbconfoption name="interfaces">eth* lo</smbconfoption>
177
<smbconfoption name="bind interfaces only">yes</smbconfoption>
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.
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.
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.
219
<sect2 id="firewallports">
220
<title>Using a Firewall</title>
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.
232
If you are setting up a firewall, you need to know what TCP and UDP ports to allow and block. Samba uses
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>
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>
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.
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.
267
<title>Using IPC$ Share-Based Denials </title>
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.
279
To do this you could use:
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>
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.
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
310
<title>NTLMv2 Security</title>
313
<indexterm><primary>NTLMv2</primary></indexterm>
314
To configure NTLMv2 authentication, the following registry keys are worth knowing about:
319
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
320
"lmcompatibilitylevel"=dword:00000003
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.
332
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
333
"NtlmMinClientSec"=dword:00080000
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.
346
<title>Upgrading Samba</title>
349
<indexterm><primary>updates</primary></indexterm>
350
<indexterm><primary>important announcements</primary></indexterm>
351
<indexterm><primary>security vulnerability</primary></indexterm>
352
Please check regularly on <ulink noescape="1" url="http://www.samba.org/">http://www.samba.org/</ulink> for
353
updates and important announcements. Occasionally security releases are made, and it is highly recommended to
354
upgrade Samba promptly when a security vulnerability is discovered. Check with your OS vendor for OS-specific
361
<title>Common Errors</title>
364
If all Samba and host platform configurations were really as intuitive as one might like them to be, this
365
chapter would not be necessary. Security issues are often vexing for a support person to resolve, not because
366
of the complexity of the problem, but because most administrators who post what turns out to be a security
367
problem request are totally convinced that the problem is with Samba.
371
<title>Smbclient Works on Localhost, but the Network Is Dead</title>
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.
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.
388
<title>Why Can Users Access Other Users' Home Directories?</title>
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.
401
User xyzzy can map his home directory. Once mapped, user xyzzy can also map anyone else's home directory.
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.
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.
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.
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.
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:
436
<smbconfoption name="users">%S</smbconfoption>
438
This is equivalent to adding
440
<smbconfoption name="valid users">%S</smbconfoption>
442
to the definition of the <smbconfsection name="[homes]"/> share, as recommended in
443
the &smb.conf; man page.