mirror of
https://github.com/The-Art-of-Hacking/h4cker.git
synced 2025-08-07 13:52:14 -04:00
adding buffer overflow examples
This commit is contained in:
parent
81da9ec76d
commit
0f5a65b7a5
4 changed files with 128 additions and 0 deletions
29
buffer_overflow_example/demeter/stack.c
Normal file
29
buffer_overflow_example/demeter/stack.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue