/************************************************************************ * G O L D F I N G E R By Nick Waterman * ************************************************************************ * This program only works on systems where you are allowed a pipe * * (file type fifo) for your .plan. It then does the following when * * anyone tries to finger you: * * o Reports where they are fingering you from * * o Tells THEM where they are * ************************************************************************/ #include #include #include #include #include #define NETSTAT "/usr/etc/netstat -f inet" main (argc, argv) int argc; char *argv[]; { FILE fname[200]; getfname(fname); checkpipe(fname); while (1) { sendplan(fname); } } int getfname(fname) char *fname; { char *dir; dir=getenv("HOME"); if (!dir) { mess("Can't get home dir from environment. Using \".\" instead."); dir="."; } sprintf(fname, "%s/.plan", dir); } int checkpipe(fname) char *fname; { struct stat buf; stat(fname, &buf); if (!(S_ISFIFO(buf.st_mode))) { mess("Your .plan file is NOT a fifo. It MUST be for this program"); mess("to work properly. Use mkfifo ~/plan or mknod ~/.plan p"); exit(21); } } int sendplan(fname) char *fname; { FILE *plan; int n; char from[100]; plan=fopen(fname, "w"); if (!plan) { mess("Cannot open plan file! Filename is:"); mess(fname); exit(22); } fprintf(plan, "RANTANPLAN kai ta koukia dablan.\n"); fprintf(plan, "Please wait while I do some stuff...\n\n"); fflush(plan); netstat(plan, from); fprintf(plan, "\nJust to make you feel unsafe.\n"); fprintf(plan, ""); fclose(plan); sleep(1); } int netstat(plan, from) FILE *plan; char *from; { FILE *statpipe; char line[100]; char *c, *d; statpipe=popen(NETSTAT, "r"); if (!statpipe) { fprintf(plan, "Sorry... I can't do my clever stuff.\n"); fprintf(plan, "Try fingering me later.\n"); mess("Couldn't run netstat. please check:"); mess(NETSTAT); return(1); } *from='\0'; while (fgets(line, 99, statpipe)) { if (strstr(line, ".finger") || strstr(line, ".79")) { d=NULL; c=strtok(line, " "); if (c) c=strtok(NULL, " "); if (c) c=strtok(NULL, " "); if (c) c=strtok(NULL, " "); if (c) c=strtok(NULL, " "); if (c) d=strtok(NULL, " "); if (d && !strcmp(d, "ESTABLISHED\n")) strcpy(from, c); } } pclose(statpipe); if (!*from) { fprintf(plan, "I can't find where you're fingering me from.\n"); fprintf(plan, "I assume you're doing it from this machine???\n"); mess("Couldn't find finger source. suspect localhost."); return(2); } if (c=strrchr(from, '.')) *c='\0'; sprintf(line, "Someone fingered you from %s", from); mess(line); fprintf(plan, "You are fingering me from %s!\n", from); fflush(plan); return(0); } mess (str) char *str; { printf("GOLDFINGER: %s\n", str); fflush(stdout); }