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>
16 This note was attached to the Samba 2.2.8 release notes because it contains an
17 important security fix. The information contained here applies to Samba
18 installations in general.
23 A new apprentice reported for duty to the chief engineer of a boiler house. He said, <quote>Here I am,
24 if you will show me the boiler I'll start working on it.</quote> Then engineer replied, <quote>You're leaning
30 Security concerns are just like that. You need to know a little about the subject to appreciate
31 how obvious most of it really is. The challenge for most of us is to discover that first morsel
32 of knowledge with which we may unlock the secrets of the masters.
38 <title>Features and Benefits</title>
41 There are three levels at which security principles must be observed in order to render a site
42 at least moderately secure. They are the perimeter firewall, the configuration of the host
43 server that is running Samba, and Samba itself.
47 Samba permits a most flexible approach to network security. As far as possible Samba implements
48 the latest protocols to permit more secure MS Windows file and print operations.
52 Samba may be secured from connections that originate from outside the local network. This may be
53 done using <emphasis>host-based protection</emphasis>, using Samba's implementation of a technology
54 known as <quote>tcpwrappers,</quote> or it may be done be using <emphasis>interface-based exclusion</emphasis>
55 so &smbd; will bind only to specifically permitted interfaces. It is also
56 possible to set specific share or resource-based exclusions, for example, on the <smbconfsection name="[IPC$]"/>
57 autoshare. The <smbconfsection name="[IPC$]"/> share is used for browsing purposes as well as to establish
62 Another method by which Samba may be secured is by setting Access Control Entries (ACEs) in an Access
63 Control List (ACL) on the shares themselves. This is discussed in
64 <link linkend="AccessControls">File, Directory, and Share Access Controls</link>.
70 <title>Technical Discussion of Protective Measures and Issues</title>
73 The key challenge of security is that protective measures suffice at best
74 only to close the door on known exploits and breach techniques. Never assume that
75 because you have followed these few measures, the Samba server is now an impenetrable
76 fortress! Given the history of information systems so far, it is only a matter of time
77 before someone will find yet another vulnerability.
81 <title>Using Host-Based Protection</title>
84 In many installations of Samba, the greatest threat comes from outside
85 your immediate network. By default, Samba accepts connections from
86 any host, which means that if you run an insecure version of Samba on
87 a host that is directly connected to the Internet, you can be
88 especially vulnerable.
92 One of the simplest fixes in this case is to use the <smbconfoption name="hosts allow"/> and
93 <smbconfoption name="hosts deny"/> options in the Samba &smb.conf; configuration file to
94 allow access to your server only from a specific range of hosts. An example might be:
98 <smbconfoption name="hosts allow">127.0.0.1 192.168.2.0/24 192.168.3.0/24</smbconfoption>
99 <smbconfoption name="hosts deny">0.0.0.0/0</smbconfoption>
100 </smbconfblock></para>
103 The above will allow SMB connections only from <constant>localhost</constant> (your own
104 computer) and from the two private networks 192.168.2 and 192.168.3. All other
105 connections will be refused as soon as the client sends its first packet. The refusal
106 will be marked as <errorname>not listening on called name</errorname> error.
112 <title>User-Based Protection</title>
115 If you want to restrict access to your server to valid users only, then the following
116 method may be of use. In the &smb.conf; <smbconfsection name="[global]"/> section put:
120 <smbconfoption name="valid users">@smbusers, jacko</smbconfoption>
121 </smbconfblock></para>
124 This restricts all server access either to the user <emphasis>jacko</emphasis>
125 or to members of the system group <emphasis>smbusers</emphasis>.
132 <title>Using Interface Protection</title>
135 By default, Samba accepts connections on any network interface that
136 it finds on your system. That means if you have an ISDN line or a PPP
137 connection to the Internet then Samba will accept connections on those
138 links. This may not be what you want.
142 You can change this behavior using options like this:
146 <smbconfoption name="interfaces">eth* lo</smbconfoption>
147 <smbconfoption name="bind interfaces only">yes</smbconfoption>
148 </smbconfblock></para>
151 This tells Samba to only listen for connections on interfaces with a
152 name starting with <constant>eth</constant> such as <constant>eth0 or eth1</constant>, plus on the loopback
153 interface called <constant>lo</constant>. The name you will need to use depends on what
154 OS you are using. In the above, I used the common name for Ethernet
159 If you use the above and someone tries to make an SMB connection to
160 your host over a PPP interface called <constant>ppp0,</constant> then he or she will get a TCP
161 connection refused reply. In that case, no Samba code is run at all because
162 the operating system has been told not to pass connections from that
163 interface to any Samba process.
168 <sect2 id="firewallports">
169 <title>Using a Firewall</title>
172 Many people use a firewall to deny access to services they do not
173 want exposed outside their network. This can be a good idea,
174 although I recommend using it in conjunction with the above
175 methods so you are protected even if your firewall is not active
180 If you are setting up a firewall, you need to know what TCP and
181 UDP ports to allow and block. Samba uses the following:
185 <member>UDP/137 - used by nmbd</member>
186 <member>UDP/138 - used by nmbd</member>
187 <member>TCP/139 - used by smbd</member>
188 <member>TCP/445 - used by smbd</member>
192 The last one is important because many older firewall setups may not be
193 aware of it, given that this port was only added to the protocol in
198 When configuring a firewall, the high order ports (1024-65535) are often
199 used for outgoing connections and therefore should be permitted through the
200 firewall. It is prudent to block incoming packets on the high order ports
201 except for established connections.
207 <title>Using IPC$ Share-Based Denials </title>
210 If the above methods are not suitable, then you could also place a
211 more specific deny on the IPC$ share that is used in the recently
212 discovered security hole. This allows you to offer access to other
213 shares while denying access to IPC$ from potentially untrustworthy
218 To do this you could use:
222 <smbconfsection name="[IPC$]"/>
223 <smbconfoption name="hosts allow">192.168.115.0/24 127.0.0.1</smbconfoption>
224 <smbconfoption name="hosts deny">0.0.0.0/0</smbconfoption>
225 </smbconfblock></para>
228 This instructs Samba that IPC$ connections are not allowed from
229 anywhere except the two listed network addresses (localhost and the 192.168.115
230 subnet). Connections to other shares are still allowed. Because the
231 IPC$ share is the only share that is always accessible anonymously,
232 this provides some level of protection against attackers who do not
233 know a valid username/password for your host.
237 If you use this method, then clients will be given an <errorname>`access denied'</errorname>
238 reply when they try to access the IPC$ share. Those clients will not be able to
239 browse shares and may also be unable to access some other resources. This is not
240 recommended unless for some reason you cannot use one of the other methods just discussed.
246 <title>NTLMv2 Security</title>
249 To configure NTLMv2 authentication, the following registry keys are worth knowing about:
254 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
255 "lmcompatibilitylevel"=dword:00000003
260 The value 0x00000003 means to send NTLMv2 response only. Clients will use NTLMv2 authentication;
261 use NTLMv2 session security if the server supports it. Domain controllers accept LM,
262 NTLM, and NTLMv2 authentication.
267 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
268 "NtlmMinClientSec"=dword:00080000
273 The value 0x00080000 means permit only NTLMv2 session security. If either NtlmMinClientSec or
274 NtlmMinServerSec is set to 0x00080000, the connection will fail if NTLMv2
275 session security is negotiated.
281 <title>Upgrading Samba</title>
284 Please check regularly on <ulink noescape="1" url="http://www.samba.org/">http://www.samba.org/</ulink> for updates and
285 important announcements. Occasionally security releases are made, and
286 it is highly recommended to upgrade Samba when a security vulnerability
287 is discovered. Check with your OS vendor for OS-specific upgrades.
293 <title>Common Errors</title>
296 If all of Samba and host platform configurations were really as intuitive as one might like them to be, this
297 section would not be necessary. Security issues are often vexing for a support person to resolve, not
298 because of the complexity of the problem, but because most administrators who post what turns
299 out to be a security problem request are totally convinced that the problem is with Samba.
303 <title>Smbclient Works on Localhost, but the Network Is Dead</title>
306 This is a common problem. Red Hat Linux (and others) installs a default firewall.
307 With the default firewall in place, only traffic on the loopback adapter (IP address 127.0.0.1)
308 is allowed through the firewall.
312 The solution is either to remove the firewall (stop it) or modify the firewall script to
313 allow SMB networking traffic through. See <link linkend="firewallports">the Using a
314 firewall</link> section.
320 <title>Why Can Users Access Home Directories of Other Users?</title>
324 We are unable to keep individual users from mapping to any other user's
325 home directory once they have supplied a valid password! They only need
326 to enter their own password. I have not found any method to configure
327 Samba so that users may map only their own home directory.
332 User xyzzy can map his home directory. Once mapped, user xyzzy can also map
333 anyone else's home directory.
337 This is not a security flaw, it is by design. Samba allows users to have
338 exactly the same access to the UNIX file system as when they were logged
339 onto the UNIX box, except that it only allows such views onto the file
340 system as are allowed by the defined shares.
344 If your UNIX home directories are set up so that one user can happily <command>cd</command>
345 into another user's directory and execute <command>ls</command>, the UNIX security solution is to change file
346 permissions on the user's home directories so that the <command>cd</command> and <command>ls</command> are denied.
350 Samba tries very hard not to second guess the UNIX administrator's security policies and
351 trusts the UNIX admin to set the policies and permissions he or she desires.
355 Samba allows the behavior you require. Simply put the <smbconfoption name="only user">%S</smbconfoption>
356 option in the <smbconfsection name="[homes]"/> share definition.
360 The <smbconfoption name="only user"></smbconfoption> works in conjunction with the <smbconfoption name="users">list</smbconfoption>,
361 so to get the behavior you require, add the line:
363 <smbconfoption name="users">%S</smbconfoption>
365 This is equivalent to adding
367 <smbconfoption name="valid users">%S</smbconfoption>
369 to the definition of the <smbconfsection name="[homes]"/> share, as recommended in
370 the &smb.conf; man page.