27 lines
546 B
C
Executable file
27 lines
546 B
C
Executable file
/* stack.c */
|
|
|
|
/* This program has a buffer overflow vulnerability. */
|
|
/* Our task is to exploit this vulnerability */
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int bof(char *str)
|
|
{
|
|
char buffer[12];
|
|
/* The following statement has a buffer overflow problem */
|
|
strcpy(buffer, str);
|
|
return 1;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
char str[517];
|
|
FILE *badfile;
|
|
badfile = fopen("badfile", "r");
|
|
fread(str, sizeof(char), 517, badfile);
|
|
bof(str);
|
|
printf("Returned Properly\n");
|
|
return 1;
|
|
}
|