This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[ira/wip.git] / docs / docbook / projdoc / securing-samba.xml
1 <chapter id="securing-samba">
2
3 <chapterinfo>
4         &author.tridge;
5         &author.jht;
6         <pubdate>17 March 2003</pubdate>
7 </chapterinfo>
8
9 <title>Securing Samba</title>
10
11 <sect1>
12 <title>Introduction</title>
13 <para>
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.
17 </para>
18
19 </sect1>
20
21 <sect1>
22 <title>Using host based protection</title>
23
24 <para>
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.
30 </para>
31
32 <para>
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
36 might be:
37 </para>
38
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>
43
44 <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.
50 </para>
51
52 </sect1>
53
54 <sect1>
55
56 <title>Using interface protection</title>
57
58 <para>
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.
63 </para>
64
65 <para>
66 You can change this behaviour using options like the following:
67 </para>
68
69 <para><programlisting>
70         interfaces = eth* lo
71         bind interfaces only = yes
72 </programlisting></para>
73
74 <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
79 adapters on Linux.
80 </para>
81
82 <para>
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.
88 </para>
89
90 </sect1>
91
92 <sect1>
93 <title>Using a firewall</title>
94
95 <para>
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
100 for some reason.
101 </para>
102
103 <para>
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:
106 </para>
107
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>
114
115 <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
118 recent years. 
119 </para>
120
121 </sect1>
122
123 <sect1>
124 <title>Using a IPC$ share deny</title>
125
126 <para>
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
131 hosts.
132 </para>
133
134 <para>
135 To do that you could use:
136 </para>
137
138 <para><programlisting>
139         [ipc$]
140              hosts allow = 192.168.115.0/24 127.0.0.1
141              hosts deny = 0.0.0.0/0
142 </programlisting></para>
143
144 <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.
151 </para>
152
153 <para>
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. 
158 </para>
159
160 <para>
161 This is not recommended unless you cannot use one of the other
162 methods listed above for some reason.
163 </para>
164
165 </sect1>
166
167 <sect1>
168 <title>NTLMv2 Security</title>
169
170 <para>
171 To configure NTLMv2 authentication the following registry keys are worth knowing about:
172 </para>
173
174 <para>
175 <programlisting>
176         [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
177         "lmcompatibilitylevel"=dword:00000003
178
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.
182
183         [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
184         "NtlmMinClientSec"=dword:00080000
185
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.
189 </programlisting>
190 </para>
191 </sect1>
192
193 <sect1>
194 <title>Upgrading Samba</title>
195
196 <para>
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
200 is discovered.
201 </para>
202
203 </sect1>
204
205 </chapter>