Created
October 13, 2011 04:48
-
-
Save thefotios/1283410 to your computer and use it in GitHub Desktop.
A school project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <pwd.h> | |
#include <sys/types.h> | |
#include <time.h> | |
#define emailAddrLen 33 | |
#define IDStringLen 9 | |
#define realNameLen 33 | |
int main(int argc, char *argv[]) | |
{ | |
// Some strings | |
const char* usage = "Usage %s <login ID> <real name>\n"; | |
const char* current = "can't get current user name! \n"; | |
const char* impersonate = "\n Hey! Are you trying to impersonate someone else?\n\n"; | |
const char* realname = "\n Hey! Do you forget you real name?\n\n"; | |
const char* success = "\nCongrats, you have got the buffer overflow working on %s! \n\n"; | |
const char* failure = | |
".\n.\n.\n" | |
"Hmmm... looks like you have not got the buffer overflow working.\n" | |
"Keep trying, once your result is correct, I will tell you.\n" | |
"Happy hacking :)\n" | |
".\n.\n.\n"; | |
char selfEmailAddr[emailAddrLen] = "[email protected]"; | |
char IDString[IDStringLen]; | |
char toEmailAddr[emailAddrLen]; | |
char realName[realNameLen]; | |
struct passwd *pw; | |
char* username; | |
char* fullname; | |
time_t rawtime; | |
struct tm *timeinfo; | |
// Check length of arguments | |
if( argc < 3 ){ | |
printf(usage, argv[0]); | |
exit(0); | |
} | |
// Check pwuid and set the results | |
if((pw = getpwuid(getuid())) == NULL){ | |
printf(current); | |
exit(1); | |
} | |
username = pw->pw_name; | |
fullname = pw->pw_gecos; | |
// Copy the arguments | |
strcpy (IDString, argv[1]); | |
strcpy (realName, argv[2]); | |
// Checking to see if the username matches | |
if(strcmp(username,IDString) != 0){ | |
printf(impersonate); | |
exit(2); | |
} | |
// Make sure that the name entered starts with the fullname | |
if( (strlen(realName) < strlen(fullname)) || | |
(strncmp(fullname, realName, strlen(fullname)) != 0) ){ | |
printf(realname); | |
exit(2); | |
} | |
// Compare the 2 email addresses | |
if(strcmp(selfEmailAddr,toEmailAddr) != 0){ | |
printf(failure); | |
exit(1); | |
}else{ | |
time( &rawtime ); | |
timeinfo = localtime( &rawtime ); | |
printf(success, asctime( timeinfo )); | |
exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment