Now that our basics are clear, let's move on to the exploitation of stack-based buffer overflows.
Exploiting stack-based buffer overflows
How to do it...
The following steps demonstrate the stack-based buffer overflow:
- Let's take a look at another simple C program:
#include<stdio.h>
#include<string.h>
void main(int argc, char *argv[])
{
char buf[120];
strcpy(buf, argv[1]);
printf(buf);
}
This program uses a vulnerable strcpy() method. We save the program to a file.
- Compile the program with gcc using fno-stack-protector and execstack:
gcc -ggdb name.c -o name -fno-stack-protector -z execstack
- Turn off address space randomization using the following code:
echo 0 > /proc/sys...