-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbufferoverflow.c
More file actions
39 lines (30 loc) · 822 Bytes
/
bufferoverflow.c
File metadata and controls
39 lines (30 loc) · 822 Bytes
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
/*
* Buffer Overflow, Segmentation Fault Example
*
* Description
* Simple C example to demonstrate a buffer overflow and cause a segmentation fault
*
* To compile this program on Linux use the following command (Kali 2.0 used)
* gcc -ggdb -fno-stack-protector -o bufferoverflow bufferoverflow.c
*
* *** Note the flag -fno-stack-protector , used to allow this simple example to be demonstrated
*
* To execute
* ./bufferoverflow
*
* Author : Patrick Lismore
* Date : 19th Dec 2015
* Twitter : @patricklismore
*/
//includes
#include <stdio.h>
#include <string.h>
//main routine
main(){
//declare a char variable to hold 20
char buffer[20];
//copy 40 char into it to cause a segmentation fault
strcpy(buffer, "1234567899876543210012345678998765432100");
//print string buffer
printf("%s\n", buffer);
}