Exploiting stack-based buffer overflows
Now that our basics are clear, let's move on to the exploitation of 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 method strcyp()
. We save the program to a file.
- We then compile the program with
gcc
using thefno-stack-protector
andexecstack
:
gcc -ggdb name.c -o name -fno-stack-protector -z execstack
- Next, we turn off address space randomization using this:
echo 0 > /proc/sys/kernel/randomize_va_space
- Now we open our program in
gdb
using this command:
gdb ./name
The following screenshot shows the output of the preceding command:
- Next, we supply our input using Python using the...