preparing for release of 2.2.0-alpha2
[Samba/ekacnet.git] / docs / textdocs / ENCRYPTION.txt
blob40c383ec525204d53929d1b4614a49ab6e8e7bcd
1 !==
2 !== ENCRYPTION.txt for Samba release 2.2.0-alpha2 30 Jan 2001
3 !==
4 Contributor:    Jeremy Allison <samba-bugs@samba.org>
5 Updated:        April 19, 1999
6 Note:           Please refer to WinNT.txt also
8 Subject:        LanManager / Samba Password Encryption.
9 ============================================================================
11 With the development of LanManager and Windows NT compatible password 
12 encryption for Samba, it is now able to validate user connections in 
13 exactly the same way as a LanManager or Windows NT server.
15 This document describes how the SMB password encryption algorithm
16 works and what issues there are in choosing whether you want to use
17 it. You should read it carefully, especially the part about security
18 and the "PROS and CONS" section.
20 How does it work ?
21 ------------------
23 LanManager encryption is somewhat similar to UNIX password
24 encryption. The server uses a file containing a hashed value of a
25 user's password.  This is created by taking the user's plaintext
26 password, capitalising it, and either truncating to 14 bytes (or
27 padding to 14 bytes with null bytes). This 14 byte value is used as
28 two 56 bit DES keys to encrypt a 'magic' eight byte value, forming a
29 16 byte value which is stored by the server and client. Let this value
30 be known as the *hashed password*.
32 Windows NT encryption is a higher quality mechanism, consisting
33 of doing an MD4 hash on a Unicode version of the user's password. This
34 also produces a 16 byte hash value that is non-reversible.
36 When a client (LanManager, Windows for WorkGroups, Windows 95 or
37 Windows NT) wishes to mount a Samba drive (or use a Samba resource) it
38 first requests a connection and negotiates the protocol that the client
39 and server will use. In the reply to this request the Samba server
40 generates and appends an 8 byte, random value - this is stored in the
41 Samba server after the reply is sent and is known as the *challenge*.
43 The challenge is different for every client connection.
45 The client then uses the hashed password (16 byte values described
46 above), appended with 5 null bytes, as three 56 bit DES keys, each of
47 which is used to encrypt the challenge 8 byte value, forming a 24 byte
48 value known as the *response*.
50 In the SMB call SMBsessionsetupX (when user level security is
51 selected) or the call SMBtconX (when share level security is selected)
52 the 24 byte response is returned by the client to the Samba server.
53 For Windows NT protocol levels the above calculation is done on
54 both hashes of the user's password and both responses are returned
55 in the SMB call, giving two 24 byte values.
57 The Samba server then reproduces the above calculation, using its own
58 stored value of the 16 byte hashed password (read from the smbpasswd
59 file - described later) and the challenge value that it kept from the
60 negotiate protocol reply. It then checks to see if the 24 byte value it
61 calculates matches the 24 byte value returned to it from the client.
63 If these values match exactly, then the client knew the correct
64 password (or the 16 byte hashed value - see security note below) and
65 is thus allowed access. If not, then the client did not know the
66 correct password and is denied access.
68 Note that the Samba server never knows or stores the cleartext of the
69 user's password - just the 16 byte hashed values derived from it. Also
70 note that the cleartext password or 16 byte hashed values are never
71 transmitted over the network - thus increasing security.
73 IMPORTANT NOTE ABOUT SECURITY
74 -----------------------------
76 The unix and SMB password encryption techniques seem similar on the
77 surface. This similarity is, however, only skin deep. The unix scheme
78 typically sends clear text passwords over the nextwork when logging
79 in. This is bad. The SMB encryption scheme never sends the cleartext
80 password over the network but it does store the 16 byte hashed values
81 on disk. This is also bad. Why? Because the 16 byte hashed values are a
82 "password equivalent". You cannot derive the user's password from them,
83 but they could potentially be used in a modified client to gain access
84 to a server. This would require considerable technical knowledge on
85 behalf of the attacker but is perfectly possible. You should thus
86 treat the smbpasswd file as though it contained the cleartext
87 passwords of all your users. Its contents must be kept secret, and the
88 file should be protected accordingly.
90 Ideally we would like a password scheme which neither requires plain
91 text passwords on the net or on disk. Unfortunately this is not
92 available as Samba is stuck with being compatible with other SMB
93 systems (WinNT, WfWg, Win95 etc). 
96 PROS AND CONS
97 -------------
99 There are advantages and disadvantages to both schemes. 
101 Advantages of SMB Encryption:
102 -----------------------------
104 - plain text passwords are not passed across the network. Someone using
105 a network sniffer cannot just record passwords going to the SMB server.
107 - WinNT doesn't like talking to a server that isn't using SMB
108 encrypted passwords. It will refuse to browse the server if the server
109 is also in user level security mode. It will insist on prompting the
110 user for the password on each connection, which is very annoying. The
111 only things you can do to stop this is to use SMB encryption.
113 Advantages of non-encrypted passwords:
114 --------------------------------------
116 - plain text passwords are not kept on disk. 
118 - uses same password file as other unix services such as login and
121 - you are probably already using other services (such as telnet and
122 ftp) which send plain text passwords over the net, so not sending them
123 for SMB isn't such a big deal.
125 Note that Windows NT 4.0 Service pack 3 changed the default for
126 permissible authentication so that plaintext passwords are *never*
127 sent over the wire. The solution to this is either to switch to
128 encrypted passwords with Samba or edit the Windows NT registry to
129 re-enable plaintext passwords. See the document WinNT.txt for
130 details on how to do this.
132 The smbpasswd file.
133 -------------------
135 In order for Samba to participate in the above protocol it must
136 be able to look up the 16 byte hashed values given a user name.
137 Unfortunately, as the UNIX password value is also a one way hash
138 function (ie. it is impossible to retrieve the cleartext of the user's
139 password given the UNIX hash of it) then a separate password file
140 containing this 16 byte value must be kept. To minimise problems with
141 these two password files, getting out of sync, the UNIX /etc/passwd and
142 the smbpasswd file, a utility, mksmbpasswd.sh, is provided to generate
143 a smbpasswd file from a UNIX /etc/passwd file.
145 To generate the smbpasswd file from your /etc/passwd file use the
146 following command :-
148 cat /etc/passwd | mksmbpasswd.sh >/usr/local/samba/private/smbpasswd
150 If you are running on a system that uses NIS, use
152 ypcat passwd | mksmbpasswd.sh >/usr/local/samba/private/smbpasswd
154 The mksmbpasswd.sh program is found in the Samba source directory. By
155 default, the smbpasswd file is stored in :-
157 /usr/local/samba/private/smbpasswd
159 The owner of the /usr/local/samba/private directory should be set to
160 root, and the permissions on it should be set to :-
162 r-x------
164 The command 
166 chmod 500 /usr/local/samba/private
168 will do the trick. Likewise, the smbpasswd file inside the private
169 directory should be owned by root and the permissions on is should be
170 set to
172 rw-------
174 by the command :-
176 chmod 600 smbpasswd.
178 The format of the smbpasswd file is
180 username:uid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:[Account type]:LCT-<last-change-time>:Long name
182 Although only the username, uid, XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
183 [Account type] and last-change-time sections are significant and
184 are looked at in the Samba code.
186 It is *VITALLY* important that there by 32 'X' characters between the
187 two ':' characters in the XXX sections - the smbpasswd and Samba code 
188 will fail to validate any entries that do not have 32 characters 
189 between ':' characters. The first XXX section is for the Lanman password
190 hash, the second is for the Windows NT version.
192 When the password file is created all users have password entries
193 consisting of 32 'X' characters. By default this disallows any access
194 as this user. When a user has a password set, the 'X' characters change
195 to 32 ascii hexadecimal digits (0-9, A-F). These are an ascii
196 representation of the 16 byte hashed value of a user's password.
198 To set a user to have no password (not recommended), edit the file
199 using vi, and replace the first 11 characters with the asci text
201 NO PASSWORD
203 Eg. To clear the password for user bob, his smbpasswd file entry would
204 look like :
206 bob:100:NO PASSWORDXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:[U          ]:LCT-00000000:Bob's full name:/bobhome:/bobshell
208 If you are allowing users to use the smbpasswd command to set their own
209 passwords, you may want to give users NO PASSWORD initially so they do
210 not have to enter a previous password when changing to their new
211 password (not recommended). In order for you to allow this the
212 smbpasswd program must be able to connect to the smbd daemon as
213 that user with no password. Enable this by adding the line :
215 null passwords = true
217 to the [global] section of the smb.conf file (this is why the
218 above scenario is not recommended). Preferably, allocate your
219 users a default password to begin with, so you do not have
220 to enable this on your server.
222 Note : This file should be protected very carefully. Anyone with
223 access to this file can (with enough knowledge of the protocols) gain
224 access to your SMB server. The file is thus more sensitive than a
225 normal unix /etc/passwd file.
227 The smbpasswd Command.
228 ----------------------
230 The smbpasswd command maintains the two 32 byte password fields in
231 the smbpasswd file. If you wish to make it similar to the unix passwd
232 or yppasswd programs, install it in /usr/local/samba/bin (or your main
233 Samba binary directory).
235 Note that as of Samba 1.9.18p4 this program MUST NOT BE INSTALLED
236 setuid root (the new smbpasswd code enforces this restriction so
237 it cannot be run this way by accident).
239 smbpasswd now works in a client-server mode where it contacts
240 the local smbd to change the user's password on its behalf. This
241 has enormous benefits - as follows.
243 1). smbpasswd no longer has to be setuid root - an enormous
244 range of potential security problems is eliminated.
246 2). smbpasswd now has the capability to change passwords
247 on Windows NT servers (this only works when the request is
248 sent to the NT Primary Domain Controller if you are changing 
249 an NT Domain user's password).
251 To run smbpasswd as a normal user just type :
253 smbpasswd
254 Old SMB password: <type old value here - or hit return if there was no old password >
255 New SMB Password: < type new value >
256 Repeat New SMB Password: < re-type new value >
258 If the old value does not match the current value stored for that user,
259 or the two new values do not match each other, then the password will
260 not be changed.
262 If invoked by an ordinary user it will only allow the user to change
263 his or her own Samba password.
265 If run by the root user smbpasswd may take an optional argument,
266 specifying the user name whose SMB password you wish to change.  Note
267 that when run as root smbpasswd does not prompt for or check the old
268 password value, thus allowing root to set passwords for users who have
269 forgotten their passwords.
271 smbpasswd is designed to work in the same way and be familiar to UNIX
272 users who use the passwd or yppasswd commands.
274 For more details on using smbpasswd refer to the man page which
275 will always be the definitive reference.
277 Setting up Samba to support LanManager Encryption.
278 --------------------------------------------------
280 This is a very brief description on how to setup samba to support
281 password encryption. More complete instructions will probably be added
282 later.
284 1) compile and install samba as usual
286 2) if your system can't compile the module getsmbpass.c then remove the
287 -DSMBGETPASS define from the Makefile.
289 3) enable encrypted passwords in smb.conf by adding the line 
290 "encrypt passwords = yes" in the [global] section
292 4) create the initial smbpasswd password file in the place you
293 specified in the Makefile. A simple way to do this based on your
294 existing Makefile (assuming it is in a reasonably standard format) is
295 like this:
297 cat /etc/passwd | mksmbpasswd.sh > /usr/local/samba/private/smbpasswd
299 Change ownership of private and smbpasswd to root.
301 chown -R root /usr/local/samba/private
303 Set the correct permissions on /usr/local/samba/private
305 chmod 500 /usr/local/samba/private
307 Set the correct permissions on /usr/local/samba/private/smbpasswd
309 chmod 600 /usr/local/samba/private/smbpasswd
311 note that the mksmbpasswd.sh script is in the samba source directory.
313 If this fails then you will find that you will need entries that look
314 like this:
316 # SMB password file.
317 tridge:148:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:[U          ]:LCT-00000000:Andrew Tridgell:/home/tridge:/bin/tcsh
319 note that the uid and username fields must be right. Also, you must get
320 the number of X's right (there should be 32).
322 5) set the passwords for users using the smbpasswd command. For
323 example, as root you could do "smbpasswd tridge"
325 6) try it out!
327 Note that you can test things using smbclient, as it also now supports
328 encryption.
330 ==============================================================================
331 Footnote:       Please refer to WinNT.txt also