/* * Stack-smashing vulnerable program based on one in * Smashing the Stack for Fun and Profit by Aleph One */ #include #include #include static unsigned int getesp(void) { __asm__("movl %esp,%eax"); } static int copy(const char *input) { char vbuf[1024]; (void) strcpy(vbuf, input); (void) fprintf(stdout, "Vulnerable buffer at %p\n", (void *)&vbuf); return (0); } int main(int argc, const char *argv[]) { (void) fprintf(stdout, "Vulnerable stack top at %p\n", (void *)getesp()); if (argc != 2) { (void) fprintf(stderr, "Usage: %s string\n", argv[0]); exit(EXIT_FAILURE); } (void) copy(argv[1]); return (0); }