home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / next / misc / 18614 < prev    next >
Encoding:
Text File  |  1992-08-12  |  3.7 KB  |  115 lines

  1. Newsgroups: comp.sys.next.misc
  2. Path: sparky!uunet!gatech!rpi!usc!sdd.hp.com!ux1.cso.uiuc.edu!news.cs.indiana.edu!umn.edu!news
  3. From: lupson@descartes (Linus Upson)
  4. Subject: Re: Audio disc on CD-ROM and CDPlayer2.1 & security
  5. Message-ID: <1992Aug12.151438.10475@news2.cis.umn.edu>
  6. Keywords: unix, setuid, rtfm
  7. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  8. Nntp-Posting-Host: descartes.geom.umn.edu
  9. Organization: University of Minnesota
  10. References: <1992Aug11.211657.14714@nic.umass.edu>
  11. Date: Wed, 12 Aug 1992 15:14:38 GMT
  12. Lines: 101
  13.  
  14. setuid scripts are bad, bad, bad...
  15.  
  16. The following is from:
  17. Frequently_Asked_Questions_about_Unix_(4_4)_[Monthly_posting]
  18.  
  19. You can ftp the whole thing (highly recommended) from rtfm.mit.edu if
  20. you don't want to graze.
  21. (/pub/usenet/comp.unix.questions).
  22.  
  23. Linus Upson
  24. lupson@geom.umn.edu
  25.  
  26. ---------------------------------------------------------------------
  27.     Right, but what about the security risks of setuid shell scripts?
  28.  
  29.     Well, suppose the script is called `/etc/setuid_script', starting
  30.     with:
  31.  
  32.     #!/bin/sh
  33.     
  34.     Now let us see what happens if we issue the following commands:
  35.  
  36.     $ cd /tmp
  37.     $ ln /etc/setuid_script -i
  38.     $ PATH=.
  39.     $ -i
  40.  
  41.     We know the last command will be rearranged to:
  42.  
  43.     /bin/sh -i
  44.  
  45.     But this command will give us an interactive shell, setuid to the
  46.     owner of the script!
  47.     Fortunately this security hole can easily be closed by making the
  48.     first line:
  49.  
  50.     #!/bin/sh -
  51.  
  52.     The `-' signals the end of the option list: the next argument `-i'
  53.     will be taken as the name of the file to read commands from, just
  54.     like it should!
  55.  
  56.     ---------
  57.  
  58.     There are more serious problems though:
  59.  
  60.     $ cd /tmp
  61.     $ ln /etc/setuid_script temp
  62.     $ nice -20 temp &
  63.     $ mv my_script temp
  64.  
  65.     The third command will be rearranged to:
  66.  
  67.     nice -20 /bin/sh - temp
  68.  
  69.     As this command runs so slowly, the fourth command might be able to
  70.     replace the original `temp' with `my_script' BEFORE `temp' is opened
  71.     by the shell!
  72.     There are 4 ways to fix this security hole:
  73.  
  74.     1)  let the OS start setuid scripts in a different, secure way
  75.         - System V R4 and 4.4BSD use the /dev/fd driver to pass the
  76.         interpreter a file descriptor for the script
  77.  
  78.     2)  let the script be interpreted indirectly, through a frontend
  79.         that makes sure everything is all right before starting the
  80.         real interpreter - if you use the `indir' program from
  81.         comp.sources.unix the setuid script will look like this:
  82.  
  83.         #!/bin/indir -u
  84.         #?/bin/sh /etc/setuid_script
  85.  
  86.     3)  make a `binary wrapper': a real executable that is setuid and
  87.         whose only task is to execute the interpreter with the name of
  88.         the script as an argument
  89.  
  90.     4)  make a general `setuid script server' that tries to locate the
  91.         requested `service' in a database of valid scripts and upon
  92.         success will start the right interpreter with the right
  93.         arguments.
  94.  
  95.     ---------
  96.  
  97.     Now that we have made sure the right file gets interpreted, are there
  98.     any risks left?
  99.  
  100.     Certainly!  For shell scripts you must not forget to set the PATH
  101.     variable to a safe path explicitly.  Can you figure out why?
  102.     Also there is the IFS variable that might cause trouble if not set
  103.     properly.  Other environment variables might turn out to compromise
  104.     security as well, e.g. SHELL...
  105.     Furthermore you must make sure the commands in the script do not
  106.     allow interactive shell escapes!
  107.     Then there is the umask which may have been set to something
  108.     strange...
  109.  
  110.     Etcetera.  You should realise that a setuid script `inherits' all the
  111.     bugs and security risks of the commands that it calls!
  112.  
  113.     All in all we get the impression setuid shell scripts are quite a
  114.     risky business!  You may be better off writing a C program instead!
  115.