/* * bitsh.c - "bitch" pseudo shell * Last update: 09/21/2006 * Author: Lloyd Dilley * Description: This small program emulates a user's login shell, but with a twist. * Replace the user's shell in /etc/passwd or add the program to the * target user's shell initialization file. Next time the user logs * in, they will be using this pseudo shell which will (hopefully) * aggravate them with a high chance of fake errors leading them to * believe that something is wrong with the system. Some commands * will actually go through to be successfully processed. Have fun! =) * License: You may freely distribute this program source code, the compiled program, * and do the same with derivative works with the condition that this license * and the above information in the header (authors, description, and notice) * of this source program, bitsh.c, must be kept intact. Furthermore, if you * find this software useful in some way, you can thank the author by buying * him a beer if you ever meet up. */ #include /* needed to handle SIGINT -- we don't want users breaking out with ctrl+c. =P */ #include /* for printf(), scanf() and system() */ #include /* for rand() */ #define MAX_CHANCE 100 /* the maximum percent chance that PERCENT_CHANCE is calculated out of */ #define PERCENT_CHANCE 40 /* the percent chance that any given command will fail with a fake error */ #define ERROR_COUNT 9 /* the amount of error strings in the errorString array */ #define ERROR_LENGTH 50 /* maximum length of error strings in the errorString array */ #define COMMAND_LENGTH 128 /* maximum length of strings accepted in our pseudo shell as commands */ #define HOSTNAME_LENGTH 255 /* maximum length of system hostname */ #define BOGUS_USERNAME "user\0" /* username to use for the shell prompt if it cannot be set */ #define BOGUS_HOSTNAME "host" /* hostname to use for the shell prompt if it cannot be set */ #define BOGUS_HOSTNAME_LENGTH 4 /* number of characters in BOGUS_HOSTNAME */ int main(void) { /* You can put your own custom error messages into the array below (don't forget to update ERROR_COUNT!) */ char errorString[ERROR_COUNT][ERROR_LENGTH]={ "I/O error.\0", "Invalid command.\0", "No such process.\0", "Permission denied.\0", "Interrupted system call.\0", "Operation not permitted.\0", "Kernel module not loaded.\0", "No such file or directory.\0", "Stack overflow (core dumped)\0"}; int i, x; /* holds rand() integers */ char command[COMMAND_LENGTH]; /* holds the command typed in the pseudo shell */ char hostname[HOSTNAME_LENGTH]; /* holds the system hostname used to populate the shell prompt */ char *username=""; /* holds the username of the user to populate the shell prompt */ /* set the system hostname or set a bogus one if not able */ if(gethostname(hostname, sizeof(hostname))!=0) strncpy(hostname, BOGUS_HOSTNAME, BOGUS_HOSTNAME_LENGTH+1); /* add 1 to append the null terminator */ /* set the user's username if able */ username=getenv("LOGNAME"); /* if the username was not able to be set above, use a bogus one */ if(username==NULL || strlen(username)==0) username=BOGUS_USERNAME; for(;;) /* infinite loop to keep the user inside the pseudo shell forever */ { signal(SIGINT, SIG_IGN); /* ignore ctrl+c */ printf("%s@%s$ ", username, hostname); /* set the pseudo shell prompt */ fgets(command, COMMAND_LENGTH, stdin); /* grab whatever they typed in the psuedo shell */ i=rand()%MAX_CHANCE; /* set the generated numbers to be from 0-99 (100 possible values) */ /* If the number generated is over 40 (default), the command will be successful 60% (default) of the time. */ if(i>PERCENT_CHANCE) /* PERCENT_CHANCE out of MAX_CHANCE the command will fail */ { system(command); /* let the operating system handle the user-provided command */ } else { x=rand()%ERROR_COUNT; /* pick a random error message from the errorString array */ printf("%s\n", errorString[x]); /* display the random error string */ } } return 0; }