home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / berkly42.txt < prev    next >
Text File  |  1999-11-04  |  14KB  |  237 lines

  1. Following is all the information that you need to understand the workings of
  2. the UNIX operating system (Berkley 4.2).
  3.  
  4. Patched together by The War
  5.  
  6.  
  7. On the security side of UNIX:
  8. -----------------------------
  9. On the Security of UNIX Dennis M. Ritchie Recently there has been much interest
  10. in the security aspects of operating systems and software. At issue is the
  11. ability to prevent undesired disclosure of information, destruction of
  12. information, and harm to the functioning of the system. This paper discusses
  13. the degree of security which can be provided under the system and offers a
  14. number of hints on how to improve security. The first fact to face is that was
  15. not developed with security, in any realistic sense, in mind; this fact alone
  16. guarantees a vast number of holes. (Actually the same statement can be made
  17. with respect to most systems.) The area of security in which is theoretically
  18. weakest is in protecting against crashing or at least crippling the operation
  19. of the system.
  20.    The problem here is not mainly in uncritical acceptance of bad parameters
  21. to system calls there may be bugs in this area, but none are known- but rather
  22. in lack of checks for excessive consumption of resources. Most notably, there
  23. is no limit on the amount of disk storage used, either in total space allocated
  24. or in the number of files or directories. Here is a particularly ghastly shell
  25. sequence guaranteed to stop the system:
  26.  
  27.      while :; do
  28.          mkdir x
  29.          cd x
  30.       done 
  31.  
  32. Ether a panic will occur because all the i-nodes on the device are used up, 
  33. or all the disk blocks will be consumed, thus preventing anyone from 
  34. writing files on the device.  In this version  of the system, users are 
  35. prevented from creating more than a set number of processes simultaneously, so
  36. unless users are in collusion it is unlikely that any one can stop the 
  37. system altogether.  However, creation of 20 or so CPU or disk-bound jobs  
  38. leaves  few  resources available for others.  Also, if many large jobs are 
  39. run simultaneously, swap space may run out, causing a panic.  It should be 
  40. evident that excessive consumption of disk space, files, swap space, and  
  41. processes can  easily occur accidentally in malfunctioning programs
  42. as well as at command level.  In fact is  essentially defenseless against 
  43. this kind of abuse, nor is there any easy fix.  The best that can be said is
  44. that it is generally fairly easy to detect what has happened when disaster
  45. strikes, to identify the user responsible, and take appropriate  action.
  46. In practice, we  have found that difficulties in this area are rather rare,
  47. but we have not been faced with malicious users, and enjoy a fairly generous
  48. supply of resources which have served to cushion us against accidental
  49. overconsumption. The picture is considerably brighter in the area of protection
  50. of information from unauthorized perusal and destruction. Here the degree of
  51. security seems (almost) adequate theoretically, and the problems lie more in
  52. the necessity for care in the actual use of the system. Each file has
  53. associated with it eleven bits of protection information together
  54. with a user identification number and a usergroup identification number (UID
  55. and GID).  Nine of the protection bits are used to specify independently
  56. permission to read, to write, and to execute the file to the user himself,
  57. to members of the user's group, and to all other users.  Each process 
  58. generated by or for a user has associated with it an effective UID and
  59. a real UID, and an effective and real GID.  When an attempt is made to access
  60. the file for  reading, writing,  or  execution, the user process's effective
  61. UID is compared against the file's UID; if a match is  obtained, access is
  62. granted provided the read, write, or execute bit respectively for the user 
  63. himself is present.  If the UID for the file and  for the process fail to
  64. match, but the GID's do match, the group bits are used; if the GID's do 
  65. not match, the bits  for other users are tested.  The last two bits of each 
  66. file's protection information, called the set-UID and set-GID  bits, are used
  67. only when the file is executed as a program.  If, in this case, the set-UID
  68. bit is on for the  file, the effective UID for the process is changed to the 
  69. UID associated with the file; the change persists until the process 
  70. terminates or until the UID changed again by another execution of a set-UID
  71. file.  Similarly the effective  group ID of a process is changed to the GID 
  72. associated with a file when that file is executed and has the set-GID  bit 
  73. set.  The real UID and GID of a process do not change when any file is
  74. executed, but only as the result of a privileged system call.  The basic
  75. notion of the set-UID and set-GID bits is that one may write a program which  
  76. is executable by others and which maintains files accessible to others 
  77. only by that program.  The classical example is the game-playing  program  
  78. which maintains records of the scores of its players.  The program itself has
  79. to read and write the score file, but no one but the game's sponsor can be 
  80. allowed unrestricted access to the file lest they manipulate the game to their
  81. own advantage.  The solution is to turn on the set-UID bit of the game program.
  82. When, and only when, it is invoked by players of the game, it may update the 
  83. score file but ordinary programs executed by others cannot access the 
  84. score.  There are a number of special cases involved in determining access 
  85. permissions.  Since executing a directory as a program is a meaningless
  86. operation, the execute-permission bit, for directories, is taken instead to 
  87. mean permission to  earch  he directory for a given file during the scanning of
  88. a path name; thus if a directory  has execute  permission but no read 
  89. permission for a given user, he may access files with known names in the  
  90. directory, but may not read (list) the entire contents of the directory. Write
  91. permission on a directory is interpreted to mean  that the user may 
  92. create and delete files in that directory; it is impossible for any 
  93. user to write directly into any directory.  Another, and from the point
  94. of view of security, much more serious special case is that there is a ``super
  95. user'' who is able  to read any file and write any nondirectory.  The
  96. super-user is also able to change the protection mode and  the owner UID and 
  97. GID of any file and to invoke privileged system calls.  It must be 
  98. recognized that the mere notion of a super-user is a theoretical, and 
  99. usually practical, blemish on any protection scheme.  The first necessity
  100. for a secure system is of course arranging that all files and 
  101. directories have the proper protection modes. Traditionally, software has been
  102. exceedingly permissive in this regard; essentially all commands create files  
  103. readable and writable by everyone. In the current version, this policy may be
  104. easily adjusted to suit the needs of the  installation or the individual 
  105. user.  Associated with each process and its descendants is a mask, which is in
  106. effect with the mode of every file and directory created by that process. In 
  107. this way, users can arrange that, by default, all their files are no more 
  108. accessible than they wish.  The standard mask, set by allows all 
  109. permissions to the user himself  and to his group, but disallows writing by
  110. others.  To maintain both data privacy and data integrity, it is necessary, 
  111. and largely sufficient, to make one's files inaccessible to others.  The lack
  112. of sufficiency could follow from the existence of set-UID programs created 
  113. by the user and the possibility of total breach of system security in one 
  114. of the ways discussed below  (or one of the ways not discussed below).  For
  115. greater protection, an encryption scheme is available.  Since the editor 
  116. is able to create encrypted documents, and the command can be used to pipe
  117. such documents into the other text-processing programs, the length of time
  118. during which cleartext versions need  be  available is strictly limited. The 
  119. encryption scheme used is not one of the strongest known, but it is judged 
  120. adequate, in the sense that  cryptanalysis is likely to require 
  121. considerably more effort than more direct methods of reading the encrypted
  122. files.  For example, a user who stores data that he regards as truly secret
  123. should be aware that he is implicitly trusting the system administrator not
  124. to install a version of the crypt command that stores every typed 
  125. password in a  file.  Needless to say, the system administrators must be at 
  126. least as careful as their most demanding user to place the correct 
  127. protection mode on the files under their control.  In particular, it is 
  128. necessary that  special files be protected from  writing, and probably 
  129. reading, by ordinary users when they store sensitive files belonging to 
  130. other users.  It is easy to write programs that examine and change files 
  131. by accessing the device on which the files live.  On the issue of  password 
  132. security, is probably better than most systems.  Passwords are stored in an 
  133. encrypted form which, in the absence of serious attention from specialists in
  134. the field, appears reasonably secure,  provided its  limitations are
  135. understood.  In the current version, it  is based on a slightly defective
  136. version of the Federal DES;  it  is  purposely defective so that easily-
  137. available hardware is useless for attempts at exhaustive key-search.
  138. Since both the encryption algorithm and the encrypted passwords are available,
  139. exhaustive enumeration of potential passwords is still feasible  up to a
  140. point.  We have observed that users choose passwords that are easy to
  141. guess: they are short, or from a limited alphabet, or in a dictionary.
  142. Passwords should be at least six characters long and randomly  chosen
  143. from an alphabet which includes digits and special characters.  Of course
  144. there also exist feasible non-cryptanalytic ways of finding out
  145. passwords.  For example: write a program which types out ``login:'' on
  146. the typewriter and  copies  whatever is  typed to a file of your own.  Then
  147. invoke the command and go away until the victim  arrives.   The  set-UID  (
  148. set-GID) notion must be used carefully if any security is to be maintained.
  149. The first thing to keep in mind is that a  writable set-UID file can have
  150. another program copied onto it.  For example, if the super-user command is
  151. writable,  anyone can copy the shell onto it and get a password-free version
  152. of A more subtle problem can come from set-UID programs which are not
  153. sufficiently careful of what is fed into them.  To take an obsolete
  154. example, the previous version of the command was set-UID and owned by the
  155. super-user.  This version sent mail to the recipient's own directory.  The
  156. notion was that one should be able to send mail to anyone even if they want
  157. to protect their directories from writing.  The trouble  was that was
  158. rather dumb: anyone could  mail someone  else's private file to himself.  Much
  159. more serious is the following scenario:  make  a file with a line like one in
  160. the password file which allows one to log in as the  super-user.  Then make a
  161. link  named  ``.mail'' to the password file in some writable directory on the
  162. same device as the password  file (say/tmp).  Finally mail the bogus login
  163. line to /tmp/.mail; You can then login as the superuser, clean up the 
  164. incriminating evidence, and have your will.  The fact that users can mount 
  165. their own disks and tapes as file systems can be another way of gaining 
  166. superuser status.  Once a disk pack is mounted, the system believes what is on
  167. it. Thus one can take a  blank disk pack, put on it anything desired, and 
  168. mount it.  There are obvious and  unfortunate consequences.   For 
  169. example: a mounted disk with garbage onit will crash the system; one of the 
  170. files  on  the  mounted disk can easily  be a password-free version of other 
  171. files can be unprotected entries for special files.  The only easy fix for 
  172. this problem is to forbid the use of to unprivileged users.  A partial
  173. solution, not so restrictive, would be  to have  the  command examine the
  174. special file for bad data, set-UID  programs owned by others, and
  175. accessible special files, and balk at  unprivileged invokers.
  176.  
  177. -
  178. Info about the /etc/passwd file:
  179. ---
  180.  
  181. NME
  182.      passwd - password file
  183.  
  184. DSCRIPTION
  185.      Passwd contains for each user the 
  186. following information:
  187.  
  188.     name (login name, contains no 
  189. upper case)
  190.      encrypted password
  191.      numerical user ID
  192.      numerical group ID
  193.      user's real name, office, 
  194. extension, home phone.
  195.      initial working directory
  196.      program to use as Shell
  197.  
  198.     The name may contain `&', meaning insert the login name.
  199.      This information is set by the chfn(1) command and used by
  200.      the finger(1) command.
  201.  
  202.     This is an ASCII file.  Each field within each user's entry
  203.      is separated from the next by a colon.  Each user is
  204.      separated from the next by a new line.  If the password
  205.      field is null, no password is demanded; if the Shell field
  206.      is null, then /bin/sh is used.
  207.  
  208.     This file resides in directory / etc.  Because of the
  209.      encrypted passwords, it can and does have general read
  210.      permission and can be used, for example, to map numerical user
  211.      ID's to names.
  212.  
  213.     Appropriate precautions must be taken to lock the file
  214.      against changes if it is to be edited with a text editor;
  215.      vipw(8) does the necessary locking.
  216.  
  217. FLES
  218.      /etc/passwd
  219.  
  220. SE ALSO
  221.      getpwent(3), login(1), crypt(3), 
  222. passwd(1), group(5),
  223.      chfn(1), finger(1), vipw(8), 
  224. adduser(8)
  225.  
  226. BGS
  227.      A binary indexed file format should be available for fast access.
  228.  
  229.     User information (name, office, etc.) should be stored elsewhere.
  230. ---
  231.  
  232.    Now if you have had the patience to read all of this and you have digested
  233. it you know everything that you need to know about the Unix system to hold up
  234. your end of an intelligent conversation.
  235.  
  236. Have fun!
  237.