home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / samba-1.9.18p7.tar.gz / samba-1.9.18p7.tar / samba-1.9.18p7 / docs / ENCRYPTION.txt < prev    next >
Text File  |  1998-05-12  |  15KB  |  362 lines

  1. !==
  2. !== ENCRYPTION.txt for Samba release 1.9.18p7 13 May 1998
  3. !==
  4. Contributor:    Jeremy Allison <samba-bugs@samba.anu.edu.au>
  5. Updated:    March 19, 1998
  6. Note:        Please refer to WinNT.txt also
  7.  
  8. Subject:    LanManager / Samba Password Encryption.
  9. ============================================================================
  10.  
  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.
  14.  
  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.
  19.  
  20. How does it work ?
  21. ------------------
  22.  
  23. LanManager encryption is somewhat similar to UNIX password
  24. encryption. The server uses a file containing a hashed value of a
  25. users password.  This is created by taking the users 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*.
  31.  
  32. Windows NT encryption is a higher quality mechanism, consisting
  33. of doing an MD4 hash on a Unicode version of the users password. This
  34. also produces a 16 byte hash value that is non-reversible.
  35.  
  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*.
  42.  
  43. The challenge is different for every client connection.
  44.  
  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*.
  49.  
  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 users password and both responses are returned
  55. in the SMB call, giving two 24 byte values.
  56.  
  57. The Samba server then reproduces the above calculation, using it's 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.
  62.  
  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 this allowed access. If not then the client did not know the
  66. correct password and is denied access.
  67.  
  68. Note that the Samba server never knows or stores the cleartext of the
  69. users 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.
  72.  
  73. IMPORTANT NOTE ABOUT SECURITY
  74. -----------------------------
  75.  
  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 users 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.
  89.  
  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). 
  94.  
  95.  
  96. PROS AND CONS
  97. -------------
  98.  
  99. There are advantages and disadvantages to both schemes. 
  100.  
  101. Advantages of SMB Encryption:
  102. -----------------------------
  103.  
  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.
  106.  
  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 promting 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.
  112.  
  113. Advantages of non-encrypted passwords:
  114. --------------------------------------
  115.  
  116. - plain text passwords are not kept on disk. 
  117.  
  118. - uses same password file as other unix services such as login and
  119. ftp
  120.  
  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.
  124.  
  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.
  131.  
  132. The smbpasswd file.
  133. -------------------
  134.  
  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 users
  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.
  144.  
  145. To generate the smbpasswd file from your /etc/passwd file use the
  146. following command :-
  147.  
  148. cat /etc/passwd | mksmbpasswd.sh >/usr/local/samba/private/smbpasswd
  149.  
  150. If you are running on a system that uses NIS, use
  151.  
  152. ypcat passwd | mksmbpasswd.sh >/usr/local/samba/private/smbpasswd
  153.  
  154. The mksmbpasswd.sh program is found in the Samba source directory. By
  155. default, the smbpasswd file is stored in :-
  156.  
  157. /usr/local/samba/private/smbpasswd
  158.  
  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 :-
  161.  
  162. r-x------
  163.  
  164. The command 
  165.  
  166. chmod 500 /usr/local/samba/private
  167.  
  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
  171.  
  172. rw-------
  173.  
  174. by the command :-
  175.  
  176. chmod 600 smbpasswd.
  177.  
  178. The format of the smbpasswd file is
  179.  
  180. username:uid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:Long name:user home dir:user shell
  181.  
  182. Although only the username, uid, and XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  183. sections are significant and are looked at in the Samba code.
  184.  
  185. It is *VITALLY* important that there by 32 'X' characters between the
  186. two ':' characters in the XXX sections - the smbpasswd and Samba code 
  187. will fail to validate any entries that do not have 32 characters 
  188. between ':' characters. The first XXX section is for the Lanman password
  189. hash, the second is for the Windows NT version.
  190.  
  191. When the password file is created all users have password entries
  192. consisting of 32 'X' characters. By default this disallows any access
  193. as this user. When a user has a password set, the 'X' characters change
  194. to 32 ascii hexadecimal digits (0-9, A-F). These are an ascii
  195. representation of the 16 byte hashed value of a users password.
  196.  
  197. To set a user to have no password (not recommended), edit the file
  198. using vi, and replace the first 11 characters with the asci text
  199.  
  200. NO PASSWORD
  201.  
  202. Eg. To clear the password for user bob, his smbpasswd file entry would
  203. look like :
  204.  
  205. bob:100:NO PASSWORDXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:Bob's full name:/bobhome:/bobshell
  206.  
  207. If you are allowing users to use the smbpasswd command to set their own
  208. passwords, you may want to give users NO PASSWORD initially so they do
  209. not have to enter a previous password when changing to their new
  210. password (not recommended). In order for you to allow this the
  211. smbpasswd program must be able to connect to the smbd daemon as
  212. that user with no password. Enable this by adding the line :
  213.  
  214. null passwords = true
  215.  
  216. to the [global] section of the smb.conf file (this is why the
  217. above scenario is not recommended). Preferebly, allocate your
  218. users a default password to begin with, so you do not have
  219. to enable this on your server.
  220.  
  221. Note : This file should be protected very carefully. Anyone with
  222. access to this file can (with enough knowledge of the protocols) gain
  223. access to your SMB server. The file is thus more sensitive than a
  224. normal unix /etc/passwd file.
  225.  
  226. Migrating to encrypted passwords
  227. --------------------------------
  228.  
  229. New with Samba 1.9.18p5 and all subsequent versions is a parameter 
  230. written by Bruce Tenison - the "update encrypted" parameter.
  231. If this parameter is set to "yes" (it defaults to "no") and an smbpasswd
  232. file exists containing all the valid users of a Samba system but 
  233. no encrypted passwords (ie. the Lanman hash and NT hash entries in
  234. the file are set to "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), then as
  235. users log in with plaintext passwords that are matched against
  236. their UNIX password entries, their plaintext passwords will be   
  237. hashed and entered into the smbpasswd file. After all the users 
  238. have successfully logged in using unencrypted passwords, the
  239. smbpasswd file will have the Lanman and NT hashes of these users
  240. UNIX passwords correctly stored. At that point the administrator
  241. can convert Samba to use encrypted passwords (and configure the
  242. Windows 95 and NT clients to send only encrypted passwords) and
  243. migrate to an encrypted setup without having to ask users to re-enter
  244. all their passwords explicitly. Note that to use this option the
  245. "encrypt passwords" parameter must be set to "no" when this option
  246. is set to "yes". See the smb.conf man page for up to date information
  247. on this parameter.
  248.  
  249. The smbpasswd Command.
  250. ----------------------
  251.  
  252. The smbpasswd command maintains the two 32 byte password fields in
  253. the smbpasswd file. If you wish to make it similar to the unix passwd
  254. or yppasswd programs, install it in /usr/local/samba/bin (or your main
  255. Samba binary directory).
  256.  
  257. Note that as of Samba 1.9.18p4 this program MUST NOT BE INSTALLED
  258. setuid root (the new smbpasswd code enforces this restriction so
  259. it cannot be run this way by accident).
  260.  
  261. smbpasswd now works in a client-server mode where it contacts
  262. the local smbd to change the users password on its behalf. This
  263. has enormous benefits - as follows.
  264.  
  265. 1). smbpasswd no longer has to be setuid root - an enourmous
  266. range of potential security problems is eliminated.
  267.  
  268. 2). smbpasswd now has the capability to change passwords
  269. on Windows NT servers (this only works when the request is
  270. sent to the NT Primary Domain Controller if you are changing 
  271. an NT Domain users password).
  272.  
  273. 3). smbpasswd can use smbd to change the UNIX password at
  274. the same time as the SMB password is being changed. For details
  275. on this see the parameters 'passwd program', 'passwd chat', and
  276. 'unix password sync' in the smb.conf man page. Note that Samba
  277. must have been compiled with -DALLOW_CHANGE_PASSWORD for this
  278. to work (and the system must be one in which UNIX password changing
  279. is supported).
  280.  
  281. To run smbpasswd as a normal user just type :
  282.  
  283. smbpasswd
  284. Old SMB password: <type old value here - or hit return if there was no old password >
  285. New SMB Password: < type new value >
  286. Repeat New SMB Password: < re-type new value >
  287.  
  288. If the old value does not match the current value stored for that user,
  289. or the two new values do not match each other, then the password will
  290. not be changed.
  291.  
  292. If invoked by an ordinary user it will only allow the user to change
  293. his or her own Samba password.
  294.  
  295. If run by the root user smbpasswd may take an optional argument,
  296. specifying the user name whose SMB password you wish to change.  Note
  297. that when run as root smbpasswd does not prompt for or check the old
  298. password value, thus allowing root to set passwords for users who have
  299. forgotten their passwords.
  300.  
  301. smbpasswd is designed to work in the same way and be familiar to UNIX
  302. users who use the passwd or yppasswd commands.
  303.  
  304. For more details on using smbpasswd refer to the man page which
  305. will always be the definitive reference.
  306.  
  307. Setting up Samba to support LanManager Encryption.
  308. --------------------------------------------------
  309.  
  310. This is a very brief description on how to setup samba to support
  311. password encryption. More complete instructions will probably be added
  312. later.
  313.  
  314. 1) compile and install samba as usual
  315.  
  316. 2) if your system can't compile the module getsmbpass.c then remove the
  317. -DSMBGETPASS define from the Makefile.
  318.  
  319. 3) enable encrypted passwords in smb.conf by adding the line 
  320. "encrypt passwords = yes" in the [global] section
  321.  
  322. 4) create the initial smbpasswd password file in the place you
  323. specified in the Makefile. A simple way to do this based on your
  324. existing Makefile (assuming it is in a reasonably standard format) is
  325. like this:
  326.  
  327. cat /etc/passwd | mksmbpasswd.sh > /usr/local/samba/private/smbpasswd
  328.  
  329. Change ownership of private and smbpasswd to root.
  330.  
  331. chown -R root /usr/local/samba/private
  332.  
  333. Set the correct permissions on /usr/local/samba/private
  334.  
  335. chmod 500 /usr/local/samba/private
  336.  
  337. Set the correct permissions on /usr/local/samba/private/smbpasswd
  338.  
  339. chmod 600 /usr/local/samba/private/smbpasswd
  340.  
  341. note that the mksmbpasswd.sh script is in the samba source directory.
  342.  
  343. If this fails then you will find that you will need entries that look
  344. like this:
  345.  
  346. # SMB password file.
  347. tridge:148:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:Andrew Tridgell:/home/tridge:/bin/tcsh
  348.  
  349. note that the uid and username fields must be right. Also, you must get
  350. the number of X's right (there should be 32).
  351.  
  352. 5) set the passwords for users using the smbpasswd command. For
  353. example, as root you could do "smbpasswd tridge"
  354.  
  355. 6) try it out!
  356.  
  357. Note that you can test things using smbclient, as it also now supports
  358. encryption.
  359.  
  360. ==============================================================================
  361. Footnote:    Please refer to WinNT.txt also
  362.