How to test Shell-Codes

Continuation of Shell-coding basics..I suggest a glance over it before you start reading this..

Testing

We'll be using a simple C program to accomplish our task.

test.c

Code:

// #include<stdio.h> we will not be needing this as we are not using any functions from the C library...Just basic logic of Pointers..
char shellcode[] = "";
int main()
{
int *ret; // a simple integer pointer pointing a address
ret = (int *)&ret + 2; // change the address pointed by
(*ret) = (int)shellcode; // change the return pointer to the shellcode .. so we'll be jumping to our shellcode right away
}

Note : In this article we'll be using the exit shell-code we made in the previous article...However this program can be used to test any shell-code..

This is the basic skeleton of the program...Check the comments...Its quite self-explanatory...

I explained the construction in the previous tutorial and would not be repeating it..

So out set of opcodes will be :-

Code:

\x31\xc0\xb0\x01\x31\xdb\xb3\x07\xcd\x80

A basic 10 byte exit shell-code..

Lets add it to 'test.c' test it

Code:

// #include<stdio.h> we will not be needing this as we are not using any functions from the C library...Just basic logic of Pointers..
char shellcode[] = "\x31\xc0\xb0\x01\x31\xdb\xb3\x07\xcd\x80";
int main()
{
int *ret; // a simple integer pointer pointing a address
ret = (int *)&ret + 2; // change the address pointed by
(*ret) = (int)shellcode;
}