e9e8c4f9f863af0e2a80be7c5ac9884ac32d1a4f
[sfrench/samba-autobuild/.git] / docs / docbook / projdoc / securing-samba.sgml
1 <chapter id="securing-samba">
2
3 <chapterinfo>
4         &author.tridge;
5         <pubdate>17 March 2003</pubdate>
6 </chapterinfo>
7
8 <title>Securing Samba</title>
9
10 <sect1>
11 <title>Introduction</title>
12 <para>
13 This note was attached to the Samba 2.2.8 release notes as it contained an
14 important security fix.  The information contained here applies to Samba
15 installations in general.
16 </para>
17
18 </sect1>
19
20 <sect1>
21 <title>Using host based protection</title>
22
23 <para>
24 In many installations of Samba the greatest threat comes for outside
25 your immediate network. By default Samba will accept connections from
26 any host, which means that if you run an insecure version of Samba on
27 a host that is directly connected to the Internet you can be
28 especially vulnerable.
29 </para>
30
31 <para>
32 One of the simplest fixes in this case is to use the <command>hosts allow</command> and
33 <command>hosts deny</command> options in the Samba &smb.conf; configuration file to only
34 allow access to your server from a specific range of hosts. An example
35 might be:
36 </para>
37
38 <para><programlisting>
39   hosts allow = 127.0.0.1 192.168.2.0/24 192.168.3.0/24
40   hosts deny = 0.0.0.0/0
41 </programlisting></para>
42
43 <para>
44 The above will only allow SMB connections from 'localhost' (your own
45 computer) and from the two private networks 192.168.2 and
46 192.168.3. All other connections will be refused connections as soon
47 as the client sends its first packet. The refusal will be marked as a
48 'not listening on called name' error.
49 </para>
50
51 </sect1>
52
53 <sect1>
54
55 <title>Using interface protection</title>
56
57 <para>
58 By default Samba will accept connections on any network interface that
59 it finds on your system. That means if you have a ISDN line or a PPP
60 connection to the Internet then Samba will accept connections on those
61 links. This may not be what you want.
62 </para>
63
64 <para>
65 You can change this behaviour using options like the following:
66 </para>
67
68 <para><programlisting>
69   interfaces = eth* lo
70   bind interfaces only = yes
71 </programlisting></para>
72
73 <para>
74 This tells Samba to only listen for connections on interfaces with a
75 name starting with 'eth' such as eth0, eth1, plus on the loopback
76 interface called 'lo'. The name you will need to use depends on what
77 OS you are using, in the above I used the common name for Ethernet
78 adapters on Linux.
79 </para>
80
81 <para>
82 If you use the above and someone tries to make a SMB connection to
83 your host over a PPP interface called 'ppp0' then they will get a TCP
84 connection refused reply. In that case no Samba code is run at all as
85 the operating system has been told not to pass connections from that
86 interface to any process.
87 </para>
88
89 </sect1>
90
91 <sect1>
92 <title>Using a firewall</title>
93
94 <para>
95 Many people use a firewall to deny access to services that they don't
96 want exposed outside their network. This can be a very good idea,
97 although I would recommend using it in conjunction with the above
98 methods so that you are protected even if your firewall is not active
99 for some reason.
100 </para>
101
102 <para>
103 If you are setting up a firewall then you need to know what TCP and
104 UDP ports to allow and block. Samba uses the following:
105 </para>
106
107 <para><programlisting>
108 UDP/137    - used by nmbd
109 UDP/138    - used by nmbd
110 TCP/139    - used by smbd
111 TCP/445    - used by smbd
112 </programlisting></para>
113
114 <para>
115 The last one is important as many older firewall setups may not be
116 aware of it, given that this port was only added to the protocol in
117 recent years. 
118 </para>
119
120 </sect1>
121
122 <sect1>
123 <title>Using a IPC$ share deny</title>
124
125 <para>
126 If the above methods are not suitable, then you could also place a
127 more specific deny on the IPC$ share that is used in the recently
128 discovered security hole. This allows you to offer access to other
129 shares while denying access to IPC$ from potentially untrustworthy
130 hosts.
131 </para>
132
133 <para>
134 To do that you could use:
135 </para>
136
137 <para><programlisting>
138   [ipc$]
139      hosts allow = 192.168.115.0/24 127.0.0.1
140      hosts deny = 0.0.0.0/0
141 </programlisting></para>
142
143 <para>
144 this would tell Samba that IPC$ connections are not allowed from
145 anywhere but the two listed places (localhost and a local
146 subnet). Connections to other shares would still be allowed. As the
147 IPC$ share is the only share that is always accessible anonymously
148 this provides some level of protection against attackers that do not
149 know a username/password for your host.
150 </para>
151
152 <para>
153 If you use this method then clients will be given a 'access denied'
154 reply when they try to access the IPC$ share. That means that those
155 clients will not be able to browse shares, and may also be unable to
156 access some other resources. 
157 </para>
158
159 <para>
160 This is not recommended unless you cannot use one of the other
161 methods listed above for some reason.
162 </para>
163
164 </sect1>
165
166 <sect1>
167 <title>Upgrading Samba</title>
168
169 <para>
170 Please check regularly on <ulink url="http://www.samba.org/">http://www.samba.org/</ulink> for updates and
171 important announcements.  Occasionally security releases are made and 
172 it is highly recommended to upgrade Samba when a security vulnerability
173 is discovered.
174 </para>
175
176 </sect1>
177
178 </chapter>