/* * eco.c * * Mike Smith * * h4cked by Jason Gao '10 * * This program is an UNSAFE implementation of our echo program. It * assumes that all strings on the command line are smaller than 4 * characters in length. Obviously, this is a bad assumption, and * thus we can use it to demonstrate the simplicity of a static buffer * overrun attack. * * If you run the program with the following perl-formated input, it * will return to the function gotcha instead of main. * * "1234" . "\xb8\xf5\xff\xbf" . "\xb4\x84\x04\x08"; */ #include #include #include #define MAX_BUF_SIZE 4 void gotcha() { printf("\nGotcha!\n"); exit(1); /* required because we destroy the caller's base pointer */ } void echo_arg(const char s[]) { char buf[MAX_BUF_SIZE]; strcpy(buf, s); printf("%s ", buf); } int main(int argc, char * argv[]) { int i; for (i = 1; i < argc; i++) echo_arg(argv[i]); printf("\n"); return 0; }