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

  1. **************************************************************************
  2.    HACK: Shell access users can use "popper" to create root owned files 
  3.  System: Unix
  4.  Source: Mark Fullmer (maf@cob.ohio-state.edu) from Bugtraq
  5.    Date: Fri, 6 May 1994
  6. **************************************************************************
  7.  
  8. On systems that have /var/spool/mail mode 'drwsrwxrwt' and use the Berkeley
  9. popper daemon, users that have access to /var/spool/mail (ie. a user with a
  10. shell login) can create arbitrary root owned files on the host that popper
  11. is executed on.Depending on the umask that popper was run with, this file may also be world
  12. writeable.
  13.  
  14. Details: version UCB Pop server (version 1.831beta)
  15.  
  16. #line 59 of pop_dropcopy.c:
  17. # currently running as root: (POP_TMPDROP is /usr/spool/mail/tmpXXXXXX)
  18.  
  19. >    strcpy(template,POP_TMPDROP);
  20. >    (void) mktemp(template);
  21.  
  22. # The race starts.
  23. # if a user guesses the pathname in "template", they could of previously
  24. # made a link to say /etc/nologin.
  25.  
  26. # instead of script to exploit this bug, you can verify it exists by adding
  27. # sleep(30) here -- after the mktemp(), before the fopen(), which will make the
  28. # race condition easy to win.  Ofcourse, you allready need to be root to be
  29. # able to do this...
  30.  
  31. >    if ( (tf=fopen(template,"w+")) == NULL ) {  /* failure, bail out    */
  32. >        pop_log(p,POP_PRIORITY,
  33. >            "Unable to create temporary temporary maildrop '%s': %s",template,
  34. >                (errno < sys_nerr) ? sys_errlist[errno] : "") ;
  35. >        return pop_msg(p,POP_FAILURE,
  36. >        "System error, can't create temporary file.");
  37. >    }
  38.  
  39. # at this point, the file is created.  Depending on the umask that popper was
  40. # run with, this file may have world write permission.
  41.  
  42. # chown/chmod won't follow your link.
  43. >    /* Now give this file to the user   */
  44. >    (void) chown(template,pwp->pw_uid, pwp->pw_gid);]
  45. >    (void) chmod(template,0600);
  46. >       /* Now link this file to the temporary maildrop.  If this fails it
  47. >     * is probably because the temporary maildrop already exists.  If so,
  48. >     * this is ok.  We can just go on our way, because by the time we try
  49. >     * to write into the file we will be running as the user.
  50. >     */
  51. >    (void) link(template,p->temp_drop);
  52. >    (void) fclose(tf);
  53. >    (void) unlink(template);
  54.  
  55. >    /* Now we run as the user. */
  56. >    (void) setuid(pwp->pw_uid);
  57. >    (void) setgid(pwp->pw_gid);
  58.  
  59. Solution.  If your /var/spool/mail is mode 'drwsrwxrwt' this code isn't
  60. necessary.  Remove lines 59-82 of pop_dropcopy.c.  This doesn't entirely
  61. solve the problem, especially if root reads their mail via popper.  The
  62. best solution is to not have /var/spool/mail with world write permissions,
  63. as this same type of problem exists in atleast one delivery agent (/bin/mail),
  64. and probably in user agents.