home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / general / cert0098.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  15.9 KB  |  409 lines

  1.  
  2. -----BEGIN PGP SIGNED MESSAGE-----
  3.  
  4. =============================================================================
  5. CERT(sm) Advisory CA-95:10 
  6. Original issue date: August 31, 1995
  7. Last revised: August 30, 1996
  8.               Information previously in the README was inserted
  9.               into the advisory, with some editing.
  10.  
  11.               A complete revision history is at the end of this file.
  12.                     
  13. Topic:  ghostscript Vulnerability
  14. - -----------------------------------------------------------------------------
  15.                     
  16.              A large portion of the technical content of this
  17.              advisory was provided by the DFN-CERT and NASIRC
  18.              response teams, and is used with their permission.
  19.  
  20. There is a vulnerability in older versions of ghostscript (gs) that enables
  21. users to execute commands and thus modify files. This problem involves the
  22. - -dSAFER option and is present in all versions of ghostscript from 2.6 through
  23. 3.22 beta.
  24.  
  25. We recommend that you apply the solution in Section III below to fix the
  26. - -dSAFER PostScript code or install the latest version of ghostscript (version
  27. 4.01). In both cases, we urge you to make -dSAFER the default mode for
  28. all versions of ghostscript starting with version 2.6.
  29.  
  30. We will update this advisory as we receive additional information.
  31. Please check advisory files regularly for updates that relate to your site.
  32.  
  33. - -----------------------------------------------------------------------------
  34.  
  35. I.   Background    
  36.  
  37.      The PostScript language, which was designed for the expression of 
  38.      graphical data, is widely used for transferring images and preformatted
  39.      text across the Internet. The language includes primitives for file 
  40.      operations, which were intended to be useful in the expression of images.
  41.      Unfortunately the operations can be abused by people intentionally 
  42.      embedding commands within an otherwise harmless image so that when 
  43.      displaying that image the PostScript viewer may perform malicious
  44.      file creations or deletions.
  45.     
  46.      This is a potentially serious problem because many images transferred
  47.      on the World Wide Web are sent in PostScript. For example, a malicious
  48.      person could install a booby-trapped image on a web-page, buried among
  49.      useful or interesting data.
  50.     
  51.      The viewer "ghostscript," a PostScript interpreter, recognizes the
  52.      command-line option: "-dSAFER". This option is intended to disable
  53.      the file operations and the %pipe PostScript operator that could be 
  54.      abused to do damage. This option is intended to protect you from this 
  55.      type of sabotage when viewing images from untrusted sources.
  56.  
  57. II.  Problem Description
  58.  
  59.      Problems exist with the ghostscript program, which supports the kind
  60.      of commands discussed above. 
  61.  
  62.      Older versions of ghostscript do not completely disable the pipe operator
  63.      that can be used execute commands that can modify files. Therefore the
  64.      option -dSAFER does not provide full protection.
  65.      
  66.      This problem is present in all versions of ghostscript between
  67.      2.6 (when the %pipe operator was added) and 3.22beta (when a fix
  68.      was made). 
  69.  
  70. III. Impact
  71.  
  72.      Attackers who have inserted malicious code into a PostScript file can 
  73.      cause commands to be executed and files to be modified on any system 
  74.      where that PostScript file is viewed with ghostscript.
  75.  
  76. IV. Solutions
  77.  
  78.      We recommend either fixing the -dSAFER PostScript code or installing
  79.      version 4.01 of ghostscript (see Sections IV.A and IV.B). In addition, 
  80.      we urge you to enable the -dSAFER option as the default (see Section
  81.      IV.C). 
  82.  
  83.      A. Fixing the -dSAFER PostScript code
  84.  
  85.         The following fix is in the form of "diff" output, which is
  86.         suitable for use with the GNU patch program.  This patch brings the
  87.         code into conformance with the version of gs_init.ps distributed
  88.         with the latest version of ghostscript (4.01) and can be
  89.         applied to the GNU versions 2.6, 2.6.1, and 2.6.2.  The file
  90.         to be patched is in the ghostscript library. As an example, 
  91.         gs_init.ps could be installed in:
  92.  
  93.           /usr/local/lib/ghostscript/gs_init.ps
  94.     
  95.         Here is the patch. Please see the Updates section at the end of this
  96.         file for cautions and for corrections to be applied in some situations.
  97.  
  98. - --------------------------------cut here--------------------------------------
  99.  
  100. *** gs_init.ps.orig     Fri Aug 25 10:42:51 1995
  101. - --- gs_init.ps  Fri Aug 25 11:16:24 1995
  102. ***************
  103. *** 302,308 ****
  104.   % If we want a "safer" system, disable some obvious ways to cause havoc.
  105.   SAFER not { (%END SAFER) .skipeof } if
  106.   /file
  107. !  { dup (r) eq
  108.       { file }
  109.       { /invalidfileaccess signalerror }
  110.      ifelse
  111. - --- 302,308 ----
  112.   % If we want a "safer" system, disable some obvious ways to cause havoc.
  113.   SAFER not { (%END SAFER) .skipeof } if
  114.   /file
  115. ! { dup (r) eq 2 index (%pipe*) .stringmatch not and
  116.       { file }
  117.       { /invalidfileaccess signalerror }
  118.      ifelse
  119. - --------------------------------cut here--------------------------------------
  120.  
  121.         The key is to change the line that says:
  122.  
  123.           { dup (r) eq
  124.  
  125.         to one that says:
  126.  
  127.           { dup (r) eq 2 index (%pipe*) .stringmatch not and
  128.  
  129.         Here are the relevant lines in the gs_init.ps file for version 2.6.2
  130.         of ghostscript before the patch:
  131.  
  132. 302  % If we want a "safer" system, disable some obvious ways to cause havoc. 
  133. 303  SAFER not { (%END SAFER) .skipeof } if
  134. 304  /file
  135. 305   { dup (r) eq
  136. 306      { file }
  137. 307      { /invalidfileaccess signalerror }
  138. 308     ifelse
  139. 309   } bind odef
  140. 310  /renamefile { /invalidfileaccess signalerror } odef
  141. 311  /deletefile { /invalidfileaccess signalerror } odef
  142. 312  %END SAFER
  143.  
  144.         Here are the same lines after the patch has been applied:
  145.  
  146. 302  % If we want a "safer" system, disable some obvious ways to cause havoc.
  147. 303  SAFER not { (%END SAFER) .skipeof } if
  148. 304  /file
  149. 305  { dup (r) eq 2 index (%pipe*) .stringmatch not and
  150. 306      { file }
  151. 307      { /invalidfileaccess signalerror }
  152. 308     ifelse
  153. 309   } bind odef
  154. 310  /renamefile { /invalidfileaccess signalerror } odef
  155. 311  /deletefile { /invalidfileaccess signalerror } odef
  156. 312  %END SAFER
  157.  
  158.  
  159.      B. Installing version 4.01
  160.   
  161.         You may wish to install Aladdin Ghostscript version 4.01.
  162.         The latest version of ghostscript is version 4.01 and
  163.         is available at the locations noted below.  
  164.  
  165.         This version of ghostscript is provided by Aladdin Enterprises and 
  166.         is subject to their licensing agreements.  Please read the "Aladdin
  167.         Ghostscript Free Public License" (included in the source code
  168.         distribution) which differs from the "GNU Public License."
  169.  
  170.         Please note that this version is not the GNU version.  The latest GNU
  171.         version, which is version 2.6.2, does not fix this problem.
  172.              
  173.           ftp://ftp.cs.wisc.edu/ghost/aladdin/ghostscript-4.01.tar.gz
  174.                 MD5=21a0fe505bbaf75e2e6aeb4e07689fb6
  175.  
  176.           ftp://ftp.cs.wisc.edu/ghost/aladdin/ghostscript-4.01jpeg.tar.gz
  177.                 MD5=5360e0aa47b415daa44623196f7e6160
  178.  
  179.           ftp://ftp.cs.wisc.edu/ghost/aladdin/ghostscript-4.01zlib.tar.gz
  180.                 MD5=8eb230a39275b0759f06fa100250fc00
  181.  
  182.         Optionally, you may need the font files for this release.  They are
  183.         available at these locations:
  184.      
  185.          ftp://ftp.cs.wisc.edu/pub/aladdin/ghostscript-fonts-std-4.01.tar.gz
  186.                 MD5=1e0fe2149affd80deaaae144227049b9
  187.  
  188.          ftp://ftp.cs.wisc.edu/pub/aladdin/ghostscript-fonts-other-4.01.tar.gz
  189.                 MD5=afe46faf7fde6518ae004a7e8d9a4af4
  190.  
  191.      C. Making -dSAFER the default
  192.      
  193.         To make -dSAFER the default mode for ghostscript for all versions
  194.         of ghostscript starting with version 2.6, the file gs_init.ps must
  195.         again be changed.  The PostScript commands which check the actual
  196.         interpreted command are collected in one single if statement in the
  197.         gs_init.ps file. By commenting out the begin and end lines of this
  198.         if statement, the check is always applied meaning that the -dSAFER
  199.         option is always enabled.
  200.  
  201.         NOTE: If you make this change, all file and %pipe operations are
  202.         disabled and cannot be re-enabled.
  203.  
  204.         The lines which must be changed are:
  205.  
  206.               303  SAFER not { (%END SAFER) .skipeof } if
  207.         and
  208.               312  %END SAFER
  209.  
  210.         These two lines should be commented out and made to look like this:
  211.  
  212.               303  % SAFER not { (%END SAFER) .skipeof } if
  213.         and
  214.               312  % %END SAFER
  215.  
  216.         If you are using ghostscript 2.6.2, the code will look like the
  217.         following when both patches noted above are installed:
  218.  
  219. 302  % If we want a "safer" system, disable some obvious ways to cause havoc.
  220. 303  % SAFER not { (%END SAFER) .skipeof } if
  221. 304  /file
  222. 305  { dup (r) eq 2 index (%pipe*) .stringmatch not and
  223. 306      { file }
  224. 307      { /invalidfileaccess signalerror }
  225. 308     ifelse
  226. 309   } bind odef
  227. 310  /renamefile { /invalidfileaccess signalerror } odef
  228. 311  /deletefile { /invalidfileaccess signalerror } odef
  229. 312  % %END SAFER
  230.  
  231.  
  232. - ---------------------------------------------------------------------------
  233. The CERT Coordination Center staff thanks the DFN-CERT and NASIRC response
  234. teams for providing a large portion of the technical content of this advisory,
  235. and we thank Wolfgang Ley for his assistance.
  236. - ---------------------------------------------------------------------------
  237.  
  238. If you believe that your system has been compromised, contact the CERT
  239. Coordination Center or your representative in the Forum of Incident
  240. Response and Security Teams (FIRST).
  241.  
  242. If you wish to send sensitive incident or vulnerability information to
  243. CERT staff by electronic mail, we strongly advise that the email be
  244. encrypted.  The CERT Coordination Center can support a shared DES key, PGP
  245. (public key available via anonymous FTP on info.cert.org), or PEM (contact
  246. CERT staff for details).
  247.  
  248. Internet email: cert@cert.org
  249. Telephone: +1 412-268-7090 (24-hour hotline)
  250.            CERT personnel answer 8:30 a.m.-5:00 p.m. EST(GMT-5)/EDT(GMT-4),
  251.            and are on call for emergencies during other hours.
  252. Fax: +1 412-268-6989
  253.  
  254. Postal address:  CERT Coordination Center
  255.                  Software Engineering Institute
  256.                  Carnegie Mellon University
  257.                  Pittsburgh, PA 15213-3890
  258.                  USA
  259.  
  260. CERT advisories and bulletins are posted on the USENET newsgroup
  261. comp.security.announce. If you would like to have future advisories and
  262. bulletins mailed to you or to a mail exploder at your site, please send mail
  263. to cert-advisory-request@cert.org.
  264.  
  265. Past CERT publications, information about FIRST representatives, and
  266. other information related to computer security are available for anonymous
  267. FTP from info.cert.org.
  268.  
  269.  
  270. This material may be reproduced and distributed without permission provided it
  271. is used for noncommercial purposes and the CERT Coordination Center, DFN-CERT,
  272. and NASIRC are acknowledged.
  273.  
  274. CERT is a service mark of Carnegie Mellon University.
  275.  
  276.  
  277. =============================================================================
  278. UPDATES
  279.  
  280. 1) We have received information that some tools that convert PostScript to
  281.    other formats break when the SAFER option is the default, as recommended
  282.    in Section III.C above.
  283.  
  284.    The problem is that these tools need the PostScript /file directive
  285.    that is disabled when the SAFER option is made the default.  To this end,
  286.    there is a fix from Joern Tellkamp (tellkamp@informatik.uni-hamburg.de),
  287.    provided by DFN-CERT that defines an UNSAFER option to ghostscript.
  288.    By default, ghostscript with the fixes listed in Section III.C above
  289.    sets the SAFER option.
  290.  
  291.    The following patch changes the SAFER option to the UNSAFER option.  By
  292.    default, SAFER is on but it can be turned off with the -dUNSAFER option to
  293.    ghostscript.  This, too, is applied to the original gs_init.ps file.
  294.  
  295.                         Begin UNSAFER Patch
  296. - ------------------------------------------------------------------------------
  297.  
  298. *** gs_init.ps          Fri Aug 25 10:42:51 1995
  299. - --- gs_init.ps.unsafer  Fri Oct 20 13:57:37 1995
  300. ***************
  301. *** 66,72 ****
  302.      currentdict /OUTPUTFILE undef
  303.    } if
  304.   currentdict /QUIET known   /QUIET exch def
  305. ! currentdict /SAFER known   /SAFER exch def
  306.   currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  307.   
  308.   % Acquire environment variables.
  309. - --- 66,72 ----
  310.      currentdict /OUTPUTFILE undef
  311.    } if
  312.   currentdict /QUIET known   /QUIET exch def
  313. ! currentdict /UNSAFER known /UNSAFER exch def
  314.   currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  315.   
  316.   % Acquire environment variables.
  317. ***************
  318. *** 299,308 ****
  319.   /.run /run load def
  320.   /run /run0 load def
  321.   
  322. ! % If we want a "safer" system, disable some obvious ways to cause havoc.
  323. ! SAFER not { (%END SAFER) .skipeof } if
  324.   /file
  325. !  { dup (r) eq
  326.       { file }
  327.       { /invalidfileaccess signalerror }
  328.      ifelse
  329. - --- 299,308 ----
  330.   /.run /run load def
  331.   /run /run0 load def
  332.   
  333. ! % If we want an "unsafer" system, enable some obvious ways to cause havoc.
  334. ! UNSAFER { (%END UNSAFER) .skipeof } if
  335.   /file
  336. ! { dup (r) eq 2 index (%pipe*) .stringmatch not and
  337.       { file }
  338.       { /invalidfileaccess signalerror }
  339.      ifelse
  340. ***************
  341. *** 309,315 ****
  342.    } bind odef
  343.   /renamefile { /invalidfileaccess signalerror } odef
  344.   /deletefile { /invalidfileaccess signalerror } odef
  345. ! %END SAFER
  346.   
  347.   % Create the error handling machinery.
  348.   % The interpreter has created the ErrorNames array.
  349. - --- 309,315 ----
  350.    } bind odef
  351.   /renamefile { /invalidfileaccess signalerror } odef
  352.   /deletefile { /invalidfileaccess signalerror } odef
  353. ! %END UNSAFER
  354.   
  355.   % Create the error handling machinery.
  356.   % The interpreter has created the ErrorNames array.
  357. - ------------------------------------------------------------------------------
  358.                         End UNSAFER Patch
  359.  
  360.    Once applied, all of the aforementioned tools need to be changed to add the
  361.    -dUNSAFER option to the rest of the arguments given to gs, the ghostscript
  362.    interpreter.
  363.  
  364. 2) We received a report that adding any of the above-mentioned patches
  365.    may cause the gs interpreter to fail (in version 2.6.0). Should this
  366.    be the case, changing '.stringmatch' to 'stringmatch' fixes this problem
  367.    (see below).  Upgrading to ghostscript version   2.6.1 also will address
  368.     the problem. 
  369.  
  370.         If you have a problem with
  371.  
  372.              ! { dup (r) eq 2 index (%pipe*) .stringmatch not and
  373.  
  374.         change to
  375.  
  376.              ! { dup (r) eq 2 index (%pipe*) stringmatch not and
  377.  
  378. 3) Since it is unknown at this time whether the Macintosh and DOS/Windows
  379.    versions of ghostscript are vulnerable, we suggest that you apply the
  380.    patch.
  381.  
  382. 4) Version 3.33 with appropriate patches will address the vulnerabilities
  383.    outlined in advisory CA-95:10. As of Nov. 8, 1995, the most recent release
  384.    of ghostscript is Version 3.51. 
  385.  
  386. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  387. Revision history
  388.  
  389. Aug. 30, 1996  Information previously in the README was inserted
  390.                 into the advisory, with editing in the Updates section.
  391. Nov. 08, 1995  Updates section - added SAFER and UNSAFER patches and
  392.                 instructions for applying them. Included a note for Macintosh
  393.                 and DOS/Windows users. Noted a recent release of ghostscript
  394.                 version 3.51. 
  395.  
  396.  
  397.  
  398.  
  399. -----BEGIN PGP SIGNATURE-----
  400. Version: 2.6.2
  401.  
  402. iQCVAwUBMicJanVP+x0t4w7BAQGglwQA1E5xCkfY1WKk+v8OnGs2txI9c3Qp6uBU
  403. 9VbkmRnc+qa2h/ZskOFgtHxHR1GwVXW1dgMUmRRpDC1TW2H5gD5wH0Dv0qM57/dS
  404. 9Gu7SWBNLdjdxi8ax5VPWU6lZxWJXGYECnfyZDqq4+zPWnf/wN2CJ5H5rEJWGGjQ
  405. X3gB2NTn+Tk=
  406. =2UcS
  407. -----END PGP SIGNATURE-----
  408.  
  409.