UNIXHackingGuide


SUBMITTED BY: ProffesorFaux

DATE: March 25, 2020, 9:51 a.m.

FORMAT: Text only

SIZE: 14.0 kB

HITS: 511

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

comments powered by Disqus