1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <err.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h>
#define BANNER \ "Welcome to " LEVELNAME ", brought to you by https://exploit.education"
struct data { char name[64]; };
struct fp { void (*fp)(); char __pad[64 - sizeof(unsigned long)]; };
void winner() { printf("Congratulations, you have passed this level\n"); }
void nowinner() { printf( "level has not been passed - function pointer has not been " "overwritten\n"); }
int main(int argc, char **argv) { struct data *d; struct fp *f;
printf("%s\n", BANNER);
if (argc < 2) { printf("Please specify an argument to copy :-)\n"); exit(1); }
d = malloc(sizeof(struct data)); f = malloc(sizeof(struct fp)); f->fp = nowinner;
strcpy(d->name, argv[1]);
printf("data is at %p, fp is at %p, will be calling %p\n", d, f, f->fp); fflush(stdout);
f->fp();
return 0; }
|