Using Metasploit Framework and PEDA

First, we will use the Metasploit Framework to create the pattern, and to do so we need to navigate to this location: /usr/share/metasploit-framework/tools/exploit/.

Now, how to create a pattern? We can create one using pattern_create.rb.

Let's take an example using our vulnerable code but with a bigger buffer, let's say 256:

#include <stdio.h>#include <string.h>#include <stdlib.h>int copytobuffer(char* input){    char buffer[256];    strcpy (buffer,input);    return 0;}void main (int argc, char *argv[]){    int local_variable = 1;    copytobuffer(argv[1]);    exit(0);}

Now, let's compile it:

$ gcc -fno-stack-protector -z execstack buffer.c -o buffer

Then we will use GDB:

$ gdb ./buffer

Next, we calculate the offset of the ...

Get Penetration Testing with Shellcode now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.