Ghostscript任意文件读写漏洞安全通告

发布时间 2018-10-11

漏洞编号和级别


CVE编号:CVE-2018-17961,危险级别:高危,CVSS分值:官方未评定


影响版本


Ghostscript version <= 9.26


漏洞概述


Ghostscript是Adobe PostScript和PDF的解释语言,很多图片处理库均有引用,常见的有 ImageMagick、Python-Matplotlib、Latex2html等。


本次发现的漏洞可使Ghostscript 的安全沙箱被绕过,恶意攻击者可通过构造恶意的图片内容,可造成任意文件读写。使用Ghostscript的Web应用存在被远程命令攻击的风险。


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

Imagemagick、libmagick、graphicsmagick、gimp、python-matplotlib、texlive-core、texmacs、latex2html、latex2rtf等


漏洞验证


EXP:https://www.exploit-db.com/exploits/45573/

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


Ubuntu 16.04 本地使用最新版 GhostScript 9.25 测试 PoC,成功读取 /etc/passwd 文件,以及向 ~/.bashrc 写入命令后门:


ImageMagick 7.0.8-12 测试:



修复建议


Ghostscript官方已给出缓解措施,请及时更新:
http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=a54c9e61e7d
http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=a6807394bd94
无法更新的可通过修改policy.xml禁用PS, EPS, PDF and XPS coders(会造成相关功能不可使用)
如:修改ImageMagick的policy文件,默认位置为/etc/ImageMagick-7/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>

如果不需要使用GhostScript,可卸载。


参考链接


https://mailclark.ai/email/original/16819467/593541/mxzCj2eeqRd2DhZOU0Es1rJVQeg?from_name=Tavis%20Ormandy