Speaker : Erica
2019 / 11 / 17
Buffer overflow is an anomaly that occurs when software writing data to a buffer overflows the buffer’s capacity, resulting in adjacent memory locations being overwritten.
A buffer, or data buffer, is an area of physical memory storage used to temporarily store data while it is being moved from one place to another.
Certain coding languages are more susceptible to buffer overflow than others. C and C++ are two popular languages with high vulnerability.
#include <stdio.h>
void Name()
{
char name[10];
printf("What's your name?\n");
gets(name);
printf("Hey %s, how are you?\n", name);
}
int main()
{
Name();
return 0;
}
Use C language :
char name[10];
It's a function can get the name.
Define a character array "name[10]"
with 10 character elements.
Ask users enter their name.
printf("What's your name?\n");
gets(name);
printf("Hey %s, how are you?\n", name);
void Name(){
You can get homebrew form here .
And install GCC:
$ gcc --version
$ whereis gcc
If you want to confirm the installation, you can execute the following command:
$ brew install gcc
You can get mingw form here .
And change the Environmental variables :
$ gcc --v
If you want to confirm the installation in Windows, you can execute the following command:
C:\MinGW\bin
Open your command line and enter :
$ gcc overflow.c -o overflow -fno-stack-protector
overflow.c is your file name.
$ gcc overflow.c -o overflow -fno-stack-protector
This command means
"Do not enable stack protector".
This option can be used to set the name of the compiled product.
$ gcc -o overflow overflow.c -fno-stack-protector
What is your name?
>>>Erica
Hey Erica, how are you?
If your input less than 10:
If you use Windows, you can just enter the file name.
$ ./overflow //overflow
What is your name?
>>>EricaOneAAAAAAAAAA
Hey EricaOneAAAAAAAAAA, how are you?
segmentation fault
If your input more than 10:
It means we use "Buffer Overflow" to let this program broken.
If you remove this command, recompile and execute, you should find a failure.
If your input less than 10
▼ Stack
name[1] ... name[10] |
rdp |
ret of Name |
If your input more than 10
▼ Stack
name[1] ... name[10] |
rdp |
ret of Name |
Erica
OneAA
AAAAAAAA
An attacker can deliberately feed a carefully crafted input into a program that will cause the program to try and store that input in a buffer that isn’t large enough, overwriting portions of memory connected to the buffer space.
2 common protections that help mitigate the risk of exploitation :
Software developers can also take precautions against buffer overflow vulnerabilities by writing in languages that have built-in protections or using special security procedures in their code.
Buffer overflow From Wikipedia. Retrieved from: https://reurl.cc/b6N9Yo
緩衝區溢位攻擊之一(Buffer Overflow) 。Retrieved from: https://reurl.cc/9zb4vd
攻擊行為-緩衝區溢位 Buffer Overflow。Retrieved from: https://reurl.cc/Ylk0VX
GCC,LLVM,CLANG 編譯器。Retrieved from: https://reurl.cc/XXamq3