Exploiting a simple stack-based buffer overflow
In this section, we’ll cover exploiting. This consists of writing a program or script that takes advantage of a vulnerability.
In this case, we’ll exploit our sample stack overflow application so that it executes arbitrary code on the system. We want to exploit the following code:
00 #include<string.h>
01
02 int main(int argc, char *argv[]) {
03 char buffer[200];
04 strcpy(buffer, argv[1]);
05 return 0;
06 } We can compile the code for the x86 architecture using the –m32 flag of the MinGW32 compiler:
packt@DESKTOP-PACKT MINGW32 /c/sources $ gcc -m32 stack_overflow.c -o stack_overflow.exe
Now, we can check that it works correctly when the first argument is short:
packt@DESKTOP-PACKT MINGW32 /c/sources $ ./stack_overflow.exe AAAAAAAAAAAA packt@DESKTOP-PACKT MINGW32 /c/sources $
Now, we can check that it works correctly when the first argument...