mirror of
https://github.com/The-Art-of-Hacking/h4cker
synced 2024-11-22 19:03:04 +00:00
30 lines
No EOL
625 B
C
30 lines
No EOL
625 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)
|
|
{
|
|
/* This tries to handle 517 bytes and the strcpy is trying to copy that to buffer which only has 12 bytes */
|
|
char str[517];
|
|
FILE *badfile;
|
|
|
|
badfile = fopen("badfile", "r");
|
|
fread(str, sizeof(char), 517, badfile);
|
|
bof(str);
|
|
|
|
printf("Returned Properly\n");
|
|
return 1;
|
|
} |