1 <chapter id="securing-samba">
6 <pubdate>17 March 2003</pubdate>
9 <title>Securing Samba</title>
12 <title>Introduction</title>
14 This note was attached to the Samba 2.2.8 release notes as it contained an
15 important security fix. The information contained here applies to Samba
16 installations in general.
22 <title>Using host based protection</title>
25 In many installations of Samba the greatest threat comes for outside
26 your immediate network. By default Samba will accept connections from
27 any host, which means that if you run an insecure version of Samba on
28 a host that is directly connected to the Internet you can be
29 especially vulnerable.
33 One of the simplest fixes in this case is to use the <command>hosts allow</command> and
34 <command>hosts deny</command> options in the Samba &smb.conf; configuration file to only
35 allow access to your server from a specific range of hosts. An example
39 <para><programlisting>
40 hosts allow = 127.0.0.1 192.168.2.0/24 192.168.3.0/24
41 hosts deny = 0.0.0.0/0
42 </programlisting></para>
45 The above will only allow SMB connections from 'localhost' (your own
46 computer) and from the two private networks 192.168.2 and
47 192.168.3. All other connections will be refused as soon
48 as the client sends its first packet. The refusal will be marked as a
49 'not listening on called name' error.
56 <title>Using interface protection</title>
59 By default Samba will accept connections on any network interface that
60 it finds on your system. That means if you have a ISDN line or a PPP
61 connection to the Internet then Samba will accept connections on those
62 links. This may not be what you want.
66 You can change this behaviour using options like the following:
69 <para><programlisting>
71 bind interfaces only = yes
72 </programlisting></para>
75 This tells Samba to only listen for connections on interfaces with a
76 name starting with 'eth' such as eth0, eth1, plus on the loopback
77 interface called 'lo'. The name you will need to use depends on what
78 OS you are using, in the above I used the common name for Ethernet
83 If you use the above and someone tries to make a SMB connection to
84 your host over a PPP interface called 'ppp0' then they will get a TCP
85 connection refused reply. In that case no Samba code is run at all as
86 the operating system has been told not to pass connections from that
87 interface to any samba process.
93 <title>Using a firewall</title>
96 Many people use a firewall to deny access to services that they don't
97 want exposed outside their network. This can be a very good idea,
98 although I would recommend using it in conjunction with the above
99 methods so that you are protected even if your firewall is not active
104 If you are setting up a firewall then you need to know what TCP and
105 UDP ports to allow and block. Samba uses the following:
108 <para><programlisting>
109 UDP/137 - used by nmbd
110 UDP/138 - used by nmbd
111 TCP/139 - used by smbd
112 TCP/445 - used by smbd
113 </programlisting></para>
116 The last one is important as many older firewall setups may not be
117 aware of it, given that this port was only added to the protocol in
124 <title>Using a IPC$ share deny</title>
127 If the above methods are not suitable, then you could also place a
128 more specific deny on the IPC$ share that is used in the recently
129 discovered security hole. This allows you to offer access to other
130 shares while denying access to IPC$ from potentially untrustworthy
135 To do that you could use:
138 <para><programlisting>
140 hosts allow = 192.168.115.0/24 127.0.0.1
141 hosts deny = 0.0.0.0/0
142 </programlisting></para>
145 this would tell Samba that IPC$ connections are not allowed from
146 anywhere but the two listed places (localhost and a local
147 subnet). Connections to other shares would still be allowed. As the
148 IPC$ share is the only share that is always accessible anonymously
149 this provides some level of protection against attackers that do not
150 know a username/password for your host.
154 If you use this method then clients will be given a 'access denied'
155 reply when they try to access the IPC$ share. That means that those
156 clients will not be able to browse shares, and may also be unable to
157 access some other resources.
161 This is not recommended unless you cannot use one of the other
162 methods listed above for some reason.
168 <title>NTLMv2 Security</title>
171 To configure NTLMv2 authentication the following registry keys are worth knowing about:
176 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
177 "lmcompatibilitylevel"=dword:00000003
179 0x3 - Send NTLMv2 response only. Clients will use NTLMv2 authentication,
180 use NTLMv2 session security if the server supports it. Domain
181 controllers accept LM, NTLM and NTLMv2 authentication.
183 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
184 "NtlmMinClientSec"=dword:00080000
186 0x80000 - NTLMv2 session security. If either NtlmMinClientSec or
187 NtlmMinServerSec is set to 0x80000, the connection will fail if NTLMv2
188 session security is not negotiated.
194 <title>Upgrading Samba</title>
197 Please check regularly on <ulink url="http://www.samba.org/">http://www.samba.org/</ulink> for updates and
198 important announcements. Occasionally security releases are made and
199 it is highly recommended to upgrade Samba when a security vulnerability