mirror of
https://github.com/The-Art-of-Hacking/h4cker.git
synced 2024-12-18 19:06:08 +00:00
29 lines
511 B
C
29 lines
511 B
C
|
/* stack.c */
|
||
|
|
||
|
/* This is the program that introduces the buffer overflow vulnerability. */
|
||
|
#include <stdlib.h>
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
int bof(char *str)
|
||
|
{
|
||
|
char buffer[12];
|
||
|
|
||
|
/* Can you spot the buffer overflow here? ;-) */
|
||
|
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;
|
||
|
}
|