what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

lookout.c

lookout.c
Posted Dec 27, 2002
Authored by Intrusive

Lookout.c watches utmp and executes a specified command when a certain user logs in.

systems | unix
SHA-256 | 166042e8d3d6caa0c2f7106191e596206f645e94fc36c5f2b2fa7e29bbaa1aba

lookout.c

Change Mirror Download
/* 

lookout.c v0.1 from intrusive - (intrusive@portalofevil.com) -

checks to see if anyone new has logged in and executes a command
(or command string) when the specified user logs in or just
notifies you of their presence with a beep.

<command(s)> is either a shell-script or a quote(") encapsulated
string containing a ';' or '&&' seperated list of commands to be
run via a single call to system() when <username> logs in.

if "any" is given for username, notification will be delivered and
any commands specified will be executed upon the login of any user"

because utmp seems to round the login time to the minute, the login
or logout of any user will cause the program to interpret it as
<username> logging in IF <username> is already present in utmp AND
less than approx one minute has elapsed between the time when
<username> was recorded in the file and the time that any user has
logged in/out.

December 8, 2002

*/

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <utmp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>

main(int argc, char **argv)
{

FILE *fptr;
struct stat stbuf;
struct utmp ubuff;

time_t lastacc, logt;
int r, x = 0;
char buff[sizeof(struct utmp)];

if((argc != 4) && (argc != 2))
{
fprintf(stderr, "usage: %s <username> [-e <command(s)>]\n\n", argv[0]);
exit(1);
}

if(argc == 4)
{
if(!strncmp(argv[2], "-e", strlen(argv[2])) == 0)
{
fprintf(stderr, "usage: %s <username> [-e <command(s)>]\n\n", argv[0]);
exit(1);
}
else
x = 1;
}

if((argc > 2) && (strlen(argv[1]) > 32))
{
fprintf(stderr, "login names must be 32 characters or less.\n");
exit(1);
}

if(stat("/var/run/utmp", &stbuf) == -1)
{
fprintf(stderr, "error getting file stats\n");
exit(1);
}

if((r = fork()) == -1)
{
fprintf(stderr, "error with fork()\n");
exit(1);
}

if(r > 0)
exit(0);

lastacc = stbuf.st_mtime;

while(1)
{
sleep(1);

if(stat("/var/run/utmp", &stbuf) == -1)
{
fprintf(stderr, "error getting file stats\n");
exit(1);
}

if(lastacc < stbuf.st_mtime)
{
if((fptr = fopen("/var/run/utmp", "r")) == NULL)
{
fprintf(stderr, "error opening utmp\n");
exit(1);
}

while(fread(&ubuff, 1, sizeof(struct utmp), fptr))
{
if((strncmp(ubuff.ut_name, argv[1], strlen(argv[1])) == 0) && (ubuff.ut_time >= lastacc))
{
printf("\a");
fprintf(stdout, "%s logged in\n", ubuff.ut_name);

if(x == 1)
system(argv[3]);

exit(0);
}

if((strncmp(argv[1], "any", 3) == 0) && (ubuff.ut_time >= lastacc))
if(!strstr(ubuff.ut_name, "LOGIN"))
{
printf("\a");
fprintf(stdout, "%s just logged in\n", ubuff.ut_name);

if(x == 1)
system(argv[3]);

exit(0);
}
}
rewind(fptr);
lastacc = stbuf.st_mtime;
fclose(fptr);
}
}
}

Login or Register to add favorites

File Archive:

July 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close