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